Skip to content

Commit

Permalink
Merge pull request #2981 from ElrondNetwork/transfer-and-execute-no-e…
Browse files Browse the repository at this point in the history
…rr-treat

Transfer and execute no err treat
  • Loading branch information
sasurobert committed Apr 9, 2021
2 parents 1e9f376 + d600ab6 commit b9dd408
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 45 deletions.
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -3,7 +3,7 @@ module github.com/ElrondNetwork/elrond-go
go 1.13

require (
github.com/ElrondNetwork/arwen-wasm-vm v1.2.3
github.com/ElrondNetwork/arwen-wasm-vm v1.2.4
github.com/ElrondNetwork/concurrent-map v0.1.3
github.com/ElrondNetwork/elastic-indexer-go v1.0.3
github.com/ElrondNetwork/elrond-go-logger v1.0.4
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Expand Up @@ -23,8 +23,8 @@ github.com/ElrondNetwork/arwen-wasm-vm v1.1.2-0.20210226164828-e74ecd83baa1/go.m
github.com/ElrondNetwork/arwen-wasm-vm v1.1.3-0.20210309184230-68eac15cd9dd/go.mod h1:anqjyN3fz8L5ySrpgOexA9YsEZVd0ixSMnORhBa12/0=
github.com/ElrondNetwork/arwen-wasm-vm v1.1.3-0.20210317161751-82d31c8caa34/go.mod h1:VZVOP47Fa2SRL6RfFbZYDpIQgFwGnfyO11ss3ACc93k=
github.com/ElrondNetwork/arwen-wasm-vm v1.1.3-0.20210319111725-093234eb3f90/go.mod h1:ecpMev5UmUkMSOB9fEz01Sf88lkuNIXp6H/+kt32XsQ=
github.com/ElrondNetwork/arwen-wasm-vm v1.2.3 h1:ouT6xQaA9PaBw5sFOQNTS9jQF3RpueZUG5HGaOJjSU0=
github.com/ElrondNetwork/arwen-wasm-vm v1.2.3/go.mod h1:Io5YGUs48YNnXlyJYSBX6Evxcc0JUfLbjF+65qdl+10=
github.com/ElrondNetwork/arwen-wasm-vm v1.2.4 h1:4mdJQUk1mueOErCwnpc1u+vusL1Me6rNc5E96kj4KVc=
github.com/ElrondNetwork/arwen-wasm-vm v1.2.4/go.mod h1:Io5YGUs48YNnXlyJYSBX6Evxcc0JUfLbjF+65qdl+10=
github.com/ElrondNetwork/big-int-util v0.0.5/go.mod h1:96viBvoTXLjZOhEvE0D+QnAwg1IJLPAK6GVHMbC7Aw4=
github.com/ElrondNetwork/big-int-util v0.1.0 h1:vTMoJ5azhVmr7jhpSD3JUjQdkdyXoEPVkOvhdw1RjV4=
github.com/ElrondNetwork/big-int-util v0.1.0/go.mod h1:96viBvoTXLjZOhEvE0D+QnAwg1IJLPAK6GVHMbC7Aw4=
Expand Down
6 changes: 3 additions & 3 deletions integrationTests/vm/esdt/esdtNFTSCs_test.go
Expand Up @@ -64,7 +64,7 @@ func TestESDTNFTIssueCreateBurnSendViaAsyncViaExecuteOnSC(t *testing.T) {
)

time.Sleep(time.Second)
nonce, round = integrationTests.WaitOperationToBeDone(t, nodes, 2, nonce, round, idxProposers)
nonce, round = integrationTests.WaitOperationToBeDone(t, nodes, 3, nonce, round, idxProposers)
time.Sleep(time.Second)

checkAddressHasNft(t, scAddress, scAddress, nodes, tokenIdentifier, 3, big.NewInt(1))
Expand All @@ -91,7 +91,7 @@ func TestESDTNFTIssueCreateBurnSendViaAsyncViaExecuteOnSC(t *testing.T) {
)

time.Sleep(time.Second)
nonce, round = integrationTests.WaitOperationToBeDone(t, nodes, 2, nonce, round, idxProposers)
nonce, round = integrationTests.WaitOperationToBeDone(t, nodes, 3, nonce, round, idxProposers)
time.Sleep(time.Second)

checkAddressHasNft(t, scAddress, scAddress, nodes, tokenIdentifier, 2, big.NewInt(1))
Expand Down Expand Up @@ -122,7 +122,7 @@ func TestESDTNFTIssueCreateBurnSendViaAsyncViaExecuteOnSC(t *testing.T) {
integrationTests.AdditionalGasLimit,
)
time.Sleep(time.Second)
nonce, round = integrationTests.WaitOperationToBeDone(t, nodes, 2, nonce, round, idxProposers)
nonce, round = integrationTests.WaitOperationToBeDone(t, nodes, 3, nonce, round, idxProposers)
time.Sleep(time.Second)

checkAddressHasNft(t, scAddress, destinationAddress, nodes, tokenIdentifier, 2, big.NewInt(1))
Expand Down
59 changes: 30 additions & 29 deletions integrationTests/vm/esdt/esdtProcess_test.go
Expand Up @@ -1017,31 +1017,8 @@ func TestScCallsScWithEsdtIntraShard_SecondScRefusesPayment(t *testing.T) {
_, err = nodes[0].AccntState.GetExistingAccount(firstScAddress)
require.Nil(t, err)

txData := txDataBuilder.NewBuilder()

// call first sc with esdt, and first sc automatically calls second sc which returns error
valueToSendToSc := int64(1000)
txData.Clear().TransferESDT(tokenIdentifier, valueToSendToSc)
txData.Str("transfer_to_second_contract_rejected")
integrationTests.CreateAndSendTransaction(
tokenIssuer,
nodes,
big.NewInt(0),
firstScAddress,
txData.ToString(),
integrationTests.AdditionalGasLimit)

time.Sleep(time.Second)
_, _ = integrationTests.WaitOperationToBeDone(t, nodes, nrRoundsToPropagateMultiShard, nonce, round, idxProposers)
time.Sleep(time.Second)

checkAddressHasESDTTokens(t, tokenIssuer.OwnAccount.Address, nodes, tokenIdentifier, initialSupply-valueToSendToSc)

esdtData := getESDTTokenData(t, firstScAddress, nodes, tokenIdentifier)
require.Equal(t, &esdt.ESDigitalToken{Value: big.NewInt(valueToSendToSc)}, esdtData)

esdtData = getESDTTokenData(t, secondScAddress, nodes, tokenIdentifier)
require.Equal(t, &esdt.ESDigitalToken{}, esdtData)
nonce, round = transferRejectedBySecondContract(t, nonce, round, nodes, tokenIssuer, idxProposers, initialSupply, tokenIdentifier, firstScAddress, secondScAddress, "transferToSecondContractRejected", 2)
_, _ = transferRejectedBySecondContract(t, nonce, round, nodes, tokenIssuer, idxProposers, initialSupply, tokenIdentifier, firstScAddress, secondScAddress, "transferToSecondContractRejectedWithTransferAndExecute", 2)
}

func TestScACallsScBWithExecOnDestESDT_TxPending(t *testing.T) {
Expand Down Expand Up @@ -1529,16 +1506,38 @@ func TestScCallsScWithEsdtCrossShard_SecondScRefusesPayment(t *testing.T) {
_, err = nodes[2].AccntState.GetExistingAccount(firstScAddress)
require.Nil(t, err)

txData := txDataBuilder.NewBuilder()
nonce, round = transferRejectedBySecondContract(t, nonce, round, nodes, tokenIssuer, idxProposers, initialSupply, tokenIdentifier, firstScAddress, secondScAddress, "transferToSecondContractRejected", 20)
_, _ = transferRejectedBySecondContract(t, nonce, round, nodes, tokenIssuer, idxProposers, initialSupply, tokenIdentifier, firstScAddress, secondScAddress, "transferToSecondContractRejectedWithTransferAndExecute", 20)
}

func transferRejectedBySecondContract(
t *testing.T,
nonce, round uint64,
nodes []*integrationTests.TestProcessorNode,
tokenIssuer *integrationTests.TestProcessorNode,
idxProposers []int,
initialSupply int64,
tokenIdentifier string,
firstScAddress []byte,
secondScAddress []byte,
functionToCall string,
nrRoundToPropagate int,
) (uint64, uint64) {
// call first sc with esdt, and first sc automatically calls second sc which returns error
valueToSendToSc := int64(1000)
txData := txDataBuilder.NewBuilder()
txData.Clear().TransferESDT(tokenIdentifier, valueToSendToSc)
txData.Str("transfer_to_second_contract_rejected")
integrationTests.CreateAndSendTransaction(tokenIssuer, nodes, big.NewInt(0), firstScAddress, txData.ToString(), integrationTests.AdditionalGasLimit)
txData.Str(functionToCall)
integrationTests.CreateAndSendTransaction(
tokenIssuer,
nodes,
big.NewInt(0),
firstScAddress,
txData.ToString(),
integrationTests.AdditionalGasLimit)

time.Sleep(time.Second)
_, _ = integrationTests.WaitOperationToBeDone(t, nodes, nrRoundsToPropagateMultiShard*2, nonce, round, idxProposers)
nonce, round = integrationTests.WaitOperationToBeDone(t, nodes, nrRoundToPropagate, nonce, round, idxProposers)
time.Sleep(time.Second)

checkAddressHasESDTTokens(t, tokenIssuer.OwnAccount.Address, nodes, tokenIdentifier, initialSupply-valueToSendToSc)
Expand All @@ -1548,6 +1547,8 @@ func TestScCallsScWithEsdtCrossShard_SecondScRefusesPayment(t *testing.T) {

esdtData = getESDTTokenData(t, secondScAddress, nodes, tokenIdentifier)
require.Equal(t, &esdt.ESDigitalToken{}, esdtData)

return nonce, round
}

func TestESDTMultiTransferFromSC(t *testing.T) {
Expand Down
Binary file modified integrationTests/vm/esdt/testdata/first-contract.wasm
Binary file not shown.
4 changes: 2 additions & 2 deletions integrationTests/vm/txsFee/asyncESDT_test.go
Expand Up @@ -111,13 +111,13 @@ func TestAsyncESDTCallSecondScRefusesPayment(t *testing.T) {
tx.Data = []byte(string(tx.Data) + "@" + hex.EncodeToString([]byte("transferToSecondContractRejected")))

retCode, err := testContext.TxProcessor.ProcessTransaction(tx)
require.Equal(t, vmcommon.UserError, retCode)
require.Equal(t, vmcommon.Ok, retCode)
require.Nil(t, err)

_, err = testContext.Accounts.Commit()
require.Nil(t, err)

utils.CheckESDTBalance(t, testContext, firstSCAddress, token, big.NewInt(0))
utils.CheckESDTBalance(t, testContext, firstSCAddress, token, big.NewInt(5000))
utils.CheckESDTBalance(t, testContext, secondSCAddress, token, big.NewInt(0))

expectedSenderBalance := big.NewInt(95000000)
Expand Down
12 changes: 6 additions & 6 deletions integrationTests/vm/txsFee/multiShard/asyncESDT_test.go
Expand Up @@ -95,10 +95,10 @@ func TestAsyncESDTTransferWithSCCallShouldWork(t *testing.T) {
_, err = testContextSender.Accounts.Commit()
require.Nil(t, err)

expectedAccumulatedFees = big.NewInt(183070)
expectedAccumulatedFees = big.NewInt(190300)
require.Equal(t, expectedAccumulatedFees, testContextFirstContract.TxFeeHandler.GetAccumulatedFees())

developerFees := big.NewInt(18306)
developerFees := big.NewInt(19029)
require.Equal(t, developerFees, testContextFirstContract.TxFeeHandler.GetDeveloperFees())

utils.CheckESDTBalance(t, testContextFirstContract, firstSCAddress, token, big.NewInt(2500))
Expand Down Expand Up @@ -215,10 +215,10 @@ func TestAsyncESDTTransferWithSCCallSecondContractAnotherToken(t *testing.T) {
_, err = testContextSender.Accounts.Commit()
require.Nil(t, err)

expectedAccumulatedFees = big.NewInt(183070)
expectedAccumulatedFees = big.NewInt(190300)
require.Equal(t, expectedAccumulatedFees, testContextFirstContract.TxFeeHandler.GetAccumulatedFees())

developerFees := big.NewInt(18306)
developerFees := big.NewInt(19029)
require.Equal(t, developerFees, testContextFirstContract.TxFeeHandler.GetDeveloperFees())

utils.CheckESDTBalance(t, testContextFirstContract, firstSCAddress, token, big.NewInt(2500))
Expand All @@ -238,7 +238,7 @@ func TestAsyncESDTTransferWithSCCallSecondContractAnotherToken(t *testing.T) {

utils.CheckESDTBalance(t, testContextSecondContract, secondSCAddress, token, big.NewInt(0))

accumulatedFee := big.NewInt(3740770)
accumulatedFee := big.NewInt(3720360)
require.Equal(t, accumulatedFee, testContextSecondContract.TxFeeHandler.GetAccumulatedFees())

developerFees = big.NewInt(0)
Expand All @@ -249,5 +249,5 @@ func TestAsyncESDTTransferWithSCCallSecondContractAnotherToken(t *testing.T) {

utils.ProcessSCRResult(t, testContextFirstContract, intermediateTxs[0], vmcommon.Ok, nil)

require.Equal(t, big.NewInt(1258280), testContextFirstContract.TxFeeHandler.GetAccumulatedFees())
require.Equal(t, big.NewInt(1278690), testContextFirstContract.TxFeeHandler.GetAccumulatedFees())
}
4 changes: 2 additions & 2 deletions integrationTests/vm/txsFee/relayedAsyncESDT_test.go
Expand Up @@ -121,13 +121,13 @@ func TestRelayedAsyncESDTCall_InvalidCallFirstContract(t *testing.T) {
rtx := vm.CreateTransaction(0, innerTx.Value, relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData)

retCode, err := testContext.TxProcessor.ProcessTransaction(rtx)
require.Equal(t, vmcommon.UserError, retCode)
require.Equal(t, vmcommon.Ok, retCode)
require.Nil(t, err)

_, err = testContext.Accounts.Commit()
require.Nil(t, err)

utils.CheckESDTBalance(t, testContext, firstSCAddress, token, big.NewInt(0))
utils.CheckESDTBalance(t, testContext, firstSCAddress, token, big.NewInt(5000))
utils.CheckESDTBalance(t, testContext, secondSCAddress, token, big.NewInt(0))

expectedSenderBalance := big.NewInt(94996270)
Expand Down

0 comments on commit b9dd408

Please sign in to comment.