Skip to content

Commit

Permalink
test: rename types to ExecutorSuite and DummyExecutor
Browse files Browse the repository at this point in the history
  • Loading branch information
tzdybal committed Nov 5, 2024
1 parent 3e6783a commit 3488348
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions proxy/grpc/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions proxy/jsonrpc/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 10 additions & 10 deletions test/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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
}
4 changes: 2 additions & 2 deletions test/dummy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
14 changes: 7 additions & 7 deletions test/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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()
Expand All @@ -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)
}

0 comments on commit 3488348

Please sign in to comment.