Skip to content

Commit

Permalink
Merge pull request #353 from multiversx/extra-check-in-e2e-tests
Browse files Browse the repository at this point in the history
Extra check in e2e tests
  • Loading branch information
iulianpascalau authored Oct 10, 2024
2 parents d93f4b1 + 627afb9 commit af47429
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ func TestRelayersShouldExecuteTransfers(t *testing.T) {
GenerateTestUSDCToken(),
GenerateTestMEMEToken(),
)

// TODO: add a test for the withdrawTotalFeesOnEthereum functionality
}

func TestRelayersShouldExecuteTransfersWithSCCallsWithArguments(t *testing.T) {
Expand Down Expand Up @@ -129,6 +127,9 @@ func testRelayersWithChainSimulatorAndTokens(tb testing.TB, manualStopChan chan

processFunc := func(tb testing.TB, setup *framework.TestSetup) bool {
if startsFromEthFlow.process() && startsFromMvXFlow.process() {
setup.TestWithdrawTotalFeesOnEthereumForTokens(startsFromMvXFlow.tokens...)
setup.TestWithdrawTotalFeesOnEthereumForTokens(startsFromEthFlow.tokens...)

return true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,3 +362,21 @@ func computeTransactionSignature(senderSk []byte, tx *transaction.FrontendTransa

return signer.Sign(privateKey, dataToSign)
}

// ExecuteVMQuery will try to execute a VM query and return the results
func (instance *chainSimulatorWrapper) ExecuteVMQuery(
ctx context.Context,
scAddress *MvxAddress,
function string,
hexParams []string,
) [][]byte {
vmRequest := &data.VmValueRequest{
Address: scAddress.Bech32(),
FuncName: function,
Args: hexParams,
}
response, err := instance.Proxy().ExecuteVMQuery(ctx, vmRequest)
require.Nil(instance, err)

return response.Data.ReturnData
}
1 change: 1 addition & 0 deletions integrationTests/relayers/slowTests/framework/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type ChainSimulatorWrapper interface {
GetESDTBalance(ctx context.Context, address *MvxAddress, token string) string
GetBlockchainTimeStamp(ctx context.Context) uint64
GetTransactionResult(ctx context.Context, hash string) *data.TransactionOnNetwork
ExecuteVMQuery(ctx context.Context, scAddress *MvxAddress, function string, hexParams []string) [][]byte
}

// EthereumBlockchainClient defines the operations supported by the Ethereum client
Expand Down
59 changes: 59 additions & 0 deletions integrationTests/relayers/slowTests/framework/multiversxHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const (
setCallsGasLimit = 80000000 // 80 million
issueTokenGasLimit = 70000000 // 70 million
createDepositGasLimit = 20000000 // 20 million
generalSCCallGasLimit = 50000000 // 50 million
gasLimitPerDataByte = 1500

aggregatorContractPath = "testdata/contracts/mvx/multiversx-price-aggregator-sc.wasm"
Expand Down Expand Up @@ -69,6 +70,10 @@ const (
unwrapTokenFunction = "unwrapToken"
setBridgedTokensWrapperAddressFunction = "setBridgedTokensWrapperAddress"
setMultiTransferAddressFunction = "setMultiTransferAddress"
withdrawRefundFeesForEthereumFunction = "withdrawRefundFeesForEthereum"
getRefundFeesForEthereumFunction = "getRefundFeesForEthereum"
withdrawTransactionFeesFunction = "withdrawTransactionFees"
getTransactionFeesFunction = "getTransactionFees"
initSupplyMintBurnEsdtSafe = "initSupplyMintBurnEsdtSafe"
initSupplyEsdtSafe = "initSupplyEsdtSafe"
)
Expand Down Expand Up @@ -940,6 +945,60 @@ func (handler *MultiversxHandler) SendDepositTransactionFromMultiversx(ctx conte
log.Info("MultiversX->Ethereum transaction sent", "hash", hash, "status", txResult.Status)
}

// TestWithdrawFees will try to withdraw the fees for the provided token from the safe contract to the owner
func (handler *MultiversxHandler) TestWithdrawFees(
ctx context.Context,
token string,
expectedDeltaForRefund *big.Int,
expectedDeltaForAccumulated *big.Int,
) {
handler.withdrawFees(ctx, token, expectedDeltaForRefund, getRefundFeesForEthereumFunction, withdrawRefundFeesForEthereumFunction)
handler.withdrawFees(ctx, token, expectedDeltaForAccumulated, getTransactionFeesFunction, withdrawTransactionFeesFunction)
}

func (handler *MultiversxHandler) withdrawFees(ctx context.Context,
token string,
expectedDelta *big.Int,
getFunction string,
withdrawFunction string,
) {
queryParams := []string{
hex.EncodeToString([]byte(token)),
}
responseData := handler.ChainSimulator.ExecuteVMQuery(ctx, handler.SafeAddress, getFunction, queryParams)
value := big.NewInt(0).SetBytes(responseData[0])
require.Equal(handler, expectedDelta.String(), value.String())
if expectedDelta.Cmp(zeroValueBigInt) == 0 {
return
}

handler.ChainSimulator.GenerateBlocks(ctx, 5) // ensure block finality
initialBalanceStr := handler.ChainSimulator.GetESDTBalance(ctx, handler.OwnerKeys.MvxAddress, token)
initialBalance, ok := big.NewInt(0).SetString(initialBalanceStr, 10)
require.True(handler, ok)

handler.ChainSimulator.ScCall(
ctx,
handler.OwnerKeys.MvxSk,
handler.MultisigAddress,
zeroStringValue,
generalSCCallGasLimit,
withdrawFunction,
[]string{
hex.EncodeToString([]byte(token)),
},
)

handler.ChainSimulator.GenerateBlocks(ctx, 5) // ensure block finality
finalBalanceStr := handler.ChainSimulator.GetESDTBalance(ctx, handler.OwnerKeys.MvxAddress, token)
finalBalance, ok := big.NewInt(0).SetString(finalBalanceStr, 10)
require.True(handler, ok)

require.Equal(handler, expectedDelta, finalBalance.Sub(finalBalance, initialBalance),
fmt.Sprintf("mismatch on balance check after the call to %s: initial balance: %s, final balance %s, expected delta: %s",
withdrawFunction, initialBalanceStr, finalBalanceStr, expectedDelta.String()))
}

func getHexBool(input bool) string {
if input {
return hexTrue
Expand Down
21 changes: 21 additions & 0 deletions integrationTests/relayers/slowTests/framework/testSetup.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,27 @@ func (setup *TestSetup) sendFromMultiversxToEthereumForToken(params TestTokenPar
}
}

// TestWithdrawTotalFeesOnEthereumForTokens will test the withdrawal functionality for the provided test tokens
func (setup *TestSetup) TestWithdrawTotalFeesOnEthereumForTokens(tokensParams ...TestTokenParams) {
for _, param := range tokensParams {
token := setup.TokensRegistry.GetTokenData(param.AbstractTokenIdentifier)

expectedAccumulated := big.NewInt(0)
for _, operation := range param.TestOperations {
if operation.ValueToSendFromMvX == nil {
continue
}
if operation.ValueToSendFromMvX.Cmp(zeroValueBigInt) == 0 {
continue
}

expectedAccumulated.Add(expectedAccumulated, feeInt)
}

setup.MultiversxHandler.TestWithdrawFees(setup.Ctx, token.MvxChainSpecificToken, zeroValueBigInt, expectedAccumulated)
}
}

// Close will close the test subcomponents
func (setup *TestSetup) Close() {
log.Info(fmt.Sprintf(LogStepMarker, "closing relayers & sc execution module"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,33 @@
"outputs": []
},
{
"name": "withdrawTotalFeesOnEthereum",
"name": "withdrawRefundFeesForEthereum",
"onlyOwner": true,
"mutability": "mutable",
"inputs": [
{
"name": "token_id",
"type": "TokenIdentifier"
},
{
"name": "multisig_owner",
"type": "Address"
}
],
"outputs": []
},
{
"name": "withdrawTransactionFees",
"onlyOwner": true,
"mutability": "mutable",
"inputs": [
{
"name": "token_id",
"type": "TokenIdentifier"
},
{
"name": "multisig_owner",
"type": "Address"
}
],
"outputs": []
Expand Down Expand Up @@ -226,6 +246,36 @@
}
]
},
{
"name": "getRefundFeesForEthereum",
"mutability": "readonly",
"inputs": [
{
"name": "token_id",
"type": "TokenIdentifier"
}
],
"outputs": [
{
"type": "BigUint"
}
]
},
{
"name": "getTransactionFees",
"mutability": "readonly",
"inputs": [
{
"name": "token_id",
"type": "TokenIdentifier"
}
],
"outputs": [
{
"type": "BigUint"
}
]
},
{
"name": "getBridgedTokensWrapperAddress",
"mutability": "readonly",
Expand Down
Binary file modified integrationTests/relayers/slowTests/testdata/contracts/mvx/esdt-safe.wasm
100644 → 100755
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,19 @@
"outputs": []
},
{
"name": "withdrawTotalFeesOnEthereum",
"name": "withdrawRefundFeesForEthereum",
"onlyOwner": true,
"mutability": "mutable",
"inputs": [
{
"name": "token_id",
"type": "TokenIdentifier"
}
],
"outputs": []
},
{
"name": "withdrawTransactionFees",
"onlyOwner": true,
"mutability": "mutable",
"inputs": [
Expand Down
Binary file modified integrationTests/relayers/slowTests/testdata/contracts/mvx/multisig.wasm
100644 → 100755
Binary file not shown.

0 comments on commit af47429

Please sign in to comment.