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

Frozen token scenario integration tests #391

Draft
wants to merge 22 commits into
base: feat/v3.1
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
49d6a38
- integrating new contracts
iulianpascalau Dec 3, 2024
cc5279d
Merge branch 'feat/v3.1' into integrate-new-v3p1-rs-contracts
iulianpascalau Dec 3, 2024
5f985ad
Merge branch 'feat/v3.1' into integrate-new-v3p1-rs-contracts
iulianpascalau Dec 5, 2024
53f478d
- bughunt new contracts
iulianpascalau Dec 9, 2024
6f9b675
- new contract
iulianpascalau Dec 9, 2024
772ed5a
Merge branch 'feat/v3.1' into integrate-new-v3p1-rs-contracts
iulianpascalau Dec 9, 2024
c4ebaab
add test for frozen token
cosmatudor Dec 9, 2024
26727da
Merge branch 'feat/v3.1' into frozen-token-scenario-integration-tests
cosmatudor Dec 9, 2024
2932dd1
refactor to send tokens to Alice at batch creation time
cosmatudor Dec 10, 2024
47db458
fix edge case
cosmatudor Dec 10, 2024
861fd80
- new contract & minor fixes
iulianpascalau Dec 11, 2024
fc63bbf
Merge branch 'feat/v3.1' into integrate-new-v3p1-rs-contracts
iulianpascalau Dec 11, 2024
cc2b9d4
Merge branch 'feat/v3.1' into integration-tests-refactor
cosmatudor Dec 12, 2024
767efe2
- added 2 new tests + integrated new contracts
iulianpascalau Dec 12, 2024
b4ada1c
- new contracts
iulianpascalau Dec 13, 2024
2ac152a
add txn to zero address on second bridge(eth -> mvx)
cosmatudor Dec 16, 2024
8eb0a2f
Merge branch 'integrate-new-v3p1-rs-contracts' into integration-tests…
cosmatudor Dec 16, 2024
9314b54
add txn to zero address (mvx -> eth)
cosmatudor Dec 16, 2024
02ef9b2
fixes
cosmatudor Dec 16, 2024
9d4021d
Merge branch 'refs/heads/feat/v3.1' into frozen-token-scenario-integr…
cosmatudor Dec 17, 2024
77444dc
Merge branch 'refs/heads/integration-tests-refactor' into frozen-toke…
cosmatudor Dec 17, 2024
c3c78f3
small fixes
cosmatudor Dec 18, 2024
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
2 changes: 1 addition & 1 deletion cmd/bridge/config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
ProposeStatusBase = 10000000
ProposeStatusForEach = 7000000
PerformActionBase = 40000000
PerformActionForEach = 5500000
PerformActionForEach = 7000000
ScCallPerByte = 100000 # 1500 tx data field + the rest for the actual storage in the contract
ScCallPerformForEach = 10000000

Expand Down
2 changes: 1 addition & 1 deletion docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3.9"

services:
chain-simulator:
image: multiversx/chainsimulator:v1.7.13-patch2
image: multiversx/chainsimulator:v1.7.13-patch2-fix1
ports:
- 8085:8085
volumes:
Expand Down
170 changes: 147 additions & 23 deletions integrationTests/relayers/slowTests/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"bytes"
"math/big"

