@@ -12,7 +12,6 @@ import (
1212
1313 "github.com/cometbft/cometbft/crypto/tmhash"
1414 tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
15- cmttypes "github.com/cometbft/cometbft/types"
1615
1716 "github.com/cosmos/evm/testutil/config"
1817 "github.com/cosmos/evm/testutil/integration/evm/factory"
@@ -33,7 +32,6 @@ import (
3332 banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
3433 consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
3534 govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
36- stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
3735)
3836
3937func (s * KeeperTestSuite ) TestContextSetConsensusParams () {
@@ -81,9 +79,11 @@ func (s *KeeperTestSuite) TestContextSetConsensusParams() {
8179
8280func (s * KeeperTestSuite ) TestGetHashFn () {
8381 s .SetupTest ()
84- header := s .Network .GetContext ().BlockHeader ()
85- h , _ := cmttypes .HeaderFromProto (& header )
86- hash := h .Hash ()
82+ s .Require ().NoError (s .Network .NextBlock ())
83+ ctx := s .Network .GetContext ()
84+ height := uint64 (ctx .BlockHeight ()) //nolint:gosec // G115
85+ headerHash := common .BytesToHash (ctx .HeaderHash ())
86+ fmt .Println ("get headerHash" , height , headerHash )
8787
8888 testCases := []struct {
8989 msg string
@@ -93,7 +93,7 @@ func (s *KeeperTestSuite) TestGetHashFn() {
9393 }{
9494 {
9595 "case 1.1: context hash cached" ,
96- uint64 ( s . Network . GetContext (). BlockHeight ()), //nolint:gosec // G115
96+ height ,
9797 func () sdk.Context {
9898 return s .Network .GetContext ().WithHeaderHash (
9999 tmhash .Sum ([]byte ("header" )),
@@ -102,51 +102,22 @@ func (s *KeeperTestSuite) TestGetHashFn() {
102102 common .BytesToHash (tmhash .Sum ([]byte ("header" ))),
103103 },
104104 {
105- "case 1.2: failed to cast CometBFT header" ,
106- uint64 ( s . Network . GetContext (). BlockHeight ()), //nolint:gosec // G115
105+ "case 1.2: works for invalid CometBFT header" ,
106+ height ,
107107 func () sdk.Context {
108108 header := tmproto.Header {}
109109 header .Height = s .Network .GetContext ().BlockHeight ()
110110 return s .Network .GetContext ().WithBlockHeader (header )
111111 },
112- common.Hash {},
113- },
114- {
115- "case 1.3: hash calculated from CometBFT header" ,
116- uint64 (s .Network .GetContext ().BlockHeight ()), //nolint:gosec // G115
117- func () sdk.Context {
118- return s .Network .GetContext ().WithBlockHeader (header )
119- },
120- common .BytesToHash (hash ),
112+ headerHash ,
121113 },
122114 {
123- "case 2.1: height lower than current one, hist info not found " ,
124- 1 ,
115+ "case 2.1: height lower than current one works " ,
116+ height ,
125117 func () sdk.Context {
126118 return s .Network .GetContext ().WithBlockHeight (10 )
127119 },
128- common.Hash {},
129- },
130- {
131- "case 2.2: height lower than current one, invalid hist info header" ,
132- 1 ,
133- func () sdk.Context {
134- s .Require ().NoError (s .Network .App .GetStakingKeeper ().SetHistoricalInfo (s .Network .GetContext (), 1 , & stakingtypes.HistoricalInfo {}))
135- return s .Network .GetContext ().WithBlockHeight (10 )
136- },
137- common.Hash {},
138- },
139- {
140- "case 2.3: height lower than current one, calculated from hist info header" ,
141- 1 ,
142- func () sdk.Context {
143- histInfo := & stakingtypes.HistoricalInfo {
144- Header : header ,
145- }
146- s .Require ().NoError (s .Network .App .GetStakingKeeper ().SetHistoricalInfo (s .Network .GetContext (), 1 , histInfo ))
147- return s .Network .GetContext ().WithBlockHeight (10 )
148- },
149- common .BytesToHash (hash ),
120+ headerHash ,
150121 },
151122 {
152123 "case 3: height greater than current one" ,
0 commit comments