Skip to content

Commit

Permalink
eth2eth: use mockapp instead of ics20
Browse files Browse the repository at this point in the history
Signed-off-by: Masanori Yoshida <[email protected]>
  • Loading branch information
siburu committed Sep 4, 2024
1 parent 248ff2c commit 1173f1e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 81 deletions.
4 changes: 2 additions & 2 deletions tests/cases/eth2eth/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ test-multi:
./scripts/init-rly
./scripts/handshake
./scripts/test-channel-upgrade multi
# ./scripts/test-tx
./scripts/test-tx

.PHONY: test-single
test-single:
./scripts/fixture single
./scripts/init-rly
./scripts/handshake
./scripts/test-channel-upgrade single
# ./scripts/test-tx
./scripts/test-tx

.PHONY: network-down
network-down:
Expand Down
112 changes: 33 additions & 79 deletions tests/cases/eth2eth/scripts/test-tx
Original file line number Diff line number Diff line change
@@ -1,114 +1,68 @@
#!/bin/bash

set -eu
set -eux

SCRIPT_DIR=$(cd $(dirname ${BASH_SOURCE:-$0}); pwd)
FIXTURES_DIR=${SCRIPT_DIR}/../fixtures

source ${SCRIPT_DIR}/util/relayer-util

ICS20_CLI="ethereum-ics20-cli"

if ! which ${ICS20_CLI} > /dev/null 2>&1; then
TMP_DIR=`mktemp -d`
git clone https://github.com/datachainlab/ethereum-ics20-cli.git ${TMP_DIR}/ethereum-ics20-cli
pushd ${TMP_DIR}/ethereum-ics20-cli
git checkout v0.0.5
go install
export PATH=$PATH:$(go env GOPATH)/bin
popd
fi

ADDRESSES_DIR_A="${FIXTURES_DIR}/ethereum/ibc0/addresses"
ADDRESSES_DIR_B="${FIXTURES_DIR}/ethereum/ibc1/addresses"

ERC20_TOKEN_ADDRESS_A=`cat ${ADDRESSES_DIR_A}/ERC20Token`
#ERC20_TOKEN_ADDRESS_B=`cat ${ADDRESSES_DIR_B}/ERC20Token`
ICS20_TRANSFER_BANK_ADDRESS_A=`cat ${ADDRESSES_DIR_A}/ICS20TransferBank`
ICS20_TRANSFER_BANK_ADDRESS_B=`cat ${ADDRESSES_DIR_B}/ICS20TransferBank`
ICS20_BANK_ADDRESS_A=`cat ${ADDRESSES_DIR_A}/ICS20Bank`
ICS20_BANK_ADDRESS_B=`cat ${ADDRESSES_DIR_B}/ICS20Bank`
MOCKAPP_A=`cat ${ADDRESSES_DIR_A}/AppV1`
MOCKAPP_B=`cat ${ADDRESSES_DIR_B}/AppV1`

CONFIG_JSON=${RELAYER_CONF}/config/config.json

CHAIN_A_ID=$(jq -r '.chains[] | select(.chain.chain_id == "ibc0").chain.eth_chain_id' ${CONFIG_JSON})
CHAIN_B_ID=$(jq -r '.chains[] | select(.chain.chain_id == "ibc1").chain.eth_chain_id' ${CONFIG_JSON})

MNEMONIC_A=$(jq -r '.chains[] | select(.chain.chain_id == "ibc0").chain.signer.mnemonic' ${CONFIG_JSON})
MNEMONIC_B=$(jq -r '.chains[] | select(.chain.chain_id == "ibc1").chain.signer.mnemonic' ${CONFIG_JSON})

RPC_ADDRESS_A=$(jq -r '.chains[] | select(.chain.chain_id == "ibc0").chain.rpc_addr' ${CONFIG_JSON})
RPC_ADDRESS_B=$(jq -r '.chains[] | select(.chain.chain_id == "ibc1").chain.rpc_addr' ${CONFIG_JSON})

