@@ -8,11 +8,12 @@ package coordinator
88
99import (
1010 "context"
11+ "crypto/rand"
1112 "maps"
12- "strconv"
1313 "testing"
1414 "time"
1515
16+ "github.com/google/uuid"
1617 "github.com/stretchr/testify/assert"
1718 "github.com/stretchr/testify/require"
1819 "google.golang.org/protobuf/proto"
@@ -99,7 +100,7 @@ func (e *vcMgrTestEnv) requireRetriedTxsTotal(t *testing.T, expectedRetriedTxsTo
99100 )
100101}
101102
102- func TestValidatorCommitterManager (t * testing.T ) {
103+ func TestValidatorCommitterManagerX (t * testing.T ) {
103104 t .Parallel ()
104105
105106 ensureZeroWaitingTxs := func (env * vcMgrTestEnv ) {
@@ -108,10 +109,10 @@ func TestValidatorCommitterManager(t *testing.T) {
108109 }
109110 }
110111
111- t .Run ("Send tx batch to use any vcservice" , func (t * testing.T ) {
112+ t .Run ("Send tx batch to use any vcservice and send a batch with larger size " , func (t * testing.T ) {
112113 t .Parallel ()
113114 env := newVcMgrTestEnv (t , 2 )
114- txBatch , expectedTxsStatus := createInputTxsNodeForTest (5 , 1 , 1 )
115+ txBatch , expectedTxsStatus := createInputTxsNodeForTest (t , 5 , 0 , 1 )
115116 env .inputTxs <- txBatch
116117
117118 outTxs := <- env .outputTxs
@@ -125,14 +126,49 @@ func TestValidatorCommitterManager(t *testing.T) {
125126 t , 5 , env .validatorCommitterManager .config .metrics .vcserviceTransactionProcessedTotal ,
126127 2 * time .Second , 100 * time .Millisecond ,
127128 )
129+
130+ totalBlocks := 3
131+ txPerBlock := 50
132+ txBatches := make (dependencygraph.TxNodeBatch , 0 , totalBlocks * txPerBlock )
133+ expectedTxsStatus = & protoblocktx.TransactionsStatus {Status : make (map [string ]* protoblocktx.StatusWithHeight )}
134+
135+ for i := range 3 {
136+ //nolint:gosec // int -> int64
137+ txBatch , txStatus := createInputTxsNodeForTest (t , txPerBlock , 1024 * 1024 , uint64 (i + 2 ))
138+ txBatches = append (txBatches , txBatch ... )
139+ maps .Copy (expectedTxsStatus .Status , txStatus .Status )
140+ }
141+
142+ env .inputTxs <- txBatches
143+
144+ // txBatch would be split into three parts, one per block.
145+ outTxs = <- env .outputTxs
146+ outTxs = append (outTxs , <- env .outputTxs ... )
147+ outTxs = append (outTxs , <- env .outputTxs ... )
148+ require .ElementsMatch (t , txBatches , outTxs )
149+
150+ outTxsStatus = <- env .outputTxsStatus
151+ status := <- env .outputTxsStatus
152+ maps .Copy (outTxsStatus .Status , status .Status )
153+ status = <- env .outputTxsStatus
154+ maps .Copy (outTxsStatus .Status , status .Status )
155+ require .Equal (t , expectedTxsStatus .Status , outTxsStatus .Status )
156+
157+ test .EventuallyIntMetric (
158+ t , 5 + totalBlocks * txPerBlock ,
159+ env .validatorCommitterManager .config .metrics .vcserviceTransactionProcessedTotal ,
160+ 2 * time .Second , 100 * time .Millisecond ,
161+ )
162+
128163 ensureZeroWaitingTxs (env )
129164 })
130165
131166 t .Run ("send batches to ensure all vcservices are used" , func (t * testing.T ) {
132167 t .Parallel ()
133168 env := newVcMgrTestEnv (t , 2 )
134- txBatch1 , expectedTxsStatus1 := createInputTxsNodeForTest (5 , 1 , 2 )
135- txBatch2 , expectedTxsStatus2 := createInputTxsNodeForTest (5 , 6 , 3 )
169+
170+ txBatch1 , expectedTxsStatus1 := createInputTxsNodeForTest (t , 5 , 0 , 2 )
171+ txBatch2 , expectedTxsStatus2 := createInputTxsNodeForTest (t , 5 , 0 , 3 )
136172
137173 require .Eventually (t , func () bool {
138174 env .inputTxs <- txBatch1
@@ -281,7 +317,7 @@ func TestValidatorCommitterManagerRecovery(t *testing.T) {
281317 env .requireRetriedTxsTotal (t , 0 )
282318
283319 numTxs := 10
284- txBatch , expectedTxsStatus := createInputTxsNodeForTest (numTxs , 0 , 0 )
320+ txBatch , expectedTxsStatus := createInputTxsNodeForTest (t , numTxs , 0 , 0 )
285321 env .inputTxs <- txBatch
286322
287323 require .Eventually (t , func () bool {
@@ -323,21 +359,36 @@ func TestValidatorCommitterManagerRecovery(t *testing.T) {
323359 }, 2 * time .Second , 1 * time .Second )
324360}
325361
326- func createInputTxsNodeForTest (numTxs , startIndex int , blkNum uint64 ) (
362+ func createInputTxsNodeForTest (t * testing. T , numTxs , valueSize int , blkNum uint64 ) (
327363 []* dependencygraph.TransactionNode , * protoblocktx.TransactionsStatus ,
328364) {
365+ t .Helper ()
366+
329367 txsNode := make ([]* dependencygraph.TransactionNode , numTxs )
330368 expectedTxsStatus := & protoblocktx.TransactionsStatus {
331369 Status : make (map [string ]* protoblocktx.StatusWithHeight ),
332370 }
333371
372+ b := make ([]byte , valueSize )
373+ _ , err := rand .Read (b )
374+ require .NoError (t , err )
375+
334376 for i := range numTxs {
335- id := "tx" + strconv . Itoa ( startIndex + i )
377+ id := uuid . NewString ( )
336378 txsNode [i ] = & dependencygraph.TransactionNode {
337379 Tx : & protovcservice.Transaction {
338380 ID : id ,
339381 BlockNumber : blkNum ,
340382 TxNum : uint32 (i ), //nolint:gosec
383+ Namespaces : []* protoblocktx.TxNamespace {
384+ {
385+ BlindWrites : []* protoblocktx.Write {
386+ {
387+ Value : b ,
388+ },
389+ },
390+ },
391+ },
341392 },
342393 }
343394 expectedTxsStatus .Status [id ] = types .CreateStatusWithHeight (protoblocktx .Status_COMMITTED , blkNum , i )
0 commit comments