Skip to content

Commit

Permalink
Merge branch 'feat/v3.1' into check-mint-burn-tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
iulianpascalau committed Dec 9, 2024
2 parents 412df5f + 05097de commit 60677dd
Show file tree
Hide file tree
Showing 11 changed files with 896 additions and 284 deletions.
268 changes: 251 additions & 17 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,11 +54,21 @@ 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{
framework.Alice: {
OnEth: big.NewInt(-5000 - 7000 - 1000),
OnEth: big.NewInt(-5000 - 7000 - 1000 - 900),
OnMvx: big.NewInt(0),
MvxToken: framework.UniversalToken,
},
Expand All @@ -66,35 +78,35 @@ func GenerateTestUSDCToken() framework.TestTokenParams {
MvxToken: framework.UniversalToken,
},
framework.SafeSC: {
OnEth: big.NewInt(5000 + 7000 + 1000),
OnEth: big.NewInt(5000 + 7000 + 1000 + 900),
OnMvx: big.NewInt(0),
MvxToken: framework.ChainSpecificToken,
},
framework.CalledTestSC: {
OnEth: big.NewInt(0),
OnMvx: big.NewInt(0),
OnMvx: big.NewInt(1000),
MvxToken: framework.UniversalToken,
},
},
framework.SecondHalfBridge: map[string]*framework.DeltaBalanceHolder{
framework.Alice: {
OnEth: big.NewInt(-5000 - 7000 - 1000),
OnEth: big.NewInt(-5000 - 7000 - 1000 - 900 + 850), // 850 is the refund value
OnMvx: big.NewInt(0),
MvxToken: framework.UniversalToken,
},
framework.Bob: {
OnEth: big.NewInt(0),
OnMvx: big.NewInt(2500 + 6700),
OnMvx: big.NewInt(5000 - 2500 + 7000 - 300),
MvxToken: framework.UniversalToken,
},
framework.Charlie: {
OnEth: big.NewInt(2450 + 250),
OnEth: big.NewInt(2500 - 50 + 300 - 50),
OnMvx: big.NewInt(0),
MvxToken: framework.UniversalToken,
},
framework.SafeSC: {
OnEth: big.NewInt(5000 + 7000 + 1000 - 2450 - 250),
OnMvx: big.NewInt(50 + 50),
OnEth: big.NewInt(5000 + 7000 + 1000 + 900 - 2450 - 250 - 850),
OnMvx: big.NewInt(50 + 50 + 50),
MvxToken: framework.ChainSpecificToken,
},
framework.CalledTestSC: {
Expand All @@ -116,13 +128,15 @@ func GenerateTestUSDCToken() framework.TestTokenParams {

// ApplyUSDCRefundBalances will apply the refund balances on the involved entities for the USDC token
func ApplyUSDCRefundBalances(token *framework.TestTokenParams) {
// called test SC will have 0 balance since eth->mvx transfer failed
token.DeltaBalances[framework.FirstHalfBridge][framework.CalledTestSC].OnMvx = big.NewInt(0)
// extra is just for the fees for the 2 transfers mvx->eth and the failed eth->mvx that needed refund
token.DeltaBalances[framework.SecondHalfBridge][framework.SafeSC].OnMvx = big.NewInt(50 + 50 + 50)
token.DeltaBalances[framework.SecondHalfBridge][framework.SafeSC].OnMvx = big.NewInt(50 + 50 + 50 + 50)
// we need to subtract the refunded value from the Ethereum Safe contract
token.DeltaBalances[framework.SecondHalfBridge][framework.SafeSC].OnEth = big.NewInt(5000 + 7000 + 1000 - 2450 - 250 - 950)
token.DeltaBalances[framework.SecondHalfBridge][framework.SafeSC].OnEth = big.NewInt(5000 + 7000 + 1000 + 900 - 2450 - 250 - 950 - 850)
// Alice will get her tokens back from the refund
token.DeltaBalances[framework.SecondHalfBridge][framework.Alice].OnEth = big.NewInt(-5000 - 7000 - 1000 + 950)
// no funds remain in the test caller SC
token.DeltaBalances[framework.SecondHalfBridge][framework.Alice].OnEth = big.NewInt(-5000 - 7000 - 1000 - 900 + 950 + 850)
// no funds remain in the called test SC
token.DeltaBalances[framework.SecondHalfBridge][framework.CalledTestSC].OnMvx = big.NewInt(0)

token.MintBurnChecks.TotalChainSpecificBurn = big.NewInt(2500 - 50 + 300 - 50 + 1000 - 50)
Expand Down Expand Up @@ -165,6 +179,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 @@ -273,11 +293,21 @@ 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{
framework.Alice: {
OnEth: big.NewInt(-5010 - 7010 - 1010),
OnEth: big.NewInt(-5010 - 7010 - 1010 - 700),
OnMvx: big.NewInt(0),
MvxToken: framework.UniversalToken,
},
Expand All @@ -299,7 +329,7 @@ func GenerateTestEUROCToken() framework.TestTokenParams {
},
framework.SecondHalfBridge: map[string]*framework.DeltaBalanceHolder{
framework.Alice: {
OnEth: big.NewInt(-5010 - 7010 - 1010),
OnEth: big.NewInt(-5010 - 7010 - 1010 - 700 + 650), // 650 is the refund value
OnMvx: big.NewInt(0),
MvxToken: framework.UniversalToken,
},
Expand All @@ -315,7 +345,7 @@ func GenerateTestEUROCToken() framework.TestTokenParams {
},
framework.SafeSC: {
OnEth: big.NewInt(0),
OnMvx: big.NewInt(50 + 50),
OnMvx: big.NewInt(50 + 50 + 50),
MvxToken: framework.ChainSpecificToken,
},
framework.CalledTestSC: {
Expand All @@ -335,7 +365,19 @@ func GenerateTestEUROCToken() framework.TestTokenParams {
}
}

// GenerateTestMEXToken will generate a test EUROC token
// ApplyEUROCRefundBalances will apply the refund balances on the involved entities for the EUROC token
func ApplyEUROCRefundBalances(token *framework.TestTokenParams) {
// called test SC will have 0 balance since eth->mvx transfer failed
token.DeltaBalances[framework.FirstHalfBridge][framework.CalledTestSC].OnMvx = big.NewInt(0)
// extra is just for the fees for the 2 transfers mvx->eth and the failed eth->mvx that needed refund
token.DeltaBalances[framework.SecondHalfBridge][framework.SafeSC].OnMvx = big.NewInt(50 + 50 + 50 + 50)
// Alice will get her tokens back from the refund
token.DeltaBalances[framework.SecondHalfBridge][framework.Alice].OnEth = big.NewInt(-5010 - 7010 - 1010 - 700 + 960 + 650)
// no funds remain in the called test SC
token.DeltaBalances[framework.SecondHalfBridge][framework.CalledTestSC].OnMvx = big.NewInt(0)
}

// 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 @@ -371,6 +413,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 @@ -443,6 +491,192 @@ 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,
},
},
DeltaBalances: map[framework.HalfBridgeIdentifier]framework.DeltaBalancesOnKeys{
framework.FirstHalfBridge: map[string]*framework.DeltaBalanceHolder{
framework.Alice: {
OnEth: big.NewInt(0),
OnMvx: big.NewInt(0),
MvxToken: framework.UniversalToken,
},
framework.Bob: {
OnEth: big.NewInt(0),
OnMvx: big.NewInt(0),
MvxToken: framework.UniversalToken,
},
framework.Charlie: {
OnEth: big.NewInt(0),
OnMvx: big.NewInt(0),
MvxToken: framework.UniversalToken,
},
framework.SafeSC: {
OnEth: big.NewInt(0),
OnMvx: big.NewInt(0),
MvxToken: framework.ChainSpecificToken,
},
framework.CalledTestSC: {
OnEth: big.NewInt(0),
OnMvx: big.NewInt(0),
MvxToken: framework.UniversalToken,
},
},
framework.SecondHalfBridge: map[string]*framework.DeltaBalanceHolder{
framework.Alice: {
OnEth: big.NewInt(0),
OnMvx: big.NewInt(0),
MvxToken: framework.UniversalToken,
},
framework.Bob: {
OnEth: big.NewInt(0),
OnMvx: big.NewInt(0),
MvxToken: framework.UniversalToken,
},
framework.Charlie: {
OnEth: big.NewInt(0),
OnMvx: big.NewInt(0),
MvxToken: framework.UniversalToken,
},
framework.SafeSC: {
OnEth: big.NewInt(0),
OnMvx: big.NewInt(0),
MvxToken: framework.ChainSpecificToken,
},
framework.CalledTestSC: {
OnEth: big.NewInt(0),
OnMvx: big.NewInt(0),
MvxToken: framework.UniversalToken,
},
},
},
}
}

// 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),
},
},
DeltaBalances: map[framework.HalfBridgeIdentifier]framework.DeltaBalancesOnKeys{
framework.FirstHalfBridge: map[string]*framework.DeltaBalanceHolder{
framework.Alice: {
OnEth: big.NewInt(0),
OnMvx: big.NewInt(0),
MvxToken: framework.UniversalToken,
},
framework.Bob: {
OnEth: big.NewInt(0),
OnMvx: big.NewInt(0),
MvxToken: framework.UniversalToken,
},
framework.Charlie: {
OnEth: big.NewInt(0),
OnMvx: big.NewInt(0),
MvxToken: framework.UniversalToken,
},
framework.SafeSC: {
OnEth: big.NewInt(0),
OnMvx: big.NewInt(0),
MvxToken: framework.ChainSpecificToken,
},
framework.CalledTestSC: {
OnEth: big.NewInt(0),
OnMvx: big.NewInt(0),
MvxToken: framework.UniversalToken,
},
},
framework.SecondHalfBridge: map[string]*framework.DeltaBalanceHolder{
framework.Alice: {
OnEth: big.NewInt(0),
OnMvx: big.NewInt(0),
MvxToken: framework.UniversalToken,
},
framework.Bob: {
OnEth: big.NewInt(0),
OnMvx: big.NewInt(0),
MvxToken: framework.UniversalToken,
},
framework.Charlie: {
OnEth: big.NewInt(0),
OnMvx: big.NewInt(0),
MvxToken: framework.UniversalToken,
},
framework.SafeSC: {
OnEth: big.NewInt(0),
OnMvx: big.NewInt(0),
MvxToken: framework.ChainSpecificToken,
},
framework.CalledTestSC: {
OnEth: big.NewInt(0),
OnMvx: big.NewInt(0),
MvxToken: framework.UniversalToken,
},
},
},
}
}

func createScCallData(function string, gasLimit uint64, args ...string) []byte {
codec := testsCommon.TestMultiversXCodec{}
callData := parsers.CallData{
Expand Down
Loading

0 comments on commit 60677dd

Please sign in to comment.