Skip to content

Commit

Permalink
- added wrapper checks in e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
iulianpascalau committed Dec 11, 2024
1 parent 663f78e commit 50c8080
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 1 deletion.
62 changes: 62 additions & 0 deletions integrationTests/relayers/slowTests/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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{
Expand All @@ -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),
},
}
}

Expand All @@ -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
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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{
Expand All @@ -247,6 +274,9 @@ func GenerateTestMEMEToken() framework.TestTokenParams {
SafeMintValue: big.NewInt(0),
SafeBurnValue: big.NewInt(0),
},
SpecialChecks: &framework.SpecialBalanceChecks{
WrapperDeltaLiquidityCheck: big.NewInt(0),
},
}
}

Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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{
Expand All @@ -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),
},
}
}

Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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{
Expand All @@ -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),
},
}
}

Expand Down Expand Up @@ -601,6 +657,9 @@ func GenerateUnlistedTokenFromEth() framework.TestTokenParams {
SafeMintValue: big.NewInt(0),
SafeBurnValue: big.NewInt(0),
},
SpecialChecks: &framework.SpecialBalanceChecks{
WrapperDeltaLiquidityCheck: big.NewInt(0),
},
}
}

Expand Down Expand Up @@ -701,6 +760,9 @@ func GenerateUnlistedTokenFromMvx() framework.TestTokenParams {
SafeMintValue: big.NewInt(0),
SafeBurnValue: big.NewInt(0),
},
SpecialChecks: &framework.SpecialBalanceChecks{
WrapperDeltaLiquidityCheck: big.NewInt(0),
},
}
}

Expand Down
11 changes: 11 additions & 0 deletions integrationTests/relayers/slowTests/edgeCases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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{
Expand All @@ -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,
Expand Down
1 change: 0 additions & 1 deletion integrationTests/relayers/slowTests/framework/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions integrationTests/relayers/slowTests/framework/multiversxHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const (
getMintBalancesFunction = "getMintBalances"
getBurnBalancesFunction = "getBurnBalances"
getTotalBalancesFunction = "getTotalBalances"
getTokenLiquidityFunction = "getTokenLiquidity"
)

var (
Expand Down Expand Up @@ -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,
Expand Down
18 changes: 18 additions & 0 deletions integrationTests/relayers/slowTests/framework/testSetup.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ func (setup *TestSetup) IssueAndConfigureTokens(tokens ...TestTokenParams) {
)
setup.initMvxInitialBalancesForChainSpecificUnsafe(token,
setup.MultiversxHandler.SafeAddress,
setup.MultiversxHandler.WrapperAddress,
)

setup.initEthInitialBalancesUnsafe(token,
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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"))
Expand Down
6 changes: 6 additions & 0 deletions integrationTests/relayers/slowTests/framework/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type TestTokenParams struct {
TestOperations []TokenOperations
DeltaBalances map[HalfBridgeIdentifier]DeltaBalancesOnKeys
MintBurnChecks *MintBurnBalances
SpecialChecks *SpecialBalanceChecks
}

// TokenData represents a test token data
Expand Down Expand Up @@ -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
}
1 change: 1 addition & 0 deletions integrationTests/relayers/slowTests/testFlow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 50c8080

Please sign in to comment.