@@ -22,51 +22,29 @@ import (
2222 "github.com/evstack/ev-node/test/mocks"
2323)
2424
25- // mockExecutor implements execution.Executor for testing
26- type mockExecutor struct {
27- maxGas uint64
28- getInfoErr error
29- filterFunc func (ctx context.Context , txs [][]byte , forceIncludedMask []bool , maxGas uint64 ) (* execution.FilterTxsResult , error )
30- }
31-
32- func (m * mockExecutor ) InitChain (ctx context.Context , genesisTime time.Time , initialHeight uint64 , chainID string ) ([]byte , error ) {
33- return []byte ("state-root" ), nil
34- }
35-
36- func (m * mockExecutor ) GetTxs (ctx context.Context ) ([][]byte , error ) {
37- return nil , nil
38- }
39-
40- func (m * mockExecutor ) ExecuteTxs (ctx context.Context , txs [][]byte , blockHeight uint64 , timestamp time.Time , prevStateRoot []byte ) ([]byte , error ) {
41- return []byte ("new-state-root" ), nil
42- }
43-
44- func (m * mockExecutor ) SetFinal (ctx context.Context , blockHeight uint64 ) error {
45- return nil
46- }
47-
48- func (m * mockExecutor ) GetExecutionInfo (ctx context.Context , height uint64 ) (execution.ExecutionInfo , error ) {
49- return execution.ExecutionInfo {MaxGas : m .maxGas }, m .getInfoErr
50- }
51-
52- func (m * mockExecutor ) FilterTxs (ctx context.Context , txs [][]byte , forceIncludedMask []bool , maxGas uint64 ) (* execution.FilterTxsResult , error ) {
53- if m .filterFunc != nil {
54- return m .filterFunc (ctx , txs , forceIncludedMask , maxGas )
55- }
56- // Default: return all txs as valid, no remaining
57- return & execution.FilterTxsResult {
58- ValidTxs : txs ,
59- ForceIncludedMask : forceIncludedMask ,
60- RemainingTxs : nil ,
61- }, nil
62- }
63-
6425// MockFullDAClient combines MockClient and MockVerifier to implement FullDAClient
6526type MockFullDAClient struct {
6627 * mocks.MockClient
6728 * mocks.MockVerifier
6829}
6930
31+ // createDefaultMockExecutor creates a MockExecutor with default passthrough behavior for FilterTxs and GetExecutionInfo
32+ func createDefaultMockExecutor (t * testing.T ) * mocks.MockExecutor {
33+ mockExec := mocks .NewMockExecutor (t )
34+ mockExec .On ("GetExecutionInfo" , mock .Anything , mock .Anything ).Return (execution.ExecutionInfo {MaxGas : 1000000 }, nil ).Maybe ()
35+ mockExec .On ("FilterTxs" , mock .Anything , mock .Anything , mock .Anything , mock .Anything ).Return (
36+ func (ctx context.Context , txs [][]byte , forceIncludedMask []bool , maxGas uint64 ) * execution.FilterTxsResult {
37+ return & execution.FilterTxsResult {
38+ ValidTxs : txs ,
39+ ForceIncludedMask : forceIncludedMask ,
40+ RemainingTxs : nil ,
41+ }
42+ },
43+ nil ,
44+ ).Maybe ()
45+ return mockExec
46+ }
47+
7048func createTestSequencer (t * testing.T , mockRetriever * common.MockForcedInclusionRetriever , gen genesis.Genesis ) * BasedSequencer {
7149 t .Helper ()
7250
@@ -82,7 +60,9 @@ func createTestSequencer(t *testing.T, mockRetriever *common.MockForcedInclusion
8260 mockDAClient .MockClient .On ("GetForcedInclusionNamespace" ).Return ([]byte ("test-forced-inclusion-ns" )).Maybe ()
8361 mockDAClient .MockClient .On ("HasForcedInclusionNamespace" ).Return (true ).Maybe ()
8462
85- seq , err := NewBasedSequencer (mockDAClient , config .DefaultConfig (), db , gen , zerolog .Nop (), & mockExecutor {})
63+ mockExec := createDefaultMockExecutor (t )
64+
65+ seq , err := NewBasedSequencer (mockDAClient , config .DefaultConfig (), db , gen , zerolog .Nop (), mockExec )
8666 require .NoError (t , err )
8767
8868 // Replace the fiRetriever with our mock so tests work as before
@@ -511,7 +491,8 @@ func TestBasedSequencer_CheckpointPersistence(t *testing.T) {
511491 mockDAClient .MockClient .On ("HasForcedInclusionNamespace" ).Return (true ).Maybe ()
512492
513493 // Create first sequencer
514- seq1 , err := NewBasedSequencer (mockDAClient , config .DefaultConfig (), db , gen , zerolog .Nop (), & mockExecutor {})
494+ mockExec1 := createDefaultMockExecutor (t )
495+ seq1 , err := NewBasedSequencer (mockDAClient , config .DefaultConfig (), db , gen , zerolog .Nop (), mockExec1 )
515496 require .NoError (t , err )
516497
517498 // Replace the fiRetriever with our mock so tests work as before
@@ -535,7 +516,8 @@ func TestBasedSequencer_CheckpointPersistence(t *testing.T) {
535516 }
536517 mockDAClient2 .MockClient .On ("GetForcedInclusionNamespace" ).Return ([]byte ("test-forced-inclusion-ns" )).Maybe ()
537518 mockDAClient2 .MockClient .On ("HasForcedInclusionNamespace" ).Return (true ).Maybe ()
538- seq2 , err := NewBasedSequencer (mockDAClient2 , config .DefaultConfig (), db , gen , zerolog .Nop (), & mockExecutor {})
519+ mockExec2 := createDefaultMockExecutor (t )
520+ seq2 , err := NewBasedSequencer (mockDAClient2 , config .DefaultConfig (), db , gen , zerolog .Nop (), mockExec2 )
539521 require .NoError (t , err )
540522
541523 // Replace the fiRetriever with our mock so tests work as before
@@ -797,9 +779,10 @@ func TestBasedSequencer_GetNextBatch_GasFilteringPreservesUnprocessedTxs(t *test
797779 // - tx1: gibberish/invalid (filtered out completely)
798780 // - tx2: valid but doesn't fit due to gas limit (returned as remaining)
799781 gasFilterCallCount := 0
800- mockExec := & mockExecutor {
801- maxGas : 1000000 ,
802- filterFunc : func (ctx context.Context , txs [][]byte , forceIncludedMask []bool , maxGas uint64 ) (* execution.FilterTxsResult , error ) {
782+ mockExec := mocks .NewMockExecutor (t )
783+ mockExec .On ("GetExecutionInfo" , mock .Anything , mock .Anything ).Return (execution.ExecutionInfo {MaxGas : 1000000 }, nil ).Maybe ()
784+ mockExec .On ("FilterTxs" , mock .Anything , mock .Anything , mock .Anything , mock .Anything ).Return (
785+ func (ctx context.Context , txs [][]byte , forceIncludedMask []bool , maxGas uint64 ) * execution.FilterTxsResult {
803786 gasFilterCallCount ++
804787 t .Logf ("FilterTxs call #%d with %d txs" , gasFilterCallCount , len (txs ))
805788 for i , tx := range txs {
@@ -817,7 +800,7 @@ func TestBasedSequencer_GetNextBatch_GasFilteringPreservesUnprocessedTxs(t *test
817800 ValidTxs : txs [:1 ], // Only tx0 fits
818801 ForceIncludedMask : []bool {true }, // All force-included
819802 RemainingTxs : txs [len (txs )- 1 :], // Last tx is gas-limited (tx2)
820- }, nil
803+ }
821804 }
822805
823806 // Subsequent calls: should receive the remaining txs (tx2, tx3, tx4)
@@ -826,9 +809,10 @@ func TestBasedSequencer_GetNextBatch_GasFilteringPreservesUnprocessedTxs(t *test
826809 ValidTxs : txs ,
827810 ForceIncludedMask : make ([]bool , len (txs )),
828811 RemainingTxs : nil ,
829- }, nil
812+ }
830813 },
831- }
814+ nil ,
815+ ).Maybe ()
832816
833817 // Create sequencer with custom executor
834818 db := syncds .MutexWrap (ds .NewMapDatastore ())
@@ -915,9 +899,10 @@ func TestBasedSequencer_GetNextBatch_RemainingTxsIndexCorrelation(t *testing.T)
915899 allProcessedTxs := make ([][]byte , 0 )
916900 filterCallCount := 0
917901
918- mockExec := & mockExecutor {
919- maxGas : 1000000 ,
920- filterFunc : func (ctx context.Context , txs [][]byte , forceIncludedMask []bool , maxGas uint64 ) (* execution.FilterTxsResult , error ) {
902+ mockExec := mocks .NewMockExecutor (t )
903+ mockExec .On ("GetExecutionInfo" , mock .Anything , mock .Anything ).Return (execution.ExecutionInfo {MaxGas : 1000000 }, nil ).Maybe ()
904+ mockExec .On ("FilterTxs" , mock .Anything , mock .Anything , mock .Anything , mock .Anything ).Return (
905+ func (ctx context.Context , txs [][]byte , forceIncludedMask []bool , maxGas uint64 ) * execution.FilterTxsResult {
921906 filterCallCount ++
922907 t .Logf ("FilterTxs call #%d with %d txs" , filterCallCount , len (txs ))
923908
@@ -927,7 +912,7 @@ func TestBasedSequencer_GetNextBatch_RemainingTxsIndexCorrelation(t *testing.T)
927912 ValidTxs : txs [:1 ], // tx0 only
928913 ForceIncludedMask : []bool {true },
929914 RemainingTxs : txs [1 :2 ], // tx1 is remaining (gas-limited)
930- }, nil
915+ }
931916 }
932917
933918 // Pass through all txs
@@ -939,9 +924,10 @@ func TestBasedSequencer_GetNextBatch_RemainingTxsIndexCorrelation(t *testing.T)
939924 ValidTxs : txs ,
940925 ForceIncludedMask : mask ,
941926 RemainingTxs : nil ,
942- }, nil
927+ }
943928 },
944- }
929+ nil ,
930+ ).Maybe ()
945931
946932 db := syncds .MutexWrap (ds .NewMapDatastore ())
947933 mockDAClient := & MockFullDAClient {
0 commit comments