PORT_ID=$(jq -r '.paths.ibc01.dst."port-id"' ${CONFIG_JSON})
CHANNEL_ID=$(jq -r '.paths.ibc01.dst."channel-id"' ${CONFIG_JSON})

WALLET_ADDRESS_A=$(${ICS20_CLI} wallet address --mnemonic="${MNEMONIC_A}" --wallet-index=1)
WALLET_ADDRESS_B=$(${ICS20_CLI} wallet address --mnemonic="${MNEMONIC_B}" --wallet-index=2)

DENOM=$(echo "$ERC20_TOKEN_ADDRESS_A" | tr '[:upper:]' '[:lower:]')
CHAIN_B_DENOM="${PORT_ID}/${CHANNEL_ID}/${DENOM}"

show_balance() {
state=$1
chain=$2
bank=$3
user_wallet=$4
denom=$5
user_name=$6
balance=$(${ICS20_CLI} ics20 balance --rpc-address=${chain} --ics20-bank-address=${bank} --wallet-address=${user_wallet} --denom=${denom})
echo "${state} ${chain} balance of ${user_name}: $balance"
}

show_balance Before ${RPC_ADDRESS_A} ${ICS20_BANK_ADDRESS_A} ${WALLET_ADDRESS_A} ${DENOM} alice
show_balance Before ${RPC_ADDRESS_A} ${ICS20_BANK_ADDRESS_A} ${WALLET_ADDRESS_B} ${DENOM} bob
show_balance Before ${RPC_ADDRESS_B} ${ICS20_BANK_ADDRESS_B} ${WALLET_ADDRESS_A} ${CHAIN_B_DENOM} alice
show_balance Before ${RPC_ADDRESS_B} ${ICS20_BANK_ADDRESS_B} ${WALLET_ADDRESS_B} ${CHAIN_B_DENOM} bob

DEPLOYER_INDEX=0
TRANSFER_AMOUNT=10

echo "!!! ibc0 deployer -> ibc0 alice !!!"

# transfer token from deployer to alice
${ICS20_CLI} erc20 transfer --rpc-address=${RPC_ADDRESS_A} --mnemonic="${MNEMONIC_A}" --from-index=${DEPLOYER_INDEX} --to-address=${WALLET_ADDRESS_A} --amount=${TRANSFER_AMOUNT} --denom=${DENOM}
PORT_A=$(jq -r '.paths.ibc01.src."port-id"' ${CONFIG_JSON})
PORT_B=$(jq -r '.paths.ibc01.dst."port-id"' ${CONFIG_JSON})
CHANNEL_A=$(jq -r '.paths.ibc01.src."channel-id"' ${CONFIG_JSON})
CHANNEL_B=$(jq -r '.paths.ibc01.dst."channel-id"' ${CONFIG_JSON})

# send a packet from ibc0 to ibc1
echo "!!! ibc0 alice -> ibc1 bob !!!"

TX_INTERVAL=1

ALICE_INDEX=1
CHAIN_B_HEIGHT=$(${ICS20_CLI} chain height --rpc-address=${RPC_ADDRESS_B})
TIMEOUT_HEIGHT=$((CHAIN_B_HEIGHT + 1000))

# transfer token from alice (ibc0) to bob (ibc1)
${ICS20_CLI} ics20 transfer --rpc-address=${RPC_ADDRESS_A} --mnemonic="${MNEMONIC_A}" --ics20-bank-address=${ICS20_BANK_ADDRESS_A} --ics20-transfer-bank-address=${ICS20_TRANSFER_BANK_ADDRESS_A} --from-index=${ALICE_INDEX} --to-address=${WALLET_ADDRESS_B} --amount=${TRANSFER_AMOUNT} --denom=${DENOM} --port-id=${PORT_ID} --channel-id=${CHANNEL_ID} --timeout-height=${TIMEOUT_HEIGHT}

