Skip to content

Commit

Permalink
- fixes after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
iulianpascalau committed Dec 2, 2024
1 parent 044607d commit 4a32880
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 95 deletions.
136 changes: 123 additions & 13 deletions integrationTests/relayers/slowTests/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func GenerateTestUSDCToken() framework.TestTokenParams {
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 @@ -78,7 +78,7 @@ 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,
},
Expand All @@ -90,7 +90,7 @@ func GenerateTestUSDCToken() framework.TestTokenParams {
},
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,
},
Expand All @@ -105,8 +105,8 @@ func GenerateTestUSDCToken() framework.TestTokenParams {
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 @@ -122,11 +122,11 @@ func GenerateTestUSDCToken() framework.TestTokenParams {
// ApplyUSDCRefundBalances will apply the refund balances on the involved entities for the USDC token
func ApplyUSDCRefundBalances(token *framework.TestTokenParams) {
// 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)
token.DeltaBalances[framework.SecondHalfBridge][framework.Alice].OnEth = big.NewInt(-5000 - 7000 - 1000 - 900 + 950 + 850)
// no funds remain in the test caller SC
token.DeltaBalances[framework.SecondHalfBridge][framework.CalledTestSC].OnMvx = big.NewInt(0)
}
Expand Down Expand Up @@ -288,7 +288,7 @@ func GenerateTestEUROCToken() framework.TestTokenParams {
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 @@ -310,7 +310,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 @@ -326,7 +326,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 Down Expand Up @@ -481,7 +481,62 @@ func GenerateUnlistedTokenFromEth() framework.TestTokenParams {
IsFaultyDeposit: true,
},
},
ESDTSafeExtraBalance: big.NewInt(0),
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,
},
},
},
}
}

Expand Down Expand Up @@ -518,7 +573,62 @@ func GenerateUnlistedTokenFromMvx() framework.TestTokenParams {
MvxSCCallData: createScCallData("callPayable", 50000000),
},
},
ESDTSafeExtraBalance: big.NewInt(0),
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,
},
},
},
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func testRelayersWithChainSimulatorAndTokens(tb testing.TB, manualStopChan chan
}

