-
Notifications
You must be signed in to change notification settings - Fork 138
/
Copy pathsteps_democracy.go
243 lines (242 loc) · 6.61 KB
/
steps_democracy.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
package main
func stepsDemocracy(consumerName string) []Step {
return []Step{
{
action: registerRepresentativeAction{
chain: chainID(consumerName),
representatives: []validatorID{validatorID("alice"), validatorID("bob")},
stakes: []uint{100000000, 40000000},
},
state: State{
chainID(consumerName): ChainState{
RepresentativePowers: &map[validatorID]uint{
validatorID("alice"): 100000000,
validatorID("bob"): 40000000,
},
Rewards: &Rewards{
IsRewarded: map[validatorID]bool{
validatorID("alice"): true,
validatorID("bob"): true,
validatorID("carol"): false,
},
IsIncrementalReward: true,
IsNativeDenom: true,
},
},
},
},
{
action: delegateTokensAction{
chain: chainID(consumerName),
from: validatorID("carol"),
to: validatorID("alice"),
amount: 500000,
},
state: State{
chainID(consumerName): ChainState{
//Check that delegators on gov-consumer chain can change representative powers
RepresentativePowers: &map[validatorID]uint{
validatorID("alice"): 100500000,
validatorID("bob"): 40000000,
},
// Check that delegating on gov-consumer does not change validator powers
ValPowers: &map[validatorID]uint{
validatorID("alice"): 511,
validatorID("bob"): 500,
validatorID("carol"): 500,
},
//Check that tokens are minted and distributed to representatives and their delegators
Rewards: &Rewards{
IsRewarded: map[validatorID]bool{
validatorID("alice"): true,
validatorID("bob"): true,
validatorID("carol"): true,
},
IsIncrementalReward: true,
IsNativeDenom: true,
},
},
},
},
{
action: submitParamChangeProposalAction{
chain: chainID(consumerName),
from: validatorID("alice"),
deposit: 10000001,
subspace: "staking",
key: "MaxValidators",
value: 105,
},
state: State{
chainID(consumerName): ChainState{
ValBalances: &map[validatorID]uint{
validatorID("alice"): 9889999998,
validatorID("bob"): 9960000001,
},
Proposals: &map[uint]Proposal{
1: ParamsProposal{
Deposit: 10000001,
Status: "PROPOSAL_STATUS_VOTING_PERIOD",
Subspace: "staking",
Key: "MaxValidators",
Value: "105",
},
},
},
},
},
{
//Have accounts vote on something on the gov-consumer chain
action: voteGovProposalAction{
chain: chainID(consumerName),
from: []validatorID{validatorID("alice"), validatorID("bob")},
vote: []string{"yes", "no"},
propNumber: 1,
},
state: State{
chainID(consumerName): ChainState{
ValBalances: &map[validatorID]uint{
validatorID("alice"): 9899999999,
validatorID("bob"): 9960000001,
},
//Check that the parameter is changed on gov-consumer chain
Params: &([]Param{{Subspace: "staking", Key: "MaxValidators", Value: "105"}}),
},
},
},
{
action: relayRewardPacketsToProviderAction{
consumerChain: chainID(consumerName),
providerChain: chainID("provi"),
port: "transfer",
channel: 1,
},
state: State{
chainID("provi"): ChainState{
//Check that tokens are minted and sent to provider chain and distributed to validators and their delegators on provider chain
Rewards: &Rewards{
IsRewarded: map[validatorID]bool{
validatorID("alice"): true,
validatorID("bob"): true,
validatorID("carol"): true,
},
IsIncrementalReward: false,
IsNativeDenom: false,
},
},
},
},
{
action: downtimeSlashAction{
chain: chainID(consumerName),
// TODO: First validator cannot be brought down until this issue is resolved:
// https://github.com/cosmos/interchain-security/issues/263
validator: validatorID("bob"),
},
state: State{
// validator should be slashed on consumer, powers not affected on either chain yet
chainID("provi"): ChainState{
ValPowers: &map[validatorID]uint{
validatorID("alice"): 511,
validatorID("bob"): 500,
validatorID("carol"): 500,
},
},
chainID(consumerName): ChainState{
ValPowers: &map[validatorID]uint{
validatorID("alice"): 511,
validatorID("bob"): 500,
validatorID("carol"): 500,
},
},
},
},
{
action: relayPacketsAction{
chain: chainID("provi"),
port: "provider",
channel: 0,
},
state: State{
chainID("provi"): ChainState{
ValPowers: &map[validatorID]uint{
validatorID("alice"): 511,
// Downtime jailing and corresponding voting power change are processed by provider
validatorID("bob"): 0,
validatorID("carol"): 500,
},
},
chainID(consumerName): ChainState{
ValPowers: &map[validatorID]uint{
validatorID("alice"): 511,
validatorID("bob"): 500,
validatorID("carol"): 500,
},
},
},
},
// A block is incremented each action, hence why VSC is committed on provider,
// and can now be relayed as packet to consumer
{
action: relayPacketsAction{
chain: chainID("provi"),
port: "provider",
channel: 0,
},
state: State{
chainID(consumerName): ChainState{
ValPowers: &map[validatorID]uint{
validatorID("alice"): 511,
// VSC now seen on consumer
validatorID("bob"): 0,
validatorID("carol"): 500,
},
},
},
},
{
action: unjailValidatorAction{
provider: chainID("provi"),
validator: validatorID("bob"),
},
state: State{
chainID("provi"): ChainState{
ValPowers: &map[validatorID]uint{
validatorID("alice"): 511,
// 1% of bob's stake should be slashed as set in config.go
validatorID("bob"): 495,
validatorID("carol"): 500,
},
},
chainID(consumerName): ChainState{
ValPowers: &map[validatorID]uint{
validatorID("alice"): 511,
validatorID("bob"): 0,
validatorID("carol"): 500,
},
},
},
},
{
action: relayPacketsAction{
chain: chainID("provi"),
port: "provider",
channel: 0,
},
state: State{
chainID(consumerName): ChainState{
ValPowers: &map[validatorID]uint{
validatorID("alice"): 511,
validatorID("bob"): 495,
validatorID("carol"): 500,
},
//Check that slashing on the gov-consumer chain does not result in slashing for the representatives or their delegators
RepresentativePowers: &map[validatorID]uint{
validatorID("alice"): 100500000,
validatorID("bob"): 40000000,
},
},
},
},
}
}