"github.com/ethereum/go-ethereum/common"
bridgeCore "github.com/multiversx/mx-bridge-eth-go/core"
"github.com/multiversx/mx-bridge-eth-go/integrationTests/relayers/slowTests/framework"
"github.com/multiversx/mx-bridge-eth-go/parsers"
Expand All @@ -16,6 +17,7 @@ import (
var (
log = logger.GetOrCreate("integrationTests/relayers/slowTests")
mvxZeroAddress = bytes.Repeat([]byte{0x00}, 32)
ethZeroAddress = common.Address{}
)

// GenerateTestUSDCToken will generate a test USDC token
Expand Down Expand Up @@ -64,6 +66,12 @@ func GenerateTestUSDCToken() framework.TestTokenParams {
ValueToSendFromMvX: nil,
InvalidReceiver: mvxZeroAddress,
},
{
ValueToTransferToMvx: nil,
ValueToSendFromMvX: big.NewInt(730),
InvalidReceiver: ethZeroAddress,
IsFaultyDeposit: true,
},
},
DeltaBalances: map[framework.HalfBridgeIdentifier]framework.DeltaBalancesOnKeys{
framework.FirstHalfBridge: map[string]*framework.DeltaBalanceHolder{
Expand Down Expand Up @@ -206,7 +214,17 @@ func GenerateTestMEMEToken() framework.TestTokenParams {
ValueToSendFromMvX: big.NewInt(38),
IsFaultyDeposit: true,
},
// TODO: add a test where the receiver is the zero address
{
ValueToTransferToMvx: nil,
ValueToSendFromMvX: big.NewInt(420),
InvalidReceiver: ethZeroAddress,
IsFaultyDeposit: true,
},
{
ValueToTransferToMvx: big.NewInt(1300),
ValueToSendFromMvX: nil,
InvalidReceiver: mvxZeroAddress,
},
},
DeltaBalances: map[framework.HalfBridgeIdentifier]framework.DeltaBalancesOnKeys{
framework.FirstHalfBridge: map[string]*framework.DeltaBalanceHolder{
Expand Down Expand Up @@ -243,7 +261,7 @@ func GenerateTestMEMEToken() framework.TestTokenParams {
MvxToken: framework.UniversalToken,
},
framework.Bob: {
OnEth: big.NewInt(4000 - 50 - 2400 + 6000 - 50 - 200 + 2000 - 50 - 1000),
OnEth: big.NewInt(4000 - 50 - 2400 + 6000 - 50 - 200 + 2000 - 50 - 1000 - 1300 + 1250),
OnMvx: big.NewInt(0),
MvxToken: framework.UniversalToken,
},
Expand All @@ -254,7 +272,7 @@ func GenerateTestMEMEToken() framework.TestTokenParams {
},
framework.SafeSC: {
OnEth: big.NewInt(0),
OnMvx: big.NewInt(4000 - 2400 + 6000 - 200 + 2000 - 1000),
OnMvx: big.NewInt(4000 - 2400 + 6000 - 200 + 2000 - 1000 - 1300 + 1300),
MvxToken: framework.ChainSpecificToken,
},
framework.CalledTestSC: {
Expand All @@ -277,8 +295,8 @@ func GenerateTestMEMEToken() framework.TestTokenParams {
MvxSafeMintValue: big.NewInt(0),
MvxSafeBurnValue: big.NewInt(0),

EthSafeMintValue: big.NewInt(4000 - 50 + 6000 - 50 + 2000 - 50),
EthSafeBurnValue: big.NewInt(2400 + 200 + 1000),
EthSafeMintValue: big.NewInt(4000 - 50 + 6000 - 50 + 2000 - 50 + 1300 - 50),
EthSafeBurnValue: big.NewInt(2400 + 200 + 1000 + 1300),
},
SpecialChecks: &framework.SpecialBalanceChecks{
WrapperDeltaLiquidityCheck: big.NewInt(0),
Expand All @@ -289,13 +307,13 @@ func GenerateTestMEMEToken() framework.TestTokenParams {
// ApplyMEMERefundBalances will apply the refund balances on the involved entities for the MEME token
func ApplyMEMERefundBalances(token *framework.TestTokenParams) {
// we need to add the 1000 MEME tokens as the third bridge was done that include the refund on the Ethereum side
token.DeltaBalances[framework.SecondHalfBridge][framework.SafeSC].OnMvx = big.NewInt(4000 - 2400 + 6000 - 200 + 2000 - 1000 + 1000)
token.DeltaBalances[framework.SecondHalfBridge][framework.SafeSC].OnMvx = big.NewInt(4000 - 2400 + 6000 - 200 + 2000 - 1300 + 1300 - 1000 + 1000)
// Bob will get his tokens back from the refund
token.DeltaBalances[framework.SecondHalfBridge][framework.Bob].OnEth = big.NewInt(4000 - 50 - 2400 + 6000 - 50 - 200 + 2000 - 50 - 1000 + 950)
token.DeltaBalances[framework.SecondHalfBridge][framework.Bob].OnEth = big.NewInt(4000 - 50 - 2400 + 6000 - 50 - 200 + 2000 - 50 - 1300 + 1250 - 1000 + 950)
// no funds remain in the test caller SC
token.DeltaBalances[framework.SecondHalfBridge][framework.CalledTestSC].OnMvx = big.NewInt(0)

token.MintBurnChecks.EthSafeMintValue = big.NewInt(4000 - 50 + 6000 - 50 + 2000 - 50 + 1000 - 50)
token.MintBurnChecks.EthSafeMintValue = big.NewInt(4000 - 50 + 6000 - 50 + 2000 - 50 + 1300 - 50 + 1000 - 50)
}

// GenerateTestEUROCToken will generate a test EUROC token
Expand Down Expand Up @@ -344,6 +362,12 @@ func GenerateTestEUROCToken() framework.TestTokenParams {
ValueToSendFromMvX: nil,
InvalidReceiver: mvxZeroAddress,
},
{
ValueToTransferToMvx: nil,
ValueToSendFromMvX: big.NewInt(853),
InvalidReceiver: ethZeroAddress,
IsFaultyDeposit: true,
},
},
DeltaBalances: map[framework.HalfBridgeIdentifier]framework.DeltaBalancesOnKeys{
framework.FirstHalfBridge: map[string]*framework.DeltaBalanceHolder{
Expand Down Expand Up @@ -480,7 +504,17 @@ func GenerateTestMEXToken() framework.TestTokenParams {
ValueToSendFromMvX: nil,
IsFaultyDeposit: true,
},
// TODO: add a test where the receiver is the zero address
{
ValueToTransferToMvx: nil,
ValueToSendFromMvX: big.NewInt(500),
InvalidReceiver: ethZeroAddress,
IsFaultyDeposit: true,
},
{
ValueToTransferToMvx: big.NewInt(3000),
ValueToSendFromMvX: nil,
InvalidReceiver: mvxZeroAddress,
},
},
DeltaBalances: map[framework.HalfBridgeIdentifier]framework.DeltaBalancesOnKeys{
framework.FirstHalfBridge: map[string]*framework.DeltaBalanceHolder{
Expand Down Expand Up @@ -517,7 +551,7 @@ func GenerateTestMEXToken() framework.TestTokenParams {
MvxToken: framework.UniversalToken,
},
framework.Bob: {
OnEth: big.NewInt(4010 - 50 - 2410 + 6010 - 50 - 210 + 2010 - 50 - 1010),
OnEth: big.NewInt(4010 - 50 - 2410 + 6010 - 50 - 210 + 2010 - 50 - 1010 - 3000 + 2950),
OnMvx: big.NewInt(0),
MvxToken: framework.UniversalToken,
},
Expand All @@ -528,7 +562,7 @@ func GenerateTestMEXToken() framework.TestTokenParams {
},
framework.SafeSC: {
OnEth: big.NewInt(0),
OnMvx: big.NewInt(50 + 50 + 50),
OnMvx: big.NewInt(50 + 50 + 50 + 50),
MvxToken: framework.ChainSpecificToken,
},
framework.CalledTestSC: {
Expand All @@ -544,15 +578,15 @@ func GenerateTestMEXToken() framework.TestTokenParams {
},
},
MintBurnChecks: &framework.MintBurnBalances{
MvxTotalUniversalMint: big.NewInt(2410 + 210 + 1010),
MvxTotalUniversalMint: big.NewInt(2410 + 210 + 1010 + 3000),
MvxTotalChainSpecificMint: big.NewInt(0),
MvxTotalUniversalBurn: big.NewInt(4010 - 50 + 6010 - 50 + 2010 - 50),
MvxTotalUniversalBurn: big.NewInt(4010 - 50 + 6010 - 50 + 2010 - 50 + 3000 - 50),
MvxTotalChainSpecificBurn: big.NewInt(0),
MvxSafeMintValue: big.NewInt(2410 + 210 + 1010),
MvxSafeBurnValue: big.NewInt(4010 - 50 + 6010 - 50 + 2010 - 50),
MvxSafeMintValue: big.NewInt(2410 + 210 + 1010 + 3000),
MvxSafeBurnValue: big.NewInt(4010 - 50 + 6010 - 50 + 2010 - 50 + 3000 - 50),

EthSafeMintValue: big.NewInt(4010 - 50 + 6010 - 50 + 2010 - 50),
EthSafeBurnValue: big.NewInt(2410 + 210 + 1010),
EthSafeMintValue: big.NewInt(4010 - 50 + 6010 - 50 + 2010 - 50 + 3000 - 50),
EthSafeBurnValue: big.NewInt(2410 + 210 + 1010 + 3000),
},
SpecialChecks: &framework.SpecialBalanceChecks{
WrapperDeltaLiquidityCheck: big.NewInt(0),
Expand All @@ -563,15 +597,15 @@ func GenerateTestMEXToken() framework.TestTokenParams {
// ApplyMEXRefundBalances will apply the refund balances on the involved entities for the MEX token
func ApplyMEXRefundBalances(token *framework.TestTokenParams) {
// 3 normal swaps + the refund one
token.DeltaBalances[framework.SecondHalfBridge][framework.SafeSC].OnMvx = big.NewInt(50 + 50 + 50 + 50)
token.DeltaBalances[framework.SecondHalfBridge][framework.SafeSC].OnMvx = big.NewInt(50 + 50 + 50 + 50 + 50)
// Bob will get his tokens back from the refund
token.DeltaBalances[framework.SecondHalfBridge][framework.Bob].OnEth = big.NewInt(4010 - 50 - 2410 + 6010 - 50 - 210 + 2010 - 50 - 1010 + 960)
token.DeltaBalances[framework.SecondHalfBridge][framework.Bob].OnEth = big.NewInt(4010 - 50 - 2410 + 6010 - 50 - 210 + 2010 - 50 - 1010 + 960 - 3000 + 2950)
// no funds remain in the test caller SC
token.DeltaBalances[framework.SecondHalfBridge][framework.CalledTestSC].OnMvx = big.NewInt(0)

token.MintBurnChecks.MvxTotalUniversalBurn = big.NewInt(4010 - 50 + 6010 - 50 + 2010 - 50 + 1010 - 50)
token.MintBurnChecks.MvxSafeBurnValue = big.NewInt(4010 - 50 + 6010 - 50 + 2010 - 50 + 1010 - 50)
token.MintBurnChecks.EthSafeMintValue = big.NewInt(4010 - 50 + 6010 - 50 + 2010 - 50 + 1010 - 50)
token.MintBurnChecks.MvxTotalUniversalBurn = big.NewInt(4010 - 50 + 6010 - 50 + 2010 - 50 + 3000 - 50 + 1010 - 50)
token.MintBurnChecks.MvxSafeBurnValue = big.NewInt(4010 - 50 + 6010 - 50 + 2010 - 50 + 3000 - 50 + 1010 - 50)
token.MintBurnChecks.EthSafeMintValue = big.NewInt(4010 - 50 + 6010 - 50 + 2010 - 50 + 3000 - 50 + 1010 - 50)
}

// GenerateUnlistedTokenFromEth will generate an unlisted token on Eth
Expand Down Expand Up @@ -788,6 +822,93 @@ func GenerateUnlistedTokenFromMvx() framework.TestTokenParams {
}
}

// GenerateFrozenToken will generate a token that will be frozen
func GenerateFrozenToken() framework.TestTokenParams {
return framework.TestTokenParams{
IssueTokenParams: framework.IssueTokenParams{
AbstractTokenIdentifier: "FROZEN",
NumOfDecimalsUniversal: 2,
NumOfDecimalsChainSpecific: 2,
MvxUniversalTokenTicker: "FROZEN",
MvxChainSpecificTokenTicker: "FROZEN",
MvxUniversalTokenDisplayName: "TestFROZEN",
MvxChainSpecificTokenDisplayName: "TestFROZEN",
ValueToMintOnMvx: "10000000000",
IsMintBurnOnMvX: true,
IsNativeOnMvX: false,
HasChainSpecificToken: false,
EthTokenName: "EthFROZEN",
EthTokenSymbol: "FROZEN",
ValueToMintOnEth: "10000000000",
IsMintBurnOnEth: true,
IsNativeOnEth: true,
IsFrozen: true,
},
TestOperations: []framework.TokenOperations{
{
ValueToTransferToMvx: big.NewInt(2000),
ValueToSendFromMvX: nil,
},
{
ValueToTransferToMvx: big.NewInt(1500),
ValueToSendFromMvX: nil,
MvxSCCallData: createScCallData("callPayable", 50000000),
},
},
DeltaBalances: map[framework.HalfBridgeIdentifier]framework.DeltaBalancesOnKeys{
framework.FirstHalfBridge: map[string]*framework.DeltaBalanceHolder{
framework.Alice: {
OnEth: big.NewInt(-2000 - 1500),
OnMvx: big.NewInt(0),
MvxToken: framework.UniversalToken,
},
framework.Bob: {
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(1500),
MvxToken: framework.UniversalToken,
},
},
framework.SecondHalfBridge: map[string]*framework.DeltaBalanceHolder{
framework.Alice: {
OnEth: big.NewInt(-2000 - 1500 + 1950),
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(50),
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 All @@ -797,5 +918,8 @@ func createScCallData(function string, gasLimit uint64, args ...string) []byte {
Arguments: args,
}

return codec.EncodeCallDataStrict(callData)
buff := codec.EncodeCallDataStrict(callData)
log.Info("working with SC call data", "buff", buff)

return buff
}
1 change: 1 addition & 0 deletions integrationTests/relayers/slowTests/edgeCases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func TestRelayerShouldExecuteSimultaneousSwapsAndNotCatchErrors(t *testing.T) {
}()

usdcToken := GenerateTestUSDCToken()
usdcToken.MultipleSpendings = big.NewInt(2)
usdcToken.TestOperations = []framework.TokenOperations{
{
ValueToTransferToMvx: big.NewInt(5000),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func NewBridgeComponents(
ProposeStatusBase: 10000000,
ProposeStatusForEach: 7000000,
PerformActionBase: 40000000,
PerformActionForEach: 5500000,
PerformActionForEach: 7000000,
ScCallPerByte: 100000,
ScCallPerformForEach: 10000000,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const (
generateBlocksUntilTxProcessedEndpoint = "simulator/generate-blocks-until-transaction-processed/%s"
numProbeRetries = 10
networkConfigEndpointTemplate = "network/status/%d"
codeMetadata = "0502"
esdtSupplyEndpointTemplate = "network/esdt/supply/%s"
)

Expand Down Expand Up @@ -130,7 +131,7 @@ func (instance *chainSimulatorWrapper) DeploySC(ctx context.Context, wasmFilePat
require.Nil(instance.TB, err)

scCode := wasm.GetSCCode(wasmFilePath)
params := []string{scCode, wasm.VMTypeHex, wasm.DummyCodeMetadataHex}
params := []string{scCode, wasm.VMTypeHex, codeMetadata}
params = append(params, parameters...)
txData := strings.Join(params, "@")

Expand Down
30 changes: 13 additions & 17 deletions integrationTests/relayers/slowTests/framework/ethereumHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,13 +351,6 @@ 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.AliceKeys.EthAddress, mintAmount)
require.NoError(handler, err)
handler.SimulatedChain.Commit()
handler.checkEthTxResult(ctx, tx.Hash())
}

return ethMintBurnAddress, ethMintBurnContract
}

Expand All @@ -374,8 +367,8 @@ func (handler *EthereumHandler) deployTestERC20Contract(ctx context.Context, par
ethGenericTokenContract, err := contract.NewGenericERC20(ethGenericTokenAddress, handler.SimulatedChain.Client())
require.NoError(handler, err)

// mint the address that will create the transfers
handler.mintTokens(ctx, ethGenericTokenContract, params.ValueToMintOnEth, handler.AliceKeys.EthAddress)
// mint to the depositor
handler.mintTokens(ctx, ethGenericTokenContract, params.ValueToMintOnEth, handler.DepositorKeys.EthAddress)
if len(params.InitialSupplyValue) > 0 {
handler.mintTokens(ctx, ethGenericTokenContract, params.InitialSupplyValue, handler.SafeAddress)
}
Expand Down Expand Up @@ -465,15 +458,18 @@ func (handler *EthereumHandler) SettleBatchOnEthereum() {
}
}

// Mint will mint the provided token on Ethereum with the provided value on the behalf of the Depositor address
func (handler *EthereumHandler) Mint(ctx context.Context, params TestTokenParams, valueToMint *big.Int) {
token := handler.TokensRegistry.GetTokenData(params.AbstractTokenIdentifier)
require.NotNil(handler, token)
require.NotNil(handler, token.EthErc20Contract)
// TransferToken will transfer the amount of tokens from one address to another
func (handler *EthereumHandler) TransferToken(
ctx context.Context,
params TestTokenParams,
from KeysHolder,
to KeysHolder,
amount *big.Int,
) {
tkData := handler.TokensRegistry.GetTokenData(params.AbstractTokenIdentifier)

// mint erc20 token into eth safe
auth, _ := bind.NewKeyedTransactorWithChainID(handler.DepositorKeys.EthSK, handler.ChainID)
tx, err := token.EthErc20Contract.Mint(auth, handler.SafeAddress, valueToMint)
auth, _ := bind.NewKeyedTransactorWithChainID(from.EthSK, handler.ChainID)
tx, err := tkData.EthErc20Contract.Transfer(auth, to.EthAddress, amount)
require.NoError(handler, err)
handler.SimulatedChain.Commit()
handler.checkEthTxResult(ctx, tx.Hash())
Expand Down
Loading
Loading