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 integration tests #355

Draft
wants to merge 3 commits into
base: feat/v3.5
Choose a base branch
from
Draft
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
86 changes: 75 additions & 11 deletions integrationTests/relayers/slowTests/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ func GenerateTestUSDCToken() framework.TestTokenParams {
ValueToTransferToMvx: big.NewInt(5000),
ValueToSendFromMvX: big.NewInt(2500),
},
{
ValueToTransferToMvx: big.NewInt(7000),
ValueToSendFromMvX: big.NewInt(300),
},
{
ValueToTransferToMvx: big.NewInt(1000),
ValueToSendFromMvX: nil,
MvxSCCallData: createScCallData("callPayable", 50000000),
},
//{
// ValueToTransferToMvx: big.NewInt(7000),
// ValueToSendFromMvX: big.NewInt(300),
//},
//{
// ValueToTransferToMvx: big.NewInt(1000),
// 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(-5000 + 2500 - 50 - 7000 + 300 - 50 - 1000), // -(eth->mvx) + (mvx->eth) - fees
ESDTSafeExtraBalance: big.NewInt(50), // extra is just for the fees for the 2 transfers mvx->eth
EthTestAddrExtraBalance: big.NewInt(-5000 + 2500 - 50), // -(eth->mvx) + (mvx->eth) - fees
}
}

Expand Down Expand Up @@ -98,6 +98,70 @@ func GenerateTestMEMEToken() framework.TestTokenParams {
}
}

// GenerateTestDOGEToken will generate a test DOGE token
func GenerateTestDOGEToken() framework.TestTokenParams {
//DOGE is ethNative = true, ethMintBurn = true, mvxNative = false, mvxMintBurn = true
return framework.TestTokenParams{
IssueTokenParams: framework.IssueTokenParams{
AbstractTokenIdentifier: "DOGE",
NumOfDecimalsUniversal: 6,
NumOfDecimalsChainSpecific: 6,
MvxUniversalTokenTicker: "DOGE",
MvxChainSpecificTokenTicker: "ETHDOGE",
MvxUniversalTokenDisplayName: "WrappedDOGE",
MvxChainSpecificTokenDisplayName: "EthereumWrappedDOGE",
ValueToMintOnMvx: "10000000000",
IsMintBurnOnMvX: true,
IsNativeOnMvX: false,
EthTokenName: "ETHDOGE",
EthTokenSymbol: "ETHD",
ValueToMintOnEth: "10000000000",
IsMintBurnOnEth: true,
IsNativeOnEth: true,
},
TestOperations: []framework.TokenOperations{
{
ValueToTransferToMvx: big.NewInt(5000),
ValueToSendFromMvX: big.NewInt(2500),
},
},
ESDTSafeExtraBalance: big.NewInt(50), // extra is just for the fees for the 2 transfers mvx->eth
EthTestAddrExtraBalance: big.NewInt(-5000 + 2500 - 50), // -(eth->mvx) + (mvx->eth) - fees
}
}

