Skip to content

Commit

Permalink
add gas overflow test case
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang committed Jan 8, 2022
1 parent c03ab15 commit af0cc18
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion x/auth/middleware/branch_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func (s *MWTestSuite) TestBranchStore() {
{"less than block gas meter", 10, false, false},
{"more than block gas meter", blockMaxGas, false, true},
{"more than block gas meter", uint64(float64(blockMaxGas) * 1.2), false, true},
{"consume MaxUint64", math.MaxUint64, false, true},
{"consume block gas when paniced", 10, true, true},
}

Expand Down Expand Up @@ -107,7 +108,8 @@ func (s *MWTestSuite) TestBranchStore() {
}
// block gas is always consumed
baseGas := uint64(24564) // baseGas is the gas consumed by middlewares
s.Require().Equal(tc.gasToConsume+baseGas, ctx.BlockGasMeter().GasConsumed())
expGasConsumed := addUint64Saturating(tc.gasToConsume, baseGas)
s.Require().Equal(expGasConsumed, ctx.BlockGasMeter().GasConsumed())
// tx fee is always deducted
s.Require().Equal(int64(0), s.app.BankKeeper.GetBalance(ctx, addr1, feeCoin.Denom).Amount.Int64())
// sender's sequence is always increased
Expand All @@ -116,5 +118,12 @@ func (s *MWTestSuite) TestBranchStore() {
s.Require().Equal(uint64(1), seq)
})
}
}

func addUint64Saturating(a, b uint64) uint64 {
if math.MaxUint64-a < b {
return math.MaxUint64
}

return a + b
}

0 comments on commit af0cc18

Please sign in to comment.