-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcancel_pending_operation_test.go
146 lines (120 loc) · 4.54 KB
/
cancel_pending_operation_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//go:build integrationtests
// +build integrationtests
package contract_test
import (
"testing"
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
coreumintegration "github.com/CoreumFoundation/coreum/v4/testutil/integration"
integrationtests "github.com/CoreumFoundation/coreumbridge-xrpl/integration-tests"
"github.com/CoreumFoundation/coreumbridge-xrpl/relayer/coreum"
"github.com/CoreumFoundation/coreumbridge-xrpl/relayer/xrpl"
)
func TestCancelPendingOperation(t *testing.T) {
t.Parallel()
ctx, chains := integrationtests.NewTestingContext(t)
relayers := genRelayers(ctx, t, chains, 2)
randomCoreumAddress := chains.Coreum.GenAccount()
chains.Coreum.FundAccountWithOptions(ctx, t, randomCoreumAddress, coreumintegration.BalancesOptions{
Amount: sdkmath.NewIntWithDecimal(1, 7),
})
issueFee := chains.Coreum.QueryAssetFTParams(ctx, t).IssueFee
coreumSenderAddress := chains.Coreum.GenAccount()
chains.Coreum.FundAccountWithOptions(ctx, t, coreumSenderAddress, coreumintegration.BalancesOptions{
Amount: issueFee.Amount.Add(sdkmath.NewIntWithDecimal(1, 7)),
})
owner, contractClient := integrationtests.DeployInstantiateAndMigrateContract(
ctx,
t,
chains,
relayers,
uint32(len(relayers)),
2,
defaultTrustSetLimitAmount,
xrpl.GenPrivKeyTxSigner().Account().String(),
10,
)
chains.Coreum.FundAccountWithOptions(ctx, t, owner, coreumintegration.BalancesOptions{
Amount: issueFee.Amount.MulRaw(2).Add(sdkmath.NewIntWithDecimal(1, 7)),
})
// recover tickets to be able to create operations from coreum to XRPL
recoverTickets(ctx, t, contractClient, owner, relayers, 4)
initialAvailableTickets, err := contractClient.GetAvailableTickets(ctx)
require.NoError(t, err)
// register XRPL originated token to create trust set operation
xrplTokenIssuer := chains.XRPL.GenAccount(ctx, t, 0)
xrplTokenCurrency := xrpl.ConvertCurrencyToString(integrationtests.GenerateXRPLCurrency(t))
xrplTokenSendingPrecision := int32(15)
xrplTokenMaxHoldingAmount := sdkmath.NewIntWithDecimal(1, 20)
_, err = contractClient.RegisterXRPLToken(
ctx,
owner,
xrplTokenIssuer.String(),
xrplTokenCurrency,
xrplTokenSendingPrecision,
xrplTokenMaxHoldingAmount,
sdkmath.ZeroInt(),
)
require.NoError(t, err)
coreumTokenDecimals := uint32(15)
coreumTokenSendingPrecision := int32(15)
coreumTokenMaxHoldingAmount := sdkmath.NewIntWithDecimal(1, 10)
initialAmount := sdkmath.NewIntWithDecimal(1, 8)
registeredCoreumOriginatedToken := issueAndRegisterCoreumOriginatedToken(
ctx,
t,
contractClient,
chains.Coreum,
coreumSenderAddress,
owner,
coreumTokenDecimals,
initialAmount,
coreumTokenSendingPrecision,
coreumTokenMaxHoldingAmount,
sdkmath.ZeroInt(),
)
// create send operation to cancel
amountToSendToXRPL := sdk.NewCoin(registeredCoreumOriginatedToken.Denom, sdkmath.NewInt(1000))
_, err = contractClient.SendToXRPL(
ctx,
coreumSenderAddress,
xrplTokenIssuer.String(),
amountToSendToXRPL,
nil)
require.NoError(t, err)
// create rotate key operation
_, err = contractClient.RotateKeys(ctx,
owner,
relayers,
2,
)
require.NoError(t, err)
pendingOperations, err := contractClient.GetPendingOperations(ctx)
require.NoError(t, err)
// trust set + send to XRPL + keys rotation
require.Len(t, pendingOperations, 3)
for _, operation := range pendingOperations {
_, err := contractClient.CancelPendingOperation(ctx, randomCoreumAddress, operation.GetOperationID())
require.True(t, coreum.IsUnauthorizedSenderError(err), err)
_, err = contractClient.CancelPendingOperation(ctx, relayers[0].CoreumAddress, operation.GetOperationID())
require.True(t, coreum.IsUnauthorizedSenderError(err), err)
_, err = contractClient.CancelPendingOperation(ctx, owner, operation.GetOperationID())
require.NoError(t, err)
}
// check that all tickets are released now
availableTickets, err := contractClient.GetAvailableTickets(ctx)
require.NoError(t, err)
require.ElementsMatch(t, initialAvailableTickets, availableTickets)
// check that token registration is cancelled correctly
registeredXRPLToken, err := contractClient.GetXRPLTokenByIssuerAndCurrency(
ctx, xrplTokenIssuer.String(), xrplTokenCurrency,
)
require.NoError(t, err)
require.Equal(t, coreum.TokenStateInactive, registeredXRPLToken.State)
// check that send to XRPL is cancelled correctly
pendingRefunds, err := contractClient.GetPendingRefunds(ctx, coreumSenderAddress)
require.NoError(t, err)
require.Len(t, pendingRefunds, 1)
require.Equal(t, amountToSendToXRPL.String(), pendingRefunds[0].Coin.String())
}