From 50c8080095a05eed8b2abfa1cddb57fecd958577 Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Wed, 11 Dec 2024 12:37:11 +0200 Subject: [PATCH] - added wrapper checks in e2e tests --- integrationTests/relayers/slowTests/common.go | 62 +++++++++++++++++++ .../relayers/slowTests/edgeCases_test.go | 11 ++++ .../relayers/slowTests/framework/keys.go | 1 - .../slowTests/framework/multiversxHandler.go | 12 ++++ .../relayers/slowTests/framework/testSetup.go | 18 ++++++ .../relayers/slowTests/framework/types.go | 6 ++ .../relayers/slowTests/testFlow.go | 1 + 7 files changed, 110 insertions(+), 1 deletion(-) diff --git a/integrationTests/relayers/slowTests/common.go b/integrationTests/relayers/slowTests/common.go index f3c8e92d..6a61f79f 100644 --- a/integrationTests/relayers/slowTests/common.go +++ b/integrationTests/relayers/slowTests/common.go @@ -87,6 +87,11 @@ func GenerateTestUSDCToken() framework.TestTokenParams { OnMvx: big.NewInt(1000), MvxToken: framework.UniversalToken, }, + framework.WrapperSC: { + OnEth: big.NewInt(0), + OnMvx: big.NewInt(5000 + 7000 + 1000), + MvxToken: framework.ChainSpecificToken, + }, }, framework.SecondHalfBridge: map[string]*framework.DeltaBalanceHolder{ framework.Alice: { @@ -114,6 +119,11 @@ func GenerateTestUSDCToken() framework.TestTokenParams { OnMvx: big.NewInt(1000), MvxToken: framework.UniversalToken, }, + framework.WrapperSC: { + OnEth: big.NewInt(0), + OnMvx: big.NewInt(5000 + 7000 + 1000 - 2500 - 300), + MvxToken: framework.ChainSpecificToken, + }, }, }, MintBurnChecks: &framework.MintBurnBalances{ @@ -124,6 +134,9 @@ func GenerateTestUSDCToken() framework.TestTokenParams { SafeMintValue: big.NewInt(5000 + 7000 + 1000 + 900), SafeBurnValue: big.NewInt(2500 - 50 + 300 - 50 + 900 - 50), }, + SpecialChecks: &framework.SpecialBalanceChecks{ + WrapperDeltaLiquidityCheck: big.NewInt(5000 + 7000 + 1000 - 2500 - 300), + }, } } @@ -139,10 +152,14 @@ func ApplyUSDCRefundBalances(token *framework.TestTokenParams) { 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) + // we need to subtract the refunded value from the wrapper contract + token.DeltaBalances[framework.SecondHalfBridge][framework.WrapperSC].OnMvx = big.NewInt(5000 + 7000 + 1000 - 2500 - 300 - 1000) token.MintBurnChecks.TotalChainSpecificBurn = big.NewInt(2500 - 50 + 300 - 50 + 1000 - 50 + 900 - 50) token.MintBurnChecks.TotalUniversalBurn = big.NewInt(2500 + 300 + 1000) token.MintBurnChecks.SafeBurnValue = big.NewInt(2500 - 50 + 300 - 50 + 1000 - 50 + 900 - 50) + + token.SpecialChecks.WrapperDeltaLiquidityCheck = big.NewInt(5000 + 7000 + 1000 - 2500 - 300 - 1000) } // GenerateTestMEMEToken will generate a test MEME token @@ -210,6 +227,11 @@ func GenerateTestMEMEToken() framework.TestTokenParams { OnMvx: big.NewInt(0), MvxToken: framework.UniversalToken, }, + framework.WrapperSC: { + OnEth: big.NewInt(0), + OnMvx: big.NewInt(0), + MvxToken: framework.ChainSpecificToken, + }, }, framework.SecondHalfBridge: map[string]*framework.DeltaBalanceHolder{ framework.Alice: { @@ -237,6 +259,11 @@ func GenerateTestMEMEToken() framework.TestTokenParams { OnMvx: big.NewInt(1000), MvxToken: framework.UniversalToken, }, + framework.WrapperSC: { + OnEth: big.NewInt(0), + OnMvx: big.NewInt(0), + MvxToken: framework.ChainSpecificToken, + }, }, }, MintBurnChecks: &framework.MintBurnBalances{ @@ -247,6 +274,9 @@ func GenerateTestMEMEToken() framework.TestTokenParams { SafeMintValue: big.NewInt(0), SafeBurnValue: big.NewInt(0), }, + SpecialChecks: &framework.SpecialBalanceChecks{ + WrapperDeltaLiquidityCheck: big.NewInt(0), + }, } } @@ -329,6 +359,11 @@ func GenerateTestEUROCToken() framework.TestTokenParams { OnMvx: big.NewInt(1010), MvxToken: framework.UniversalToken, }, + framework.WrapperSC: { + OnEth: big.NewInt(0), + OnMvx: big.NewInt(0), + MvxToken: framework.ChainSpecificToken, + }, }, framework.SecondHalfBridge: map[string]*framework.DeltaBalanceHolder{ framework.Alice: { @@ -356,6 +391,11 @@ func GenerateTestEUROCToken() framework.TestTokenParams { OnMvx: big.NewInt(1010), MvxToken: framework.UniversalToken, }, + framework.WrapperSC: { + OnEth: big.NewInt(0), + OnMvx: big.NewInt(0), + MvxToken: framework.ChainSpecificToken, + }, }, }, MintBurnChecks: &framework.MintBurnBalances{ @@ -366,6 +406,9 @@ func GenerateTestEUROCToken() framework.TestTokenParams { SafeMintValue: big.NewInt(5010 + 7010 + 1010 + 700), SafeBurnValue: big.NewInt(2510 - 50 + 310 - 50 + 700 - 50), }, + SpecialChecks: &framework.SpecialBalanceChecks{ + WrapperDeltaLiquidityCheck: big.NewInt(0), + }, } } @@ -449,6 +492,11 @@ func GenerateTestMEXToken() framework.TestTokenParams { OnMvx: big.NewInt(0), MvxToken: framework.UniversalToken, }, + framework.WrapperSC: { + OnEth: big.NewInt(0), + OnMvx: big.NewInt(0), + MvxToken: framework.ChainSpecificToken, + }, }, framework.SecondHalfBridge: map[string]*framework.DeltaBalanceHolder{ framework.Alice: { @@ -476,6 +524,11 @@ func GenerateTestMEXToken() framework.TestTokenParams { OnMvx: big.NewInt(1010), MvxToken: framework.UniversalToken, }, + framework.WrapperSC: { + OnEth: big.NewInt(0), + OnMvx: big.NewInt(0), + MvxToken: framework.ChainSpecificToken, + }, }, }, MintBurnChecks: &framework.MintBurnBalances{ @@ -486,6 +539,9 @@ func GenerateTestMEXToken() framework.TestTokenParams { SafeMintValue: big.NewInt(2410 + 210 + 1010), SafeBurnValue: big.NewInt(4010 - 50 + 6010 - 50 + 2010 - 50), }, + SpecialChecks: &framework.SpecialBalanceChecks{ + WrapperDeltaLiquidityCheck: big.NewInt(0), + }, } } @@ -601,6 +657,9 @@ func GenerateUnlistedTokenFromEth() framework.TestTokenParams { SafeMintValue: big.NewInt(0), SafeBurnValue: big.NewInt(0), }, + SpecialChecks: &framework.SpecialBalanceChecks{ + WrapperDeltaLiquidityCheck: big.NewInt(0), + }, } } @@ -701,6 +760,9 @@ func GenerateUnlistedTokenFromMvx() framework.TestTokenParams { SafeMintValue: big.NewInt(0), SafeBurnValue: big.NewInt(0), }, + SpecialChecks: &framework.SpecialBalanceChecks{ + WrapperDeltaLiquidityCheck: big.NewInt(0), + }, } } diff --git a/integrationTests/relayers/slowTests/edgeCases_test.go b/integrationTests/relayers/slowTests/edgeCases_test.go index cc290eb1..d35932b9 100644 --- a/integrationTests/relayers/slowTests/edgeCases_test.go +++ b/integrationTests/relayers/slowTests/edgeCases_test.go @@ -66,6 +66,11 @@ func TestRelayerShouldExecuteSimultaneousSwapsAndNotCatchErrors(t *testing.T) { OnMvx: big.NewInt(0), MvxToken: framework.ChainSpecificToken, }, + framework.WrapperSC: { + OnEth: big.NewInt(0), + OnMvx: big.NewInt(5000), + MvxToken: framework.ChainSpecificToken, + }, }, framework.SecondHalfBridge: map[string]*framework.DeltaBalanceHolder{ framework.Alice: { @@ -83,6 +88,11 @@ func TestRelayerShouldExecuteSimultaneousSwapsAndNotCatchErrors(t *testing.T) { OnMvx: big.NewInt(50), MvxToken: framework.ChainSpecificToken, }, + framework.WrapperSC: { + OnEth: big.NewInt(0), + OnMvx: big.NewInt(5000 + 5000 - 200), + MvxToken: framework.ChainSpecificToken, + }, }, } usdcToken.MintBurnChecks = &framework.MintBurnBalances{ @@ -93,6 +103,7 @@ func TestRelayerShouldExecuteSimultaneousSwapsAndNotCatchErrors(t *testing.T) { SafeMintValue: big.NewInt(5000 + 5000), SafeBurnValue: big.NewInt(200 - 50), } + usdcToken.SpecialChecks.WrapperDeltaLiquidityCheck = big.NewInt(5000 + 5000 - 200) _ = testRelayersWithChainSimulatorAndTokensForSimultaneousSwaps( t, diff --git a/integrationTests/relayers/slowTests/framework/keys.go b/integrationTests/relayers/slowTests/framework/keys.go index c8f7fdbd..8e9c4435 100644 --- a/integrationTests/relayers/slowTests/framework/keys.go +++ b/integrationTests/relayers/slowTests/framework/keys.go @@ -61,7 +61,6 @@ const ( WrapperSC = "Wrapper SC" CalledTestSC = "Called test SC" SafeSC = "Safe SC" - AddressZero = "AddressZero" ) // NewKeysStore will create a KeysStore instance and generate all keys diff --git a/integrationTests/relayers/slowTests/framework/multiversxHandler.go b/integrationTests/relayers/slowTests/framework/multiversxHandler.go index d96cd8b3..e965b190 100644 --- a/integrationTests/relayers/slowTests/framework/multiversxHandler.go +++ b/integrationTests/relayers/slowTests/framework/multiversxHandler.go @@ -82,6 +82,7 @@ const ( getMintBalancesFunction = "getMintBalances" getBurnBalancesFunction = "getBurnBalances" getTotalBalancesFunction = "getTotalBalances" + getTokenLiquidityFunction = "getTokenLiquidity" ) var ( @@ -1212,6 +1213,17 @@ func (handler *MultiversxHandler) HasRefundBatch(ctx context.Context) bool { return len(responseData) != 0 } +// GetWrapperLiquidity invokes the getTokenLiquidity function, returning the stored liquidity on the wrapper contract +func (handler *MultiversxHandler) GetWrapperLiquidity(ctx context.Context, token string) *big.Int { + queryParams := []string{ + hex.EncodeToString([]byte(token)), + } + responseData := handler.ChainSimulator.ExecuteVMQuery(ctx, handler.WrapperAddress, getTokenLiquidityFunction, queryParams) + require.Greater(handler, len(responseData), 0) + value := big.NewInt(0).SetBytes(responseData[0]) + return value +} + func (handler *MultiversxHandler) scCallAndCheckTx( ctx context.Context, sender KeysHolder, diff --git a/integrationTests/relayers/slowTests/framework/testSetup.go b/integrationTests/relayers/slowTests/framework/testSetup.go index ff1bb7d6..d349a5df 100644 --- a/integrationTests/relayers/slowTests/framework/testSetup.go +++ b/integrationTests/relayers/slowTests/framework/testSetup.go @@ -178,6 +178,7 @@ func (setup *TestSetup) IssueAndConfigureTokens(tokens ...TestTokenParams) { ) setup.initMvxInitialBalancesForChainSpecificUnsafe(token, setup.MultiversxHandler.SafeAddress, + setup.MultiversxHandler.WrapperAddress, ) setup.initEthInitialBalancesUnsafe(token, @@ -686,6 +687,13 @@ func (setup *TestSetup) CheckCorrectnessOnMintBurnTokens(tokens ...TestTokenPara } } +// ExecuteSpecialChecks will trigger the special checks +func (setup *TestSetup) ExecuteSpecialChecks(tokens ...TestTokenParams) { + for _, params := range tokens { + setup.executeSpecialChecks(params) + } +} + func (setup *TestSetup) checkTotalMintBurnOnMvx(token TestTokenParams) { tokenData := setup.TokensRegistry.GetTokenData(token.AbstractTokenIdentifier) @@ -713,6 +721,16 @@ func (setup *TestSetup) checkSafeContractMintBurnOnMvx(token TestTokenParams) { require.Equal(setup, token.MintBurnChecks.SafeBurnValue.String(), burn.String(), fmt.Sprintf("safe contract, token: %s", tokenData.MvxChainSpecificToken)) } +func (setup *TestSetup) executeSpecialChecks(token TestTokenParams) { + tokenData := setup.TokensRegistry.GetTokenData(token.AbstractTokenIdentifier) + + actualValue := setup.MultiversxHandler.GetWrapperLiquidity(setup.Ctx, tokenData.MvxChainSpecificToken) + initialBalance := setup.getBalanceMappingForAddressAndToken(setup.MultiversxHandler.WrapperAddress.Bech32(), token) + expectedValue := big.NewInt(0).Add(initialBalance, token.SpecialChecks.WrapperDeltaLiquidityCheck) + + require.Equal(setup, expectedValue.String(), actualValue.String(), fmt.Sprintf("wrapper contract, token: %s", tokenData.MvxChainSpecificToken)) +} + // Close will close the test subcomponents func (setup *TestSetup) Close() { log.Info(fmt.Sprintf(LogStepMarker, "closing relayers & sc execution module")) diff --git a/integrationTests/relayers/slowTests/framework/types.go b/integrationTests/relayers/slowTests/framework/types.go index 6ab2e2f7..36c187cf 100644 --- a/integrationTests/relayers/slowTests/framework/types.go +++ b/integrationTests/relayers/slowTests/framework/types.go @@ -57,6 +57,7 @@ type TestTokenParams struct { TestOperations []TokenOperations DeltaBalances map[HalfBridgeIdentifier]DeltaBalancesOnKeys MintBurnChecks *MintBurnBalances + SpecialChecks *SpecialBalanceChecks } // TokenData represents a test token data @@ -97,3 +98,8 @@ type ESDTSupply struct { Minted string `json:"minted"` Burned string `json:"burned"` } + +// SpecialBalanceChecks stores the special checks that are done at the end of the test +type SpecialBalanceChecks struct { + WrapperDeltaLiquidityCheck *big.Int +} diff --git a/integrationTests/relayers/slowTests/testFlow.go b/integrationTests/relayers/slowTests/testFlow.go index 8fc3bc5e..8fc816d7 100644 --- a/integrationTests/relayers/slowTests/testFlow.go +++ b/integrationTests/relayers/slowTests/testFlow.go @@ -56,6 +56,7 @@ func (flow *testFlow) process() (finished bool) { transferDoneForSecondHalf := flow.setup.AreAllTransfersCompleted(framework.SecondHalfBridge, flow.tokens...) if !flow.secondHalfBridgeDone && transferDoneForSecondHalf { flow.setup.CheckCorrectnessOnMintBurnTokens(flow.tokens...) + flow.setup.ExecuteSpecialChecks(flow.tokens...) flow.secondHalfBridgeDone = true log.Info(fmt.Sprintf(framework.LogStepMarker, flow.messageAfterSecondHalfBridge))