Skip to content

Commit

Permalink
Merge branch 'feat/v3.1' into refactored-balance-checking
Browse files Browse the repository at this point in the history
# Conflicts:
#	integrationTests/relayers/slowTests/common.go
#	integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go
#	integrationTests/relayers/slowTests/framework/keys.go
#	integrationTests/relayers/slowTests/framework/testSetup.go
#	integrationTests/relayers/slowTests/framework/types.go
  • Loading branch information
iulianpascalau committed Dec 2, 2024
2 parents f3f3498 + 257b1cf commit 044607d
Show file tree
Hide file tree
Showing 11 changed files with 572 additions and 246 deletions.
114 changes: 112 additions & 2 deletions integrationTests/relayers/slowTests/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package slowTests

import (
"bytes"
"math/big"

bridgeCore "github.com/multiversx/mx-bridge-eth-go/core"
Expand All @@ -13,7 +14,8 @@ import (
)

var (
log = logger.GetOrCreate("integrationTests/relayers/slowTests")
log = logger.GetOrCreate("integrationTests/relayers/slowTests")
mvxZeroAddress = bytes.Repeat([]byte{0x00}, 32)
)

// GenerateTestUSDCToken will generate a test USDC token
Expand Down Expand Up @@ -52,6 +54,16 @@ func GenerateTestUSDCToken() framework.TestTokenParams {
ValueToSendFromMvX: nil,
MvxSCCallData: createScCallData("callPayable", 50000000),
},
{
ValueToTransferToMvx: big.NewInt(20),
ValueToSendFromMvX: nil,
IsFaultyDeposit: true,
},
{
ValueToTransferToMvx: big.NewInt(900),
ValueToSendFromMvX: nil,
InvalidReceiver: mvxZeroAddress,
},
},
DeltaBalances: map[framework.HalfBridgeIdentifier]framework.DeltaBalancesOnKeys{
framework.FirstHalfBridge: map[string]*framework.DeltaBalanceHolder{
Expand Down Expand Up @@ -155,6 +167,12 @@ func GenerateTestMEMEToken() framework.TestTokenParams {
ValueToSendFromMvX: big.NewInt(2000),
MvxSCCallData: createScCallData("callPayable", 50000000),
},
{
ValueToTransferToMvx: nil,
ValueToSendFromMvX: big.NewInt(38),
IsFaultyDeposit: true,
},
// TODO: add a test where the receiver is the zero address
},
DeltaBalances: map[framework.HalfBridgeIdentifier]framework.DeltaBalancesOnKeys{
framework.FirstHalfBridge: map[string]*framework.DeltaBalanceHolder{
Expand Down Expand Up @@ -256,6 +274,16 @@ func GenerateTestEUROCToken() framework.TestTokenParams {
ValueToSendFromMvX: nil,
MvxSCCallData: createScCallData("callPayable", 50000000),
},
{
ValueToTransferToMvx: big.NewInt(24),
ValueToSendFromMvX: nil,
IsFaultyDeposit: true,
},
{
ValueToTransferToMvx: big.NewInt(700),
ValueToSendFromMvX: nil,
InvalidReceiver: mvxZeroAddress,
},
},
DeltaBalances: map[framework.HalfBridgeIdentifier]framework.DeltaBalancesOnKeys{
framework.FirstHalfBridge: map[string]*framework.DeltaBalanceHolder{
Expand Down Expand Up @@ -311,7 +339,7 @@ func GenerateTestEUROCToken() framework.TestTokenParams {
}
}

// GenerateTestMEXToken will generate a test EUROC token
// GenerateTestMEXToken will generate a test MEX token
func GenerateTestMEXToken() framework.TestTokenParams {
//MEX is ethNative = false, ethMintBurn = true, mvxNative = true, mvxMintBurn = true
return framework.TestTokenParams{
Expand Down Expand Up @@ -347,6 +375,12 @@ func GenerateTestMEXToken() framework.TestTokenParams {
ValueToSendFromMvX: big.NewInt(2010),
MvxSCCallData: createScCallData("callPayable", 50000000),
},
{
ValueToTransferToMvx: big.NewInt(10),
ValueToSendFromMvX: nil,
IsFaultyDeposit: true,
},
// TODO: add a test where the receiver is the zero address
},
DeltaBalances: map[framework.HalfBridgeIdentifier]framework.DeltaBalancesOnKeys{
framework.FirstHalfBridge: map[string]*framework.DeltaBalanceHolder{
Expand Down Expand Up @@ -412,6 +446,82 @@ func ApplyMEXRefundBalances(token *framework.TestTokenParams) {
token.DeltaBalances[framework.SecondHalfBridge][framework.CalledTestSC].OnMvx = big.NewInt(0)
}

// GenerateUnlistedTokenFromEth will generate an unlisted token on Eth
func GenerateUnlistedTokenFromEth() framework.TestTokenParams {
return framework.TestTokenParams{
IssueTokenParams: framework.IssueTokenParams{
AbstractTokenIdentifier: "ULTKE",
NumOfDecimalsUniversal: 6,
NumOfDecimalsChainSpecific: 6,
MvxUniversalTokenTicker: "ULTKE",
MvxChainSpecificTokenTicker: "ULTKE",
MvxUniversalTokenDisplayName: "TestULTKE",
MvxChainSpecificTokenDisplayName: "TestULTKE",
ValueToMintOnMvx: "10000000000",
IsMintBurnOnMvX: true,
IsNativeOnMvX: false,
HasChainSpecificToken: false,
EthTokenName: "EthULTKE",
EthTokenSymbol: "ULTKE",
ValueToMintOnEth: "10000000000",
IsMintBurnOnEth: true,
IsNativeOnEth: true,
PreventWhitelist: true,
},
TestOperations: []framework.TokenOperations{
{
ValueToTransferToMvx: big.NewInt(5010),
ValueToSendFromMvX: nil,
IsFaultyDeposit: true,
},
{
ValueToTransferToMvx: big.NewInt(1010),
ValueToSendFromMvX: nil,
MvxSCCallData: createScCallData("callPayable", 50000000),
IsFaultyDeposit: true,
},
},
ESDTSafeExtraBalance: big.NewInt(0),
}
}

// GenerateUnlistedTokenFromMvx will generate an unlisted token on Mvx
func GenerateUnlistedTokenFromMvx() framework.TestTokenParams {
return framework.TestTokenParams{
IssueTokenParams: framework.IssueTokenParams{
AbstractTokenIdentifier: "ULTKM",
NumOfDecimalsUniversal: 2,
NumOfDecimalsChainSpecific: 2,
MvxUniversalTokenTicker: "ULTKM",
MvxChainSpecificTokenTicker: "ULTKM",
MvxUniversalTokenDisplayName: "TestULTKM",
MvxChainSpecificTokenDisplayName: "TestULTKM",
ValueToMintOnMvx: "10000000000",
IsMintBurnOnMvX: true,
IsNativeOnMvX: true,
HasChainSpecificToken: false,
EthTokenName: "EthULTKM",
EthTokenSymbol: "ULTKM",
ValueToMintOnEth: "10000000000",
IsMintBurnOnEth: true,
IsNativeOnEth: false,
PreventWhitelist: true,
},
TestOperations: []framework.TokenOperations{
{
ValueToTransferToMvx: nil,
ValueToSendFromMvX: big.NewInt(4010),
},
{
ValueToTransferToMvx: nil,
ValueToSendFromMvX: big.NewInt(2010),
MvxSCCallData: createScCallData("callPayable", 50000000),
},
},
ESDTSafeExtraBalance: big.NewInt(0),
}
}

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 @@ -48,6 +48,15 @@ func TestRelayersShouldExecuteTransfersWithMintBurnTokens(t *testing.T) {
)
}

func TestRelayersShouldNotExecuteTransfersWithNonWhitelistedTokens(t *testing.T) {
_ = testRelayersWithChainSimulatorAndTokens(
t,
make(chan error),
GenerateUnlistedTokenFromEth(),
GenerateUnlistedTokenFromMvx(),
)
}

func TestRelayersShouldExecuteTransfersWithSCCallsWithArguments(t *testing.T) {
dummyAddress := strings.Repeat("2", 32)
dummyUint64 := string([]byte{37})
Expand Down Expand Up @@ -182,7 +191,7 @@ func testRelayersWithChainSimulatorAndTokens(tb testing.TB, manualStopChan chan
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,17 @@ func (instance *chainSimulatorWrapper) DeploySC(ctx context.Context, wasmFilePat
}

hash := instance.signAndSend(ctx, ownerSK, ftx, 1)
txResult := instance.GetTransactionResult(ctx, hash)
txResult, txStatus := instance.GetTransactionResult(ctx, hash)

jsonData, err := json.MarshalIndent(txResult, "", " ")
require.Nil(instance, err)
require.Equal(instance, transaction.TxStatusSuccess, txStatus, fmt.Sprintf("tx hash: %s,\n tx: %s", hash, string(jsonData)))

return NewMvxAddressFromBech32(instance.TB, txResult.Logs.Events[0].Address), hash, txResult
}

// GetTransactionResult tries to get a transaction result. It may wait a few blocks
func (instance *chainSimulatorWrapper) GetTransactionResult(ctx context.Context, hash string) *data.TransactionOnNetwork {
func (instance *chainSimulatorWrapper) GetTransactionResult(ctx context.Context, hash string) (*data.TransactionOnNetwork, transaction.TxStatus) {
instance.GenerateBlocksUntilTxProcessed(ctx, hash)

txResult, err := instance.proxyInstance.GetTransactionInfoWithResults(ctx, hash)
Expand All @@ -161,11 +165,7 @@ func (instance *chainSimulatorWrapper) GetTransactionResult(ctx context.Context,
txStatus, err := instance.proxyInstance.ProcessTransactionStatus(ctx, hash)
require.Nil(instance, err)

jsonData, err := json.MarshalIndent(txResult.Data.Transaction, "", " ")
require.Nil(instance, err)
require.Equal(instance, transaction.TxStatusSuccess, txStatus, fmt.Sprintf("tx hash: %s,\n tx: %s", hash, string(jsonData)))

return &txResult.Data.Transaction
return &txResult.Data.Transaction, txStatus
}

// GenerateBlocks calls the chain simulator generate block endpoint
Expand Down Expand Up @@ -200,7 +200,7 @@ func (instance *chainSimulatorWrapper) GenerateBlocksUntilTxProcessed(ctx contex
}

// ScCall will make the provided sc call
func (instance *chainSimulatorWrapper) ScCall(ctx context.Context, senderSK []byte, contract *MvxAddress, value string, gasLimit uint64, function string, parameters []string) (string, *data.TransactionOnNetwork) {
func (instance *chainSimulatorWrapper) ScCall(ctx context.Context, senderSK []byte, contract *MvxAddress, value string, gasLimit uint64, function string, parameters []string) (string, *data.TransactionOnNetwork, transaction.TxStatus) {
return instance.SendTx(ctx, senderSK, contract, value, gasLimit, createTxData(function, parameters))
}

Expand All @@ -218,12 +218,12 @@ func createTxData(function string, parameters []string) []byte {
}

// SendTx will build and send a transaction
func (instance *chainSimulatorWrapper) SendTx(ctx context.Context, senderSK []byte, receiver *MvxAddress, value string, gasLimit uint64, dataField []byte) (string, *data.TransactionOnNetwork) {
func (instance *chainSimulatorWrapper) SendTx(ctx context.Context, senderSK []byte, receiver *MvxAddress, value string, gasLimit uint64, dataField []byte) (string, *data.TransactionOnNetwork, transaction.TxStatus) {
hash := instance.SendTxWithoutGenerateBlocks(ctx, senderSK, receiver, value, gasLimit, dataField)
instance.GenerateBlocks(ctx, 1)
txResult := instance.GetTransactionResult(ctx, hash)
txResult, txStatus := instance.GetTransactionResult(ctx, hash)

return hash, txResult
return hash, txResult, txStatus
}

// SendTxWithoutGenerateBlocks will build and send a transaction and won't call the generate blocks command
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ func (handler *EthereumHandler) IssueAndWhitelistToken(ctx context.Context, para

handler.TokensRegistry.RegisterEthAddressAndContract(params.AbstractTokenIdentifier, erc20Address, erc20ContractInstance)

if params.PreventWhitelist {
return
}

// whitelist eth token
auth, _ := bind.NewKeyedTransactorWithChainID(handler.OwnerKeys.EthSK, handler.ChainID)
tx, err := handler.SafeContract.WhitelistToken(
Expand Down Expand Up @@ -444,6 +448,10 @@ func (handler *EthereumHandler) SendDepositTransactionFromEthereum(
tx, err = handler.SafeContract.Deposit(auth, token.EthErc20Address, operation.ValueToTransferToMvx, to.MvxAddress.AddressSlice())
}

if operation.IsFaultyDeposit {
require.NotNil(handler, err)
return
}
require.NoError(handler, err)
handler.SimulatedChain.Commit()
handler.checkEthTxResult(ctx, tx.Hash())
Expand Down
7 changes: 4 additions & 3 deletions integrationTests/relayers/slowTests/framework/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/multiversx/mx-bridge-eth-go/clients/multiversx"
"github.com/multiversx/mx-chain-core-go/data/transaction"
sdkCore "github.com/multiversx/mx-sdk-go/core"
"github.com/multiversx/mx-sdk-go/data"
)
Expand All @@ -32,16 +33,16 @@ type ChainSimulatorWrapper interface {
Proxy() multiversx.Proxy
GetNetworkAddress() string
DeploySC(ctx context.Context, path string, ownerSK []byte, gasLimit uint64, extraParams []string) (*MvxAddress, string, *data.TransactionOnNetwork)
ScCall(ctx context.Context, senderSK []byte, contract *MvxAddress, value string, gasLimit uint64, function string, parameters []string) (string, *data.TransactionOnNetwork)
ScCall(ctx context.Context, senderSK []byte, contract *MvxAddress, value string, gasLimit uint64, function string, parameters []string) (string, *data.TransactionOnNetwork, transaction.TxStatus)
ScCallWithoutGenerateBlocks(ctx context.Context, senderSK []byte, contract *MvxAddress, value string, gasLimit uint64, function string, parameters []string) string
SendTx(ctx context.Context, senderSK []byte, receiver *MvxAddress, value string, gasLimit uint64, dataField []byte) (string, *data.TransactionOnNetwork)
SendTx(ctx context.Context, senderSK []byte, receiver *MvxAddress, value string, gasLimit uint64, dataField []byte) (string, *data.TransactionOnNetwork, transaction.TxStatus)
SendTxWithoutGenerateBlocks(ctx context.Context, senderSK []byte, receiver *MvxAddress, value string, gasLimit uint64, dataField []byte) string
FundWallets(ctx context.Context, wallets []string)
GenerateBlocksUntilEpochReached(ctx context.Context, epoch uint32)
GenerateBlocks(ctx context.Context, numBlocks int)
GetESDTBalance(ctx context.Context, address *MvxAddress, token string) string
GetBlockchainTimeStamp(ctx context.Context) uint64
GetTransactionResult(ctx context.Context, hash string) *data.TransactionOnNetwork
GetTransactionResult(ctx context.Context, hash string) (*data.TransactionOnNetwork, transaction.TxStatus)
ExecuteVMQuery(ctx context.Context, scAddress *MvxAddress, function string, hexParams []string) [][]byte
}

Expand Down
1 change: 1 addition & 0 deletions integrationTests/relayers/slowTests/framework/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const (
WrapperSC = "Wrapper SC"
CalledTestSC = "Called test SC"
SafeSC = "Safe SC"
AddressZero = "AddressZero"
)

// NewKeysStore will create a KeysStore instance and generate all keys
Expand Down
Loading

0 comments on commit 044607d

Please sign in to comment.