Skip to content

Commit

Permalink
Merge pull request #364 from multiversx/more-e2e-tests
Browse files Browse the repository at this point in the history
Integrate new contracts & added more e2e tests
  • Loading branch information
dragos-rebegea authored Oct 22, 2024
2 parents d7415cd + 4541076 commit 9993ccc
Show file tree
Hide file tree
Showing 14 changed files with 370 additions and 136 deletions.
2 changes: 1 addition & 1 deletion integrationTests/relayers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func CreateBridgeComponentsConfig(index int, workingDir string, gasStationURL st
MultisigContractAddress: "3009d97FfeD62E57d444e552A9eDF9Ee6Bc8644c",
PrivateKeyFile: fmt.Sprintf("testdata/ethereum%d.sk", index),
IntervalToResendTxsInSeconds: 10,
GasLimitBase: 200000,
GasLimitBase: 350000,
GasLimitForEach: 30000,
GasStation: config.GasStationConfig{
Enabled: len(gasStationURL) > 0,
Expand Down
5 changes: 3 additions & 2 deletions integrationTests/relayers/multiversXToEth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
)

var zero = big.NewInt(0)
var relayerEthBalance = big.NewInt(1000000000)

func asyncCancelCall(cancelHandler func(), delay time.Duration) {
go func() {
Expand Down Expand Up @@ -55,7 +56,7 @@ func TestRelayersShouldExecuteSimpleTransfersFromMultiversXToEth(t *testing.T) {
return expectedStatuses, true
}
ethereumChainMock.BalanceAtCalled = func(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error) {
return big.NewInt(260000000), nil
return relayerEthBalance, nil
}
multiversXChainMock := mock.NewMultiversXChainMock()
for i := 0; i < len(deposits); i++ {
Expand Down Expand Up @@ -152,7 +153,7 @@ func testRelayersShouldExecuteTransfersFromMultiversXToEthIfTransactionsAppearIn
return expectedStatuses, true
}
ethereumChainMock.BalanceAtCalled = func(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error) {
return big.NewInt(260000000), nil
return relayerEthBalance, nil
}
multiversXChainMock := mock.NewMultiversXChainMock()
for i := 0; i < len(deposits); i++ {
Expand Down
94 changes: 90 additions & 4 deletions integrationTests/relayers/slowTests/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ func GenerateTestUSDCToken() framework.TestTokenParams {
ValueToMintOnMvx: "10000000000",
IsMintBurnOnMvX: true,
IsNativeOnMvX: false,
EthTokenName: "ETHTOKEN",
EthTokenSymbol: "ETHT",
HasChainSpecificToken: true,
EthTokenName: "EthUSDC",
EthTokenSymbol: "USDC",
ValueToMintOnEth: "10000000000",
IsMintBurnOnEth: false,
IsNativeOnEth: true,
Expand Down Expand Up @@ -72,8 +73,9 @@ func GenerateTestMEMEToken() framework.TestTokenParams {
ValueToMintOnMvx: "10000000000",
IsMintBurnOnMvX: false,
IsNativeOnMvX: true,
EthTokenName: "ETHMEME",
EthTokenSymbol: "ETHM",
HasChainSpecificToken: true,
EthTokenName: "EthMEME",
EthTokenSymbol: "MEME",
ValueToMintOnEth: "10000000000",
IsMintBurnOnEth: true,
IsNativeOnEth: false,
Expand All @@ -98,6 +100,90 @@ func GenerateTestMEMEToken() framework.TestTokenParams {
}
}

// GenerateTestEUROCToken will generate a test EUROC token
func GenerateTestEUROCToken() framework.TestTokenParams {
//EUROC is ethNative = true, ethMintBurn = true, mvxNative = false, mvxMintBurn = true
return framework.TestTokenParams{
IssueTokenParams: framework.IssueTokenParams{
AbstractTokenIdentifier: "EUROC",
NumOfDecimalsUniversal: 6,
NumOfDecimalsChainSpecific: 6,
MvxUniversalTokenTicker: "EUROC",
MvxChainSpecificTokenTicker: "EUROC",
MvxUniversalTokenDisplayName: "TestEUROC",
MvxChainSpecificTokenDisplayName: "TestEUROC",
ValueToMintOnMvx: "10000000000",
IsMintBurnOnMvX: true,
IsNativeOnMvX: false,
HasChainSpecificToken: false,
EthTokenName: "EthEuroC",
EthTokenSymbol: "EUROC",
ValueToMintOnEth: "10000000000",
IsMintBurnOnEth: true,
IsNativeOnEth: true,
},
TestOperations: []framework.TokenOperations{
{
ValueToTransferToMvx: big.NewInt(5010),
ValueToSendFromMvX: big.NewInt(2510),
},
{
ValueToTransferToMvx: big.NewInt(7010),
ValueToSendFromMvX: big.NewInt(310),
},
{
ValueToTransferToMvx: big.NewInt(1010),
ValueToSendFromMvX: nil,
MvxSCCallData: createScCallData("callPayable", 50000000),
},
},
ESDTSafeExtraBalance: big.NewInt(100), // extra is just for the fees for the 2 transfers mvx->eth
EthTestAddrExtraBalance: big.NewInt(-5010 + 2510 - 50 - 7010 + 310 - 50 - 1010), // -(eth->mvx) + (mvx->eth) - fees
}
}

// GenerateTestMEXToken will generate a test EUROC token
func GenerateTestMEXToken() framework.TestTokenParams {
//MEX is ethNative = false, ethMintBurn = true, mvxNative = true, mvxMintBurn = true
return framework.TestTokenParams{
IssueTokenParams: framework.IssueTokenParams{
AbstractTokenIdentifier: "MEX",
NumOfDecimalsUniversal: 2,
NumOfDecimalsChainSpecific: 2,
MvxUniversalTokenTicker: "MEX",
MvxChainSpecificTokenTicker: "MEX",
MvxUniversalTokenDisplayName: "TestMEX",
MvxChainSpecificTokenDisplayName: "TestMEX",
ValueToMintOnMvx: "10000000000",
IsMintBurnOnMvX: true,
IsNativeOnMvX: true,
HasChainSpecificToken: false,
EthTokenName: "EthMex",
EthTokenSymbol: "MEX",
ValueToMintOnEth: "10000000000",
IsMintBurnOnEth: true,
IsNativeOnEth: false,
},
TestOperations: []framework.TokenOperations{
{
ValueToTransferToMvx: big.NewInt(2410),
ValueToSendFromMvX: big.NewInt(4010),
},
{
ValueToTransferToMvx: big.NewInt(210),
ValueToSendFromMvX: big.NewInt(6010),
},
{
ValueToTransferToMvx: big.NewInt(1010),
ValueToSendFromMvX: big.NewInt(2010),
MvxSCCallData: createScCallData("callPayable", 50000000),
},
},
ESDTSafeExtraBalance: big.NewInt(150), // just the fees should be collected in ESDT safe
EthTestAddrExtraBalance: big.NewInt(4010 - 50 + 6010 - 50 + 2010 - 50),
}
}

func createScCallData(function string, gasLimit uint64, args ...string) []byte {
codec := testsCommon.TestMultiversXCodec{}
callData := parsers.CallData{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ func TestRelayersShouldExecuteTransfers(t *testing.T) {
)
}

func TestRelayersShouldExecuteTransfersWithMintBurnTokens(t *testing.T) {
_ = testRelayersWithChainSimulatorAndTokens(
t,
make(chan error),
GenerateTestEUROCToken(),
GenerateTestMEXToken(),
)
}

func TestRelayersShouldExecuteTransfersWithSCCallsWithArguments(t *testing.T) {
dummyAddress := strings.Repeat("2", 32)
dummyUint64 := string([]byte{37})
Expand All @@ -58,7 +67,39 @@ func TestRelayersShouldExecuteTransfersWithSCCallsWithArguments(t *testing.T) {
memeToken,
)

testCallPayableWithParamsWasCalled(testSetup, 37, usdcToken.AbstractTokenIdentifier, memeToken.AbstractTokenIdentifier)
testCallPayableWithParamsWasCalled(
testSetup,
37,
usdcToken.AbstractTokenIdentifier,
memeToken.AbstractTokenIdentifier,
)
}

func TestRelayersShouldExecuteTransfersWithSCCallsWithArgumentsWithMintBurnTokens(t *testing.T) {
dummyAddress := strings.Repeat("2", 32)
dummyUint64 := string([]byte{37})

callData := createScCallData("callPayableWithParams", 50000000, dummyUint64, dummyAddress)

eurocToken := GenerateTestEUROCToken()
eurocToken.TestOperations[2].MvxSCCallData = callData

mexToken := GenerateTestMEXToken()
mexToken.TestOperations[2].MvxSCCallData = callData

testSetup := testRelayersWithChainSimulatorAndTokens(
t,
make(chan error),
eurocToken,
mexToken,
)

testCallPayableWithParamsWasCalled(
testSetup,
37,
eurocToken.AbstractTokenIdentifier,
mexToken.AbstractTokenIdentifier,
)
}

func TestRelayerShouldExecuteTransfersAndNotCatchErrors(t *testing.T) {
Expand Down Expand Up @@ -258,6 +299,7 @@ func TestRelayersShouldNotExecuteTransfers(t *testing.T) {
badToken.IsMintBurnOnEth = false
badToken.IsNativeOnMvX = true
badToken.IsMintBurnOnMvX = false
badToken.HasChainSpecificToken = true

expectedStringInLogs := "error = invalid setup isNativeOnEthereum = true, isNativeOnMultiversX = true"
testRelayersShouldNotExecuteTransfers(t, expectedStringInLogs, badToken)
Expand All @@ -268,6 +310,7 @@ func TestRelayersShouldNotExecuteTransfers(t *testing.T) {
badToken.IsMintBurnOnEth = false
badToken.IsNativeOnMvX = true
badToken.IsMintBurnOnMvX = true
badToken.HasChainSpecificToken = false

expectedStringInLogs := "error = invalid setup isNativeOnEthereum = true, isNativeOnMultiversX = true"
testRelayersShouldNotExecuteTransfers(t, expectedStringInLogs, badToken)
Expand All @@ -278,6 +321,7 @@ func TestRelayersShouldNotExecuteTransfers(t *testing.T) {
badToken.IsMintBurnOnEth = true
badToken.IsNativeOnMvX = true
badToken.IsMintBurnOnMvX = false
badToken.HasChainSpecificToken = true

testEthContractsShouldError(t, badToken)
})
Expand All @@ -287,6 +331,7 @@ func TestRelayersShouldNotExecuteTransfers(t *testing.T) {
badToken.IsMintBurnOnEth = true
badToken.IsNativeOnMvX = false
badToken.IsMintBurnOnMvX = true
badToken.HasChainSpecificToken = true

testEthContractsShouldError(t, badToken)
})
Expand Down Expand Up @@ -394,6 +439,12 @@ func testCallPayableWithParamsWasCalled(testSetup *framework.TestSetup, value ui
return
}

universalTokens := make([]string, 0, len(tokens))
for _, identifier := range tokens {
tkData := testSetup.TokensRegistry.GetTokenData(identifier)
universalTokens = append(universalTokens, tkData.MvxUniversalToken)
}

vmRequest := &data.VmValueRequest{
Address: testSetup.MultiversxHandler.TestCallerAddress.Bech32(),
FuncName: "getCalledDataParams",
Expand All @@ -405,11 +456,20 @@ func testCallPayableWithParamsWasCalled(testSetup *framework.TestSetup, value ui
returnedData := vmResponse.Data.ReturnData
require.Equal(testSetup, len(tokens), len(returnedData))

for i, token := range tokens {
buff := returnedData[i]
mapUniversalTokens := make(map[string]int)
for _, tokenIdentifier := range universalTokens {
mapUniversalTokens[tokenIdentifier] = 0
}

for _, buff := range returnedData {
parsedValue, parsedToken := processCalledDataParams(buff)
assert.Equal(testSetup, value, parsedValue)
assert.Contains(testSetup, parsedToken, token)
mapUniversalTokens[parsedToken]++
}

assert.Equal(testSetup, len(tokens), len(mapUniversalTokens))
for _, numTokens := range mapUniversalTokens {
assert.Equal(testSetup, 1, numTokens)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,13 @@ func (handler *EthereumHandler) deployTestERC20Contract(ctx context.Context, par
require.NoError(handler, err)
require.Equal(handler, mintAmount.String(), balance.String())

if params.IsNativeOnEth {
tx, err = ethMintBurnContract.Mint(auth, handler.TestKeys.EthAddress, mintAmount)
require.NoError(handler, err)
handler.SimulatedChain.Commit()
handler.checkEthTxResult(ctx, tx.Hash())
}

return ethMintBurnAddress, ethMintBurnContract
}

Expand Down
Loading

0 comments on commit 9993ccc

Please sign in to comment.