2017-01-29 21:29:43 -08:00
|
|
|
#! /bin/bash
|
2017-02-26 09:52:24 -08:00
|
|
|
set -e
|
2017-01-29 21:29:43 -08:00
|
|
|
|
|
|
|
cd $GOPATH/src/github.com/tendermint/basecoin/demo
|
|
|
|
|
2017-02-26 09:52:24 -08:00
|
|
|
LOG_DIR="."
|
2017-04-27 02:07:45 -07:00
|
|
|
TM_VERSION="v0.9.2"
|
2017-02-26 09:52:24 -08:00
|
|
|
|
|
|
|
if [[ "$CIRCLECI" == "true" ]]; then
|
|
|
|
# set log dir
|
|
|
|
LOG_DIR="${CIRCLE_ARTIFACTS}"
|
|
|
|
|
|
|
|
# install tendermint
|
|
|
|
set +e
|
|
|
|
go get github.com/tendermint/tendermint
|
|
|
|
pushd $GOPATH/src/github.com/tendermint/tendermint
|
2017-04-27 02:07:45 -07:00
|
|
|
git checkout $TM_VERSION
|
2017-02-26 09:52:24 -08:00
|
|
|
glide install
|
|
|
|
go install ./cmd/tendermint
|
|
|
|
popd
|
|
|
|
set -e
|
|
|
|
fi
|
|
|
|
|
|
|
|
set -u
|
|
|
|
|
2017-01-29 21:29:43 -08:00
|
|
|
function removeQuotes() {
|
|
|
|
temp="${1%\"}"
|
|
|
|
temp="${temp#\"}"
|
|
|
|
echo "$temp"
|
|
|
|
}
|
|
|
|
|
2017-02-13 20:22:31 -08:00
|
|
|
function waitForNode() {
|
|
|
|
addr=$1
|
|
|
|
set +e
|
|
|
|
curl -s $addr/status > /dev/null
|
|
|
|
ERR=$?
|
2017-02-26 09:52:24 -08:00
|
|
|
i=0
|
2017-02-13 20:22:31 -08:00
|
|
|
while [ "$ERR" != 0 ]; do
|
2017-02-26 09:52:24 -08:00
|
|
|
if [[ "$i" == 10 ]]; then
|
2017-03-23 15:51:15 -07:00
|
|
|
echo "waited too long for chain to start"
|
2017-02-26 09:52:24 -08:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
echo "...... still waiting on $addr"
|
2017-02-13 20:22:31 -08:00
|
|
|
sleep 1
|
|
|
|
curl -s $addr/status > /dev/null
|
|
|
|
ERR=$?
|
2017-02-26 09:52:24 -08:00
|
|
|
i=$((i+1))
|
2017-02-13 20:22:31 -08:00
|
|
|
done
|
|
|
|
set -e
|
|
|
|
echo "... node $addr is up"
|
|
|
|
}
|
|
|
|
|
|
|
|
function waitForBlock() {
|
|
|
|
addr=$1
|
|
|
|
b1=`curl -s $addr/status | jq .result[1].latest_block_height`
|
|
|
|
b2=$b1
|
2017-02-16 12:36:46 -08:00
|
|
|
while [ "$b2" == "$b1" ]; do
|
2017-02-13 20:22:31 -08:00
|
|
|
echo "Waiting for node $addr to commit a block ..."
|
|
|
|
sleep 1
|
|
|
|
b2=`curl -s $addr/status | jq .result[1].latest_block_height`
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2017-03-13 17:46:40 -07:00
|
|
|
# make basecoin root vars
|
2017-03-13 22:50:10 -07:00
|
|
|
export BCHOME="."
|
2017-03-14 00:11:49 -07:00
|
|
|
BCHOME1="./data/chain1"
|
|
|
|
BCHOME2="./data/chain2"
|
2017-02-13 20:22:31 -08:00
|
|
|
|
2017-01-29 21:29:43 -08:00
|
|
|
# grab the chain ids
|
2017-03-14 00:11:49 -07:00
|
|
|
CHAIN_ID1=$(cat $BCHOME1/genesis.json | jq .chain_id)
|
2017-01-29 21:29:43 -08:00
|
|
|
CHAIN_ID1=$(removeQuotes $CHAIN_ID1)
|
2017-03-14 00:11:49 -07:00
|
|
|
CHAIN_ID2=$(cat $BCHOME2/genesis.json | jq .chain_id)
|
2017-01-29 21:29:43 -08:00
|
|
|
CHAIN_ID2=$(removeQuotes $CHAIN_ID2)
|
|
|
|
echo "CHAIN_ID1: $CHAIN_ID1"
|
|
|
|
echo "CHAIN_ID2: $CHAIN_ID2"
|
|
|
|
|
|
|
|
# make reusable chain flags
|
2017-03-13 22:50:10 -07:00
|
|
|
CHAIN_FLAGS1="--chain_id $CHAIN_ID1 --from $BCHOME1/key.json"
|
|
|
|
CHAIN_FLAGS2="--chain_id $CHAIN_ID2 --from $BCHOME2/key.json --node tcp://localhost:36657"
|
2017-03-13 17:46:40 -07:00
|
|
|
|
2017-01-29 21:29:43 -08:00
|
|
|
|
|
|
|
echo ""
|
|
|
|
echo "... starting chains"
|
|
|
|
echo ""
|
|
|
|
# start the first node
|
2017-04-26 22:38:38 -07:00
|
|
|
TMROOT=$BCHOME1 tendermint node --skip_upnp --log_level=info &> $LOG_DIR/chain1_tendermint.log &
|
2017-03-13 22:50:10 -07:00
|
|
|
BCHOME=$BCHOME1 basecoin start --without-tendermint &> $LOG_DIR/chain1_basecoin.log &
|
2017-01-29 21:29:43 -08:00
|
|
|
|
|
|
|
# start the second node
|
2017-04-26 22:38:38 -07:00
|
|
|
TMROOT=$BCHOME2 tendermint node --skip_upnp --log_level=info --node_laddr tcp://localhost:36656 --rpc_laddr tcp://localhost:36657 --proxy_app tcp://localhost:36658 &> $LOG_DIR/chain2_tendermint.log &
|
2017-03-13 22:50:10 -07:00
|
|
|
BCHOME=$BCHOME2 basecoin start --address tcp://localhost:36658 --without-tendermint &> $LOG_DIR/chain2_basecoin.log &
|
2017-01-29 21:29:43 -08:00
|
|
|
|
|
|
|
echo ""
|
|
|
|
echo "... waiting for chains to start"
|
|
|
|
echo ""
|
2017-02-13 20:22:31 -08:00
|
|
|
|
|
|
|
waitForNode localhost:46657
|
|
|
|
waitForNode localhost:36657
|
2017-01-29 21:29:43 -08:00
|
|
|
|
2017-03-06 01:50:24 -08:00
|
|
|
# TODO: remove the sleep
|
|
|
|
# Without it we sometimes get "Account bytes are empty for address: 053BA0F19616AFF975C8756A2CBFF04F408B4D47"
|
|
|
|
sleep 3
|
|
|
|
|
2017-01-29 21:29:43 -08:00
|
|
|
echo "... registering chain1 on chain2"
|
|
|
|
echo ""
|
|
|
|
# register chain1 on chain2
|
2017-04-26 22:38:38 -07:00
|
|
|
basecoin tx ibc --amount 10mycoin $CHAIN_FLAGS2 register --ibc_chain_id $CHAIN_ID1 --genesis $BCHOME1/genesis.json
|
2017-01-29 21:29:43 -08:00
|
|
|
|
|
|
|
echo ""
|
|
|
|
echo "... creating egress packet on chain1"
|
|
|
|
echo ""
|
|
|
|
# create a packet on chain1 destined for chain2
|
|
|
|
PAYLOAD="DEADBEEF" #TODO
|
2017-03-08 23:19:07 -08:00
|
|
|
basecoin tx ibc --amount 10mycoin $CHAIN_FLAGS1 packet create --ibc_from $CHAIN_ID1 --to $CHAIN_ID2 --type coin --payload $PAYLOAD --ibc_sequence 1
|
2017-01-29 21:29:43 -08:00
|
|
|
|
|
|
|
echo ""
|
|
|
|
echo "... querying for packet data"
|
|
|
|
echo ""
|
|
|
|
# query for the packet data and proof
|
2017-02-12 19:01:17 -08:00
|
|
|
QUERY_RESULT=$(basecoin query ibc,egress,$CHAIN_ID1,$CHAIN_ID2,1)
|
2017-02-14 14:21:21 -08:00
|
|
|
HEIGHT=$(echo $QUERY_RESULT | jq .height)
|
2017-01-29 21:29:43 -08:00
|
|
|
PACKET=$(echo $QUERY_RESULT | jq .value)
|
|
|
|
PROOF=$(echo $QUERY_RESULT | jq .proof)
|
2017-01-29 22:43:07 -08:00
|
|
|
PACKET=$(removeQuotes $PACKET)
|
|
|
|
PROOF=$(removeQuotes $PROOF)
|
|
|
|
echo ""
|
2017-01-29 21:29:43 -08:00
|
|
|
echo "QUERY_RESULT: $QUERY_RESULT"
|
2017-02-14 14:21:21 -08:00
|
|
|
echo "HEIGHT: $HEIGHT"
|
2017-01-29 21:29:43 -08:00
|
|
|
echo "PACKET: $PACKET"
|
|
|
|
echo "PROOF: $PROOF"
|
|
|
|
|
2017-01-29 22:43:07 -08:00
|
|
|
|
2017-02-16 12:36:46 -08:00
|
|
|
# the query returns the height of the next block, which contains the app hash
|
|
|
|
# but which may not be committed yet, so we have to wait for it to query the commit
|
2017-01-29 22:43:07 -08:00
|
|
|
echo ""
|
2017-02-16 12:36:46 -08:00
|
|
|
echo "... waiting for a block to be committed"
|
2017-01-29 22:43:07 -08:00
|
|
|
echo ""
|
|
|
|
|
2017-02-13 20:22:31 -08:00
|
|
|
waitForBlock localhost:46657
|
|
|
|
waitForBlock localhost:36657
|
|
|
|
|
2017-01-29 21:29:43 -08:00
|
|
|
echo ""
|
|
|
|
echo "... querying for block data"
|
|
|
|
echo ""
|
|
|
|
# get the header and commit for the height
|
2017-02-12 19:01:17 -08:00
|
|
|
HEADER_AND_COMMIT=$(basecoin block $HEIGHT)
|
2017-01-29 22:43:07 -08:00
|
|
|
HEADER=$(echo $HEADER_AND_COMMIT | jq .hex.header)
|
|
|
|
HEADER=$(removeQuotes $HEADER)
|
|
|
|
COMMIT=$(echo $HEADER_AND_COMMIT | jq .hex.commit)
|
|
|
|
COMMIT=$(removeQuotes $COMMIT)
|
|
|
|
echo ""
|
2017-01-29 21:29:43 -08:00
|
|
|
echo "HEADER_AND_COMMIT: $HEADER_AND_COMMIT"
|
|
|
|
echo "HEADER: $HEADER"
|
|
|
|
echo "COMMIT: $COMMIT"
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
echo "... updating state of chain1 on chain2"
|
|
|
|
echo ""
|
|
|
|
# update the state of chain1 on chain2
|
2017-02-23 17:17:11 -08:00
|
|
|
basecoin tx ibc --amount 10mycoin $CHAIN_FLAGS2 update --header 0x$HEADER --commit 0x$COMMIT
|
2017-01-29 21:29:43 -08:00
|
|
|
|
|
|
|
echo ""
|
|
|
|
echo "... posting packet from chain1 on chain2"
|
|
|
|
echo ""
|
|
|
|
# post the packet from chain1 to chain2
|
2017-03-08 23:19:07 -08:00
|
|
|
basecoin tx ibc --amount 10mycoin $CHAIN_FLAGS2 packet post --ibc_from $CHAIN_ID1 --height $HEIGHT --packet 0x$PACKET --proof 0x$PROOF
|
2017-01-29 22:43:07 -08:00
|
|
|
|
|
|
|
echo ""
|
|
|
|
echo "... checking if the packet is present on chain2"
|
|
|
|
echo ""
|
2017-02-13 20:22:31 -08:00
|
|
|
# query for the packet on chain2
|
2017-02-12 19:01:17 -08:00
|
|
|
basecoin query --node tcp://localhost:36657 ibc,ingress,test_chain_2,test_chain_1,1
|
2017-02-07 17:35:43 -08:00
|
|
|
|
|
|
|
echo ""
|
|
|
|
echo "DONE!"
|