From ece02659167f9244629b86738cb7ab5463bba767 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Zdyba=C5=82?= Date: Mon, 16 Dec 2024 17:07:08 +0100 Subject: [PATCH 1/3] 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. --- test/suite.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/suite.go b/test/suite.go index 28574db..92a5e34 100644 --- a/test/suite.go +++ b/test/suite.go @@ -59,3 +59,27 @@ func (s *ExecutorSuite) TestSetFinal() { err = s.Exec.SetFinal(context.TODO(), 2) s.Require().NoError(err) } + +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) + + stateRoot, maxBytes, err = s.Exec.ExecuteTxs(ctx, txs, i, time.Now(), stateRoot) + s.Require().NoError(err) + + err = s.Exec.SetFinal(ctx, i) + s.Require().NoError(err) + } +} From 42eb500e959bdc4e5a197e50ec1405d8602824fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Zdyba=C5=82?= Date: Tue, 17 Dec 2024 21:11:47 +0100 Subject: [PATCH 2/3] chore: fix linter errors --- test/suite.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/suite.go b/test/suite.go index 92a5e34..5926f15 100644 --- a/test/suite.go +++ b/test/suite.go @@ -60,6 +60,7 @@ func (s *ExecutorSuite) TestSetFinal() { 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) @@ -78,6 +79,7 @@ func (s *ExecutorSuite) TestMultipleBlocks() { stateRoot, maxBytes, err = s.Exec.ExecuteTxs(ctx, txs, i, time.Now(), stateRoot) s.Require().NoError(err) + s.Require().NotZero(maxBytes) err = s.Exec.SetFinal(ctx, i) s.Require().NoError(err) From b08de5259c763db24dda33596f2cb9ac1ec7bfcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Zdyba=C5=82?= Date: Tue, 17 Dec 2024 21:17:08 +0100 Subject: [PATCH 3/3] test: use more deterministic block time --- test/suite.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/suite.go b/test/suite.go index 5926f15..b6c0068 100644 --- a/test/suite.go +++ b/test/suite.go @@ -77,7 +77,8 @@ func (s *ExecutorSuite) TestMultipleBlocks() { txs, err := s.Exec.GetTxs(ctx) s.Require().NoError(err) - stateRoot, maxBytes, err = s.Exec.ExecuteTxs(ctx, txs, i, time.Now(), stateRoot) + 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)