Skip to content

Commit

Permalink
Merge pull request #385 from multiversx/refactored-balance-checking
Browse files Browse the repository at this point in the history
Refactored balance checking mechanism in e2e tests
  • Loading branch information
iulianpascalau authored Dec 3, 2024
2 parents 257b1cf + 4a32880 commit d71371a
Show file tree
Hide file tree
Showing 11 changed files with 632 additions and 406 deletions.
399 changes: 340 additions & 59 deletions integrationTests/relayers/slowTests/common.go

Large diffs are not rendered by default.

43 changes: 33 additions & 10 deletions integrationTests/relayers/slowTests/edgeCases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import (
)

func TestRelayerShouldExecuteSimultaneousSwapsAndNotCatchErrors(t *testing.T) {
t.Skip("TODO: fix this test")

errorString := "ERROR"
mockLogObserver := mock.NewMockLogObserver(errorString, "got invalid action ID")
err := logger.AddLogObserver(mockLogObserver, &logger.PlainFormatter{})
Expand Down Expand Up @@ -51,15 +49,40 @@ func TestRelayerShouldExecuteSimultaneousSwapsAndNotCatchErrors(t *testing.T) {
MvxForceSCCall: false,
},
}
usdcToken.ESDTSafeExtraBalance = big.NewInt(50)
usdcToken.ExtraBalances = map[string]framework.ExtraBalanceHolder{
"Alice": {
SentAmount: big.NewInt(-5000),
ReceivedAmount: big.NewInt(0),
usdcToken.DeltaBalances = map[framework.HalfBridgeIdentifier]framework.DeltaBalancesOnKeys{
framework.FirstHalfBridge: map[string]*framework.DeltaBalanceHolder{
framework.Alice: {
OnEth: big.NewInt(-5000),
OnMvx: big.NewInt(0),
MvxToken: framework.UniversalToken,
},
framework.Bob: {
OnEth: big.NewInt(0),
OnMvx: big.NewInt(5000),
MvxToken: framework.UniversalToken,
},
framework.SafeSC: {
OnEth: big.NewInt(5000),
OnMvx: big.NewInt(0),
MvxToken: framework.ChainSpecificToken,
},
},
"Bob": {
SentAmount: big.NewInt(-200),
ReceivedAmount: big.NewInt(5000),
framework.SecondHalfBridge: map[string]*framework.DeltaBalanceHolder{
framework.Alice: {
OnEth: big.NewInt(-5000 - 5000 + 150),
OnMvx: big.NewInt(0),
MvxToken: framework.UniversalToken,
},
framework.Bob: {
OnEth: big.NewInt(0),
OnMvx: big.NewInt(5000 + 4800),
MvxToken: framework.UniversalToken,
},
framework.SafeSC: {
OnEth: big.NewInt(5000 + 5000 - 150),
OnMvx: big.NewInt(50),
MvxToken: framework.ChainSpecificToken,
},
},
}

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 Expand Up @@ -311,11 +311,29 @@ func createBadToken() framework.TestTokenParams {
MvxSCCallData: createScCallData("callPayable", 50000000),
},
},
ESDTSafeExtraBalance: big.NewInt(0),
ExtraBalances: map[string]framework.ExtraBalanceHolder{
"Alice": {SentAmount: big.NewInt(-5000 - 7000 - 1000), ReceivedAmount: big.NewInt(0), RefundAmount: big.NewInt(0)},
"Bob": {SentAmount: big.NewInt(-2500 - 300), ReceivedAmount: big.NewInt(5000 + 7000), RefundAmount: big.NewInt(0)},
"Charlie": {SentAmount: big.NewInt(0), ReceivedAmount: big.NewInt(2500 - 50 + 300 - 50), RefundAmount: big.NewInt(0)},
DeltaBalances: map[framework.HalfBridgeIdentifier]framework.DeltaBalancesOnKeys{
framework.FirstHalfBridge: map[string]*framework.DeltaBalanceHolder{
framework.Alice: {
OnEth: big.NewInt(-5000 - 7000 - 1000),
OnMvx: big.NewInt(0),
MvxToken: framework.UniversalToken,
},
framework.Bob: {
OnEth: big.NewInt(0),
OnMvx: big.NewInt(5000 + 7000),
MvxToken: framework.UniversalToken,
},
framework.SafeSC: {
OnEth: big.NewInt(5000 + 7000),
OnMvx: big.NewInt(0),
MvxToken: framework.ChainSpecificToken,
},
framework.CalledTestSC: {
OnEth: big.NewInt(0),
OnMvx: big.NewInt(0),
MvxToken: framework.UniversalToken,
},
},
},
}
}
Expand Down
18 changes: 18 additions & 0 deletions integrationTests/relayers/slowTests/framework/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@ import (
logger "github.com/multiversx/mx-chain-logger-go"
)

// HalfBridgeIdentifier is the type that holds the half-bridge identifier (counter)
type HalfBridgeIdentifier string

// TokenBalanceType represents the token type that should be checked for balance
type TokenBalanceType string

const (
// FirstHalfBridge represents the first half bridge in the tests
FirstHalfBridge HalfBridgeIdentifier = "first half bridge"
// SecondHalfBridge represents the second half bridge in the tests
SecondHalfBridge HalfBridgeIdentifier = "second half bridge"

// UniversalToken is the universal token identifier
UniversalToken TokenBalanceType = "universal"
// ChainSpecificToken is the chain-specific token identifier
ChainSpecificToken TokenBalanceType = "chain-specific"
)

var (
log = logger.GetOrCreate("integrationtests/slowtests")
addressPubkeyConverter, _ = pubkeyConverter.NewBech32PubkeyConverter(32, "erd")
Expand Down
3 changes: 3 additions & 0 deletions integrationTests/relayers/slowTests/framework/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ const (
Alice = "Alice"
Bob = "Bob"
Charlie = "Charlie"
WrapperSC = "Wrapper SC"
CalledTestSC = "Called test SC"
SafeSC = "Safe SC"
AddressZero = "AddressZero"
)

Expand Down
Loading

0 comments on commit d71371a

Please sign in to comment.