Skip to content

Commit 0f22f9f

Browse files
zsystmvladjdkAlex | Interchain Labs
authored
tests: add precompile solidity e2e tests (cosmos#253)
* update launch script path & remove duplicate We should use only one launch script. Managing both is extra un-necessary overhead * chore: add private keys info in local_node.sh * add bech32 and bank e2e tests * add undelegate test * faster local node and udpate delegate test * add create validator tc * update delegate tc include event checking also * update test codes added event checking to undelegate tc receipt has hash field instead of transactionHash * chore: remove un-used variable * add edit validator tc * add cancel unbonding tc * chore: format test files * add redelegate tc * skip gas estimation for faster tests * add redelegations query test * chore: refactor variable names * chore: change filename * add validators query test and fix gov interface * add set withdraw address tc * order test sequences and add withdraw delegator reward tc * add claim rewards tc * add withdraw validator commission * add fund community pool tc * add deposit validator rewards pool tc * add validator queries tc * chore: unify convention * add erc20 tc * update local node script it should contains every precompiles by default * fix slashing query and add e2e tests for it * fix: decode bech32 consensus address before converting to bytes The consensus address was previously used in its bech32-encoded form (a 52-character string), which is incorrect. This led to attempts to interpret a bech32 string directly as a 20-byte address, resulting in invalid conversions and data loss. This fix ensures the bech32 consensus address is properly decoded into its original 20-byte form before further processing, preserving the correct address representation expected in EVM-compatible byte format. * add gov tc * add more tcs to gov precompile (should fix cancel) * fix cancel proposal tc * add p256 tc * remove un-used variables * add werc20 tc * more timeout and verbose log * fix local_node.sh * add edgecase test for staking precompile and lint local node script * revert solidity test script change * chore: trim comments * p256 happy case * refactoring * refactor: make findEvent as common * check delegation shares and balance also * add checking user balance for withdraw delegator reward test * add checking user balance for claim rewards tc * strict balance check * add user balance check for fund community pool tc * add user balance check for deposit validator rewards pool tc * should use owner, not contract address itself * add event checks for erc20 precompile tc * add balance checks for werc20 tc * add balance check for gov deposit tc * add balance check for gov cancel proposal tc --------- Co-authored-by: Vlad J <[email protected]> Co-authored-by: Alex | Interchain Labs <[email protected]>
1 parent ebc4b6c commit 0f22f9f

26 files changed

+1872
-226
lines changed

local_node.sh

Lines changed: 55 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ KEYALGO="eth_secp256k1"
1010

1111
LOGLEVEL="info"
1212
# Set dedicated home directory for the evmd instance
13-
HOMEDIR="$HOME/.evmd"
13+
CHAINDIR="$HOME/.evmd"
1414

1515
BASEFEE=10000000
1616

1717
# Path variables
18-
CONFIG=$HOMEDIR/config/config.toml
19-
APP_TOML=$HOMEDIR/config/app.toml
20-
GENESIS=$HOMEDIR/config/genesis.json
21-
TMP_GENESIS=$HOMEDIR/config/tmp_genesis.json
18+
CONFIG_TOML=$CHAINDIR/config/config.toml
19+
APP_TOML=$CHAINDIR/config/app.toml
20+
GENESIS=$CHAINDIR/config/genesis.json
21+
TMP_GENESIS=$CHAINDIR/config/tmp_genesis.json
2222

2323
# validate dependencies are installed
2424
command -v jq >/dev/null 2>&1 || {
@@ -76,8 +76,8 @@ fi
7676
# User prompt if neither -y nor -n was passed as a flag
7777
# and an existing local node configuration is found.
7878
if [[ $overwrite = "" ]]; then
79-
if [ -d "$HOMEDIR" ]; then
80-
printf "\nAn existing folder at '%s' was found. You can choose to delete this folder and start a new local node with new keys from genesis. When declined, the existing local node is started. \n" "$HOMEDIR"
79+
if [ -d "$CHAINDIR" ]; then
80+
printf "\nAn existing folder at '%s' was found. You can choose to delete this folder and start a new local node with new keys from genesis. When declined, the existing local node is started. \n" "$CHAINDIR"
8181
echo "Overwrite the existing configuration and start a new local node? [y/n]"
8282
read -r overwrite
8383
else
@@ -88,41 +88,46 @@ fi
8888
# Setup local node if overwrite is set to Yes, otherwise skip setup
8989
if [[ $overwrite == "y" || $overwrite == "Y" ]]; then
9090
# Remove the previous folder
91-
rm -rf "$HOMEDIR"
91+
rm -rf "$CHAINDIR"
9292

9393
# Set client config
94-
evmd config set client chain-id "$CHAINID" --home "$HOMEDIR"
95-
evmd config set client keyring-backend "$KEYRING" --home "$HOMEDIR"
94+
evmd config set client chain-id "$CHAINID" --home "$CHAINDIR"
95+
evmd config set client keyring-backend "$KEYRING" --home "$CHAINDIR"
9696

97-
# myKey address 0x7cb61d4117ae31a12e393a1cfa3bac666481d02e | os10jmp6sgh4cc6zt3e8gw05wavvejgr5pwjnpcky
97+
# myKey address 0x7cb61d4117ae31a12e393a1cfa3bac666481d02e | cosmos10jmp6sgh4cc6zt3e8gw05wavvejgr5pwjnpcky
98+
# myKey's private key: 0xe9b1d63e8acd7fe676acb43afb390d4b0202dab61abec9cf2a561e4becb147de # gitleaks:allow
9899
VAL_KEY="mykey"
99100
VAL_MNEMONIC="gesture inject test cycle original hollow east ridge hen combine junk child bacon zero hope comfort vacuum milk pitch cage oppose unhappy lunar seat"
100101

101-
# dev0 address 0xc6fe5d33615a1c52c08018c47e8bc53646a0e101 | os1cml96vmptgw99syqrrz8az79xer2pcgp84pdun
102+
# dev0 address 0xC6Fe5D33615a1C52c08018c47E8Bc53646A0E101 | cosmos1cml96vmptgw99syqrrz8az79xer2pcgp84pdun
103+
# dev0's private key: 0x88cbead91aee890d27bf06e003ade3d4e952427e88f88d31d61d3ef5e5d54305 # gitleaks:allow
102104
USER1_KEY="dev0"
103105
USER1_MNEMONIC="copper push brief egg scan entry inform record adjust fossil boss egg comic alien upon aspect dry avoid interest fury window hint race symptom"
104106

105-
# dev1 address 0x963ebdf2e1f8db8707d05fc75bfeffba1b5bac17 | os1jcltmuhplrdcwp7stlr4hlhlhgd4htqh3a79sq
107+
# dev1 address 0x963EBDf2e1f8DB8707D05FC75bfeFFBa1B5BaC17 | cosmos1jcltmuhplrdcwp7stlr4hlhlhgd4htqh3a79sq
108+
# dev1's private key: 0x741de4f8988ea941d3ff0287911ca4074e62b7d45c991a51186455366f10b544 # gitleaks:allow
106109
USER2_KEY="dev1"
107110
USER2_MNEMONIC="maximum display century economy unlock van census kite error heart snow filter midnight usage egg venture cash kick motor survey drastic edge muffin visual"
108111

109-
# dev2 address 0x40a0cb1C63e026A81B55EE1308586E21eec1eFa9 | os1gzsvk8rruqn2sx64acfsskrwy8hvrmafqkaze8
112+
# dev2 address 0x40a0cb1C63e026A81B55EE1308586E21eec1eFa9 | cosmos1gzsvk8rruqn2sx64acfsskrwy8hvrmafqkaze8
113+
# dev2's private key: 0x3b7955d25189c99a7468192fcbc6429205c158834053ebe3f78f4512ab432db9 # gitleaks:allow
110114
USER3_KEY="dev2"
111115
USER3_MNEMONIC="will wear settle write dance topic tape sea glory hotel oppose rebel client problem era video gossip glide during yard balance cancel file rose"
112116

113-
# dev3 address 0x498B5AeC5D439b733dC2F58AB489783A23FB26dA | os1fx944mzagwdhx0wz7k9tfztc8g3lkfk6rrgv6l
117+
# dev3 address 0x498B5AeC5D439b733dC2F58AB489783A23FB26dA | cosmos1fx944mzagwdhx0wz7k9tfztc8g3lkfk6rrgv6l
118+
# dev3's private key: 0x8a36c69d940a92fcea94b36d0f2928c7a0ee19a90073eda769693298dfa9603b # gitleaks:allow
114119
USER4_KEY="dev3"
115120
USER4_MNEMONIC="doll midnight silk carpet brush boring pluck office gown inquiry duck chief aim exit gain never tennis crime fragile ship cloud surface exotic patch"
116121

117122
# Import keys from mnemonics
118-
echo "$VAL_MNEMONIC" | evmd keys add "$VAL_KEY" --recover --keyring-backend "$KEYRING" --algo "$KEYALGO" --home "$HOMEDIR"
119-
echo "$USER1_MNEMONIC" | evmd keys add "$USER1_KEY" --recover --keyring-backend "$KEYRING" --algo "$KEYALGO" --home "$HOMEDIR"
120-
echo "$USER2_MNEMONIC" | evmd keys add "$USER2_KEY" --recover --keyring-backend "$KEYRING" --algo "$KEYALGO" --home "$HOMEDIR"
121-
echo "$USER3_MNEMONIC" | evmd keys add "$USER3_KEY" --recover --keyring-backend "$KEYRING" --algo "$KEYALGO" --home "$HOMEDIR"
122-
echo "$USER4_MNEMONIC" | evmd keys add "$USER4_KEY" --recover --keyring-backend "$KEYRING" --algo "$KEYALGO" --home "$HOMEDIR"
123+
echo "$VAL_MNEMONIC" | evmd keys add "$VAL_KEY" --recover --keyring-backend "$KEYRING" --algo "$KEYALGO" --home "$CHAINDIR"
124+
echo "$USER1_MNEMONIC" | evmd keys add "$USER1_KEY" --recover --keyring-backend "$KEYRING" --algo "$KEYALGO" --home "$CHAINDIR"
125+
echo "$USER2_MNEMONIC" | evmd keys add "$USER2_KEY" --recover --keyring-backend "$KEYRING" --algo "$KEYALGO" --home "$CHAINDIR"
126+
echo "$USER3_MNEMONIC" | evmd keys add "$USER3_KEY" --recover --keyring-backend "$KEYRING" --algo "$KEYALGO" --home "$CHAINDIR"
127+
echo "$USER4_MNEMONIC" | evmd keys add "$USER4_KEY" --recover --keyring-backend "$KEYRING" --algo "$KEYALGO" --home "$CHAINDIR"
123128

124129
# Set moniker and chain-id for the example chain (Moniker can be anything, chain-id must be an integer)
125-
evmd init $MONIKER -o --chain-id "$CHAINID" --home "$HOMEDIR"
130+
echo "$VAL_MNEMONIC" | evmd init $MONIKER -o --chain-id "$CHAINID" --home "$CHAINDIR" --recover
126131

127132
# Change parameter token denominations to desired value
128133
jq '.app_state["staking"]["params"]["bond_denom"]="atest"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
@@ -148,36 +153,34 @@ if [[ $overwrite == "y" || $overwrite == "Y" ]]; then
148153
# Set gas limit in genesis
149154
jq '.consensus.params.block.max_gas="10000000"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
150155

151-
if [[ $1 == "pending" ]]; then
152-
if [[ "$OSTYPE" == "darwin"* ]]; then
153-
sed -i '' 's/timeout_propose = "3s"/timeout_propose = "30s"/g' "$CONFIG"
154-
sed -i '' 's/timeout_propose_delta = "500ms"/timeout_propose_delta = "5s"/g' "$CONFIG"
155-
sed -i '' 's/timeout_prevote = "1s"/timeout_prevote = "10s"/g' "$CONFIG"
156-
sed -i '' 's/timeout_prevote_delta = "500ms"/timeout_prevote_delta = "5s"/g' "$CONFIG"
157-
sed -i '' 's/timeout_precommit = "1s"/timeout_precommit = "10s"/g' "$CONFIG"
158-
sed -i '' 's/timeout_precommit_delta = "500ms"/timeout_precommit_delta = "5s"/g' "$CONFIG"
159-
sed -i '' 's/timeout_commit = "5s"/timeout_commit = "150s"/g' "$CONFIG"
160-
sed -i '' 's/timeout_broadcast_tx_commit = "10s"/timeout_broadcast_tx_commit = "150s"/g' "$CONFIG"
161-
else
162-
sed -i 's/timeout_propose = "3s"/timeout_propose = "30s"/g' "$CONFIG"
163-
sed -i 's/timeout_propose_delta = "500ms"/timeout_propose_delta = "5s"/g' "$CONFIG"
164-
sed -i 's/timeout_prevote = "1s"/timeout_prevote = "10s"/g' "$CONFIG"
165-
sed -i 's/timeout_prevote_delta = "500ms"/timeout_prevote_delta = "5s"/g' "$CONFIG"
166-
sed -i 's/timeout_precommit = "1s"/timeout_precommit = "10s"/g' "$CONFIG"
167-
sed -i 's/timeout_precommit_delta = "500ms"/timeout_precommit_delta = "5s"/g' "$CONFIG"
168-
sed -i 's/timeout_commit = "5s"/timeout_commit = "150s"/g' "$CONFIG"
169-
sed -i 's/timeout_broadcast_tx_commit = "10s"/timeout_broadcast_tx_commit = "150s"/g' "$CONFIG"
170-
fi
156+
if [[ "$OSTYPE" == "darwin"* ]]; then
157+
sed -i '' 's/timeout_propose = "3s"/timeout_propose = "2s"/g' "$CONFIG_TOML"
158+
sed -i '' 's/timeout_propose_delta = "500ms"/timeout_propose_delta = "200ms"/g' "$CONFIG_TOML"
159+
sed -i '' 's/timeout_prevote = "1s"/timeout_prevote = "500ms"/g' "$CONFIG_TOML"
160+
sed -i '' 's/timeout_prevote_delta = "500ms"/timeout_prevote_delta = "200ms"/g' "$CONFIG_TOML"
161+
sed -i '' 's/timeout_precommit = "1s"/timeout_precommit = "500ms"/g' "$CONFIG_TOML"
162+
sed -i '' 's/timeout_precommit_delta = "500ms"/timeout_precommit_delta = "200ms"/g' "$CONFIG_TOML"
163+
sed -i '' 's/timeout_commit = "5s"/timeout_commit = "1s"/g' "$CONFIG_TOML"
164+
sed -i '' 's/timeout_broadcast_tx_commit = "10s"/timeout_broadcast_tx_commit = "5s"/g' "$CONFIG_TOML"
165+
else
166+
sed -i 's/timeout_propose = "3s"/timeout_propose = "2s"/g' "$CONFIG_TOML"
167+
sed -i 's/timeout_propose_delta = "500ms"/timeout_propose_delta = "200ms"/g' "$CONFIG_TOML"
168+
sed -i 's/timeout_prevote = "1s"/timeout_prevote = "500ms"/g' "$CONFIG_TOML"
169+
sed -i 's/timeout_prevote_delta = "500ms"/timeout_prevote_delta = "200ms"/g' "$CONFIG_TOML"
170+
sed -i 's/timeout_precommit = "1s"/timeout_precommit = "500ms"/g' "$CONFIG_TOML"
171+
sed -i 's/timeout_precommit_delta = "500ms"/timeout_precommit_delta = "200ms"/g' "$CONFIG_TOML"
172+
sed -i 's/timeout_commit = "5s"/timeout_commit = "1s"/g' "$CONFIG_TOML"
173+
sed -i 's/timeout_broadcast_tx_commit = "10s"/timeout_broadcast_tx_commit = "5s"/g' "$CONFIG_TOML"
171174
fi
172175

173176
# enable prometheus metrics and all APIs for dev node
174177
if [[ "$OSTYPE" == "darwin"* ]]; then
175-
sed -i '' 's/prometheus = false/prometheus = true/' "$CONFIG"
178+
sed -i '' 's/prometheus = false/prometheus = true/' "$CONFIG_TOML"
176179
sed -i '' 's/prometheus-retention-time = 0/prometheus-retention-time = 1000000000000/g' "$APP_TOML"
177180
sed -i '' 's/enabled = false/enabled = true/g' "$APP_TOML"
178181
sed -i '' 's/enable = false/enable = true/g' "$APP_TOML"
179182
else
180-
sed -i 's/prometheus = false/prometheus = true/' "$CONFIG"
183+
sed -i 's/prometheus = false/prometheus = true/' "$CONFIG_TOML"
181184
sed -i 's/prometheus-retention-time = "0"/prometheus-retention-time = "1000000000000"/g' "$APP_TOML"
182185
sed -i 's/enabled = false/enabled = true/g' "$APP_TOML"
183186
sed -i 's/enable = false/enable = true/g' "$APP_TOML"
@@ -194,14 +197,14 @@ if [[ $overwrite == "y" || $overwrite == "Y" ]]; then
194197
sed -i.bak 's/pruning-interval = "0"/pruning-interval = "10"/g' "$APP_TOML"
195198

196199
# Allocate genesis accounts (cosmos formatted addresses)
197-
evmd genesis add-genesis-account "$VAL_KEY" 100000000000000000000000000atest --keyring-backend "$KEYRING" --home "$HOMEDIR"
198-
evmd genesis add-genesis-account "$USER1_KEY" 1000000000000000000000atest --keyring-backend "$KEYRING" --home "$HOMEDIR"
199-
evmd genesis add-genesis-account "$USER2_KEY" 1000000000000000000000atest --keyring-backend "$KEYRING" --home "$HOMEDIR"
200-
evmd genesis add-genesis-account "$USER3_KEY" 1000000000000000000000atest --keyring-backend "$KEYRING" --home "$HOMEDIR"
201-
evmd genesis add-genesis-account "$USER4_KEY" 1000000000000000000000atest --keyring-backend "$KEYRING" --home "$HOMEDIR"
200+
evmd genesis add-genesis-account "$VAL_KEY" 100000000000000000000000000atest --keyring-backend "$KEYRING" --home "$CHAINDIR"
201+
evmd genesis add-genesis-account "$USER1_KEY" 1000000000000000000000atest --keyring-backend "$KEYRING" --home "$CHAINDIR"
202+
evmd genesis add-genesis-account "$USER2_KEY" 1000000000000000000000atest --keyring-backend "$KEYRING" --home "$CHAINDIR"
203+
evmd genesis add-genesis-account "$USER3_KEY" 1000000000000000000000atest --keyring-backend "$KEYRING" --home "$CHAINDIR"
204+
evmd genesis add-genesis-account "$USER4_KEY" 1000000000000000000000atest --keyring-backend "$KEYRING" --home "$CHAINDIR"
202205

203206
# Sign genesis transaction
204-
evmd genesis gentx "$VAL_KEY" 1000000000000000000000atest --gas-prices ${BASEFEE}atest --keyring-backend "$KEYRING" --chain-id "$CHAINID" --home "$HOMEDIR"
207+
evmd genesis gentx "$VAL_KEY" 1000000000000000000000atest --gas-prices ${BASEFEE}atest --keyring-backend "$KEYRING" --chain-id "$CHAINID" --home "$CHAINDIR"
205208
## In case you want to create multiple validators at genesis
206209
## 1. Back to `evmd keys add` step, init more keys
207210
## 2. Back to `evmd add-genesis-account` step, add balance for those
@@ -210,10 +213,10 @@ if [[ $overwrite == "y" || $overwrite == "Y" ]]; then
210213
## 5. Copy the `gentx-*` folders under `~/.clonedOsd/config/gentx/` folders into the original `~/.evmd/config/gentx`
211214

212215
# Collect genesis tx
213-
evmd genesis collect-gentxs --home "$HOMEDIR"
216+
evmd genesis collect-gentxs --home "$CHAINDIR"
214217

215218
# Run this to ensure everything worked and that the genesis file is setup correctly
216-
evmd genesis validate-genesis --home "$HOMEDIR"
219+
evmd genesis validate-genesis --home "$CHAINDIR"
217220

218221
if [[ $1 == "pending" ]]; then
219222
echo "pending mode is on, please wait for the first block committed."
@@ -224,6 +227,6 @@ fi
224227
evmd start "$TRACE" \
225228
--log_level $LOGLEVEL \
226229
--minimum-gas-prices=0.0001atest \
227-
--home "$HOMEDIR" \
230+
--home "$CHAINDIR" \
228231
--json-rpc.api eth,txpool,personal,net,debug,web3 \
229232
--chain-id "$CHAINID"

precompiles/slashing/slashing.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ func (p Precompile) run(evm *vm.EVM, contract *vm.Contract, readOnly bool) (bz [
119119
bz, err = p.GetSigningInfo(ctx, method, contract, args)
120120
case GetSigningInfosMethod:
121121
bz, err = p.GetSigningInfos(ctx, method, contract, args)
122+
case GetParamsMethod:
123+
bz, err = p.GetParams(ctx, method, contract, args)
122124
default:
123125
return nil, fmt.Errorf(cmn.ErrUnknownMethod, method.Name)
124126
}

0 commit comments

Comments
 (0)