From 3488348cdd30e4de8cf7f654c86522a726e08d2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Zdyba=C5=82?= Date: Tue, 5 Nov 2024 23:02:59 +0100 Subject: [PATCH] test: rename types to ExecutorSuite and DummyExecutor --- proxy/grpc/proxy_test.go | 4 ++-- proxy/jsonrpc/proxy_test.go | 4 ++-- test/dummy.go | 20 ++++++++++---------- test/dummy_test.go | 4 ++-- test/suite.go | 14 +++++++------- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/proxy/grpc/proxy_test.go b/proxy/grpc/proxy_test.go index c74fda1..a88b871 100644 --- a/proxy/grpc/proxy_test.go +++ b/proxy/grpc/proxy_test.go @@ -26,14 +26,14 @@ func dialer(listener *bufconn.Listener) func(context.Context, string) (net.Conn, } type ProxyTestSuite struct { - test.ExecuteSuite + test.ExecutorSuite server *grpc.Server client *grpcproxy.Client cleanup func() } func (s *ProxyTestSuite) SetupTest() { - exec := test.NewExecute() + exec := test.NewDummyExecutor() config := &grpcproxy.Config{ DefaultTimeout: time.Second, MaxRequestSize: bufSize, diff --git a/proxy/jsonrpc/proxy_test.go b/proxy/jsonrpc/proxy_test.go index 7bed78f..cd7b245 100644 --- a/proxy/jsonrpc/proxy_test.go +++ b/proxy/jsonrpc/proxy_test.go @@ -13,14 +13,14 @@ import ( ) type ProxyTestSuite struct { - test.ExecuteSuite + test.ExecutorSuite server *httptest.Server client *jsonrpcproxy.Client cleanup func() } func (s *ProxyTestSuite) SetupTest() { - exec := test.NewExecute() + exec := test.NewDummyExecutor() config := &jsonrpcproxy.Config{ DefaultTimeout: time.Second, MaxRequestSize: 1024 * 1024, diff --git a/test/dummy.go b/test/dummy.go index cf8fc8d..2214aea 100644 --- a/test/dummy.go +++ b/test/dummy.go @@ -6,16 +6,16 @@ import ( "github.com/rollkit/go-execution/types" ) -// Execute is a dummy implementation of the Execute interface for testing -type Execute struct { +// DummyExecutor is a dummy implementation of the DummyExecutor interface for testing +type DummyExecutor struct { stateRoot types.Hash maxBytes uint64 txs []types.Tx } -// NewExecute creates a new dummy Execute instance -func NewExecute() *Execute { - return &Execute{ +// NewDummyExecutor creates a new dummy DummyExecutor instance +func NewDummyExecutor() *DummyExecutor { + return &DummyExecutor{ stateRoot: types.Hash{1, 2, 3}, maxBytes: 1000000, txs: make([]types.Tx, 0), @@ -24,22 +24,22 @@ func NewExecute() *Execute { // InitChain initializes the chain state with the given genesis time, initial height, and chain ID. // It returns the state root hash, the maximum byte size, and an error if the initialization fails. -func (e *Execute) InitChain(genesisTime time.Time, initialHeight uint64, chainID string) (types.Hash, uint64, error) { +func (e *DummyExecutor) InitChain(genesisTime time.Time, initialHeight uint64, chainID string) (types.Hash, uint64, error) { return e.stateRoot, e.maxBytes, nil } -// GetTxs returns the list of transactions (types.Tx) within the Execute instance and an error if any. -func (e *Execute) GetTxs() ([]types.Tx, error) { +// GetTxs returns the list of transactions (types.Tx) within the DummyExecutor instance and an error if any. +func (e *DummyExecutor) GetTxs() ([]types.Tx, error) { return e.txs, nil } // ExecuteTxs simulate execution of transactions. -func (e *Execute) ExecuteTxs(txs []types.Tx, blockHeight uint64, timestamp time.Time, prevStateRoot types.Hash) (types.Hash, uint64, error) { +func (e *DummyExecutor) ExecuteTxs(txs []types.Tx, blockHeight uint64, timestamp time.Time, prevStateRoot types.Hash) (types.Hash, uint64, error) { e.txs = append(e.txs, txs...) return e.stateRoot, e.maxBytes, nil } // SetFinal marks block at given height as finalized. Currently not implemented. -func (e *Execute) SetFinal(blockHeight uint64) error { +func (e *DummyExecutor) SetFinal(blockHeight uint64) error { return nil } diff --git a/test/dummy_test.go b/test/dummy_test.go index 40670ec..94af8b6 100644 --- a/test/dummy_test.go +++ b/test/dummy_test.go @@ -7,11 +7,11 @@ import ( ) type DummyTestSuite struct { - ExecuteSuite + ExecutorSuite } func (s *DummyTestSuite) SetupTest() { - s.Exec = NewExecute() + s.Exec = NewDummyExecutor() } func TestDummySuite(t *testing.T) { diff --git a/test/suite.go b/test/suite.go index ddcf192..244dc90 100644 --- a/test/suite.go +++ b/test/suite.go @@ -9,14 +9,14 @@ import ( "github.com/rollkit/go-execution/types" ) -// ExecuteSuite is a reusable test suite for Execution API implementations. -type ExecuteSuite struct { +// ExecutorSuite is a reusable test suite for Execution API implementations. +type ExecutorSuite struct { suite.Suite - Exec execution.Execute + Exec execution.Executor } // TestInitChain tests InitChain method. -func (s *ExecuteSuite) TestInitChain() { +func (s *ExecutorSuite) TestInitChain() { genesisTime := time.Now().UTC() initialHeight := uint64(1) chainID := "test-chain" @@ -28,14 +28,14 @@ func (s *ExecuteSuite) TestInitChain() { } // TestGetTxs tests GetTxs method. -func (s *ExecuteSuite) TestGetTxs() { +func (s *ExecutorSuite) TestGetTxs() { txs, err := s.Exec.GetTxs() s.Require().NoError(err) s.NotNil(txs) } // TestExecuteTxs tests ExecuteTxs method. -func (s *ExecuteSuite) TestExecuteTxs() { +func (s *ExecutorSuite) TestExecuteTxs() { txs := []types.Tx{[]byte("tx1"), []byte("tx2")} blockHeight := uint64(1) timestamp := time.Now().UTC() @@ -48,7 +48,7 @@ func (s *ExecuteSuite) TestExecuteTxs() { } // TestSetFinal tests SetFinal method. -func (s *ExecuteSuite) TestSetFinal() { +func (s *ExecutorSuite) TestSetFinal() { err := s.Exec.SetFinal(1) s.Require().NoError(err) }