Skip to content

Instantly share code, notes, and snippets.

@samalba
Last active November 28, 2018 01:18
Show Gist options
  • Save samalba/a6694d7221eb33f2acc4628c3a530d7f to your computer and use it in GitHub Desktop.
Save samalba/a6694d7221eb33f2acc4628c3a530d7f to your computer and use it in GitHub Desktop.
Demo a testnet of 2 nodes using the github.com/cosmos/sdk-application-tutorial

How to use

Requirements:

Demo

# Start node1
./collab node1

# Start node2 (using the config and genesis of node1)
./collab node2

# Check that the block heigth is the same on the 2 nodes:
docker exec -it ns-node-1 nameservicecli status | jq .sync_info.latest_block_height
docker exec -it ns-node-2 nameservicecli status | jq .sync_info.latest_block_height

# Create new local key (on node1 and node2)
TODO

# Send some funds from node1 to node2
./collab.sh cli1 tx send --amount 1000000mycoin --chain-id test-chain-1Ifdo4 --from cosmos1hxczm2qgw70lhr5zs3qxs25vkd26fhf4ms3l8u --to cosmos1cjwzx4zr46tdyu9t222f0xaedh0mwk4fpnpjlh
#!/bin/sh
set -e
DATA=$(PWD)/data
NAME="nameservice"
NODE1="ns-node-1"
NODE2="ns-node-2"
MOUNT1="-v ${DATA}/${NODE1}/${NAME}d:/root/.${NAME}d -v ${DATA}/${NODE1}/${NAME}cli:/root/.${NAME}cli"
MOUNT2="-v ${DATA}/${NODE2}/${NAME}d:/root/.${NAME}d -v ${DATA}/${NODE2}/${NAME}cli:/root/.${NAME}cli"
start_node1() {
# Init genesis + config
[ -d "${DATA}/${NODE1}" ] || docker run --rm -it $MOUNT1 $NAME ${NAME}d init
# Init start node
docker run --name $NODE1 -d -p 26656:26656 -p 26657:26657 $MOUNT1 $NAME ${NAME}d start --moniker $NODE1
}
start_node2() {
[ -d "${DATA}/${NODE2}" ] && echo "!!! Warning: node2 data dir still exists, run 'reset' before?"
# Get node1 id
id_node1=$(docker exec -it $NODE1 ${NAME}cli status | jq -r .node_info.id)
ip_node1=$(docker inspect -f '{{ .NetworkSettings.IPAddress }}' $NODE1)
seed="${id_node1}@${ip_node1}:26656"
# Init genesis + config
docker run --rm -it $MOUNT2 $NAME ${NAME}d init
# Update config & genesis
cp -v ${DATA}/${NODE1}/${NAME}d/config/genesis.json ${DATA}/${NODE2}/${NAME}d/config
sed -ibak -E "s/^persistent_peers.+$/persistent_peers = \"${seed}\"/" data/${NODE2}/${NAME}d/config/config.toml
# Start node2
docker run --name $NODE2 -d -p 36656:26656 -p 36657:26657 $MOUNT2 $NAME ${NAME}d start --moniker $NODE2
}
case $1 in
"node1")
start_node1
;;
"node2")
start_node2
;;
"cli1")
shift
docker exec -it $NODE1 ${NAME}cli $*
;;
"cli2")
shift
docker exec -it $NODE2 ${NAME}cli $*
;;
"reset")
docker rm -f $NODE1 || true
docker rm -f $NODE2 || true
rm -rf ${DATA} || true
echo "Cleared all data"
;;
*)
echo "Invalid arg"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment