diff --git a/server/v2/cometbft/abci_test.go b/server/v2/cometbft/abci_test.go index af2c06760143..85433d426cfe 100644 --- a/server/v2/cometbft/abci_test.go +++ b/server/v2/cometbft/abci_test.go @@ -32,6 +32,7 @@ import ( var ( sum = sha256.Sum256([]byte("test-hash")) + emptyHash = sha256.Sum256([]byte("")) DefaulConsensusParams = &v1.ConsensusParams{ Block: &v1.BlockParams{ MaxGas: 5000000, @@ -124,6 +125,7 @@ func TestConsensus_InitChain_Without_UpdateParam(t *testing.T) { _, err = c.FinalizeBlock(context.Background(), &abciproto.FinalizeBlockRequest{ Time: time.Now(), Height: 1, + Hash: emptyHash[:], }) require.NoError(t, err) assertStoreLatestVersion(t, mockStore, 1) @@ -144,6 +146,7 @@ func TestConsensus_InitChain_With_UpdateParam(t *testing.T) { _, err = c.FinalizeBlock(context.Background(), &abciproto.FinalizeBlockRequest{ Time: time.Now(), Height: 1, + Hash: emptyHash[:], }) require.NoError(t, err) @@ -159,15 +162,16 @@ func TestConsensus_InitChain_Invalid_Height(t *testing.T) { InitialHeight: 2, }) require.NoError(t, err) - assertStoreLatestVersion(t, mockStore, 0) + assertStoreLatestVersion(t, mockStore, 1) - // Shouldn't be able to commit genesis block 2 + // Shouldn't be able to commit genesis block 3 _, err = c.FinalizeBlock(context.Background(), &abciproto.FinalizeBlockRequest{ Time: time.Now(), - Height: 2, + Height: 3, + Hash: emptyHash[:], }) require.Error(t, err) - require.True(t, strings.Contains(err.Error(), "unable to commit the changeset")) + require.True(t, strings.Contains(err.Error(), "invalid height")) } func TestConsensus_FinalizeBlock_Invalid_Height(t *testing.T) { @@ -182,12 +186,14 @@ func TestConsensus_FinalizeBlock_Invalid_Height(t *testing.T) { _, err = c.FinalizeBlock(context.Background(), &abciproto.FinalizeBlockRequest{ Time: time.Now(), Height: 1, + Hash: emptyHash[:], }) require.NoError(t, err) _, err = c.FinalizeBlock(context.Background(), &abciproto.FinalizeBlockRequest{ Time: time.Now(), Height: 3, + Hash: emptyHash[:], }) require.Error(t, err) } @@ -206,6 +212,7 @@ func TestConsensus_FinalizeBlock_NoTxs(t *testing.T) { _, err = c.FinalizeBlock(context.Background(), &abciproto.FinalizeBlockRequest{ Time: time.Now(), Height: 1, + Hash: emptyHash[:], }) require.NoError(t, err) @@ -236,6 +243,7 @@ func TestConsensus_FinalizeBlock_MultiTxs_OutOfGas(t *testing.T) { _, err = c.FinalizeBlock(context.Background(), &abciproto.FinalizeBlockRequest{ Time: time.Now(), Height: 1, + Hash: emptyHash[:], }) require.NoError(t, err) @@ -267,6 +275,7 @@ func TestConsensus_FinalizeBlock_MultiTxs(t *testing.T) { _, err = c.FinalizeBlock(context.Background(), &abciproto.FinalizeBlockRequest{ Time: time.Now(), Height: 1, + Hash: emptyHash[:], }) require.NoError(t, err) @@ -554,6 +563,7 @@ func TestConsensus_Info(t *testing.T) { _, err = c.FinalizeBlock(context.Background(), &abciproto.FinalizeBlockRequest{ Time: time.Now(), Height: 1, + Hash: emptyHash[:], }) require.NoError(t, err) @@ -598,6 +608,7 @@ func TestConsensus_Query(t *testing.T) { Time: time.Now(), Height: 1, Txs: [][]byte{mockTx.Bytes()}, + Hash: emptyHash[:], }) require.NoError(t, err) @@ -695,17 +706,12 @@ func setUpConsensus(t *testing.T, gasLimit uint64, mempool mempool.Mempool[mock. // Check target version same with store's latest version // And should have commit info of target version -// If block 0, commitInfo returned should be nil func assertStoreLatestVersion(t *testing.T, store types.Store, target uint64) { t.Helper() version, err := store.GetLatestVersion() require.NoError(t, err) - require.Equal(t, version, target) + require.Equal(t, target, version) commitInfo, err := store.GetStateCommitment().GetCommitInfo(version) require.NoError(t, err) - if target != 0 { - require.Equal(t, commitInfo.Version, target) - } else { - require.Nil(t, commitInfo) - } + require.Equal(t, target, commitInfo.Version) } diff --git a/server/v2/cometbft/internal/mock/mock_store.go b/server/v2/cometbft/internal/mock/mock_store.go index 8048dc48be96..e9f7be3edcb3 100644 --- a/server/v2/cometbft/internal/mock/mock_store.go +++ b/server/v2/cometbft/internal/mock/mock_store.go @@ -59,7 +59,6 @@ func (s *MockStore) StateLatest() (uint64, corestore.ReaderMap, error) { } func (s *MockStore) Commit(changeset *corestore.Changeset) (corestore.Hash, error) { - v, _, _ := s.StateLatest() err := s.Storage.ApplyChangeset(changeset) if err != nil { return []byte{}, err @@ -70,8 +69,7 @@ func (s *MockStore) Commit(changeset *corestore.Changeset) (corestore.Hash, erro return []byte{}, err } - commitInfo, err := s.Committer.Commit(v + 1) - fmt.Println("commitInfo", commitInfo, err) + _, err = s.Committer.Commit(changeset.Version) return []byte{}, err }