Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More refund scenarios for integration tests #390

Merged
merged 3 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions integrationTests/relayers/slowTests/framework/testSetup.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ func (setup *TestSetup) checkContractMvxBalanceForToken(params TestTokenParams)
if operation.ValueToTransferToMvx == nil {
continue
}
if len(operation.MvxSCCallData) == 0 && !operation.MvxForceSCCall {
if !setup.hasCallData(operation) {
continue
}
if operation.MvxFaultySCCall {
Expand Down Expand Up @@ -496,7 +496,7 @@ func (setup *TestSetup) checkEthMintedBalanceForToken(params TestTokenParams) bo
func (setup *TestSetup) getMvxTotalRefundAmountForToken(params TestTokenParams) *big.Int {
totalRefund := big.NewInt(0)
for _, operation := range params.TestOperations {
if len(operation.MvxSCCallData) == 0 && !operation.MvxForceSCCall {
if !setup.hasCallData(operation) {
continue
}
if !operation.MvxFaultySCCall {
Expand Down Expand Up @@ -561,7 +561,7 @@ func (setup *TestSetup) createDepositOnMultiversxForToken(from KeysHolder, to Ke
continue
}

if operation.InvalidReceiver != nil {
if operation.InvalidReceiver != nil && !setup.hasCallData(operation) {
invalidReceiver := common.Address(operation.InvalidReceiver)
to = KeysHolder{EthAddress: invalidReceiver}
}
Expand Down Expand Up @@ -628,13 +628,22 @@ func (setup *TestSetup) createDepositOnEthereumForToken(from KeysHolder, to Keys

if operation.InvalidReceiver != nil {
invalidReceiver := NewMvxAddressFromBytes(setup, operation.InvalidReceiver)
to = KeysHolder{MvxAddress: invalidReceiver}

if setup.hasCallData(operation) {
targetSCAddress = invalidReceiver
} else {
to = KeysHolder{MvxAddress: invalidReceiver}
}
}

setup.EthereumHandler.SendDepositTransactionFromEthereum(setup.Ctx, from, to, targetSCAddress, token, operation)
}
}

func (setup *TestSetup) hasCallData(operation TokenOperations) bool {
return len(operation.MvxSCCallData) != 0 || operation.MvxForceSCCall
}

// TestWithdrawTotalFeesOnEthereumForTokens will test the withdrawal functionality for the provided test tokens
func (setup *TestSetup) TestWithdrawTotalFeesOnEthereumForTokens(tokensParams ...TestTokenParams) {
for _, param := range tokensParams {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

bridgeCore "github.com/multiversx/mx-bridge-eth-go/core"
"github.com/multiversx/mx-bridge-eth-go/integrationTests/relayers/slowTests/framework"
"github.com/multiversx/mx-sdk-go/data"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -108,6 +109,73 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) {
mexToken,
)
})
t.Run("uninitialized contract should refund", func(t *testing.T) {
callData := createScCallData("claim", 50000000)
uninitializedSCAddressBytes, _ := data.NewAddressFromBech32String("erd1qqqqqqqqqqqqqpgqcc69ts8409p3h77q5chsaqz57y6hugvc4fvs64k74v")
usdcToken := GenerateTestUSDCToken()
usdcToken.TestOperations[2].MvxSCCallData = callData
usdcToken.TestOperations[2].MvxFaultySCCall = true
usdcToken.TestOperations[2].InvalidReceiver = uninitializedSCAddressBytes.AddressBytes()
ApplyUSDCRefundBalances(&usdcToken)

memeToken := GenerateTestMEMEToken()
memeToken.TestOperations[2].MvxSCCallData = callData
memeToken.TestOperations[2].MvxFaultySCCall = true
memeToken.TestOperations[2].InvalidReceiver = uninitializedSCAddressBytes.AddressBytes()
ApplyMEMERefundBalances(&memeToken)

eurocToken := GenerateTestEUROCToken()
eurocToken.TestOperations[2].MvxSCCallData = callData
eurocToken.TestOperations[2].MvxFaultySCCall = true
eurocToken.TestOperations[2].InvalidReceiver = uninitializedSCAddressBytes.AddressBytes()
ApplyEUROCRefundBalances(&eurocToken)

mexToken := GenerateTestMEXToken()
mexToken.TestOperations[2].MvxSCCallData = callData
mexToken.TestOperations[2].MvxFaultySCCall = true
mexToken.TestOperations[2].InvalidReceiver = uninitializedSCAddressBytes.AddressBytes()
ApplyMEXRefundBalances(&mexToken)

testRelayersWithChainSimulatorAndTokensAndRefund(
t,
make(chan error),
usdcToken,
memeToken,
eurocToken,
mexToken,
)
})
t.Run("built-in function should refund", func(t *testing.T) {
callData := createScCallData("SaveKeyValue", 50000000, "6b657930", "76616c756530")
usdcToken := GenerateTestUSDCToken()
usdcToken.TestOperations[2].MvxSCCallData = callData
usdcToken.TestOperations[2].MvxFaultySCCall = true
ApplyUSDCRefundBalances(&usdcToken)

memeToken := GenerateTestMEMEToken()
memeToken.TestOperations[2].MvxSCCallData = callData
memeToken.TestOperations[2].MvxFaultySCCall = true
ApplyMEMERefundBalances(&memeToken)

eurocToken := GenerateTestEUROCToken()
eurocToken.TestOperations[2].MvxSCCallData = callData
eurocToken.TestOperations[2].MvxFaultySCCall = true
ApplyEUROCRefundBalances(&eurocToken)

mexToken := GenerateTestMEXToken()
mexToken.TestOperations[2].MvxSCCallData = callData
mexToken.TestOperations[2].MvxFaultySCCall = true
ApplyMEXRefundBalances(&mexToken)

testRelayersWithChainSimulatorAndTokensAndRefund(
t,
make(chan error),
usdcToken,
memeToken,
eurocToken,
mexToken,
)
})
t.Run("wrong deposit with empty sc call data should refund", func(t *testing.T) {
usdcToken := GenerateTestUSDCToken()
usdcToken.TestOperations[2].MvxSCCallData = nil
Expand Down Expand Up @@ -204,6 +272,37 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) {
mexToken,
)
})
t.Run("high gas limit should refund", func(t *testing.T) {
callData := createScCallData("callPayable", 610000000)
usdcToken := GenerateTestUSDCToken()
usdcToken.TestOperations[2].MvxSCCallData = callData
usdcToken.TestOperations[2].MvxFaultySCCall = true
ApplyUSDCRefundBalances(&usdcToken)

memeToken := GenerateTestMEMEToken()
memeToken.TestOperations[2].MvxSCCallData = callData
memeToken.TestOperations[2].MvxFaultySCCall = true
ApplyMEMERefundBalances(&memeToken)

eurocToken := GenerateTestEUROCToken()
eurocToken.TestOperations[2].MvxSCCallData = callData
eurocToken.TestOperations[2].MvxFaultySCCall = true
ApplyEUROCRefundBalances(&eurocToken)

mexToken := GenerateTestMEXToken()
mexToken.TestOperations[2].MvxSCCallData = callData
mexToken.TestOperations[2].MvxFaultySCCall = true
ApplyMEXRefundBalances(&mexToken)

testRelayersWithChainSimulatorAndTokensAndRefund(
t,
make(chan error),
usdcToken,
memeToken,
eurocToken,
mexToken,
)
})
t.Run("extra parameter should refund", func(t *testing.T) {
callData := createScCallData("callPayable", 50000000, "extra parameter")
usdcToken := GenerateTestUSDCToken()
Expand Down
Loading