2020-10-20 17:53:13 +00:00
|
|
|
package keeper_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (suite *KeeperTestSuite) TestBeginBlock() {
|
|
|
|
req := abci.RequestBeginBlock{
|
|
|
|
Header: abci.Header{
|
|
|
|
LastBlockId: abci.BlockID{
|
2021-03-19 03:04:29 +00:00
|
|
|
Hash: []byte("last hash"),
|
2020-10-20 17:53:13 +00:00
|
|
|
},
|
|
|
|
Height: 10,
|
|
|
|
},
|
2021-03-19 03:04:29 +00:00
|
|
|
Hash: []byte("hash"),
|
2020-10-20 17:53:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// get the initial consumption
|
|
|
|
initialConsumed := suite.ctx.GasMeter().GasConsumed()
|
|
|
|
|
|
|
|
// update the counters
|
|
|
|
suite.app.EvmKeeper.Bloom.SetInt64(10)
|
|
|
|
suite.app.EvmKeeper.TxCount = 10
|
|
|
|
|
|
|
|
suite.app.EvmKeeper.BeginBlock(suite.ctx, abci.RequestBeginBlock{})
|
|
|
|
suite.Require().NotZero(suite.app.EvmKeeper.Bloom.Int64())
|
|
|
|
suite.Require().NotZero(suite.app.EvmKeeper.TxCount)
|
|
|
|
|
|
|
|
suite.Require().Equal(int64(initialConsumed), int64(suite.ctx.GasMeter().GasConsumed()))
|
|
|
|
|
|
|
|
suite.app.EvmKeeper.BeginBlock(suite.ctx, req)
|
|
|
|
suite.Require().Zero(suite.app.EvmKeeper.Bloom.Int64())
|
|
|
|
suite.Require().Zero(suite.app.EvmKeeper.TxCount)
|
|
|
|
|
|
|
|
suite.Require().Equal(int64(initialConsumed), int64(suite.ctx.GasMeter().GasConsumed()))
|
|
|
|
|
2021-03-19 03:04:29 +00:00
|
|
|
lastHeight, found := suite.app.EvmKeeper.GetBlockHash(suite.ctx, req.Hash)
|
2020-10-20 17:53:13 +00:00
|
|
|
suite.Require().True(found)
|
2021-03-19 03:04:29 +00:00
|
|
|
suite.Require().Equal(int64(10), lastHeight)
|
2020-10-20 17:53:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *KeeperTestSuite) TestEndBlock() {
|
|
|
|
// update the counters
|
|
|
|
suite.app.EvmKeeper.Bloom.SetInt64(10)
|
|
|
|
|
|
|
|
// set gas limit to 1 to ensure no gas is consumed during the operation
|
|
|
|
initialConsumed := suite.ctx.GasMeter().GasConsumed()
|
|
|
|
|
|
|
|
_ = suite.app.EvmKeeper.EndBlock(suite.ctx, abci.RequestEndBlock{Height: 100})
|
|
|
|
|
|
|
|
suite.Require().Equal(int64(initialConsumed), int64(suite.ctx.GasMeter().GasConsumed()))
|
|
|
|
|
|
|
|
bloom, found := suite.app.EvmKeeper.GetBlockBloom(suite.ctx, 100)
|
|
|
|
suite.Require().True(found)
|
|
|
|
suite.Require().Equal(int64(10), bloom.Big().Int64())
|
|
|
|
|
|
|
|
}
|