@@ -5,13 +5,16 @@ package integrationtests
5
5
import (
6
6
"context"
7
7
"encoding/hex"
8
+ "math/big"
9
+ "testing"
10
+
11
+ "github.com/multiversx/mx-chain-core-go/core"
8
12
dataBlock "github.com/multiversx/mx-chain-core-go/data/block"
9
13
"github.com/multiversx/mx-chain-core-go/data/outport"
14
+ "github.com/multiversx/mx-chain-core-go/data/smartContractResult"
10
15
"github.com/multiversx/mx-chain-core-go/data/transaction"
11
16
indexerdata "github.com/multiversx/mx-chain-es-indexer-go/process/dataindexer"
12
17
"github.com/stretchr/testify/require"
13
- "math/big"
14
- "testing"
15
18
)
16
19
17
20
func TestRelayedTxV3 (t * testing.T ) {
@@ -97,3 +100,270 @@ func TestRelayedTxV3(t *testing.T) {
97
100
string (genericResponse .Docs [0 ].Source ),
98
101
)
99
102
}
103
+
104
+ func TestRelayedTxV3WithSignalErrorAndCompletedEvent (t * testing.T ) {
105
+ setLogLevelDebug ()
106
+
107
+ esClient , err := createESClient (esURL )
108
+ require .Nil (t , err )
109
+
110
+ esProc , err := CreateElasticProcessor (esClient )
111
+ require .Nil (t , err )
112
+
113
+ txHash := []byte ("relayedTxV3WithSignalErrorAndCompletedEvent" )
114
+ header := & dataBlock.Header {
115
+ Round : 50 ,
116
+ TimeStamp : 5040 ,
117
+ }
118
+
119
+ body := & dataBlock.Body {
120
+ MiniBlocks : dataBlock.MiniBlockSlice {
121
+ {
122
+ Type : dataBlock .TxBlock ,
123
+ SenderShardID : 0 ,
124
+ ReceiverShardID : 0 ,
125
+ TxHashes : [][]byte {txHash },
126
+ },
127
+ },
128
+ }
129
+
130
+ initialTx := & transaction.Transaction {
131
+ Nonce : 1000 ,
132
+ SndAddr : decodeAddress ("erd1ykqd64fxxpp4wsz0v7sjqem038wfpzlljhx4mhwx8w9lcxmdzcfszrp64a" ),
133
+ RcvAddr : decodeAddress ("erd1ykqd64fxxpp4wsz0v7sjqem038wfpzlljhx4mhwx8w9lcxmdzcfszrp64a" ),
134
+ GasLimit : 300_000 ,
135
+ GasPrice : 1000000000 ,
136
+ Value : big .NewInt (0 ),
137
+ InnerTransactions : []* transaction.Transaction {
138
+ {
139
+ Nonce : 5 ,
140
+ SndAddr : decodeAddress ("erd10ksryjr065ad5475jcg82pnjfg9j9qtszjsrp24anl6ym7cmeddshwnru8" ),
141
+ RcvAddr : decodeAddress ("erd1aduqqezzw0u3j7tywlq3mrl0yn4z6f6vytdju8gg0neq38fauyzsa5yy6r" ),
142
+ GasLimit : 50_000 ,
143
+ GasPrice : 1000000000 ,
144
+ Value : big .NewInt (10000000000000000 ),
145
+ },
146
+ {
147
+ Nonce : 3 ,
148
+ SndAddr : decodeAddress ("erd10ksryjr065ad5475jcg82pnjfg9j9qtszjsrp24anl6ym7cmeddshwnru8" ),
149
+ RcvAddr : decodeAddress ("erd1aduqqezzw0u3j7tywlq3mrl0yn4z6f6vytdju8gg0neq38fauyzsa5yy6r" ),
150
+ GasLimit : 50_000 ,
151
+ GasPrice : 1000000000 ,
152
+ Value : big .NewInt (10000000000000000 ),
153
+ },
154
+ {
155
+ Nonce : 4 ,
156
+ SndAddr : decodeAddress ("erd10ksryjr065ad5475jcg82pnjfg9j9qtszjsrp24anl6ym7cmeddshwnru8" ),
157
+ RcvAddr : decodeAddress ("erd1aduqqezzw0u3j7tywlq3mrl0yn4z6f6vytdju8gg0neq38fauyzsa5yy6r" ),
158
+ GasLimit : 50_000 ,
159
+ GasPrice : 1000000000 ,
160
+ Value : big .NewInt (10000000000000000 ),
161
+ },
162
+ },
163
+ }
164
+
165
+ txInfo := & outport.TxInfo {
166
+ Transaction : initialTx ,
167
+ FeeInfo : & outport.FeeInfo {
168
+ GasUsed : 10556000 ,
169
+ Fee : big .NewInt (2257820000000000 ),
170
+ InitialPaidFee : big .NewInt (2306320000000000 ),
171
+ },
172
+ ExecutionOrder : 0 ,
173
+ }
174
+
175
+ pool := & outport.TransactionPool {
176
+ Transactions : map [string ]* outport.TxInfo {
177
+ hex .EncodeToString (txHash ): txInfo ,
178
+ },
179
+ Logs : []* outport.LogData {
180
+ {
181
+ TxHash : hex .EncodeToString (txHash ),
182
+ Log : & transaction.Log {
183
+ Address : decodeAddress ("erd1ykqd64fxxpp4wsz0v7sjqem038wfpzlljhx4mhwx8w9lcxmdzcfszrp64a" ),
184
+ Events : []* transaction.Event {
185
+ {
186
+ Address : decodeAddress ("erd1ykqd64fxxpp4wsz0v7sjqem038wfpzlljhx4mhwx8w9lcxmdzcfszrp64a" ),
187
+ Identifier : []byte (core .CompletedTxEventIdentifier ),
188
+ Topics : [][]byte {[]byte ("t1" ), []byte ("t2" )},
189
+ },
190
+ nil ,
191
+ },
192
+ },
193
+ },
194
+ {
195
+ TxHash : hex .EncodeToString (txHash ),
196
+ Log : & transaction.Log {
197
+ Address : decodeAddress ("erd1ykqd64fxxpp4wsz0v7sjqem038wfpzlljhx4mhwx8w9lcxmdzcfszrp64a" ),
198
+ Events : []* transaction.Event {
199
+ {
200
+ Address : decodeAddress ("erd1ykqd64fxxpp4wsz0v7sjqem038wfpzlljhx4mhwx8w9lcxmdzcfszrp64a" ),
201
+ Identifier : []byte (core .SignalErrorOperation ),
202
+ Topics : [][]byte {[]byte ("t1" ), []byte ("t2" )},
203
+ },
204
+ nil ,
205
+ },
206
+ },
207
+ },
208
+ },
209
+ }
210
+ err = esProc .SaveTransactions (createOutportBlockWithHeader (body , header , pool , nil , testNumOfShards ))
211
+ require .Nil (t , err )
212
+
213
+ ids := []string {hex .EncodeToString (txHash )}
214
+ genericResponse := & GenericResponse {}
215
+ err = esClient .DoMultiGet (context .Background (), ids , indexerdata .TransactionsIndex , true , genericResponse )
216
+ require .Nil (t , err )
217
+
218
+ require .JSONEq (t ,
219
+ readExpectedResult ("./testdata/relayedTxV3/relayed-tx-v3-with-events.json" ),
220
+ string (genericResponse .Docs [0 ].Source ),
221
+ )
222
+ }
223
+
224
+ func TestRelayedV3WithSCRCross (t * testing.T ) {
225
+ setLogLevelDebug ()
226
+
227
+ esClient , err := createESClient (esURL )
228
+ require .Nil (t , err )
229
+
230
+ esProc , err := CreateElasticProcessor (esClient )
231
+ require .Nil (t , err )
232
+
233
+ txHash := []byte ("relayedTxV3WithScrCross" )
234
+ header := & dataBlock.Header {
235
+ Round : 50 ,
236
+ TimeStamp : 5040 ,
237
+ }
238
+
239
+ body := & dataBlock.Body {
240
+ MiniBlocks : dataBlock.MiniBlockSlice {
241
+ {
242
+ Type : dataBlock .TxBlock ,
243
+ SenderShardID : 0 ,
244
+ ReceiverShardID : 0 ,
245
+ TxHashes : [][]byte {txHash },
246
+ },
247
+ },
248
+ }
249
+
250
+ initialTx := & transaction.Transaction {
251
+ Nonce : 1000 ,
252
+ SndAddr : decodeAddress ("erd1ykqd64fxxpp4wsz0v7sjqem038wfpzlljhx4mhwx8w9lcxmdzcfszrp64a" ),
253
+ RcvAddr : decodeAddress ("erd1ykqd64fxxpp4wsz0v7sjqem038wfpzlljhx4mhwx8w9lcxmdzcfszrp64a" ),
254
+ GasLimit : 300_000 ,
255
+ GasPrice : 1000000000 ,
256
+ Value : big .NewInt (0 ),
257
+ InnerTransactions : []* transaction.Transaction {
258
+ {
259
+ Nonce : 5 ,
260
+ SndAddr : decodeAddress ("erd10ksryjr065ad5475jcg82pnjfg9j9qtszjsrp24anl6ym7cmeddshwnru8" ),
261
+ RcvAddr : decodeAddress ("erd1aduqqezzw0u3j7tywlq3mrl0yn4z6f6vytdju8gg0neq38fauyzsa5yy6r" ),
262
+ GasLimit : 50_000 ,
263
+ GasPrice : 1000000000 ,
264
+ Value : big .NewInt (10000000000000000 ),
265
+ },
266
+ {
267
+ Nonce : 3 ,
268
+ SndAddr : decodeAddress ("erd10ksryjr065ad5475jcg82pnjfg9j9qtszjsrp24anl6ym7cmeddshwnru8" ),
269
+ RcvAddr : decodeAddress ("erd1aduqqezzw0u3j7tywlq3mrl0yn4z6f6vytdju8gg0neq38fauyzsa5yy6r" ),
270
+ GasLimit : 50_000 ,
271
+ GasPrice : 1000000000 ,
272
+ Value : big .NewInt (10000000000000000 ),
273
+ },
274
+ },
275
+ }
276
+
277
+ txInfo := & outport.TxInfo {
278
+ Transaction : initialTx ,
279
+ FeeInfo : & outport.FeeInfo {
280
+ GasUsed : 10556000 ,
281
+ Fee : big .NewInt (2257820000000000 ),
282
+ InitialPaidFee : big .NewInt (2306320000000000 ),
283
+ },
284
+ ExecutionOrder : 0 ,
285
+ }
286
+
287
+ pool := & outport.TransactionPool {
288
+ Transactions : map [string ]* outport.TxInfo {
289
+ hex .EncodeToString (txHash ): txInfo ,
290
+ },
291
+ Logs : []* outport.LogData {
292
+ {
293
+ TxHash : hex .EncodeToString (txHash ),
294
+ Log : & transaction.Log {
295
+ Address : decodeAddress ("erd1ykqd64fxxpp4wsz0v7sjqem038wfpzlljhx4mhwx8w9lcxmdzcfszrp64a" ),
296
+ Events : []* transaction.Event {
297
+ {
298
+ Address : decodeAddress ("erd1ykqd64fxxpp4wsz0v7sjqem038wfpzlljhx4mhwx8w9lcxmdzcfszrp64a" ),
299
+ Identifier : []byte (core .CompletedTxEventIdentifier ),
300
+ Topics : [][]byte {[]byte ("t1" ), []byte ("t2" )},
301
+ },
302
+ nil ,
303
+ },
304
+ },
305
+ },
306
+ },
307
+ }
308
+ err = esProc .SaveTransactions (createOutportBlockWithHeader (body , header , pool , nil , testNumOfShards ))
309
+ require .Nil (t , err )
310
+
311
+ ids := []string {hex .EncodeToString (txHash )}
312
+ genericResponse := & GenericResponse {}
313
+ err = esClient .DoMultiGet (context .Background (), ids , indexerdata .TransactionsIndex , true , genericResponse )
314
+ require .Nil (t , err )
315
+
316
+ require .JSONEq (t ,
317
+ readExpectedResult ("./testdata/relayedTxV3/relayed-v3-execution-source.json" ),
318
+ string (genericResponse .Docs [0 ].Source ),
319
+ )
320
+
321
+ // execute scr on destination
322
+ header = & dataBlock.Header {
323
+ Round : 60 ,
324
+ TimeStamp : 6040 ,
325
+ }
326
+
327
+ scrInfo := & outport.SCRInfo {
328
+ SmartContractResult : & smartContractResult.SmartContractResult {
329
+ OriginalTxHash : txHash ,
330
+ },
331
+ FeeInfo : & outport.FeeInfo {
332
+ Fee : big .NewInt (0 ),
333
+ InitialPaidFee : big .NewInt (0 ),
334
+ },
335
+ ExecutionOrder : 0 ,
336
+ }
337
+
338
+ pool = & outport.TransactionPool {
339
+ SmartContractResults : map [string ]* outport.SCRInfo {
340
+ hex .EncodeToString ([]byte ("scr" )): scrInfo ,
341
+ },
342
+ Logs : []* outport.LogData {
343
+ {
344
+ TxHash : hex .EncodeToString ([]byte ("scr" )),
345
+ Log : & transaction.Log {
346
+ Address : decodeAddress ("erd1ykqd64fxxpp4wsz0v7sjqem038wfpzlljhx4mhwx8w9lcxmdzcfszrp64a" ),
347
+ Events : []* transaction.Event {
348
+ {
349
+ Address : decodeAddress ("erd1ykqd64fxxpp4wsz0v7sjqem038wfpzlljhx4mhwx8w9lcxmdzcfszrp64a" ),
350
+ Identifier : []byte (core .SignalErrorOperation ),
351
+ Topics : [][]byte {[]byte ("t1" ), []byte ("t2" )},
352
+ },
353
+ nil ,
354
+ },
355
+ },
356
+ },
357
+ },
358
+ }
359
+ err = esProc .SaveTransactions (createOutportBlockWithHeader (body , header , pool , nil , testNumOfShards ))
360
+ require .Nil (t , err )
361
+
362
+ err = esClient .DoMultiGet (context .Background (), ids , indexerdata .TransactionsIndex , true , genericResponse )
363
+ require .Nil (t , err )
364
+
365
+ require .JSONEq (t ,
366
+ readExpectedResult ("./testdata/relayedTxV3/relayed-v3-execution-scr-on-dest.json" ),
367
+ string (genericResponse .Docs [0 ].Source ),
368
+ )
369
+ }
0 commit comments