Skip to content

Commit

Permalink
test: add test for applyblock
Browse files Browse the repository at this point in the history
  • Loading branch information
ninabarbakadze committed Jun 19, 2024
1 parent 25990ea commit a8021ba
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions rpc/core/tx_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
27 changes: 27 additions & 0 deletions state/execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
4 changes: 3 additions & 1 deletion store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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())
}
Expand Down

0 comments on commit a8021ba

Please sign in to comment.