Skip to content

Commit

Permalink
add test for frozen token
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmatudor committed Dec 9, 2024
1 parent 908e47c commit c4ebaab
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 0 deletions.
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 @@ -367,6 +367,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

0 comments on commit c4ebaab

Please sign in to comment.