cast send \
--rpc-url $RPC_ADDRESS_A \
--mnemonic "$MNEMONIC_A" \
--mnemonic-index ${ALICE_INDEX} \
$MOCKAPP_A \
'sendPacket(bytes,string,string,(uint64,uint64),uint64)' \
$(cast from-utf8 'mock packet data') \
$PORT_A \
$CHANNEL_A \
'(0,100000)' \
$(date -d 1hour +%s%N)

waitRelay "sendPacket" "unrelayed-packets" "src"
${RLY} tx relay ${PATH_NAME} --src-seqs 1

waitRelay "recvPacket" "unrelayed-acknowledgements" "dst"
${RLY} tx acks ${PATH_NAME} --dst-seqs 1

show_balance After ${RPC_ADDRESS_A} ${ICS20_BANK_ADDRESS_A} ${WALLET_ADDRESS_A} ${DENOM} alice
show_balance After ${RPC_ADDRESS_A} ${ICS20_BANK_ADDRESS_A} ${WALLET_ADDRESS_B} ${DENOM} bob
show_balance After ${RPC_ADDRESS_B} ${ICS20_BANK_ADDRESS_B} ${WALLET_ADDRESS_A} ${CHAIN_B_DENOM} alice
show_balance After ${RPC_ADDRESS_B} ${ICS20_BANK_ADDRESS_B} ${WALLET_ADDRESS_B} ${CHAIN_B_DENOM} bob

BOB_INDEX=2

# send a packet from ibc1 to ibc0
echo "!!! ibc1 bob -> ibc0 alice !!!"

# transfer token from bob (ibc1) to alice (ibc0)
${ICS20_CLI} ics20 transfer --rpc-address=${RPC_ADDRESS_B} --mnemonic="${MNEMONIC_B}" --ics20-bank-address=${ICS20_BANK_ADDRESS_B} --ics20-transfer-bank-address=${ICS20_TRANSFER_BANK_ADDRESS_B} --from-index=${BOB_INDEX} --to-address=${WALLET_ADDRESS_A} --amount=${TRANSFER_AMOUNT} --denom=${CHAIN_B_DENOM} --port-id=${PORT_ID} --channel-id=${CHANNEL_ID} --timeout-height=${TIMEOUT_HEIGHT}
BOB_INDEX=2
cast send \
--rpc-url $RPC_ADDRESS_B \
--mnemonic "$MNEMONIC_B" \
--mnemonic-index ${BOB_INDEX} \
$MOCKAPP_B \
'sendPacket(bytes,string,string,(uint64,uint64),uint64)' \
$(cast from-utf8 'mock packet data') \
$PORT_B \
$CHANNEL_B \
'(0,100000)' \
$(date -d 1hour +%s%N)

waitRelay "sendPacket" "unrelayed-packets" "dst"
${RLY} tx relay ${PATH_NAME} --dst-seqs 1

waitRelay "recvPacket" "unrelayed-acknowledgements" "src"
${RLY} tx acks ${PATH_NAME} --src-seqs 1

show_balance After ${RPC_ADDRESS_A} ${ICS20_BANK_ADDRESS_A} ${WALLET_ADDRESS_A} ${DENOM} alice
show_balance After ${RPC_ADDRESS_A} ${ICS20_BANK_ADDRESS_A} ${WALLET_ADDRESS_B} ${DENOM} bob
show_balance After ${RPC_ADDRESS_B} ${ICS20_BANK_ADDRESS_B} ${WALLET_ADDRESS_A} ${CHAIN_B_DENOM} alice
show_balance After ${RPC_ADDRESS_B} ${ICS20_BANK_ADDRESS_B} ${WALLET_ADDRESS_B} ${CHAIN_B_DENOM} bob

0 comments on commit 1173f1e

Please sign in to comment.