processFunc := func(tb testing.TB, setup *framework.TestSetup) bool {
if startsFromEthFlow.process() && startsFromMvXFlow.process() && startsFromEthFlow.areTokensFullyRefunded() {
if startsFromEthFlow.process() && startsFromMvXFlow.process() {
setup.TestWithdrawTotalFeesOnEthereumForTokens(startsFromMvXFlow.tokens...)
setup.TestWithdrawTotalFeesOnEthereumForTokens(startsFromEthFlow.tokens...)

Expand Down
55 changes: 1 addition & 54 deletions integrationTests/relayers/slowTests/framework/testSetup.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,6 @@ const (
mvxHrp = "erd"
)

// CurrentActorState represents the state of an actor in a transaction
type CurrentActorState struct {
isSender bool
HasToReceiveRefund bool
}

var (
senderState = CurrentActorState{
isSender: true,
HasToReceiveRefund: false,
}
receiverState = CurrentActorState{
isSender: false,
HasToReceiveRefund: false,
}
)

// TestSetup is the struct that holds all subcomponents for the testing infrastructure
type TestSetup struct {
testing.TB
Expand Down Expand Up @@ -331,7 +314,7 @@ func (setup *TestSetup) getMvxAddressFromEntityName(entityName string) *MvxAddre
return nil
}

func (setup *TestSetup) getBalanceMappingForAddressAndToken(addr string, token TestTokenParams) *big.Int {
func (setup *TestSetup) getBalanceMappingForAddressAndToken(address string, token TestTokenParams) *big.Int {
setup.mutBalances.Lock()
defer setup.mutBalances.Unlock()

Expand Down Expand Up @@ -385,18 +368,6 @@ func (setup *TestSetup) getEthAddressFromEntityName(entityName string) (common.A
return common.Address{}, false
}

func (setup *TestSetup) getExtraBalanceForHolder(address string, params TestTokenParams) ExtraBalanceHolder {
setup.mutBalances.Lock()
defer setup.mutBalances.Unlock()

holderName := AddressZero
if address != "" {
holderName = setup.AddressToName[address]
}

return params.ExtraBalances[holderName]
}

func (setup *TestSetup) checkContractMvxBalanceForToken(params TestTokenParams) bool {
mvxBalance := setup.MultiversxHandler.GetESDTUniversalTokenBalance(setup.Ctx, setup.MultiversxHandler.CalleeScAddress, params.AbstractTokenIdentifier)
expectedValueOnContract := big.NewInt(0)
Expand Down Expand Up @@ -484,30 +455,6 @@ func (setup *TestSetup) computeExpectedValueFromMvx(params TestTokenParams) *big
return expectedValue
}

// IsTransferDoneFromEthereumWithRefund returns true if all provided tokens are bridged from Ethereum towards MultiversX including refunds
func (setup *TestSetup) IsTransferDoneFromEthereumWithRefund(holder KeysHolder, tokens ...TestTokenParams) bool {
isDone := true
for _, params := range tokens {
isDone = isDone && setup.isTransferDoneFromEthWithRefundForToken(holder, params)
}

return isDone
}

func (setup *TestSetup) isTransferDoneFromEthWithRefundForToken(holder KeysHolder, params TestTokenParams) bool {
// if token is prevented from whitelist, we can't check the balances
if params.PreventWhitelist {
return true
}

actorState := CurrentActorState{
isSender: true,
HasToReceiveRefund: true,
}

return setup.checkHolderEthBalanceForToken(holder, actorState, params)
}

func (setup *TestSetup) checkMvxBurnedTokenBalance(params TestTokenParams) bool {
token := setup.GetTokenData(params.AbstractTokenIdentifier)
burnedTokens := setup.MultiversxHandler.GetBurnedAmountForToken(setup.Ctx, token.MvxChainSpecificToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func testRelayersWithChainSimulatorAndTokensAndRefund(tb testing.TB, manualStopC
}

processFunc := func(tb testing.TB, setup *framework.TestSetup) bool {
if startsFromEthFlow.process() && startsFromMvXFlow.process() && startsFromMvXFlow.areTokensFullyRefunded() {
if startsFromEthFlow.process() && startsFromMvXFlow.process() {
return true
}

Expand Down
19 changes: 4 additions & 15 deletions integrationTests/relayers/slowTests/startsFromEthereumFlow.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ func (flow *startsFromEthereumFlow) process() (finished bool) {
return false
}

if flow.setup.MultiversxHandler.HasRefundBatch(flow.setup.Ctx) {
flow.setup.MultiversxHandler.MoveRefundBatchToSafe(flow.setup.Ctx)
}

transferDoneForSecondHalf := flow.setup.AreAllTransfersCompleted(framework.SecondHalfBridge, flow.tokens...)
if !flow.mvxToEthDone && transferDoneForSecondHalf {
flow.mvxToEthDone = true
Expand All @@ -46,18 +50,3 @@ func (flow *startsFromEthereumFlow) process() (finished bool) {

return false
}

func (flow *startsFromEthereumFlow) areTokensFullyRefunded() bool {
if len(flow.tokens) == 0 {
return true
}
if !flow.ethToMvxDone {
return false // regular flow is not completed
}

if flow.setup.MultiversxHandler.HasRefundBatch(flow.setup.Ctx) {
flow.setup.MultiversxHandler.MoveRefundBatchToSafe(flow.setup.Ctx)
}

return flow.setup.IsTransferDoneFromEthereumWithRefund(flow.setup.AliceKeys, flow.tokens...)
}
11 changes: 0 additions & 11 deletions integrationTests/relayers/slowTests/startsFromMultiversxFlow.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,3 @@ func (flow *startsFromMultiversXFlow) process() (finished bool) {

return false
}

func (flow *startsFromMultiversXFlow) areTokensFullyRefunded() bool {
if len(flow.tokens) == 0 {
return true
}
if !flow.ethToMvxDone {
return false // regular flow is not completed
}

return flow.setup.IsTransferDoneFromEthereumWithRefund(flow.setup.BobKeys, flow.tokens...)
}

0 comments on commit 4a32880

Please sign in to comment.