-
Notifications
You must be signed in to change notification settings - Fork 16
/
test_subdao_proposal.sh
executable file
·305 lines (264 loc) · 13.6 KB
/
test_subdao_proposal.sh
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
BIN=neutrond
CHAIN_ID=test-1
NEUTRON_DIR=${NEUTRON_DIR:-../neutron}
HOME=${NEUTRON_DIR}/data/test-1/
# NOTE: this username is used to execute all transactions. It is also used here as the
# timelock's owner.
ADMIN=demowallet1
ADMIN_ADDR=$(${BIN} keys show ${ADMIN} -a --keyring-backend test --home ${HOME})
USERNAME_1=demowallet1
USERNAME_2=demowallet3
USERNAME_3=rly1
PROPOSE_ADDRESS=neutron1eyfccmjm6732k7wp4p6gdjwhxjwsvje44j0hfx8nkgrm8fs7vqfs8hrpdj
PRE_PROPOSE_ADDRESS=neutron18v47nqmhvejx3vc498pantg8vr435xa0rt6x0m6kzhp6yuqmcp8s7t5v3x
VOTING=neutron1aaf9r6s7nxhysuegqrxv0wpm27ypyv4886medd3mrkrw6t4yfcnsu2zdzj
# DAO addresses
VAULT_ADDRESS=neutron1qeyjez6a9dwlghf9d6cy44fxmsajztw257586akk6xn6k88x0gus5djz4e
CORE_ADDRESS=neutron1yyca08xqdgvjz0psg56z67ejh9xms6l436u8y58m82npdqqhmmtqxfjftn
RES=$(${BIN} q wasm contract-state smart $CORE_ADDRESS '{"proposal_modules": {}}' \
--chain-id ${CHAIN_ID} --output json --home ${HOME} --node tcp://127.0.0.1:26657)
echo $RES
# STAKING
# untrn funds from wallet 1
RES=$(${BIN} tx wasm execute $VAULT_ADDRESS "{\"bond\": {}}" --amount 1000untrn --from ${USERNAME_1} -y \
--chain-id ${CHAIN_ID} --output json --broadcast-mode=block --gas-prices 0.0025untrn --gas 1000000 \
--keyring-backend test --home ${HOME} --node tcp://127.0.0.1:26657)
echo "staking from wallet 1:"
echo $RES
#untrn funds from wallet 2
RES=$(${BIN} tx wasm execute $VAULT_ADDRESS "{\"bond\": {}}" --amount 1000untrn --from ${USERNAME_2} -y \
--chain-id ${CHAIN_ID} --output json --broadcast-mode=block --gas-prices 0.0025untrn --gas 1000000 \
--keyring-backend test --home ${HOME} --node tcp://127.0.0.1:26657)
echo "staking from wallet 2:"
echo $RES
#untrn funds from wallet 3
RES=$(${BIN} tx wasm execute $VAULT_ADDRESS "{\"bond\": {}}" --amount 1000untrn --from ${USERNAME_3} -y \
--chain-id ${CHAIN_ID} --output json --broadcast-mode=block --gas-prices 0.0025untrn --gas 1000000 \
--keyring-backend test --home ${HOME} --node tcp://127.0.0.1:26657)
echo "staking from wallet 3:"
echo $RES
CORE_CONTRACT_ADDR=neutron1k95lcrdzamyeu882dtuclrzqmv6ay0axfa3wng8jla0ty52tzn4qsvxcpk
PROPOSAL_SINGLE_CONTRACT_ADDR=neutron1qyl0j7a24amk8k8gcmvv07y2zjx7nkcwpk73js24euh64hkja6esg9jar3
PRE_PROPOSE_SINGLE_CONTRACT_ADDR=neutron1ell22k43hs2jtx8x50jz96agaqju5jwn87ued0mzcfglzlw6um0ssqx6x5
CW4_VOTE_CONTRACT_ADDR=neutron15v8jqq6aqhsuykdgdevx3qqcj9lp4h27ypsycds4cmv6er9qv0vs99alac
TIMELOCK_SINGLE_CONTRACT_ADDR=neutron1yev7tj6lm9lf6mc0y6sxvwscu8rq76zlr4t8s63c5wj4v8u847kssmkmny
echo """
#############################################################################
#
# PROPOSAL COMPLETE EXECUTION SCENARIO:
# 1. Publish proposal,
# 2. Vote \"yes\",
# 3. Execute proposal on the proposal contract level (sends to timelock),
# 4. Try to execute before timelock expires (nothing happens),
# 5. Try to execute after timelock expires (status changes to \"executed\").
#
#############################################################################
#"""
RES=$(${BIN} tx bank send ${ADMIN_ADDR} ${TIMELOCK_SINGLE_CONTRACT_ADDR} 5000untrn -y --chain-id ${CHAIN_ID} --output json \
--broadcast-mode=block --gas-prices 0.0025untrn --gas 1000000 --keyring-backend test \
--home ${HOME} --node tcp://127.0.0.1:26657)
echo "> Sent 5000untrn from ADMIN_ADDR to TIMELOCK_SINGLE_CONTRACT_ADDR, tx hash:" $(echo $RES | jq -r '.txhash')
PROPOSAL_MSG='{
"propose":{
"msg":{
"propose":{
"title":"TEST_TIMELOCK_PROPOSAL",
"description":"A proposal to test the timelock functionality",
"msgs":[
{
"bank":{
"send":{
"to_address":"'"${ADMIN_ADDR}"'",
"amount":[
{
"denom":"untrn",
"amount":"10"
}
]
}
}
}
]
}
}
}
}
'
RES=$(${BIN} tx wasm execute $PRE_PROPOSE_SINGLE_CONTRACT_ADDR "$PROPOSAL_MSG" --amount 10untrn --from ${ADMIN_ADDR} -y \
--chain-id ${CHAIN_ID} --output json --broadcast-mode=block --gas-prices 0.0025untrn --gas 1000000 \
--keyring-backend test --home ${HOME} --node tcp://127.0.0.1:26657)
echo "> Submitted proposal, tx hash:" $(echo $RES | jq -r '.txhash')
RES=$(${BIN} tx wasm execute $PROPOSAL_SINGLE_CONTRACT_ADDR '{"vote": {"proposal_id": 1, "vote": "yes"}}' \
--from ${ADMIN_ADDR} -y --chain-id ${CHAIN_ID} --output json --broadcast-mode=block --gas-prices 0.0025untrn \
--gas 1000000 --keyring-backend test --home ${HOME} --node tcp://127.0.0.1:26657)
echo "> Submitted a YES vote (1 / 1 members), tx hash:" $(echo $RES | jq -r '.txhash')
RES=$(${BIN} q wasm contract-state smart $PROPOSAL_SINGLE_CONTRACT_ADDR '{"proposal": {"proposal_id": 1}}' \
--chain-id ${CHAIN_ID} --output json --home ${HOME} --node tcp://127.0.0.1:26657)
PROPOSAL_STATUS=$(echo $RES | jq -r '.data.proposal.status')
if [ $PROPOSAL_STATUS == "passed" ]; then
echo '> Proposal status (in proposal contract) is "passed", all good'
else
echo "ERROR: Proposal status is \"${PROPOSAL_STATUS}\", should be \"passed\""
exit 1
fi
RES=$(${BIN} tx wasm execute $PROPOSAL_SINGLE_CONTRACT_ADDR '{"execute": {"proposal_id": 1}}' --from ${ADMIN_ADDR} \
-y --chain-id ${CHAIN_ID} --output json --broadcast-mode=block --gas-prices 0.0025untrn --gas 1000000 \
--keyring-backend test --home ${HOME} --node tcp://127.0.0.1:26657)
echo "> Execute the proposal (should send it to timelock), tx hash:" $(echo $RES | jq -r '.txhash')
RES=$(${BIN} q wasm contract-state smart $TIMELOCK_SINGLE_CONTRACT_ADDR '{"proposal": {"proposal_id": 1}}' \
--chain-id ${CHAIN_ID} --output json --home ${HOME} --node tcp://127.0.0.1:26657)
PROPOSAL_STATUS=$(echo $RES | jq -r '.data.status')
if [ $PROPOSAL_STATUS == "timelocked" ]; then
echo '> Proposal status (in timelock contract) is "timelocked", all good'
else
echo "ERROR: Proposal status is \"${PROPOSAL_STATUS}\", should be \"timelocked\""
exit 1
fi
${BIN} tx wasm execute $TIMELOCK_SINGLE_CONTRACT_ADDR '{"execute_proposal": {"proposal_id": 1}}' --from ${ADMIN_ADDR} \
-y --chain-id ${CHAIN_ID} --output json --broadcast-mode=block --gas-prices 0.0025untrn --gas 1000000 \
--keyring-backend test --home ${HOME} --node tcp://127.0.0.1:26657 > /dev/null 2>&1
echo "> Tried to execute the proposal before timelock expires (suppressing output)"
RES=$(${BIN} q wasm contract-state smart $TIMELOCK_SINGLE_CONTRACT_ADDR '{"proposal": {"proposal_id": 1}}' \
--chain-id ${CHAIN_ID} --output json --home ${HOME} --node tcp://127.0.0.1:26657)
PROPOSAL_STATUS=$(echo $RES | jq -r '.data.status')
if [ $PROPOSAL_STATUS == "timelocked" ]; then
echo '> Proposal status (in timelock contract) is still "timelocked", all good'
else
echo "ERROR: Proposal status is \"${PROPOSAL_STATUS}\", should be \"timelocked\""
exit 1
fi
echo "> Waiting for 20 seconds for the timelock to expire..."
sleep 20
RES=$(${BIN} tx wasm execute $TIMELOCK_SINGLE_CONTRACT_ADDR '{"execute_proposal": {"proposal_id": 1}}' \
--from ${ADMIN_ADDR} -y --chain-id ${CHAIN_ID} --output json --broadcast-mode=block --gas-prices 0.0025untrn \
--gas 1000000 --keyring-backend test --home ${HOME} --node tcp://127.0.0.1:26657)
echo "> Tried to execute the proposal *after* timelock expires, tx hash:" $(echo $RES | jq -r '.txhash')
RES=$(${BIN} q wasm contract-state smart $TIMELOCK_SINGLE_CONTRACT_ADDR '{"proposal": {"proposal_id": 1}}' --chain-id ${CHAIN_ID} --output json --home ${HOME} --node tcp://127.0.0.1:26657)
PROPOSAL_STATUS=$(echo $RES | jq -r '.data.status')
if [ $PROPOSAL_STATUS == "executed" ]; then
echo '> Proposal status (in timelock contract) is "executed", all good'
else
echo "ERROR: Proposal status is \"${PROPOSAL_STATUS}\", should be \"executed\""
exit 1
fi
echo """
#############################################################################
#
# PROPOSAL OVERRULE SCENARIO:
# 1. Publish proposal,
# 2. Vote \"yes\",
# 3. Execute proposal on the proposal contract level (sends to timelock),
# 4. Overrule proposal,
# 5. Try to execute after the proposal was overruled (returns an error).
#
#############################################################################
"""
RES=$(${BIN} tx bank send ${ADMIN_ADDR} ${TIMELOCK_SINGLE_CONTRACT_ADDR} 5000untrn -y --chain-id ${CHAIN_ID} --output json \
--broadcast-mode=block --gas-prices 0.0025untrn --gas 1000000 --keyring-backend test \
--home ${HOME} --node tcp://127.0.0.1:26657)
echo "> Sent 5000untrn from ADMIN_ADDR to TIMELOCK_SINGLE_CONTRACT_ADDR, tx hash:" $(echo $RES | jq -r '.txhash')
PROPOSAL_MSG='{
"propose":{
"msg":{
"propose":{
"title":"TEST_TIMELOCK_PROPOSAL",
"description":"A proposal to test the timelock functionality",
"msgs":[
{
"bank":{
"send":{
"to_address":"'"${ADMIN_ADDR}"'",
"amount":[
{
"denom":"untrn",
"amount":"10"
}
]
}
}
}
]
}
}
}
}
'
RES=$(${BIN} tx wasm execute $PRE_PROPOSE_SINGLE_CONTRACT_ADDR "$PROPOSAL_MSG" --amount 10untrn --from ${ADMIN_ADDR} -y \
--chain-id ${CHAIN_ID} --output json --broadcast-mode=block --gas-prices 0.0025untrn --gas 1000000 \
--keyring-backend test --home ${HOME} --node tcp://127.0.0.1:26657)
echo "> Submitted proposal, tx hash:" $(echo $RES | jq -r '.txhash')
RES=$(${BIN} tx wasm execute $PROPOSAL_SINGLE_CONTRACT_ADDR '{"vote": {"proposal_id": 2, "vote": "yes"}}' \
--from ${ADMIN_ADDR} -y --chain-id ${CHAIN_ID} --output json --broadcast-mode=block --gas-prices 0.0025untrn \
--gas 1000000 --keyring-backend test --home ${HOME} --node tcp://127.0.0.1:26657)
echo "> Submitted a YES vote (1 / 1 members), tx hash:" $(echo $RES | jq -r '.txhash')
RES=$(${BIN} q wasm contract-state smart $PROPOSAL_SINGLE_CONTRACT_ADDR '{"proposal": {"proposal_id": 2}}' \
--chain-id ${CHAIN_ID} --output json --home ${HOME} --node tcp://127.0.0.1:26657)
PROPOSAL_STATUS=$(echo $RES | jq -r '.data.proposal.status')
if [ $PROPOSAL_STATUS == "passed" ]; then
echo '> Proposal status (in proposal contract) is "passed", all good'
else
echo "ERROR: Proposal status is \"${PROPOSAL_STATUS}\", should be \"passed\""
exit 1
fi
RES=$(${BIN} tx wasm execute $PROPOSAL_SINGLE_CONTRACT_ADDR '{"execute": {"proposal_id": 2}}' --from ${ADMIN_ADDR} \
-y --chain-id ${CHAIN_ID} --output json --broadcast-mode=block --gas-prices 0.0025untrn --gas 1000000 \
--keyring-backend test --home ${HOME} --node tcp://127.0.0.1:26657)
echo "> Execute the proposal (should send it to timelock), tx hash:" $(echo $RES | jq -r '.txhash')
RES=$(${BIN} q wasm contract-state smart $TIMELOCK_SINGLE_CONTRACT_ADDR '{"proposal": {"proposal_id": 2}}' \
--chain-id ${CHAIN_ID} --output json --home ${HOME} --node tcp://127.0.0.1:26657)
PROPOSAL_STATUS=$(echo $RES | jq -r '.data.status')
if [ $PROPOSAL_STATUS == "timelocked" ]; then
echo '> Proposal status (in timelock contract) is "timelocked", all good'
else
echo "ERROR: Proposal status is \"${PROPOSAL_STATUS}\", should be \"timelocked\""
exit 1
fi
# -------------------- OVERRULING --------------------
PROP='{
"propose": {
"msg": {
"propose_overrule": {
"timelock_contract": "'"${TIMELOCK_SINGLE_CONTRACT_ADDR}"'",
"proposal_id": 2
}
}
}
}'
# PROPOSAL 1 (to pass)
#propose proposal we're going to pass
RES=$(${BIN} tx wasm execute $PRE_PROPOSE_ADDRESS "$PROP" --amount 1000untrn --from ${USERNAME_1} -y \
--chain-id ${CHAIN_ID} --output json --broadcast-mode=block --gas-prices 0.0025untrn --gas 1000000 \
--keyring-backend test --home ${HOME} --node tcp://127.0.0.1:26657)
echo "propose proposal to be passed:"
echo $RES
#### vote YES from wallet 1
RES=$(${BIN} tx wasm execute $PROPOSE_ADDRESS "{\"vote\": {\"proposal_id\": 1, \"vote\": \"yes\"}}" \
--from ${USERNAME_1} -y --chain-id ${CHAIN_ID} --output json --broadcast-mode=block --gas-prices 0.0025untrn \
--gas 1000000 --keyring-backend test --home ${HOME} --node tcp://127.0.0.1:26657)
echo "vote YES from wallet1:"
echo $RES
#### vote YES from wallet 2
RES=$(${BIN} tx wasm execute $PROPOSE_ADDRESS "{\"vote\": {\"proposal_id\": 1, \"vote\": \"yes\"}}" \
--from ${USERNAME_2} -y --chain-id ${CHAIN_ID} --output json --broadcast-mode=block --gas-prices 0.0025untrn \
--gas 1000000 --keyring-backend test --home ${HOME} --node tcp://127.0.0.1:26657)
echo "vote YES from wallet2:"
echo $RES
RES=$(${BIN} tx wasm execute $PROPOSE_ADDRESS "{\"execute\": {\"proposal_id\": 1}}" --from ${USERNAME_1} \
-y --chain-id ${CHAIN_ID} --output json --broadcast-mode=block --gas-prices 0.0025untrn --gas 1000000 \
--keyring-backend test --home ${HOME} --node tcp://127.0.0.1:26657)
echo "execute proposal:"
echo $RES
# -------------------- TRYING TO EXECUTE --------------------
RES=$(${BIN} q wasm contract-state smart $TIMELOCK_SINGLE_CONTRACT_ADDR '{"proposal": {"proposal_id": 2}}' --chain-id ${CHAIN_ID} --output json --home ${HOME} --node tcp://127.0.0.1:26657)
PROPOSAL_STATUS=$(echo $RES | jq -r '.data.status')
if [ $PROPOSAL_STATUS == "overruled" ]; then
echo '> Proposal status (in timelock contract) is "overruled", all good'
else
echo "ERROR: Proposal status is \"${PROPOSAL_STATUS}\", should be \"overruled\""
exit 1
fi
RES=$(${BIN} tx wasm execute $TIMELOCK_SINGLE_CONTRACT_ADDR '{"execute_proposal": {"proposal_id": 2}}' \
--from ${ADMIN_ADDR} -y --chain-id ${CHAIN_ID} --output json --broadcast-mode=block --gas-prices 0.0025untrn \
--gas 1000000 --keyring-backend test --home ${HOME} --node tcp://127.0.0.1:26657) > /dev/null 2>&1
echo "> Tried to execute the overruled proposal, should return an error"
grep -q 'Wrong proposal status (overruled)' <<< $RES && echo "> Received an error, all good" || echo "ERROR: proposal execution did not fail"