Skip to content

Commit

Permalink
test: ensure correct tx removal
Browse files Browse the repository at this point in the history
  • Loading branch information
tzdybal committed Jan 15, 2025
1 parent d28d873 commit 13f1c5a
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions test/dummy_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package test

import (
"context"
"github.com/rollkit/go-execution/types"

Check failure on line 5 in test/dummy_test.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

File is not properly formatted (goimports)
"github.com/stretchr/testify/require"
"testing"
"time"

"github.com/stretchr/testify/suite"
)
Expand All @@ -17,3 +21,37 @@ func (s *DummyTestSuite) SetupTest() {
func TestDummySuite(t *testing.T) {
suite.Run(t, new(DummyTestSuite))
}

func TestTxRemoval(t *testing.T) {
exec := NewDummyExecutor()
tx1 := types.Tx([]byte{1, 2, 3})
tx2 := types.Tx([]byte{3, 2, 1})

exec.InjectTx(tx1)
exec.InjectTx(tx2)

// first execution of GetTxs - nothing special
txs, err := exec.GetTxs(context.Background())
require.NoError(t, err)
require.Len(t, txs, 2)
require.Contains(t, txs, tx1)
require.Contains(t, txs, tx2)

// ExecuteTxs was not called, so 2 txs should still be returned
txs, err = exec.GetTxs(context.Background())
require.NoError(t, err)
require.Len(t, txs, 2)
require.Contains(t, txs, tx1)
require.Contains(t, txs, tx2)

state, _, err := exec.ExecuteTxs(context.Background(), []types.Tx{tx1}, 1, time.Now(), nil)
require.NoError(t, err)
require.NotEmpty(t, state)

// ExecuteTxs was called, 1 tx remaining in mempool
txs, err = exec.GetTxs(context.Background())
require.NoError(t, err)
require.Len(t, txs, 1)
require.NotContains(t, txs, tx1)
require.Contains(t, txs, tx2)
}

0 comments on commit 13f1c5a

Please sign in to comment.