-
Notifications
You must be signed in to change notification settings - Fork 618
/
Copy pathintermediary_account_test.go
151 lines (123 loc) · 5.34 KB
/
intermediary_account_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
147
148
149
150
151
package keeper_test
import (
sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/osmosis-labs/osmosis/osmomath"
"github.com/osmosis-labs/osmosis/v28/x/superfluid/types"
)
func (s *KeeperTestSuite) TestIntermediaryAccountCreation() {
testCases := []struct {
name string
validatorStats []stakingtypes.BondStatus
delegatorNumber int64
superDelegations []superfluidDelegation
}{
{
"test intermediary account with single superfluid delegation",
[]stakingtypes.BondStatus{stakingtypes.Bonded},
1,
[]superfluidDelegation{{0, 0, 0, 1000000}},
},
{
"test multiple intermediary accounts with multiple superfluid delegation",
[]stakingtypes.BondStatus{stakingtypes.Bonded, stakingtypes.Bonded},
2,
[]superfluidDelegation{{0, 0, 0, 1000000}, {1, 1, 0, 1000000}},
},
// Can create intermediary account with unbonded, unbonding validators
{
"test intermediary account with unbonded validator",
[]stakingtypes.BondStatus{stakingtypes.Bonded, stakingtypes.Unbonded},
2,
[]superfluidDelegation{{0, 0, 0, 1000000}, {1, 1, 0, 1000000}},
},
{
"test intermediary account with unbonding validator",
[]stakingtypes.BondStatus{stakingtypes.Bonded, stakingtypes.Unbonding},
2,
[]superfluidDelegation{{0, 0, 0, 1000000}, {1, 1, 0, 1000000}},
},
}
for _, tc := range testCases {
s.Run(tc.name, func() {
s.SetupTest()
valAddrs := s.SetupValidators(tc.validatorStats)
delAddrs := CreateRandomAccounts(int(tc.delegatorNumber))
// we create two additional pools: total three pools, 10 gauges
denoms, _ := s.SetupGammPoolsAndSuperfluidAssets([]osmomath.Dec{osmomath.NewDec(20), osmomath.NewDec(20)})
var interAccs []types.SuperfluidIntermediaryAccount
for _, superDelegation := range tc.superDelegations {
delAddr := delAddrs[superDelegation.delIndex]
valAddr := valAddrs[superDelegation.valIndex]
denom := denoms[superDelegation.lpIndex]
// check intermediary Account prior to superfluid delegation, should have nil Intermediary Account
expAcc := types.NewSuperfluidIntermediaryAccount(denom, valAddr.String(), 0)
interAcc := s.App.SuperfluidKeeper.GetIntermediaryAccount(s.Ctx, expAcc.GetAccAddress())
s.Require().NotEqual(expAcc.GetAccAddress(), interAcc.GetAccAddress())
s.Require().Equal("", interAcc.Denom)
s.Require().Equal(uint64(0), interAcc.GaugeId)
s.Require().Equal("", interAcc.ValAddr)
lock := s.setupSuperfluidDelegate(delAddr, valAddr, denom, superDelegation.lpAmount)
// check that intermediary Account connection is established
interAccConnection := s.App.SuperfluidKeeper.GetLockIdIntermediaryAccountConnection(s.Ctx, lock.ID)
s.Require().Equal(expAcc.GetAccAddress(), interAccConnection)
interAcc = s.App.SuperfluidKeeper.GetIntermediaryAccount(s.Ctx, interAccConnection)
s.Require().Equal(expAcc.GetAccAddress(), interAcc.GetAccAddress())
// check on interAcc that has been created
s.Require().Equal(denom, interAcc.Denom)
s.Require().Equal(valAddr.String(), interAcc.ValAddr)
interAccs = append(interAccs, interAcc)
}
s.checkIntermediaryAccountDelegations(interAccs)
})
}
}
func (s *KeeperTestSuite) TestIntermediaryAccountsSetGetDeleteFlow() {
s.SetupTest()
// initial check
accs := s.App.SuperfluidKeeper.GetAllIntermediaryAccounts(s.Ctx)
s.Require().Len(accs, 0)
// set account
valAddr := sdk.ValAddress([]byte("addr1---------------"))
acc := types.NewSuperfluidIntermediaryAccount(DefaultGammAsset, valAddr.String(), 1)
s.App.SuperfluidKeeper.SetIntermediaryAccount(s.Ctx, acc)
// get account
gacc := s.App.SuperfluidKeeper.GetIntermediaryAccount(s.Ctx, acc.GetAccAddress())
s.Require().Equal(gacc.Denom, DefaultGammAsset)
s.Require().Equal(gacc.ValAddr, valAddr.String())
s.Require().Equal(gacc.GaugeId, uint64(1))
// check accounts
accs = s.App.SuperfluidKeeper.GetAllIntermediaryAccounts(s.Ctx)
s.Require().Equal(accs, []types.SuperfluidIntermediaryAccount{acc})
// delete asset
s.App.SuperfluidKeeper.DeleteIntermediaryAccount(s.Ctx, acc.GetAccAddress())
// get account
gacc = s.App.SuperfluidKeeper.GetIntermediaryAccount(s.Ctx, acc.GetAccAddress())
s.Require().Equal(gacc.Denom, "")
s.Require().Equal(gacc.ValAddr, "")
s.Require().Equal(gacc.GaugeId, uint64(0))
// check accounts
accs = s.App.SuperfluidKeeper.GetAllIntermediaryAccounts(s.Ctx)
s.Require().Len(accs, 0)
}
func (s *KeeperTestSuite) TestLockIdIntermediaryAccountConnection() {
s.SetupTest()
// get account
addr := s.App.SuperfluidKeeper.GetLockIdIntermediaryAccountConnection(s.Ctx, 1)
s.Require().Equal(addr.String(), "")
// set account
valAddr := sdk.ValAddress([]byte("addr1---------------"))
acc := types.NewSuperfluidIntermediaryAccount(DefaultGammAsset, valAddr.String(), 1)
s.App.SuperfluidKeeper.SetLockIdIntermediaryAccountConnection(s.Ctx, 1, acc)
// get account
addr = s.App.SuperfluidKeeper.GetLockIdIntermediaryAccountConnection(s.Ctx, 1)
s.Require().Equal(addr.String(), acc.GetAccAddress().String())
// check get all
conns := s.App.SuperfluidKeeper.GetAllLockIdIntermediaryAccountConnections(s.Ctx)
s.Require().Len(conns, 1)
// delete account
s.App.SuperfluidKeeper.DeleteLockIdIntermediaryAccountConnection(s.Ctx, 1)
// get account
addr = s.App.SuperfluidKeeper.GetLockIdIntermediaryAccountConnection(s.Ctx, 1)
s.Require().Equal(addr.String(), "")
}