From a8021ba3d2e4587adfa58d16e82423a424b9b240 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 19 Jun 2024 18:06:52 +0200 Subject: [PATCH] test: add test for applyblock --- rpc/core/tx_status_test.go | 1 + state/execution_test.go | 27 +++++++++++++++++++++++++++ store/store_test.go | 4 +++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/rpc/core/tx_status_test.go b/rpc/core/tx_status_test.go index e286188562..836fab5da7 100644 --- a/rpc/core/tx_status_test.go +++ b/rpc/core/tx_status_test.go @@ -125,6 +125,7 @@ func TestTxStatus(t *testing.T) { assert.Equal(t, txStatus.Status, tt.expectedStatus) assert.Equal(t, height, txStatus.Height) assert.Equal(t, uint32(i), txStatus.Index) + assert.Equal(t, uint32(0), txStatus.ExecutionCode) } } diff --git a/state/execution_test.go b/state/execution_test.go index 4f03832a09..c16fc3bcf1 100644 --- a/state/execution_test.go +++ b/state/execution_test.go @@ -71,6 +71,33 @@ func TestApplyBlock(t *testing.T) { assert.EqualValues(t, 1, state.Version.Consensus.App, "App version wasn't updated") } +func TestApplyBlockWithBlockStore(t *testing.T) { + app := &testApp{} + cc := proxy.NewLocalClientCreator(app) + proxyApp := proxy.NewAppConns(cc) + err := proxyApp.Start() + require.Nil(t, err) + defer proxyApp.Stop() //nolint:errcheck // ignore for tests + blockStore := mocks.NewBlockStore(t) + + state, stateDB, _ := makeState(1, 1) + stateStore := sm.NewStore(stateDB, sm.StoreOptions{ + DiscardABCIResponses: false, + }) + + blockExec := sm.NewBlockExecutor(stateStore, log.TestingLogger(), proxyApp.Consensus(), + mmock.Mempool{}, sm.EmptyEvidencePool{}, sm.WithBlockStore(blockStore)) + + block := makeBlock(state, 1) + blockID := types.BlockID{Hash: block.Hash(), PartSetHeader: block.MakePartSet(testPartSize).Header()} + + // Check that SaveTxInfo is called with correct arguments + blockStore.On("SaveTxInfo", block, mock.AnythingOfType("[]uint32")).Return(nil) + + _, _, err = blockExec.ApplyBlock(state, blockID, block, nil) + require.Nil(t, err) +} + // TestBeginBlockValidators ensures we send absent validators list. func TestBeginBlockValidators(t *testing.T) { app := &testApp{} diff --git a/store/store_test.go b/store/store_test.go index 6bdd453bc6..a858b9f396 100644 --- a/store/store_test.go +++ b/store/store_test.go @@ -424,6 +424,7 @@ func TestSaveTxInfo(t *testing.T) { require.Equal(t, block.Height, txInfo.Height) require.Equal(t, block.Height, int64(777)) require.Equal(t, txInfo.Height, int64(777)) + require.Equal(t, uint32(1), txInfo.Code) require.Equal(t, uint32(5), txInfo.Index) } @@ -599,7 +600,8 @@ func TestPruneBlocksPrunesTxs(t *testing.T) { partSet := block.MakePartSet(2) seenCommit := makeTestCommit(h, cmttime.Now()) blockStore.SaveBlock(block, partSet, seenCommit) - blockStore.SaveTxInfo(block, make([]uint32, len(block.Txs))) + err := blockStore.SaveTxInfo(block, make([]uint32, len(block.Txs))) + require.NoError(t, err) for _, tx := range block.Txs { indexedTxHashes = append(indexedTxHashes, tx.Hash()) }