Skip to content

Commit

Permalink
fix config type and scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
yito88 committed Nov 8, 2023
1 parent 665cec3 commit f75d910
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 14 deletions.
2 changes: 1 addition & 1 deletion crates/relayer/src/chain/namada.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ impl ChainEndpoint for NamadaChain {

fn bootstrap(config: ChainConfig, rt: Arc<TokioRuntime>) -> Result<Self, Error> {
#[allow(irrefutable_let_patterns)]
let ChainConfig::CosmosSdk(config) = config
let ChainConfig::Namada(config) = config
else {
return Err(Error::config(ConfigError::wrong_type()));
};
Expand Down
190 changes: 190 additions & 0 deletions e2e/namada-gaia-simple-transfers
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
#!/bin/bash

# This script sets up Namada and Gaia locally
# `make build-release` and `make build-wasm-scripts` on Namada directory in advance
# Run with `namada-gaia-simple-transfers ${namada_dir}`

set -e

NAMADA_DIR=$1
if [ -z "${NAMADA_DIR}" ]
then
echo "ERROR: Namada directory should be given"
exit 1
fi
cd $(dirname $0)
HERMES_DIR=${PWD%/e2e*}

# edit for your environment
NAMADAC="${NAMADA_DIR}/target/debug/namadac"
NAMADAN="${NAMADA_DIR}/target/debug/namadan"
NAMADAW="${NAMADA_DIR}/target/debug/namadaw"
DATA_DIR="${HERMES_DIR}/data"
IBC_TOKEN="transfer/channel-0/samoleans"

NAMADA_LEDGER_ADDR="127.0.0.1:27657"

GAIA_CHAIN_CONFIG="
[[chains]]
id = 'gaia-0'
type = 'CosmosSdk'
rpc_addr = 'http://127.0.0.1:26657'
grpc_addr = 'http://127.0.0.1:9090'
event_source = { mode = 'push', url = 'ws://127.0.0.1:26657/websocket', batch_delay = '500ms' }
account_prefix = 'cosmos'
key_name = 'testkey'
store_prefix = 'ibc'
gas_price = { price = 0.001, denom = 'stake' }
"

#### main ####
mkdir -p ${DATA_DIR}

# Gaia
rm -rf ${DATA_DIR}/gaia-0

${HERMES_DIR}/scripts/one-chain gaiad gaia-0 ${DATA_DIR} \
26657 26656 6060 9090 10000

# Namada
${HERMES_DIR}/scripts/setup-namada-single-node ${NAMADA_DIR}
base_dir=${DATA_DIR}/namada

cd ${HERMES_DIR}
chain_id=$(grep id config_for_namada.toml | sed -e s/\'//g | awk '{print $3}')

# Add Gaia chain config
echo "${GAIA_CHAIN_CONFIG}" >> config_for_namada.toml

# add Gaia key
cargo run -q --bin hermes -- --config config_for_namada.toml \
keys add --chain gaia-0 --key-file ${DATA_DIR}/gaia-0/user_seed.json --overwrite

# Initialize Relayer's balance on Namada
${NAMADAC} --base-dir ${base_dir} \
transfer \
--source albert \
--target relayer \
--token nam \
--amount 10000 \
--node ${NAMADA_LEDGER_ADDR}

${NAMADAC} --base-dir ${base_dir} \
transfer \
--source albert \
--target relayer \
--token apfel \
--amount 1000 \
--node ${NAMADA_LEDGER_ADDR}

# create a channel
cargo run --bin hermes -- --config config_for_namada.toml \
create channel --a-chain ${chain_id} \
--b-chain gaia-0 \
--a-port transfer \
--b-port transfer \
--new-client-connection --yes

# Transfer 100 samoleans from Gaia to Namada
namada_receiver=$(${NAMADAW} --base-dir ${base_dir} address find --alias relayer | awk '{print $4}')
cargo run --bin hermes -- --config config_for_namada.toml \
tx ft-transfer \
--dst-chain ${chain_id} \
--src-chain gaia-0 \
--src-port transfer \
--src-channel channel-0 \
--amount 100 \
--receiver ${namada_receiver} \
--denom samoleans \
--timeout-height-offset 1000

# packet-recv
cargo run --bin hermes -- --config config_for_namada.toml \
tx packet-recv \
--dst-chain ${chain_id} \
--src-chain gaia-0 \
--src-port transfer \
--src-channel channel-0

# packet-ack
cargo run --bin hermes -- --config config_for_namada.toml \
tx packet-ack \
--dst-chain gaia-0 \
--src-chain ${chain_id} \
--src-port transfer \
--src-channel channel-0

echo "Balances on Namada"
${NAMADAC} --base-dir ${base_dir} balance \
--token ${IBC_TOKEN} \
--owner relayer \
--node ${NAMADA_LEDGER_ADDR}

echo "Balances on Gaia"
gaia_user=$(gaiad --home ${DATA_DIR}/gaia-0 \
keys --keyring-backend="test" show user -a)
gaiad query bank balances ${gaia_user}

# transfer back 50 samoleans from Namada to Gaia
${NAMADAC} --base-dir ${base_dir} ibc-transfer \
--source relayer \
--receiver ${gaia_user} \
--token ${IBC_TOKEN} \
--amount 50 \
--signing-keys relayer \
--channel-id channel-0 \
--node ${NAMADA_LEDGER_ADDR}

# packet-recv
cargo run --bin hermes -- --config config_for_namada.toml \
tx packet-recv \
--dst-chain gaia-0 \
--src-chain ${chain_id} \
--src-port transfer \
--src-channel channel-0

# packet-ack
cargo run --bin hermes -- --config config_for_namada.toml \
tx packet-ack \
--dst-chain ${chain_id} \
--src-chain gaia-0 \
--src-port transfer \
--src-channel channel-0

echo "Balances on Namada"
${NAMADAC} --base-dir ${base_dir} balance \
--token ${IBC_TOKEN} \
--owner relayer \
--node ${NAMADA_LEDGER_ADDR}

echo "Balances on Gaia"
gaiad query bank balances ${gaia_user}

echo "==== Start Hermes ===="
cargo run --bin hermes -- --config config_for_namada.toml \
start > ${HERMES_DIR}/e2e/hermes.log 2>&1 &

# transfer 200 apfel from Namada to Gaia
${NAMADAC} --base-dir ${base_dir} ibc-transfer \
--source relayer \
--receiver ${gaia_user} \
--token apfel \
--amount 200 \
--signing-keys relayer \
--channel-id channel-0 \
--node ${NAMADA_LEDGER_ADDR}

# wait for relaying
sleep 10

echo "Balances on Namada"
${NAMADAC} --base-dir ${base_dir} balance \
--owner relayer \
--node ${NAMADA_LEDGER_ADDR}

echo "Balances on Gaia"
gaiad query bank balances ${gaia_user}

killall hermes
killall gaiad
killall namadan
26 changes: 16 additions & 10 deletions e2e/namada-simple-transfers
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ cargo run --bin hermes -- --config config_for_namada.toml \
--b-port transfer \
--new-client-connection --yes

# faucet apfel on chain_a
# faucet apfel on chain_a and chain_b
base_dir_a=${DATA_DIR}/namada-a
base_dir_b=${DATA_DIR}/namada-b
${NAMADAC} --base-dir ${base_dir_a} transfer \
--source albert \
--target relayer \
Expand All @@ -71,9 +72,16 @@ ${NAMADAC} --base-dir ${base_dir_a} transfer \
--signing-keys albert-key \
--node ${LEDGER_ADDR_A}

${NAMADAC} --base-dir ${base_dir_b} transfer \
--source albert \
--target relayer \
--token apfel \
--amount 1000 \
--signing-keys albert-key \
--node ${LEDGER_ADDR_B}

# Get the receiver addresses
receiver_a=$(${NAMADAW} --base-dir ${base_dir_a} address find --alias relayer | awk '{print $4}')
base_dir_b=${DATA_DIR}/namada-b
receiver_b=$(${NAMADAW} --base-dir ${base_dir_b} address find --alias relayer | awk '{print $4}')

# transfer 100 apfel from chain_a to chain_b
Expand Down Expand Up @@ -157,11 +165,11 @@ ${NAMADAC} --base-dir ${base_dir_b} balance \
--owner relayer \
--node ${LEDGER_ADDR_B}

# Start Hermes
echo "==== Start Hermes ===="
cargo run --bin hermes -- --config config_for_namada.toml \
start > ${HERMES_DIR}/e2e/hermes.log 2>&1 &

# transfer 300 apfel from chain_a to chain_b
# transfer 200 apfel from chain_a to chain_b
${NAMADAC} --base-dir ${base_dir_a} ibc-transfer \
--source relayer \
--receiver ${receiver_b} \
Expand All @@ -171,28 +179,26 @@ ${NAMADAC} --base-dir ${base_dir_a} ibc-transfer \
--channel-id channel-0 \
--node ${LEDGER_ADDR_A}

# transfer 300 apfel from chain_a to chain_b twice
${NAMADAC} --base-dir ${base_dir_a} ibc-transfer \
# transfer 300 apfel from chain_b to chain_a
${NAMADAC} --base-dir ${base_dir_b} ibc-transfer \
--source relayer \
--receiver ${receiver_b} \
--receiver ${receiver_a} \
--token apfel \
--amount 300 \
--signing-keys relayer \
--channel-id channel-0 \
--node ${LEDGER_ADDR_A}
--node ${LEDGER_ADDR_B}

# wait for relaying
sleep 10

echo "Balances on chain A"
${NAMADAC} --base-dir ${base_dir_a} balance \
--token apfel \
--owner relayer \
--node ${LEDGER_ADDR_A}

echo "Balances on chain B"
${NAMADAC} --base-dir ${base_dir_b} balance \
--token ${received_token} \
--owner relayer \
--node ${LEDGER_ADDR_B}

Expand Down
4 changes: 2 additions & 2 deletions scripts/setup-namada
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ port = 3001
[[chains]]
id = '_CHAIN_ID_A_'
type = 'namada'
type = 'Namada'
rpc_addr = 'http://127.0.0.1:27657'
grpc_addr = 'http://127.0.0.1:9090'
event_source = { mode = 'push', url = 'ws://127.0.0.1:27657/websocket', batch_delay = '500ms' }
Expand All @@ -71,7 +71,7 @@ gas_price = { price = 0.001, denom = 'nam' }
[[chains]]
id = '_CHAIN_ID_B_'
type = 'namada'
type = 'Namada'
rpc_addr = 'http://127.0.0.1:28657'
grpc_addr = 'http://127.0.0.1:9090'
event_source = { mode = 'push', url = 'ws://127.0.0.1:28657/websocket', batch_delay = '500ms' }
Expand Down
2 changes: 1 addition & 1 deletion scripts/setup-namada-single-node
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ port = 3001
[[chains]]
id = '_CHAIN_ID_'
type = 'namada'
type = 'Namada'
rpc_addr = 'http://127.0.0.1:27657'
grpc_addr = 'http://127.0.0.1:9090'
event_source = { mode = 'push', url = 'ws://127.0.0.1:27657/websocket', batch_delay = '500ms' }
Expand Down

0 comments on commit f75d910

Please sign in to comment.