// GenerateTestCOINToken will generate a test MEME token
func GenerateTestCOINToken() framework.TestTokenParams {
//COIN is ethNative = false, ethMintBurn = true, mvxNative = true, mvxMintBurn = true
return framework.TestTokenParams{
IssueTokenParams: framework.IssueTokenParams{
AbstractTokenIdentifier: "COIN",
NumOfDecimalsUniversal: 1,
NumOfDecimalsChainSpecific: 1,
MvxUniversalTokenTicker: "COIN",
MvxChainSpecificTokenTicker: "ETHCOIN",
MvxUniversalTokenDisplayName: "WrappedCOIN",
MvxChainSpecificTokenDisplayName: "EthereumWrappedCOIN",
ValueToMintOnMvx: "10000000000",
IsMintBurnOnMvX: true,
IsNativeOnMvX: true,
EthTokenName: "ETHCOIN",
EthTokenSymbol: "ETHC",
ValueToMintOnEth: "10000000000",
IsMintBurnOnEth: true,
IsNativeOnEth: false,
},
TestOperations: []framework.TokenOperations{
{
ValueToTransferToMvx: big.NewInt(2400),
ValueToSendFromMvX: big.NewInt(4000),
},
},
ESDTSafeExtraBalance: big.NewInt(4000),
EthTestAddrExtraBalance: big.NewInt(4000 - 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 @@ -8,6 +8,7 @@ package slowTests
import (
"context"
"encoding/binary"
"encoding/json"
"errors"
"fmt"
"math/big"
Expand All @@ -16,6 +17,8 @@ import (
"testing"
"time"

"github.com/ethereum/go-ethereum"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/multiversx/mx-bridge-eth-go/integrationTests/mock"
"github.com/multiversx/mx-bridge-eth-go/integrationTests/relayers/slowTests/framework"
Expand All @@ -34,9 +37,13 @@ func TestRelayersShouldExecuteTransfers(t *testing.T) {
_ = testRelayersWithChainSimulatorAndTokens(
t,
make(chan error),
GenerateTestUSDCToken(),
GenerateTestMEMEToken(),
//GenerateTestUSDCToken(),
//GenerateTestMEMEToken(),
GenerateTestDOGEToken(),
//GenerateTestCOINToken(),
)

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

func TestRelayersShouldExecuteTransfersWithSCCallsWithArguments(t *testing.T) {
Expand Down Expand Up @@ -135,9 +142,32 @@ func testRelayersWithChainSimulatorAndTokens(tb testing.TB, manualStopChan chan

// commit blocks in order to execute incoming txs from relayers
setup.EthereumHandler.SimulatedChain.Commit()

blockNum, err := setup.EthereumHandler.EthChainWrapper.BlockNumber(context.Background())
if err != nil {
fmt.Errorf("error getting block number: %v", err)
}
fmt.Println("================= BLOCK NUMBER", blockNum)
filterQuery := ethereum.FilterQuery{
ToBlock: big.NewInt(int64(blockNum)),
}
logs, err := setup.EthereumHandler.EthChainWrapper.FilterLogs(context.Background(), filterQuery)
fmt.Println("================================= LOGS ===============================")
for _, log := range logs {
logJson, err := json.MarshalIndent(log, "", " ")
if err != nil {
fmt.Println("Error marshaling log:", err)
continue
}
fmt.Println("Log:")
fmt.Println(string(logJson))
fmt.Println("********")
}
setup.ChainSimulator.GenerateBlocks(setup.Ctx, 1)
require.LessOrEqual(tb, setup.ScCallerModuleInstance.GetNumSentTransaction(), setup.GetNumScCallsOperations())

require.True(tb, false)

return false
}

Expand Down Expand Up @@ -350,7 +380,7 @@ func testRelayersShouldNotExecuteTransfers(
case <-mockLogObserver.LogFoundChan():
chanCnt++
if chanCnt >= numOfErrorsToWait {
log.Info(fmt.Sprintf("test passed, relayers are stuck, expected string `%s` found in all relayers' logs for %d times", expectedStringInLogs, numOfErrorsToWait))
log.Info(fmt.Sprintf("test passed, relayers are stuck, expected string %s found in all relayers' logs for %d times", expectedStringInLogs, numOfErrorsToWait))
stopChan <- nil
return
}
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
7 changes: 7 additions & 0 deletions integrationTests/relayers/slowTests/framework/testSetup.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ func (setup *TestSetup) isTransferDoneFromEthereumForToken(params TestTokenParam
}

receiverBalance := setup.MultiversxHandler.GetESDTUniversalTokenBalance(setup.Ctx, setup.TestKeys.MvxAddress, params.AbstractTokenIdentifier)
fmt.Println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|-----", receiverBalance.String())
fmt.Println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|-----", expectedValueOnReceiver.String())
if receiverBalance.String() != expectedValueOnReceiver.String() {
return false
}
Expand Down Expand Up @@ -282,10 +284,15 @@ func (setup *TestSetup) isTransferDoneFromMultiversXForToken(params TestTokenPar
setup.mutBalances.Unlock()

ethTestBalance := setup.EthereumHandler.GetBalance(setup.TestKeys.EthAddress, params.AbstractTokenIdentifier)
fmt.Println("@@@@@@@@@@@@ethTestBalance", ethTestBalance.String())
fmt.Println("@@@@@@@@@@@@expectedReceiver", expectedReceiver.String())
isTransferDoneFromMultiversX := ethTestBalance.String() == expectedReceiver.String()

expectedEsdtSafe := big.NewInt(0).Add(initialBalanceForSafe, params.ESDTSafeExtraBalance)
balanceForSafe := setup.MultiversxHandler.GetESDTChainSpecificTokenBalance(setup.Ctx, setup.MultiversxHandler.SafeAddress, params.AbstractTokenIdentifier)

fmt.Println("@@@@@@@@@@@@expectedEsdtSafe", expectedEsdtSafe.String())
fmt.Println("@@@@@@@@@@@@balanceForSafe", balanceForSafe.String())
isSafeContractOnCorrectBalance := expectedEsdtSafe.String() == balanceForSafe.String()

return isTransferDoneFromMultiversX && isSafeContractOnCorrectBalance
Expand Down
Loading