@@ -20,25 +20,19 @@ func TestInitChain_Idempotency(t *testing.T) {
2020 chainID := "test-chain"
2121
2222 // First call initializes genesis state
23- stateRoot1 , maxBytes1 , err := exec .InitChain (ctx , genesisTime , initialHeight , chainID )
23+ stateRoot1 , err := exec .InitChain (ctx , genesisTime , initialHeight , chainID )
2424 if err != nil {
2525 t .Fatalf ("InitChain failed on first call: %v" , err )
2626 }
27- if maxBytes1 != 1024 {
28- t .Errorf ("Expected maxBytes 1024, got %d" , maxBytes1 )
29- }
3027
3128 // Second call should return the same genesis state root
32- stateRoot2 , maxBytes2 , err := exec .InitChain (ctx , genesisTime , initialHeight , chainID )
29+ stateRoot2 , err := exec .InitChain (ctx , genesisTime , initialHeight , chainID )
3330 if err != nil {
3431 t .Fatalf ("InitChain failed on second call: %v" , err )
3532 }
3633 if ! bytes .Equal (stateRoot1 , stateRoot2 ) {
3734 t .Errorf ("Genesis state roots do not match: %s vs %s" , stateRoot1 , stateRoot2 )
3835 }
39- if maxBytes2 != 1024 {
40- t .Errorf ("Expected maxBytes 1024, got %d" , maxBytes2 )
41- }
4236}
4337
4438func TestGetTxs (t * testing.T ) {
@@ -58,43 +52,34 @@ func TestGetTxs(t *testing.T) {
5852 // though for buffered channels it should be immediate unless full.
5953 time .Sleep (10 * time .Millisecond )
6054
61- // First call to GetTxs should retrieve the injected transactions
6255 txs , err := exec .GetTxs (ctx )
6356 if err != nil {
64- t .Fatalf ("GetTxs returned error on first call : %v" , err )
57+ t .Fatalf ("GetTxs returned error: %v" , err )
6558 }
6659 if len (txs ) != 2 {
67- t .Errorf ("Expected 2 transactions on first call , got %d" , len (txs ))
60+ t .Errorf ("Expected 2 transactions, got %d" , len (txs ))
6861 }
69-
70- // Verify the content (order might not be guaranteed depending on channel internals, but likely FIFO here)
71- foundTx1 := false
72- foundTx2 := false
73- for _ , tx := range txs {
74- if reflect .DeepEqual (tx , tx1 ) {
75- foundTx1 = true
76- }
77- if reflect .DeepEqual (tx , tx2 ) {
78- foundTx2 = true
79- }
62+ if ! reflect .DeepEqual (txs [0 ], tx1 ) {
63+ t .Errorf ("Expected first tx 'a=1', got %s" , string (txs [0 ]))
8064 }
81- if ! foundTx1 || ! foundTx2 {
82- t .Errorf ("Did not retrieve expected transactions. Got: %v " , txs )
65+ if ! reflect . DeepEqual ( txs [ 1 ], tx2 ) {
66+ t .Errorf ("Expected second tx 'b=2', got %s " , string ( txs [ 1 ]) )
8367 }
8468
85- // Second call to GetTxs should return no transactions as the channel was drained
86- txsAfterDrain , err := exec .GetTxs (ctx )
69+ // GetTxs should drain the channel, so a second call should return empty or nil
70+ txsAgain , err := exec .GetTxs (ctx )
8771 if err != nil {
88- t .Fatalf ("GetTxs returned error on second call: %v" , err )
72+ t .Fatalf ("GetTxs ( second call) returned error : %v" , err )
8973 }
90- if len (txsAfterDrain ) != 0 {
91- t .Errorf ("Expected 0 transactions after drain , got %d" , len (txsAfterDrain ))
74+ if len (txsAgain ) != 0 {
75+ t .Errorf ("Expected 0 transactions on second call (drained) , got %d" , len (txsAgain ))
9276 }
9377
94- // Test injecting again after draining
78+ // Inject another transaction and verify it's available
9579 tx3 := []byte ("c=3" )
9680 exec .InjectTx (tx3 )
9781 time .Sleep (10 * time .Millisecond )
82+
9883 txsAfterReinject , err := exec .GetTxs (ctx )
9984 if err != nil {
10085 t .Fatalf ("GetTxs returned error after re-inject: %v" , err )
@@ -120,13 +105,10 @@ func TestExecuteTxs_Valid(t *testing.T) {
120105 []byte ("key2=value2" ),
121106 }
122107
123- stateRoot , maxBytes , err := exec .ExecuteTxs (ctx , txs , 1 , time .Now (), []byte ("" ))
108+ stateRoot , err := exec .ExecuteTxs (ctx , txs , 1 , time .Now (), []byte ("" ))
124109 if err != nil {
125110 t .Fatalf ("ExecuteTxs failed: %v" , err )
126111 }
127- if maxBytes != 1024 {
128- t .Errorf ("Expected maxBytes 1024, got %d" , maxBytes )
129- }
130112
131113 // Check that stateRoot contains the updated key-value pairs
132114 rootStr := string (stateRoot )
@@ -152,13 +134,10 @@ func TestExecuteTxs_Invalid(t *testing.T) {
152134 []byte ("" ),
153135 }
154136
155- stateRoot , maxBytes , err := exec .ExecuteTxs (ctx , txs , 1 , time .Now (), []byte ("" ))
137+ stateRoot , err := exec .ExecuteTxs (ctx , txs , 1 , time .Now (), []byte ("" ))
156138 if err != nil {
157139 t .Fatalf ("ExecuteTxs should handle gibberish gracefully, got error: %v" , err )
158140 }
159- if maxBytes != 1024 {
160- t .Errorf ("Expected maxBytes 1024, got %d" , maxBytes )
161- }
162141
163142 // State root should still be computed (empty block is valid)
164143 if stateRoot == nil {
@@ -173,7 +152,7 @@ func TestExecuteTxs_Invalid(t *testing.T) {
173152 []byte ("" ),
174153 }
175154
176- stateRoot2 , _ , err := exec .ExecuteTxs (ctx , mixedTxs , 2 , time .Now (), stateRoot )
155+ stateRoot2 , err := exec .ExecuteTxs (ctx , mixedTxs , 2 , time .Now (), stateRoot )
177156 if err != nil {
178157 t .Fatalf ("ExecuteTxs should filter invalid transactions and process valid ones, got error: %v" , err )
179158 }
@@ -213,7 +192,7 @@ func TestReservedKeysExcludedFromAppHash(t *testing.T) {
213192 ctx := context .Background ()
214193
215194 // Initialize chain to set up genesis state (this writes genesis reserved keys)
216- _ , _ , err = exec .InitChain (ctx , time .Now (), 1 , "test-chain" )
195+ _ , err = exec .InitChain (ctx , time .Now (), 1 , "test-chain" )
217196 if err != nil {
218197 t .Fatalf ("Failed to initialize chain: %v" , err )
219198 }
@@ -223,7 +202,7 @@ func TestReservedKeysExcludedFromAppHash(t *testing.T) {
223202 []byte ("user/key1=value1" ),
224203 []byte ("user/key2=value2" ),
225204 }
226- _ , _ , err = exec .ExecuteTxs (ctx , txs , 1 , time .Now (), []byte ("" ))
205+ _ , err = exec .ExecuteTxs (ctx , txs , 1 , time .Now (), []byte ("" ))
227206 if err != nil {
228207 t .Fatalf ("Failed to execute transactions: %v" , err )
229208 }
@@ -279,7 +258,7 @@ func TestReservedKeysExcludedFromAppHash(t *testing.T) {
279258 moreTxs := [][]byte {
280259 []byte ("user/key3=value3" ),
281260 }
282- _ , _ , err = exec .ExecuteTxs (ctx , moreTxs , 2 , time .Now (), stateRootAfterReservedKeyWrite )
261+ _ , err = exec .ExecuteTxs (ctx , moreTxs , 2 , time .Now (), stateRootAfterReservedKeyWrite )
283262 if err != nil {
284263 t .Fatalf ("Failed to execute more transactions: %v" , err )
285264 }
0 commit comments