1919#
2020# AUTOBAHN=true EVM_GOVERNANCE_VOTING_PERIOD=30s DOCKER_DETACH=true make docker-cluster-start
2121#
22- # then run this script from the repository root. It needs cast and jq.
22+ # then run this script from the repository root. It drives the chain with each
23+ # node's own seid over its EVM JSON-RPC, and needs only docker and jq.
2324set -euo pipefail
2425
25- GAS_PRICE=${GAS_PRICE:- 1gwei}
2626NODES=4
27- PORTS=(8545 8547 8549 8551)
28- # The validators' evm_voter keys: anvil accounts 0 to 3 of the test mnemonic.
29- VOTER_KEYS=(
30- 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
31- 0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d
32- 0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a
33- 0x7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6
34- )
35- # Anvil account 9 sends the transfers that produce blocks; Autobahn makes no
36- # empty blocks.
37- TICK_KEY=0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6
38- GOV=0x0000000000000000000000000000000000001006
39- PARAMS=0x0000000000000000000000000000000000001013
40- UPGRADE=0x0000000000000000000000000000000000001015
41- # gov.DefaultParams' minimum expedited deposit: 20,000,000 usei.
42- EXPEDITED_DEPOSIT=20ether
27+ # The test mnemonic. Anvil accounts 0 to 3 are the validators' evm_voter keys;
28+ # account 9 sends the transfers that produce blocks, as Autobahn makes no empty
29+ # blocks.
30+ MNEMONIC=" test test test test test test test test test test test junk"
31+ KEY_INDEXES=" 0 1 2 3 9"
32+ # The keyring, in sei-node-0, that signs every transaction.
33+ KEY_HOME=/tmp/evmonly-upgrade-keys
34+ EVM_RPC=http://127.0.0.1:8545
35+ # gov.DefaultParams' minimum expedited deposit.
36+ EXPEDITED_DEPOSIT=20000000usei
4337TEST_UPGRADE=vX.Y-test
4438TEST_MINOR_UPGRADE=vX.Y-minor-test
45- SUBMIT_PROPOSAL_TOPIC=$( cast keccak " SubmitProposal(uint64,address,uint8,bool)" )
4639# The 72h max deposit period, in nanoseconds, the test upgrade's handler sets.
4740DEPOSIT_PERIOD_AFTER=259200000000000
4841TEST_BINARY=build/seid-test-upgrade
@@ -58,40 +51,89 @@ check() {
5851 if [ " $got " = " $want " ]; then pass " $what " ; else fail " $what : got '$got ', want '$want '" ; fi
5952}
6053
61- rpc () { echo " http://127.0.0.1:${PORTS[$1]} " ; }
62- height () { cast block-number --rpc-url " $( rpc " $1 " ) " 2> /dev/null || echo unreachable; }
54+ node_sh () { docker exec " sei-node-$1 " sh -c " $2 " ; }
6355
64- # tick sends one transfer, which seals a block, and waits up to 20s for it.
65- tick () {
66- cast send --rpc-url " $( rpc 0) " --private-key " $TICK_KEY " --legacy --gas-price " $GAS_PRICE " \
67- --timeout 20 0x0000000000000000000000000000000000000001 --value 1 > /dev/null 2>&1
56+ # seid_q runs a seid query in node $1 against that node's EVM JSON-RPC.
57+ seid_q () {
58+ local n=$1
59+ shift
60+ docker exec " sei-node-$n " seid " $@ " --evm-rpc " $EVM_RPC "
6861}
6962
70- # gov_send sends a gov call from voter key $1 and prints its receipt as JSON.
71- gov_send () {
63+ # seid_q_or_none runs a seid query in node $1 and prints its output. A query
64+ # failing with message $2 prints nothing and succeeds; any other failure
65+ # prints its error to stderr and fails.
66+ seid_q_or_none () {
67+ local n=$1 none=$2 err
68+ shift 2
69+ { err=$( seid_q " $n " " $@ " 2>&1 >&3 3>& -) ; } 3>&1 && return 0
70+ case " $err " in * " $none " * ) return 0 ;; esac
71+ echo " $err " | head -1 >&2
72+ return 1
73+ }
74+
75+ # seid_tx runs a seid transaction in node 0, signed by key $1 of KEY_HOME.
76+ seid_tx () {
7277 local key=$1
7378 shift
74- cast send --json --rpc-url " $( rpc 0) " --private-key " $key " --legacy --gas-price " $GAS_PRICE " \
75- --gas-limit 2000000 " $GOV " " $@ "
79+ docker exec sei-node-0 seid " $@ " --from " $key " --keyring-backend test --home " $KEY_HOME " --evm-rpc " $EVM_RPC "
80+ }
81+
82+ # gov_tx sends a seid tx gov command from key $1 and prints its result as JSON.
83+ gov_tx () {
84+ local key=$1
85+ shift
86+ seid_tx " $key " tx gov " $@ " -y -o json
87+ }
88+
89+ height () {
90+ local h
91+ h=$( seid_q " $1 " q block 2> /dev/null | jq -r .number 2> /dev/null) || h=
92+ case " $h " in 0x* ) echo $(( h)) ;; * ) echo unreachable ;; esac
93+ }
94+
95+ # tick sends one transfer, which seals a block, and waits up to 20s for it.
96+ tick () {
97+ local before i
98+ before=$( height 0)
99+ [ " $before " != unreachable ] || return 1
100+ seid_tx key9 tx evm send 0x0000000000000000000000000000000000000001 1 > /dev/null 2>&1 || return 1
101+ for i in $( seq 1 20) ; do
102+ [ " $( height 0) " != unreachable ] && [ " $( height 0) " -gt " $before " ] && return 0
103+ sleep 1
104+ done
105+ return 1
76106}
77107
78- # proposal_id prints the id a submit receipt's SubmitProposal event carries .
108+ # proposal_id prints the id in a submit-proposal result .
79109proposal_id () {
80- jq -r --arg topic " $SUBMIT_PROPOSAL_TOPIC " ' .logs[] | select(.topics[0] == $topic) | .topics[1]' | cast to-dec
110+ jq -r ' .logs[0].events[] | select(.type == "submit_proposal") | .attributes[] | select(.key == "proposal_id") | .value'
111+ }
112+
113+ # submit_upgrade submits an expedited software upgrade of plan $1 at height $2
114+ # with info $3, and prints its proposal id.
115+ submit_upgrade () {
116+ gov_tx key0 submit-proposal software-upgrade " $1 " --upgrade-height " $2 " --upgrade-info " $3 " \
117+ --title upgrade --description " schedules $1 " --is-expedited --deposit " $EXPEDITED_DEPOSIT " | proposal_id
118+ }
119+
120+ # submit_cancel submits an expedited cancel of plan $1 and prints its result.
121+ submit_cancel () {
122+ gov_tx key0 submit-proposal cancel-software-upgrade --name " $1 " \
123+ --title cancel --description " cancels $1 " --is-expedited --deposit " $EXPEDITED_DEPOSIT "
81124}
82125
83126# pass_proposal has every voter vote yes on proposal $1 and ticks until it
84- # leaves the voting period.
127+ # leaves the voting period, printing its final status .
85128pass_proposal () {
86129 local id=$1 i status
87130 for i in 0 1 2 3; do
88- gov_send " ${VOTER_KEYS[$i]} " " vote(uint64,int32) " " $id " 1 > /dev/null
131+ gov_tx " key $i " vote " $id " yes > /dev/null
89132 done
90133 for i in $( seq 1 60) ; do
91134 tick || true
92- status=$( cast call --rpc-url " $( rpc 0) " " $GOV " " proposal(uint64)((uint64,int32,(uint256,uint256,uint256,uint256),uint64,uint64,uint256,uint64,uint64,bool,uint8,bytes))" " $id " |
93- sed -n ' s/^(\([0-9]*\), \([0-9]*\),.*/\2/p' )
94- if [ " $status " != 2 ]; then
135+ status=$( seid_q 0 q gov proposal " $id " -o json | jq -r .status)
136+ if [ " $status " != PROPOSAL_STATUS_VOTING_PERIOD ]; then
95137 echo " $status "
96138 return
97139 fi
@@ -100,14 +142,40 @@ pass_proposal() {
100142 echo timeout
101143}
102144
103- plan_name () { cast call --rpc-url " $( rpc " $1 " ) " " $UPGRADE " " currentPlan()((string,uint64,string))" | sed -n ' s/^("\([^"]*\)", .*/\1/p' ; }
104- applied () { cast call --rpc-url " $( rpc " $1 " ) " " $UPGRADE " " appliedPlan(string)(uint64)" " $2 " ; }
105- max_deposit_period () {
106- cast call --rpc-url " $( rpc " $1 " ) " " $PARAMS " " param(string,string)(bytes)" gov depositparams.max_deposit_period | cast to-dec
145+ # plan_name prints the name of the plan node $1 has scheduled, nothing when it
146+ # has none, and "query failed" when the query fails.
147+ plan_name () {
148+ local out
149+ out=$( seid_q_or_none " $1 " " no upgrade scheduled" q upgrade plan -o json) || { echo " query failed" ; return ; }
150+ [ -z " $out " ] || echo " $out " | jq -r .name
107151}
108- block_hash () { cast block " $2 " --field hash --rpc-url " $( rpc " $1 " ) " ; }
109152
110- node_sh () { docker exec " sei-node-$1 " sh -c " $2 " ; }
153+ # applied prints the height node $1 applied plan $2 at, 0 when it never applied
154+ # it, and "query failed" when the query fails.
155+ applied () {
156+ local out h
157+ out=$( seid_q_or_none " $1 " " no upgrade found" q upgrade applied " $2 " ) || { echo " query failed" ; return ; }
158+ [ -n " $out " ] || { echo 0; return ; }
159+ h=$( echo " $out " | jq -r .number 2> /dev/null)
160+ case " $h " in 0x* ) echo $(( h)) ;; * ) echo " unparsed: $h " ;; esac
161+ }
162+
163+ # cancel_outcome submits a cancel of plan $1 and prints refused when the gov
164+ # precompile refuses it during gas estimation, sent when it is sent, and the
165+ # error otherwise.
166+ cancel_outcome () {
167+ local err
168+ if err=$( submit_cancel " $1 " 2>&1 > /dev/null) ; then
169+ echo sent
170+ return
171+ fi
172+ case " $err " in
173+ * " estimate gas: upgrade is not scheduled" * ) echo refused ;;
174+ * ) echo " $err " | head -1 ;;
175+ esac
176+ }
177+ max_deposit_period () { seid_q " $1 " q gov params -o json | jq -r .deposit_params.max_deposit_period; }
178+ block_hash () { seid_q " $1 " q block " $2 " | jq -r .hash; }
111179
112180# restart_node stops seid on node $1, waiting up to 30s for it to exit, then
113181# starts it from binary $2 as step5_start_sei.sh does.
@@ -142,12 +210,16 @@ tick_past() {
142210 done
143211}
144212
213+ # serving reports whether node $1 answers over its EVM JSON-RPC, which it does
214+ # from genesis, before it has a block.
215+ serving () { seid_q_or_none " $1 " " no upgrade scheduled" q upgrade plan > /dev/null 2>&1 ; }
216+
145217# wait_ready waits for node $1 to serve RPC, polling every 2s up to $2 times
146218# (default 60).
147219wait_ready () {
148220 local i
149221 for i in $( seq 1 " ${2:- 60} " ) ; do
150- if cast chain-id --rpc-url " $( rpc " $1 " ) " > /dev/null 2>&1 ; then return 0; fi
222+ if serving " $1 " ; then return 0; fi
151223 sleep 2
152224 done
153225 return 1
@@ -165,21 +237,34 @@ for n in $(seq 0 $((NODES - 1))); do
165237 fi
166238done
167239
240+ log " Importing the test keys into $KEY_HOME in sei-node-0"
241+ node_sh 0 " rm -rf $KEY_HOME "
242+ for i in $KEY_INDEXES ; do
243+ echo " $MNEMONIC " | docker exec -i sei-node-0 seid keys add " key$i " --recover \
244+ --hd-path " m/44'/60'/0'/0/$i " --keyring-backend test --home " $KEY_HOME " > /dev/null
245+ done
246+
247+ log " Sending a teaser transfer so the chain leaves genesis"
248+ # Autobahn makes no empty blocks, and a node reports no latest block before
249+ # the first one, so a transfer produces block 1 before anything reads a block.
250+ seid_tx key9 tx evm send 0x0000000000000000000000000000000000000001 1 > /dev/null
251+ for i in $( seq 1 20) ; do
252+ [ " $( height 0) " != unreachable ] && break
253+ sleep 1
254+ done
255+ [ " $( height 0) " != unreachable ] || { echo " the chain produced no first block" >&2 ; exit 1; }
256+
168257log " Building the giga_test_upgrade binary in sei-node-0"
169258node_sh 0 " cd /sei-protocol/sei-chain && export PATH=\$ PATH:/usr/local/go/bin && \
170259 LEDGER_ENABLED=false go build -tags 'netgo giga_test_upgrade' -o $TEST_BINARY ./cmd/seid"
171260node_sh 0 " cp \$ HOME/go/bin/seid /sei-protocol/sei-chain/build/seid-old"
172261
173262log " Scheduling $TEST_UPGRADE "
174- # Gov writes its genesis state at the chain's first block and refuses calls
175- # until then, so a transaction must produce that block first.
176- tick || fail " the chain produced no first block"
177263start=$( height 0)
178264target=$(( start + 40 ))
179- id=$( gov_send " ${VOTER_KEYS[0]} " " submitSoftwareUpgradeProposal(string,string,bool,(string,uint64,string))" \
180- " upgrade" " schedules $TEST_UPGRADE " true " ($TEST_UPGRADE ,$target ,docker-run)" --value " $EXPEDITED_DEPOSIT " | proposal_id)
265+ id=$( submit_upgrade " $TEST_UPGRADE " " $target " docker-run)
181266echo " proposal $id plans $TEST_UPGRADE at block $target "
182- check " upgrade proposal passes" " $( pass_proposal " $id " ) " 3
267+ check " upgrade proposal passes" " $( pass_proposal " $id " ) " PROPOSAL_STATUS_PASSED
183268deposit_period_before=$( max_deposit_period 0)
184269check " the max deposit period is not yet the handler's" " $( [ " $deposit_period_before " != " $DEPOSIT_PERIOD_AFTER " ] && echo yes || echo no) " yes
185270for n in 0 1 2 3; do
@@ -239,17 +324,15 @@ wait_ready 3 || fail "node 3 did not come back"
239324
240325log " Cancelling a plan before its height"
241326tick || fail " no block before the cancel"
242- cancelled=$(( $(height 0 ) + 40 ))
243- id=$( gov_send " ${VOTER_KEYS[0]} " " submitSoftwareUpgradeProposal(string,string,bool,(string,uint64,string))" \
244- " upgrade" " schedules never-applied" true " (never-applied,$cancelled ,none)" --value " $EXPEDITED_DEPOSIT " | proposal_id)
245- check " second upgrade proposal passes" " $( pass_proposal " $id " ) " 3
327+ cancelled=$(( $(height 0 ) + 40 ))
328+ id=$( submit_upgrade never-applied " $cancelled " none)
329+ check " second upgrade proposal passes" " $( pass_proposal " $id " ) " PROPOSAL_STATUS_PASSED
246330check " the second plan is scheduled" " $( plan_name 0) " never-applied
247- status=$( gov_send " ${VOTER_KEYS[0]} " " submitCancelSoftwareUpgradeProposal(string,string,bool,string)" \
248- " cancel" " cancels another plan" true not-scheduled --value " $EXPEDITED_DEPOSIT " 2> /dev/null | jq -r ' .status // empty' 2> /dev/null || true)
249- check " a cancel naming another plan fails" " $status " 0x0
250- id=$( gov_send " ${VOTER_KEYS[0]} " " submitCancelSoftwareUpgradeProposal(string,string,bool,string)" \
251- " cancel" " cancels never-applied" true never-applied --value " $EXPEDITED_DEPOSIT " | proposal_id)
252- check " cancel proposal passes" " $( pass_proposal " $id " ) " 3
331+ # seid estimates gas before sending, so the gov precompile's refusal stops the
332+ # cancel before any transaction is sent.
333+ check " a cancel naming another plan is refused" " $( cancel_outcome not-scheduled) " refused
334+ id=$( submit_cancel never-applied | proposal_id)
335+ check " cancel proposal passes" " $( pass_proposal " $id " ) " PROPOSAL_STATUS_PASSED
253336for n in 0 1 2 3; do check " node $n has no plan after the cancel" " $( plan_name " $n " ) " " " ; done
254337tick_past $(( cancelled + 1 ))
255338for n in 0 1 2 3; do
@@ -259,11 +342,9 @@ done
259342
260343log " Applying minor upgrade $TEST_MINOR_UPGRADE "
261344tick || fail " no block before the minor upgrade"
262- minor=$(( $(height 0 ) + 40 ))
263- id=$( gov_send " ${VOTER_KEYS[0]} " " submitSoftwareUpgradeProposal(string,string,bool,(string,uint64,string))" \
264- " upgrade" " schedules $TEST_MINOR_UPGRADE " true " ($TEST_MINOR_UPGRADE ,$minor ,{\" upgradeType\" :\" minor\" })" \
265- --value " $EXPEDITED_DEPOSIT " | proposal_id)
266- check " minor upgrade proposal passes" " $( pass_proposal " $id " ) " 3
345+ minor=$(( $(height 0 ) + 40 ))
346+ id=$( submit_upgrade " $TEST_MINOR_UPGRADE " " $minor " ' {"upgradeType":"minor"}' )
347+ check " minor upgrade proposal passes" " $( pass_proposal " $id " ) " PROPOSAL_STATUS_PASSED
267348tick || true
268349sleep 5
269350for n in 0 1 2 3; do
0 commit comments