Skip to content

Commit

Permalink
test: test for executing multiple blocks in ExecutorSuite (#45)
Browse files Browse the repository at this point in the history
* test: test for executing multiple blocks in ExecutorSuite

This test ensures the Executor properly handles multiple blocks, including initializing the chain, processing transactions, and maintaining state consistency.

* chore: fix linter errors

* test: use more deterministic block time
  • Loading branch information
tzdybal authored Dec 18, 2024
1 parent 42bc230 commit 3572118
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,30 @@ func (s *ExecutorSuite) TestSetFinal() {
err = s.Exec.SetFinal(context.TODO(), 2)
s.Require().NoError(err)
}

// TestMultipleBlocks is a basic test ensuring that all API methods used together can be used to produce multiple blocks.
func (s *ExecutorSuite) TestMultipleBlocks() {
genesisTime := time.Now().UTC()
initialHeight := uint64(1)
chainID := "test-chain"
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

stateRoot, maxBytes, err := s.Exec.InitChain(ctx, genesisTime, initialHeight, chainID)
s.Require().NoError(err)
s.NotEqual(types.Hash{}, stateRoot)
s.Greater(maxBytes, uint64(0))

for i := initialHeight; i <= 10; i++ {
txs, err := s.Exec.GetTxs(ctx)
s.Require().NoError(err)

blockTime := genesisTime.Add(time.Duration(i+1) * time.Second) //nolint:gosec
stateRoot, maxBytes, err = s.Exec.ExecuteTxs(ctx, txs, i, blockTime, stateRoot)
s.Require().NoError(err)
s.Require().NotZero(maxBytes)

err = s.Exec.SetFinal(ctx, i)
s.Require().NoError(err)
}
}

0 comments on commit 3572118

Please sign in to comment.