Skip to content

Commit

Permalink
docs: update the instructions for local testing with ganache or hardh…
Browse files Browse the repository at this point in the history
…at (#413)

* docs: update the instructions for local test
  • Loading branch information
gsk967 authored Dec 20, 2022
1 parent 96b53d0 commit 62de3e9
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 56 deletions.
9 changes: 9 additions & 0 deletions test/.env.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ETHRPC=http://localhost:8545
MYETH=0xfac5EC50BdfbB803f5cFc9BF0A0C2f52aDE5b6dd
MYETHPK=0x06e48d48a55cc6843acb2c3c23431480ec42fca02683f4d8d3d471372e5317ee
MYETH2=0x02fa1b44e2EF8436e6f35D5F56607769c658c225
MYETH2PK=0x4faf826f3d3a5fa60103392446a72dea01145c6158c6dd29f6faab9ec9917a1b
MYETH3=0xd8f468c1B719cc2d50eB1E3A55cFcb60e23758CD
MYETH3PK=0x11f746395f0dd459eff05d1bc557b81c3f7ebb1338a8cc9d36966d0bb2dcea21
CHAIN_ID=888
UMEE_PEGGO_PATH=$PWD
2 changes: 1 addition & 1 deletion test/cosmos/multinode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ if [[ ! -d "$hdir" ]]; then
cat $n0cfgDir/genesis.json | jq '.app_state["crisis"]["constant_fee"]["denom"]="'$DENOM'"' > $n0cfgDir/tmp_genesis.json && mv $n0cfgDir/tmp_genesis.json $n0cfgDir/genesis.json
cat $n0cfgDir/genesis.json | jq '.app_state["gov"]["deposit_params"]["min_deposit"][0]["denom"]="'$DENOM'"' > $n0cfgDir/tmp_genesis.json && mv $n0cfgDir/tmp_genesis.json $n0cfgDir/genesis.json
cat $n0cfgDir/genesis.json | jq '.app_state["mint"]["params"]["mint_denom"]="'$DENOM'"' > $n0cfgDir/tmp_genesis.json && mv $n0cfgDir/tmp_genesis.json $n0cfgDir/genesis.json
cat $n0cfgDir/genesis.json | jq '.app_state["gravity"]["params"]["bridge_chain_id"]="5"' > $n0cfgDir/tmp_genesis.json && mv $n0cfgDir/tmp_genesis.json $n0cfgDir/genesis.json
cat $n0cfgDir/genesis.json | jq '.app_state["gravity"]["params"]["bridge_chain_id"]="'$CHAIN_ID'"' > $n0cfgDir/tmp_genesis.json && mv $n0cfgDir/tmp_genesis.json $n0cfgDir/genesis.json
fi

echo "NOTE: Setting Governance Voting Period to 10 seconds for rapid testing"
Expand Down
9 changes: 9 additions & 0 deletions test/env.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ETHRPC=http://localhost:8545
MYETH=0xfac5EC50BdfbB803f5cFc9BF0A0C2f52aDE5b6dd
MYETHPK=0x06e48d48a55cc6843acb2c3c23431480ec42fca02683f4d8d3d471372e5317ee
MYETH2=0x02fa1b44e2EF8436e6f35D5F56607769c658c225
MYETH2PK=0x4faf826f3d3a5fa60103392446a72dea01145c6158c6dd29f6faab9ec9917a1b
MYETH3=0xd8f468c1B719cc2d50eB1E3A55cFcb60e23758CD
MYETH3PK=0x11f746395f0dd459eff05d1bc557b81c3f7ebb1338a8cc9d36966d0bb2dcea21
CHAIN_ID=888
UMEE_PEGGO_PATH=$PWD
40 changes: 20 additions & 20 deletions test/eth/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,39 @@ function GetChainId(): number {

const balance = "100000000000000000000000000"

const privateKeys = [
// val0 0xfac5EC50BdfbB803f5cFc9BF0A0C2f52aDE5b6dd
"0x06e48d48a55cc6843acb2c3c23431480ec42fca02683f4d8d3d471372e5317ee",
// val1 0x02fa1b44e2EF8436e6f35D5F56607769c658c225
"0x4faf826f3d3a5fa60103392446a72dea01145c6158c6dd29f6faab9ec9917a1b",
// val2 0xd8f468c1B719cc2d50eB1E3A55cFcb60e23758CD
"0x11f746395f0dd459eff05d1bc557b81c3f7ebb1338a8cc9d36966d0bb2dcea21",
]


const peggoAccounts: HardhatNetworkAccountUserConfig[] = [
{
// val0 0xC6Fe5D33615a1C52c08018c47E8Bc53646A0E101
privateKey: "0x88cbead91aee890d27bf06e003ade3d4e952427e88f88d31d61d3ef5e5d54305",
balance: balance,
},
{
// val1 0x963EBDf2e1f8DB8707D05FC75bfeFFBa1B5BaC17
privateKey: "0x741de4f8988ea941d3ff0287911ca4074e62b7d45c991a51186455366f10b544",
privateKey: privateKeys[0],
balance: balance,
},
{
// val2 0x6880D7bfE96D49501141375ED835C24cf70E2bD7
privateKey: "0x39a4c898dda351d54875d5ebb3e1c451189116faa556c3c04adc860dd1000608",
privateKey: privateKeys[1],
balance: balance,
},
{
// user 0x727AEE334987c52fA7b567b2662BDbb68614e48C
privateKey: "0x6c212553111b370a8ffdc682954495b7b90a73cedab7106323646a4f2c4e668f",
privateKey: privateKeys[2],
balance: balance,
},
]


const peggoTestNetwork: HardhatNetworkUserConfig = {
chainId: GetChainId(),
accounts: peggoAccounts,
mining: {
// It will produce empty blocks every 3 seconds
interval: 3000
}
}

const config: HardhatUserConfig = {
Expand All @@ -61,18 +68,11 @@ const config: HardhatUserConfig = {
ganache: {
chainId: GetChainId(),
url: "http://127.0.0.1:8545",
accounts: [
"0x88cbead91aee890d27bf06e003ade3d4e952427e88f88d31d61d3ef5e5d54305",
"0x741de4f8988ea941d3ff0287911ca4074e62b7d45c991a51186455366f10b544",
"0x39a4c898dda351d54875d5ebb3e1c451189116faa556c3c04adc860dd1000608",
"0x6c212553111b370a8ffdc682954495b7b90a73cedab7106323646a4f2c4e668f",
]
accounts: privateKeys
},
goerli: {
url: env.ETHRPC,
accounts: [
"0x88cbead91aee890d27bf06e003ade3d4e952427e88f88d31d61d3ef5e5d54305"
]
accounts: privateKeys
}
},
etherscan: {
Expand Down
18 changes: 8 additions & 10 deletions test/eth/run_ganache.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
#!/bin/bash -eux

CWD="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
DATA_DIR=${DATA_DIR:-$CWD/data}
DATA_DIR=${DATA_DIR:-$PWD/data}

rm -rf $DATA_DIR
mkdir -p $DATA_DIR

ganache="ganache"

if pgrep -x $ganache >/dev/null
if pgrep -x ganache >/dev/null
then
echo "$ganache is running, going to kill all"
ps -ef | grep $ganache | grep -v grep | awk '{print $2}' | xargs kill
echo "ganache is running, going to kill all"
ps -ef | grep ganache | grep -v grep | awk '{print $2}' | xargs kill
fi

$ganache \
ganache \
--chain.chainId 888 \
--account '0x88cbead91aee890d27bf06e003ade3d4e952427e88f88d31d61d3ef5e5d54305,1000000000000000000' \
--account '0x741de4f8988ea941d3ff0287911ca4074e62b7d45c991a51186455366f10b544,1000000000000000000' \
--account '0x39a4c898dda351d54875d5ebb3e1c451189116faa556c3c04adc860dd1000608,1000000000000000000' \
--account '0x6c212553111b370a8ffdc682954495b7b90a73cedab7106323646a4f2c4e668f,1000000000000000000' \
--account '0x06e48d48a55cc6843acb2c3c23431480ec42fca02683f4d8d3d471372e5317ee,1000000000000000000' \
--account '0x4faf826f3d3a5fa60103392446a72dea01145c6158c6dd29f6faab9ec9917a1b,1000000000000000000' \
--account '0x11f746395f0dd459eff05d1bc557b81c3f7ebb1338a8cc9d36966d0bb2dcea21,1000000000000000000' \
--blockTime 1 \
> $DATA_DIR/ganache.log 2>&1 &
93 changes: 68 additions & 25 deletions test/manual-test-peggo.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,38 @@

- You have `umeed` in your path
- You have `jq`, `perl` and `curl`
- You have 3 funded wallets in [goerli](https://goerli.etherscan.io/)
- [Faucet](https://goerli-faucet.mudit.blog/) (sometimes it does not work)
- You can choose any eth test networks like [goerli](https://goerli.etherscan.io/) , [ganache](https://github.com/trufflesuite/ganache) or [hardhat](https://hardhat.org)
- [Install ganache](https://github.com/trufflesuite/ganache/tree/v7.5.0#command-line-use)
```shell
$ npm install ganache --global
```

- [Install hardhat](https://hardhat.org/hardhat-runner/docs/getting-started#installation)
```shell
$ npm install --save-dev hardhat
```
- You have 3 funded wallets in [goerli](https://goerli.etherscan.io/), [ganache](https://github.com/trufflesuite/ganache) or [hardhat](https://hardhat.org)
- [Faucet](https://goerli-faucet.mudit.blog/) (sometimes it does not work) for goreli

- You should set the following enviroment variables

```shell
$~ UMEE_PEGGO_PATH=${peggo_root_path_in_your_local_enviroment}
$~ ETHRPC=https://goerli-infura.brave.com/f7106c838853428280fa0c585acc9485
$~ MYETH=0xfac5EC50BdfbB803f5cFc9BF0A0C2f52aDE5b6dd
$~ MYETHPK=06e48d48a55cc6843acb2c3c23431480ec42fca02683f4d8d3d471372e5317ee
$~ MYETH2=0x02fa1b44e2EF8436e6f35D5F56607769c658c225
$~ MYETH2PK=4faf826f3d3a5fa60103392446a72dea01145c6158c6dd29f6faab9ec9917a1b
$~ MYETH3=0xd8f468c1B719cc2d50eB1E3A55cFcb60e23758CD
$~ MYETH3PK=11f746395f0dd459eff05d1bc557b81c3f7ebb1338a8cc9d36966d0bb2dcea21
$~ CHAIN_ID=888
$ UMEE_PEGGO_PATH=${peggo_root_path_in_your_local_enviroment}
$ ETHRPC=https://goerli-infura.brave.com/f7106c838853428280fa0c585acc9485
$ MYETH=0xfac5EC50BdfbB803f5cFc9BF0A0C2f52aDE5b6dd
$ MYETHPK=06e48d48a55cc6843acb2c3c23431480ec42fca02683f4d8d3d471372e5317ee
$ MYETH2=0x02fa1b44e2EF8436e6f35D5F56607769c658c225
$ MYETH2PK=4faf826f3d3a5fa60103392446a72dea01145c6158c6dd29f6faab9ec9917a1b
$ MYETH3=0xd8f468c1B719cc2d50eB1E3A55cFcb60e23758CD
$ MYETH3PK=11f746395f0dd459eff05d1bc557b81c3f7ebb1338a8cc9d36966d0bb2dcea21
$ CHAIN_ID=888
```

or

```shell
# test/env.local file contains env variables for testing the peggo
$ source $UMEE_PEGGO_PATH/test/env.local
```

<!--
Expand All @@ -40,12 +58,30 @@ set TOKEN_ADDRESS 0xdcbb485f280284ec571e11eb09490677a5bdd569

- To test the peggo bridge manually execute the next steps

### If you want run local eth networks (Ganache or Hardhat)

- Run the `ganache`

```shell
$ bash $UMEE_PEGGO_PATH/test/eth/run_ganache.sh
```

or

- Run the `hardhat`

```shell
# Install dependencies
$ cd $UMEE_PEGGO_PATH/test/eth && npm install
# Run the hardhat
$ npx hardhat node
```
### Start umee chain multinode

- Run the `multinode.sh`

```shell
$~ bash $UMEE_PEGGO_PATH/test/cosmos/multinode.sh umeed
$ bash $UMEE_PEGGO_PATH/test/cosmos/multinode.sh umeed
```

### Deploy a new Gravity bridge smartcontract
Expand All @@ -54,13 +90,13 @@ $~ bash $UMEE_PEGGO_PATH/test/cosmos/multinode.sh umeed
set the `BRIDGEADDR` env variable with the contract address of the bridge smartcontract

```shell
$~ BRIDGEADDR=0xaB3BB333676fBF3c88554A455633aC9168cDD0Af
$ BRIDGEADDR=0xaB3BB333676fBF3c88554A455633aC9168cDD0Af
```

- Or you can deploy a new bridge

```shell
$~ PEGGO_ETH_PK=$MYETHPK peggo bridge deploy-gravity --eth-rpc $ETHRPC
$ PEGGO_ETH_PK=$MYETHPK peggo bridge deploy-gravity --eth-rpc $ETHRPC
```

__Expected Result__
Expand All @@ -69,7 +105,9 @@ __Expected Result__
- Set the `BRIDGEADDR` variable

```shell
$~ BRIDGEADDR=0x86C4B780936D59b475291EE69D10A0260cD46F11
# Check the `Address` in response
# Ex BRIDGEADDR=0x86C4B780936D59b475291EE69D10A0260cD46F11
$ BRIDGEADDR={Adderss}
```

- Wait until the gravity bridge is confirmed in ethereum (14 blocks)
Expand All @@ -80,7 +118,7 @@ $~ BRIDGEADDR=0x86C4B780936D59b475291EE69D10A0260cD46F11
the following commands one in each shell

```shell
$~ PEGGO_ETH_PK=$MYETHPK peggo orchestrator $BRIDGEADDR \
$ PEGGO_ETH_PK=$MYETHPK peggo orchestrator $BRIDGEADDR \
--eth-rpc=$ETHRPC \
--relay-batches=true \
--valset-relay-mode="all" \
Expand All @@ -94,7 +132,7 @@ $~ PEGGO_ETH_PK=$MYETHPK peggo orchestrator $BRIDGEADDR \
```

```shell
$~ PEGGO_ETH_PK=$MYETH2PK peggo orchestrator $BRIDGEADDR \
$ PEGGO_ETH_PK=$MYETH2PK peggo orchestrator $BRIDGEADDR \
--eth-rpc=$ETHRPC \
--relay-batches=true \
--valset-relay-mode="all" \
Expand All @@ -108,7 +146,7 @@ $~ PEGGO_ETH_PK=$MYETH2PK peggo orchestrator $BRIDGEADDR \
```

```shell
$~ PEGGO_ETH_PK=$MYETH3PK peggo orchestrator $BRIDGEADDR \
$ PEGGO_ETH_PK=$MYETH3PK peggo orchestrator $BRIDGEADDR \
--eth-rpc=$ETHRPC \
--relay-batches=true \
--valset-relay-mode="all" \
Expand All @@ -127,7 +165,10 @@ $~ PEGGO_ETH_PK=$MYETH3PK peggo orchestrator $BRIDGEADDR \
token in eth

```shell
$~ PEGGO_ETH_PK=$MYETHPK peggo bridge deploy-erc20 $BRIDGEADDR uumee --eth-rpc $ETHRPC
$ PEGGO_ETH_PK=$MYETHPK peggo bridge deploy-erc20 $BRIDGEADDR uumee --eth-rpc $ETHRPC

or
$ PEGGO_ETH_PK=$MYETHPK peggo bridge deploy-erc20-raw $BRIDGEADDR uumee Umee UMEE 6 --eth-rpc $ETHRPC
```

__Expected Result__
Expand All @@ -136,7 +177,8 @@ __Expected Result__
- Set transaction hash in `ERC20_UMEE_TX_HASH`

```shell
$~ ERC20_UMEE_TX_HASH="0xf185d0f54f42ed0f303400db5e6d1d83637acce12971f7fc48b3e33b8e11ad0b"
# Ex: ERC20_UMEE_TX_HASH="0xf185d0f54f42ed0f303400db5e6d1d83637acce12971f7fc48b3e33b8e11ad0b"
$ ERC20_UMEE_TX_HASH={Tx_Hash}
```

<!--
Expand All @@ -148,21 +190,21 @@ set ERC20_UMEE_TX_HASH 0xf185d0f54f42ed0f303400db5e6d1d83637acce12971f7fc48b3e33
- You can get the contract address of the deployed umee contract

```shell
$~ curl -X POST --data '{"jsonrpc":"2.0","method":"eth_getTransactionReceipt",
$ curl -X POST --data '{"jsonrpc":"2.0","method":"eth_getTransactionReceipt",
"params":["'$ERC20_UMEE_TX_HASH'"],"id":1}' $ETHRPC | jq -r '.result.logs[0].address'
```

- Or even directly set the `TOKEN_ADDRESS` env variable with the contract
address of the deployed umee contract

```shell
$~ TOKEN_ADDRESS=`curl -X POST --data '{"jsonrpc":"2.0","method":"eth_getTransactionReceipt",
$ TOKEN_ADDRESS=`curl -X POST --data '{"jsonrpc":"2.0","method":"eth_getTransactionReceipt",
"params":["'$ERC20_UMEE_TX_HASH'"],"id":1}' $ETHRPC | jq -r '.result.logs[0].address'`
```

<!--
```fish
$~ set TOKEN_ADDRESS (curl -X POST --data '{"jsonrpc":"2.0","method":"eth_getTransactionReceipt", "params":["'$ERC20_UMEE_TX_HASH'"],"id":1}' $ETHRPC | jq -r '.result.logs[0].address')
$ set TOKEN_ADDRESS (curl -X POST --data '{"jsonrpc":"2.0","method":"eth_getTransactionReceipt", "params":["'$ERC20_UMEE_TX_HASH'"],"id":1}' $ETHRPC | jq -r '.result.logs[0].address')
```
-->

Expand All @@ -171,7 +213,7 @@ $~ set TOKEN_ADDRESS (curl -X POST --data '{"jsonrpc":"2.0","method":"eth_getTra
### Send transaction from umee to eth

```shell
$~ umeed tx gravity send-to-eth $MYETH 10000uumee 1uumee \
$ umeed tx gravity send-to-eth $MYETH 10000uumee 1uumee \
--from val \
--chain-id $CHAIN_ID \
--keyring-backend=test \
Expand All @@ -181,7 +223,8 @@ $~ umeed tx gravity send-to-eth $MYETH 10000uumee 1uumee \

### Send transaction from eth to umee

```shell $~ PEGGO_ETH_PK=$MYETHPK peggo bridge send-to-cosmos \
```shell
$ PEGGO_ETH_PK=$MYETHPK peggo bridge send-to-cosmos \
$BRIDGEADDR $TOKEN_ADDRESS umee1pprgkthxc2yhr5gvuk2tcjjchfhq6n96xg427t 1 \
--eth-rpc $ETHRPC
```

0 comments on commit 62de3e9

Please sign in to comment.