Skip to content

Commit

Permalink
test: Add TxInjector interface and integrate with test suites (#50)
Browse files Browse the repository at this point in the history
Introduced the TxInjector interface for injecting transactions into test cases. Updated ExecutorSuite, proxy_test, and DummyTestSuite to utilize TxInjector. Adjusted test assertions to validate transaction injection functionality.

Resolves #15
  • Loading branch information
tzdybal authored Jan 16, 2025
1 parent a398e4d commit 0cb0d62
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions proxy/grpc/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func (s *ProxyTestSuite) SetupTest() {

s.client = client
s.Exec = client
s.TxInjector = exec
s.cleanup = func() {
_ = client.Stop()
s.server.Stop()
Expand Down
4 changes: 3 additions & 1 deletion test/dummy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ type DummyTestSuite struct {
}

func (s *DummyTestSuite) SetupTest() {
s.Exec = NewDummyExecutor()
dummy := NewDummyExecutor()
s.Exec = dummy
s.TxInjector = dummy
}

func TestDummySuite(t *testing.T) {
Expand Down
25 changes: 23 additions & 2 deletions test/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ import (
// ExecutorSuite is a reusable test suite for Execution API implementations.
type ExecutorSuite struct {
suite.Suite
Exec execution.Executor
Exec execution.Executor
TxInjector TxInjector
}

// TxInjector provides an interface for injecting transactions into a test suite.
type TxInjector interface {
InjectTx(tx types.Tx)
}

// TestInitChain tests InitChain method.
Expand All @@ -30,9 +36,24 @@ func (s *ExecutorSuite) TestInitChain() {

// TestGetTxs tests GetTxs method.
func (s *ExecutorSuite) TestGetTxs() {
s.skipIfInjectorNotSet()

tx1 := types.Tx("tx1")
tx2 := types.Tx("tx2")

s.TxInjector.InjectTx(tx1)
s.TxInjector.InjectTx(tx2)
txs, err := s.Exec.GetTxs(context.TODO())
s.Require().NoError(err)
s.Empty(txs)
s.Require().Len(txs, 2)
s.Require().Contains(txs, tx1)
s.Require().Contains(txs, tx2)
}

func (s *ExecutorSuite) skipIfInjectorNotSet() {
if s.TxInjector == nil {
s.T().Skipf("Skipping %s because TxInjector is not provided", s.T().Name())
}
}

// TestExecuteTxs tests ExecuteTxs method.
Expand Down

0 comments on commit 0cb0d62

Please sign in to comment.