-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #319 from multiversx/relayed-v3-multiple-scrs-with…
…-refund Multiple scrs with refund
- Loading branch information
Showing
13 changed files
with
281 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
//go:build integrationtests | ||
|
||
package integrationtests | ||
|
||
import ( | ||
"context" | ||
"encoding/hex" | ||
"math/big" | ||
"testing" | ||
|
||
dataBlock "github.com/multiversx/mx-chain-core-go/data/block" | ||
"github.com/multiversx/mx-chain-core-go/data/outport" | ||
"github.com/multiversx/mx-chain-core-go/data/smartContractResult" | ||
"github.com/multiversx/mx-chain-core-go/data/transaction" | ||
indexerdata "github.com/multiversx/mx-chain-es-indexer-go/process/dataindexer" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestRelayedV3TransactionWithMultipleRefunds(t *testing.T) { | ||
setLogLevelDebug() | ||
|
||
esClient, err := createESClient(esURL) | ||
require.Nil(t, err) | ||
|
||
esProc, err := CreateElasticProcessor(esClient) | ||
require.Nil(t, err) | ||
|
||
txHash := []byte("relayedTxV3WithMultipleRefunds") | ||
header := &dataBlock.Header{ | ||
Round: 50, | ||
TimeStamp: 5040, | ||
} | ||
|
||
body := &dataBlock.Body{ | ||
MiniBlocks: dataBlock.MiniBlockSlice{ | ||
{ | ||
Type: dataBlock.TxBlock, | ||
SenderShardID: 0, | ||
ReceiverShardID: 0, | ||
TxHashes: [][]byte{txHash}, | ||
}, | ||
}, | ||
} | ||
|
||
initialTx := &transaction.Transaction{ | ||
Nonce: 1000, | ||
SndAddr: decodeAddress("erd1ykqd64fxxpp4wsz0v7sjqem038wfpzlljhx4mhwx8w9lcxmdzcfszrp64a"), | ||
RcvAddr: decodeAddress("erd1qqqqqqqqqqqqqpgqak8zt22wl2ph4tswtyc39namqx6ysa2sd8ss4xmlj3"), | ||
RelayerAddr: decodeAddress("erd10ksryjr065ad5475jcg82pnjfg9j9qtszjsrp24anl6ym7cmeddshwnru8"), | ||
Signature: []byte("d"), | ||
RelayerSignature: []byte("a"), | ||
GasLimit: 500_000_000, | ||
GasPrice: 1000000000, | ||
Value: big.NewInt(0), | ||
Data: []byte("doSomething"), | ||
} | ||
|
||
txInfo := &outport.TxInfo{ | ||
Transaction: initialTx, | ||
FeeInfo: &outport.FeeInfo{ | ||
GasUsed: 180_150_000, | ||
Fee: big.NewInt(2864760000000000), | ||
InitialPaidFee: big.NewInt(2864760000000000), | ||
}, | ||
ExecutionOrder: 0, | ||
} | ||
|
||
pool := &outport.TransactionPool{ | ||
Transactions: map[string]*outport.TxInfo{ | ||
hex.EncodeToString(txHash): txInfo, | ||
}, | ||
} | ||
err = esProc.SaveTransactions(createOutportBlockWithHeader(body, header, pool, nil, testNumOfShards)) | ||
require.Nil(t, err) | ||
|
||
ids := []string{hex.EncodeToString(txHash)} | ||
genericResponse := &GenericResponse{} | ||
err = esClient.DoMultiGet(context.Background(), ids, indexerdata.TransactionsIndex, true, genericResponse) | ||
require.Nil(t, err) | ||
|
||
require.JSONEq(t, | ||
readExpectedResult("./testdata/relayedTxV3/relayed-v3-no-refund.json"), | ||
string(genericResponse.Docs[0].Source), | ||
) | ||
|
||
// execute first SCR with refund | ||
pool = &outport.TransactionPool{ | ||
SmartContractResults: map[string]*outport.SCRInfo{ | ||
"scrHash": { | ||
SmartContractResult: &smartContractResult.SmartContractResult{ | ||
OriginalTxHash: txHash, | ||
}, | ||
FeeInfo: &outport.FeeInfo{ | ||
GasRefunded: 9_692_000, | ||
Fee: big.NewInt(96920000000000), | ||
}, | ||
}, | ||
}, | ||
} | ||
err = esProc.SaveTransactions(createOutportBlockWithHeader(body, header, pool, nil, testNumOfShards)) | ||
require.Nil(t, err) | ||
|
||
ids = []string{hex.EncodeToString(txHash)} | ||
genericResponse = &GenericResponse{} | ||
err = esClient.DoMultiGet(context.Background(), ids, indexerdata.TransactionsIndex, true, genericResponse) | ||
require.Nil(t, err) | ||
|
||
require.JSONEq(t, | ||
readExpectedResult("./testdata/relayedTxV3/relayed-v3-with-one-refund.json"), | ||
string(genericResponse.Docs[0].Source), | ||
) | ||
|
||
// execute second SCR with refund | ||
pool = &outport.TransactionPool{ | ||
SmartContractResults: map[string]*outport.SCRInfo{ | ||
"scrHash": { | ||
SmartContractResult: &smartContractResult.SmartContractResult{ | ||
OriginalTxHash: txHash, | ||
}, | ||
FeeInfo: &outport.FeeInfo{ | ||
GasRefunded: 9_692_000, | ||
Fee: big.NewInt(96920000000000), | ||
}, | ||
}, | ||
}, | ||
} | ||
err = esProc.SaveTransactions(createOutportBlockWithHeader(body, header, pool, nil, testNumOfShards)) | ||
require.Nil(t, err) | ||
|
||
ids = []string{hex.EncodeToString(txHash)} | ||
genericResponse = &GenericResponse{} | ||
err = esClient.DoMultiGet(context.Background(), ids, indexerdata.TransactionsIndex, true, genericResponse) | ||
require.Nil(t, err) | ||
|
||
require.JSONEq(t, | ||
readExpectedResult("./testdata/relayedTxV3/relayed-v3-with-two-refunds.json"), | ||
string(genericResponse.Docs[0].Source), | ||
) | ||
} |
28 changes: 28 additions & 0 deletions
28
integrationtests/testdata/relayedTxV3/relayed-v3-no-refund.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"miniBlockHash": "785a251c08b314939528e553ac879dbee0627fbe2b76c0bca601c3f1e7162640", | ||
"nonce": 1000, | ||
"round": 50, | ||
"value": "0", | ||
"valueNum": 0, | ||
"receiver": "erd1qqqqqqqqqqqqqpgqak8zt22wl2ph4tswtyc39namqx6ysa2sd8ss4xmlj3", | ||
"sender": "erd1ykqd64fxxpp4wsz0v7sjqem038wfpzlljhx4mhwx8w9lcxmdzcfszrp64a", | ||
"receiverShard": 0, | ||
"senderShard": 0, | ||
"gasPrice": 1000000000, | ||
"gasLimit": 500000000, | ||
"gasUsed": 180150000, | ||
"fee": "2864760000000000", | ||
"feeNum": 0.00286476, | ||
"initialPaidFee": "2864760000000000", | ||
"data": "ZG9Tb21ldGhpbmc=", | ||
"signature": "64", | ||
"timestamp": 5040, | ||
"status": "success", | ||
"searchOrder": 0, | ||
"isScCall": true, | ||
"operation": "transfer", | ||
"function": "doSomething", | ||
"isRelayed": true, | ||
"relayer": "erd10ksryjr065ad5475jcg82pnjfg9j9qtszjsrp24anl6ym7cmeddshwnru8", | ||
"relayerSignature": "61" | ||
} |
29 changes: 29 additions & 0 deletions
29
integrationtests/testdata/relayedTxV3/relayed-v3-with-one-refund.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"miniBlockHash": "785a251c08b314939528e553ac879dbee0627fbe2b76c0bca601c3f1e7162640", | ||
"nonce": 1000, | ||
"round": 50, | ||
"value": "0", | ||
"valueNum": 0, | ||
"receiver": "erd1qqqqqqqqqqqqqpgqak8zt22wl2ph4tswtyc39namqx6ysa2sd8ss4xmlj3", | ||
"sender": "erd1ykqd64fxxpp4wsz0v7sjqem038wfpzlljhx4mhwx8w9lcxmdzcfszrp64a", | ||
"receiverShard": 0, | ||
"senderShard": 0, | ||
"gasPrice": 1000000000, | ||
"gasLimit": 500000000, | ||
"gasUsed": 170458000, | ||
"fee": "2767840000000000", | ||
"feeNum": 0.00276784, | ||
"initialPaidFee": "2864760000000000", | ||
"data": "ZG9Tb21ldGhpbmc=", | ||
"signature": "64", | ||
"timestamp": 5040, | ||
"status": "success", | ||
"searchOrder": 0, | ||
"isScCall": true, | ||
"operation": "transfer", | ||
"function": "doSomething", | ||
"isRelayed": true, | ||
"relayer": "erd10ksryjr065ad5475jcg82pnjfg9j9qtszjsrp24anl6ym7cmeddshwnru8", | ||
"relayerSignature": "61", | ||
"hadRefund": true | ||
} |
29 changes: 29 additions & 0 deletions
29
integrationtests/testdata/relayedTxV3/relayed-v3-with-two-refunds.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"miniBlockHash": "785a251c08b314939528e553ac879dbee0627fbe2b76c0bca601c3f1e7162640", | ||
"nonce": 1000, | ||
"round": 50, | ||
"value": "0", | ||
"valueNum": 0, | ||
"receiver": "erd1qqqqqqqqqqqqqpgqak8zt22wl2ph4tswtyc39namqx6ysa2sd8ss4xmlj3", | ||
"sender": "erd1ykqd64fxxpp4wsz0v7sjqem038wfpzlljhx4mhwx8w9lcxmdzcfszrp64a", | ||
"receiverShard": 0, | ||
"senderShard": 0, | ||
"gasPrice": 1000000000, | ||
"gasLimit": 500000000, | ||
"gasUsed": 160766000, | ||
"fee": "2670920000000000", | ||
"feeNum": 0.0026709200000000002, | ||
"initialPaidFee": "2864760000000000", | ||
"data": "ZG9Tb21ldGhpbmc=", | ||
"signature": "64", | ||
"timestamp": 5040, | ||
"status": "success", | ||
"searchOrder": 0, | ||
"isScCall": true, | ||
"operation": "transfer", | ||
"function": "doSomething", | ||
"isRelayed": true, | ||
"relayer": "erd10ksryjr065ad5475jcg82pnjfg9j9qtszjsrp24anl6ym7cmeddshwnru8", | ||
"relayerSignature": "61", | ||
"hadRefund": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters