Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frozen token scenario integration tests #391

Draft
wants to merge 2 commits into
base: feat/v3.1
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions integrationTests/relayers/slowTests/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,93 @@ func GenerateUnlistedTokenFromMvx() framework.TestTokenParams {
}
}

// GenerateFrozenToken will generate a token that will be frozen
func GenerateFrozenToken() framework.TestTokenParams {
return framework.TestTokenParams{
IssueTokenParams: framework.IssueTokenParams{
AbstractTokenIdentifier: "FROZEN",
NumOfDecimalsUniversal: 2,
NumOfDecimalsChainSpecific: 2,
MvxUniversalTokenTicker: "FROZEN",
MvxChainSpecificTokenTicker: "FROZEN",
MvxUniversalTokenDisplayName: "TestFROZEN",
MvxChainSpecificTokenDisplayName: "TestFROZEN",
ValueToMintOnMvx: "10000000000",
IsMintBurnOnMvX: true,
IsNativeOnMvX: false,
HasChainSpecificToken: false,
EthTokenName: "EthFROZEN",
EthTokenSymbol: "FROZEN",
ValueToMintOnEth: "10000000000",
IsMintBurnOnEth: true,
IsNativeOnEth: true,
IsFrozen: true,
},
TestOperations: []framework.TokenOperations{
{
ValueToTransferToMvx: big.NewInt(2000),
ValueToSendFromMvX: nil,
},
{
ValueToTransferToMvx: big.NewInt(1500),
ValueToSendFromMvX: nil,
MvxSCCallData: createScCallData("callPayable", 50000000),
},
},
DeltaBalances: map[framework.HalfBridgeIdentifier]framework.DeltaBalancesOnKeys{
framework.FirstHalfBridge: map[string]*framework.DeltaBalanceHolder{
framework.Alice: {
OnEth: big.NewInt(-2000 - 1500),
OnMvx: big.NewInt(0),
MvxToken: framework.UniversalToken,
},
framework.Bob: {
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(-2000 - 1500 + 1950 + 1450),
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(50),
MvxToken: framework.ChainSpecificToken,
},
framework.CalledTestSC: {
OnEth: big.NewInt(0),
OnMvx: big.NewInt(0),
MvxToken: framework.UniversalToken,
},
},
},
}
}

func createScCallData(function string, gasLimit uint64, args ...string) []byte {
codec := testsCommon.TestMultiversXCodec{}
callData := parsers.CallData{
Expand Down
32 changes: 32 additions & 0 deletions integrationTests/relayers/slowTests/framework/multiversxHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
slashAmount = "00"
zeroStringValue = "0"
canAddSpecialRoles = "canAddSpecialRoles"
canFreeze = "canFreeze"
trueStr = "true"
esdtRoleLocalMint = "ESDTRoleLocalMint"
esdtRoleLocalBurn = "ESDTRoleLocalBurn"
Expand Down Expand Up @@ -59,6 +60,7 @@ const (
pauseFunction = "pause"
issueFunction = "issue"
setSpecialRoleFunction = "setSpecialRole"
freezeFunction = "freeze"
esdtTransferFunction = "ESDTTransfer"
setPairDecimalsFunction = "setPairDecimals"
addWrappedTokenFunction = "addWrappedToken"
Expand Down Expand Up @@ -564,6 +566,9 @@ func (handler *MultiversxHandler) issueAndWhitelistTokensWithChainSpecific(ctx c
if params.PreventWhitelist {
return
}
if params.IsFrozen {
handler.freezeToken(ctx, params)
}
handler.setLocalRolesForUniversalTokenOnWrapper(ctx, params)
handler.transferChainSpecificTokenToSCs(ctx, params)
handler.addUniversalTokenToWrapper(ctx, params)
Expand All @@ -586,6 +591,9 @@ func (handler *MultiversxHandler) issueAndWhitelistTokens(ctx context.Context, p
if params.PreventWhitelist {
return
}
if params.IsFrozen {
handler.freezeToken(ctx, params)
}

handler.setRolesForSpecificTokenOnSafe(ctx, params)
handler.addMappingInMultisig(ctx, params)
Expand All @@ -609,6 +617,8 @@ func (handler *MultiversxHandler) issueUniversalToken(ctx context.Context, param
hex.EncodeToString([]byte(params.MvxUniversalTokenTicker)),
hex.EncodeToString(valueToMintInt.Bytes()),
fmt.Sprintf("%02x", params.NumOfDecimalsUniversal),
hex.EncodeToString([]byte(canFreeze)),
hex.EncodeToString([]byte(trueStr)),
hex.EncodeToString([]byte(canAddSpecialRoles)),
hex.EncodeToString([]byte(trueStr))}

Expand All @@ -635,6 +645,8 @@ func (handler *MultiversxHandler) issueChainSpecificToken(ctx context.Context, p
hex.EncodeToString([]byte(params.MvxChainSpecificTokenTicker)),
hex.EncodeToString(valueToMintInt.Bytes()),
fmt.Sprintf("%02x", params.NumOfDecimalsChainSpecific),
hex.EncodeToString([]byte(canFreeze)),
hex.EncodeToString([]byte(trueStr)),
hex.EncodeToString([]byte(canAddSpecialRoles)),
hex.EncodeToString([]byte(trueStr))}

Expand Down Expand Up @@ -940,6 +952,26 @@ func (handler *MultiversxHandler) setMaxBridgeAmountOnMultitransfer(ctx context.
log.Info("multi-transfer set max bridge amount for token tx executed", "hash", hash, "status", txResult.Status)
}

func (handler *MultiversxHandler) freezeToken(ctx context.Context, params IssueTokenParams) {
tkData := handler.TokensRegistry.GetTokenData(params.AbstractTokenIdentifier)

scCallParams := []string{
hex.EncodeToString([]byte(tkData.MvxUniversalToken)),
handler.BobKeys.MvxAddress.Hex(),
}

hash, txResult := handler.scCallAndCheckTx(
ctx,
handler.OwnerKeys,
handler.ESDTSystemContractAddress,
zeroStringValue,
setCallsGasLimit,
freezeFunction,
scCallParams)

log.Info("freeze token tx executed", "hash", hash, "status", txResult.Status)
}

func (handler *MultiversxHandler) getTokenNameFromResult(txResult data.TransactionOnNetwork) string {
for _, event := range txResult.Logs.Events {
if event.Identifier == issueFunction {
Expand Down
1 change: 1 addition & 0 deletions integrationTests/relayers/slowTests/framework/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type IssueTokenParams struct {
InitialSupplyParams
AbstractTokenIdentifier string
PreventWhitelist bool
IsFrozen bool

// MultiversX
NumOfDecimalsUniversal int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,15 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) {
mexToken,
)
})
t.Run("frozen token for receiver should refund", func(t *testing.T) {
frozenToken := GenerateFrozenToken()

testRelayersWithChainSimulatorAndTokensAndRefund(
t,
make(chan error),
frozenToken,
)
})
}

func testRelayersWithChainSimulatorAndTokensAndRefund(tb testing.TB, manualStopChan chan error, tokens ...framework.TestTokenParams) {
Expand Down
Loading