Skip to content

Commit

Permalink
Merge pull request #430 from multiversx/deposit-with-blacklisted-toke…
Browse files Browse the repository at this point in the history
…ns-e2e-test
  • Loading branch information
cosmatudor authored Feb 25, 2025
2 parents 294688f + bd3bd9f commit 86599c9
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,61 @@ func TestRelayersShouldExecuteTransfers(t *testing.T) {
eurocToken,
)
})
t.Run("1 universal blacklisted token, 1 chain specific blacklisted token, 1 good token", func(t *testing.T) {
memeToken := slowTests.GenerateTestMEMEToken()
memeToken.IsBlacklisted = true
memeToken.TestOperations = []framework.TokenOperations{
{
ValueToTransferToMvx: nil,
ValueToSendFromMvX: big.NewInt(1800),
},
}
memeToken.MintBurnChecks = &framework.MintBurnBalances{
MvxTotalUniversalMint: big.NewInt(0),
MvxTotalChainSpecificMint: big.NewInt(0),
MvxTotalUniversalBurn: big.NewInt(0),
MvxTotalChainSpecificBurn: big.NewInt(0),
MvxSafeMintValue: big.NewInt(0),
MvxSafeBurnValue: big.NewInt(0),

EthSafeMintValue: big.NewInt(0),
EthSafeBurnValue: big.NewInt(0),
}
memeToken.SpecialChecks = &framework.SpecialBalanceChecks{
WrapperDeltaLiquidityCheck: big.NewInt(0),
}

mexToken := slowTests.GenerateTestMEXToken()
mexToken.IsBlacklisted = true
mexToken.TestOperations = []framework.TokenOperations{
{
ValueToTransferToMvx: nil,
ValueToSendFromMvX: big.NewInt(2700),
},
}
mexToken.MintBurnChecks = &framework.MintBurnBalances{
MvxTotalUniversalMint: big.NewInt(0),
MvxTotalChainSpecificMint: big.NewInt(0),
MvxTotalUniversalBurn: big.NewInt(0),
MvxTotalChainSpecificBurn: big.NewInt(0),
MvxSafeMintValue: big.NewInt(0),
MvxSafeBurnValue: big.NewInt(0),

EthSafeMintValue: big.NewInt(0),
EthSafeBurnValue: big.NewInt(0),
}
mexToken.SpecialChecks = &framework.SpecialBalanceChecks{
WrapperDeltaLiquidityCheck: big.NewInt(0),
}

tadaToken := slowTests.GenerateTestTADAToken()

_ = slowTests.NewTestEnvironmentWithChainSimulatorAndTokens(
t,
make(chan error),
memeToken,
mexToken,
tadaToken,
)
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,10 @@ func TestRelayersShouldNotExecuteTransfers(t *testing.T) {
slowTests.GenerateUnlistedTokenFromMvx(),
)
})
t.Run("mvx token with transfer role for no actor, blacklisted, frozen should fail when creating deposit", func(t *testing.T) {
t.Run("mvx token with transfer role for no actor should fail when creating deposit", func(t *testing.T) {
// meme token
memeToken := slowTests.GenerateTestMEMEToken()
memeToken.IsFrozen = true
memeToken.AddressesWithTransferRole = []string{framework.Owner}
memeToken.IsBlacklisted = true

memeToken.TestOperations = []framework.TokenOperations{
{
Expand Down Expand Up @@ -164,9 +162,7 @@ func TestRelayersShouldNotExecuteTransfers(t *testing.T) {

// mex token
mexToken := slowTests.GenerateTestMEXToken()
mexToken.IsFrozen = true
mexToken.AddressesWithTransferRole = []string{framework.Owner}
mexToken.IsBlacklisted = true

mexToken.TestOperations = []framework.TokenOperations{
{
Expand Down Expand Up @@ -257,12 +253,11 @@ func TestRelayersShouldNotExecuteTransfers(t *testing.T) {
mexToken,
)
})
t.Run("mvx token with transfer role only for Alice, blacklisted, frozen should fail when withdrawing fees", func(t *testing.T) {
t.Run("mvx token with transfer role only for Alice, frozen, should fail when withdrawing fees", func(t *testing.T) {
// meme token
memeToken := slowTests.GenerateTestMEMEToken()
memeToken.IsFrozen = true
memeToken.AddressesWithTransferRole = []string{framework.Alice}
memeToken.IsBlacklisted = true

memeToken.TestOperations = []framework.TokenOperations{
{
Expand Down Expand Up @@ -350,7 +345,6 @@ func TestRelayersShouldNotExecuteTransfers(t *testing.T) {
mexToken := slowTests.GenerateTestMEXToken()
mexToken.IsFrozen = true
mexToken.AddressesWithTransferRole = []string{framework.Alice}
mexToken.IsBlacklisted = true

mexToken.TestOperations = []framework.TokenOperations{
{
Expand Down
39 changes: 35 additions & 4 deletions integrationTests/relayers/slowTests/framework/testSetup.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,7 @@ func (setup *TestSetup) AreAllTransfersCompleted(halfBridgeIdentifier HalfBridge
}

func (setup *TestSetup) isTransferDone(halfBridgeIdentifier HalfBridgeIdentifier, token TestTokenParams) bool {
// if token is prevented from whitelist or Alice don't have the permission to transfer it, we can't check the balances
if token.PreventWhitelist || !setup.hasAddressTransferRole(token, Alice) {
if setup.shouldAvoidChecks(token) {
return true
}

Expand All @@ -297,6 +296,21 @@ func (setup *TestSetup) isTransferDone(halfBridgeIdentifier HalfBridgeIdentifier
return true
}

func (setup *TestSetup) shouldAvoidChecks(token TestTokenParams) bool {
if token.PreventWhitelist {
return true
}
// if Alice doesn't have transfer role, we can't check the balances
if !setup.hasAddressTransferRole(token, Alice) {
return true
}
if token.IsBlacklisted {
return true
}

return false
}

func (setup *TestSetup) isBalanceOkOnMvx(entityName string, deltaBalance *DeltaBalanceHolder, token TestTokenParams) bool {
address := setup.getMvxAddressFromEntityName(entityName)

Expand Down Expand Up @@ -454,7 +468,7 @@ func (setup *TestSetup) createDepositOnMultiversxForToken(from KeysHolder, to Ke

depositValue.Add(depositValue, operation.ValueToSendFromMvX)

if operation.IsFaultyDeposit || params.PreventWhitelist || !setup.hasAddressTransferRole(params, Alice) {
if setup.isWrongDeposit(operation, params) {
setup.MultiversxHandler.SendWrongDepositTransactionFromMultiversx(setup.Ctx, from, to, token, params, operation.ValueToSendFromMvX)
} else {
setup.MultiversxHandler.SendDepositTransactionFromMultiversx(setup.Ctx, from, to, token, params, operation.ValueToSendFromMvX)
Expand All @@ -464,6 +478,23 @@ func (setup *TestSetup) createDepositOnMultiversxForToken(from KeysHolder, to Ke
return depositValue
}

func (setup *TestSetup) isWrongDeposit(operation TokenOperations, params TestTokenParams) bool {
if params.IsBlacklisted {
return true
}
if params.PreventWhitelist {
return true
}
if operation.IsFaultyDeposit {
return true
}
if !setup.hasAddressTransferRole(params, Alice) {
return true
}

return false
}

// CreateBatchOnEthereum will create deposits that will be gathered in a batch on Ethereum
func (setup *TestSetup) CreateBatchOnEthereum(mvxCalleeScAddress sdkCore.AddressHandler, tokensParams ...TestTokenParams) {
for _, params := range tokensParams {
Expand Down Expand Up @@ -565,7 +596,7 @@ func (setup *TestSetup) TestWithdrawTotalFeesOnEthereumForTokens(tokensParams ..
expectedRefund := big.NewInt(0)
expectedAccumulated := big.NewInt(0)

if param.PreventWhitelist || !setup.hasAddressTransferRole(param, Alice) {
if setup.shouldAvoidChecks(param) {
continue
}

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 86599c9

Please sign in to comment.