mirror of
				https://github.com/0glabs/0g-chain.git
				synced 2025-11-03 23:57:26 +00:00 
			
		
		
		
	ensure akava balances are backed by, not equal to (#1230)
module balance
This commit is contained in:
		
							parent
							
								
									30a071f83b
								
							
						
					
					
						commit
						ab7b3ec82f
					
				@ -24,10 +24,13 @@ func AllInvariants(bankK types.BankKeeper, k Keeper) sdk.Invariant {
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// FullyBackedInvariant ensures all minor balances are backed exactly by the coins in the module account.
 | 
			
		||||
// FullyBackedInvariant ensures all minor balances are backed by the coins in the module account.
 | 
			
		||||
//
 | 
			
		||||
// The module balance can be greater than the sum of all minor balances. This can happen in rare cases
 | 
			
		||||
// where the evm module burns tokens.
 | 
			
		||||
func FullyBackedInvariant(bankK types.BankKeeper, k Keeper) sdk.Invariant {
 | 
			
		||||
	broken := false
 | 
			
		||||
	message := sdk.FormatInvariant(types.ModuleName, "fully backed broken", "minor balances do not match module account")
 | 
			
		||||
	message := sdk.FormatInvariant(types.ModuleName, "fully backed broken", "sum of minor balances greater than module account")
 | 
			
		||||
 | 
			
		||||
	return func(ctx sdk.Context) (string, bool) {
 | 
			
		||||
 | 
			
		||||
@ -40,7 +43,7 @@ func FullyBackedInvariant(bankK types.BankKeeper, k Keeper) sdk.Invariant {
 | 
			
		||||
		bankAddr := authtypes.NewModuleAddress(types.ModuleName)
 | 
			
		||||
		bankBalance := bankK.GetBalance(ctx, bankAddr, CosmosDenom).Amount.Mul(ConversionMultiplier)
 | 
			
		||||
 | 
			
		||||
		broken = !totalMinorBalances.Equal(bankBalance)
 | 
			
		||||
		broken = totalMinorBalances.GT(bankBalance)
 | 
			
		||||
 | 
			
		||||
		return message, broken
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -87,11 +87,11 @@ func (suite *invariantTestSuite) TestFullyBackedInvariant() {
 | 
			
		||||
	_, broken = suite.runInvariant("fully-backed", keeper.FullyBackedInvariant)
 | 
			
		||||
	suite.Equal(false, broken)
 | 
			
		||||
 | 
			
		||||
	// break invariant by decreasing minor balances without decreasing module balance
 | 
			
		||||
	suite.Keeper.RemoveBalance(suite.Ctx, suite.Addrs[0], sdk.OneInt())
 | 
			
		||||
	// break invariant by increasing total minor balances above module balance
 | 
			
		||||
	suite.Keeper.AddBalance(suite.Ctx, suite.Addrs[0], sdk.OneInt())
 | 
			
		||||
 | 
			
		||||
	message, broken := suite.runInvariant("fully-backed", keeper.FullyBackedInvariant)
 | 
			
		||||
	suite.Equal("evmutil: fully backed broken invariant\nminor balances do not match module account\n", message)
 | 
			
		||||
	suite.Equal("evmutil: fully backed broken invariant\nsum of minor balances greater than module account\n", message)
 | 
			
		||||
	suite.Equal(true, broken)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user