commit
662c6325af
|
@ -3,3 +3,5 @@ vendor
|
|||
merkleeyes.db
|
||||
build
|
||||
shunit2
|
||||
docs/guide/*.sh
|
||||
|
||||
|
|
|
@ -9,17 +9,13 @@ this example we explore a simple plugin named `counter`.
|
|||
|
||||
## Example Plugin
|
||||
|
||||
The design of the `basecoin` and `basecli` tools makes it easy to extend for custom
|
||||
functionality. We provide examples of such extensions in the basecoin repository under `docs/guide/counter`.
|
||||
You can install them from the basecoin directory with:
|
||||
|
||||
```
|
||||
`go install ./docs/guide/counter/cmd/...
|
||||
```
|
||||
|
||||
This will give you both the `counter` and `countercli` binaries.
|
||||
The former is just like `basecoin`, but with the counter plugin activated.
|
||||
The latter is just like `basecli`, but with support for sending transactions to the counter plugin.
|
||||
The design of the `basecoin` tool makes it easy to extend for custom
|
||||
functionality. The Counter plugin is bundled with basecoin, so if you have
|
||||
already [installed basecoin](install.md) and run `make install` then you should
|
||||
be able to run a full node with `counter` and the a light-client `countercli`
|
||||
from terminal. The Counter plugin is just like the `basecoin` tool. They
|
||||
both use the same library of commands, including one for signing and
|
||||
broadcasting `SendTx`.
|
||||
|
||||
Counter transactions take two custom inputs, a boolean argument named `valid`,
|
||||
and a coin amount named `countfee`. The transaction is only accepted if both
|
||||
|
@ -83,7 +79,7 @@ The Counter value should be 2, because we sent a second valid transaction.
|
|||
And this time, since we sent a countfee (which must be less than or equal to the
|
||||
total amount sent with the tx), it stores the `TotalFees` on the counter as well.
|
||||
|
||||
Keep it mind that, just like with `basecli`, the `countercli` verifies a proof
|
||||
Keep it mind that, just like with `basecli`, the `countercli` verifies a proof
|
||||
that the query response is correct and up-to-date.
|
||||
|
||||
Now, before we implement our own plugin and tooling, it helps to understand the
|
||||
|
@ -170,7 +166,7 @@ alone, but you should change any occurrences of `counter` to whatever your
|
|||
plugin tool is going to be called. You must also register your plugin(s) with
|
||||
the basecoin app with `RegisterStartPlugin`.
|
||||
|
||||
The light-client is located in `cmd/countercli/main.go` and allows for
|
||||
The light-client is located in `cmd/countercli/main.go` and allows for
|
||||
transaction and query commands. This file can also be left mostly alone besides replacing the application name and adding
|
||||
references to new plugin commands.
|
||||
|
||||
|
|
|
@ -210,7 +210,7 @@ Otherwise, open up 5 (yes 5!) terminal tabs....
|
|||
All commands will be prefixed by the name of the terminal window in which to
|
||||
run it...
|
||||
|
||||
```bash
|
||||
```
|
||||
# first, clean up any old garbage for a fresh slate...
|
||||
rm -rf ~/.ibcdemo/
|
||||
```
|
||||
|
@ -218,7 +218,7 @@ rm -rf ~/.ibcdemo/
|
|||
Set up some accounts so we can init everything nicely:
|
||||
|
||||
**Client1**
|
||||
```bash
|
||||
```
|
||||
export BCHOME=~/.ibcdemo/chain1/client
|
||||
CHAIN_ID=test-chain-1
|
||||
PORT=12347
|
||||
|
@ -229,7 +229,7 @@ basecli keys new gotnone
|
|||
Prepare the genesis block and start the server:
|
||||
|
||||
**Server1**
|
||||
```bash
|
||||
```
|
||||
# set up the directory, chainid and port of this chain...
|
||||
export BCHOME=~/.ibcdemo/chain1/server
|
||||
CHAIN_ID=test-chain-1
|
||||
|
@ -245,7 +245,7 @@ Attach the client to the chain and confirm state. The first account should
|
|||
have money, the second none:
|
||||
|
||||
**Client1**
|
||||
```bash
|
||||
```
|
||||
basecli init --chain-id=${CHAIN_ID} --node=tcp://localhost:${PORT}
|
||||
ME=$(basecli keys get money | awk '{print $2}')
|
||||
YOU=$(basecli keys get gotnone | awk '{print $2}')
|
||||
|
@ -261,7 +261,7 @@ on this chain, as the "cool" key only has money on chain 1.
|
|||
|
||||
|
||||
**Client2**
|
||||
```bash
|
||||
```
|
||||
export BCHOME=~/.ibcdemo/chain2/client
|
||||
CHAIN_ID=test-chain-2
|
||||
PORT=23457
|
||||
|
@ -272,7 +272,7 @@ basecli keys new broke
|
|||
Prepare the genesis block and start the server:
|
||||
|
||||
**Server2**
|
||||
```bash
|
||||
```
|
||||
# set up the directory, chainid and port of this chain...
|
||||
export BCHOME=~/.ibcdemo/chain2/server
|
||||
CHAIN_ID=test-chain-2
|
||||
|
@ -288,7 +288,7 @@ Attach the client to the chain and confirm state. The first account should
|
|||
have money, the second none:
|
||||
|
||||
**Client2**
|
||||
```bash
|
||||
```
|
||||
basecli init --chain-id=${CHAIN_ID} --node=tcp://localhost:${PORT}
|
||||
ME=$(basecli keys get moremoney | awk '{print $2}')
|
||||
YOU=$(basecli keys get broke | awk '{print $2}')
|
||||
|
@ -307,7 +307,7 @@ for now, we have to transfer some cash from the rich accounts before we start
|
|||
the actual relay.
|
||||
|
||||
**Client1**
|
||||
```bash
|
||||
```
|
||||
# note that this key.json file is a hardcoded demo for all chains, this will
|
||||
# be updated in a future release
|
||||
RELAY_KEY=${BCHOME}/../server/key.json
|
||||
|
@ -317,7 +317,7 @@ basecli query account $RELAY_ADDR
|
|||
```
|
||||
|
||||
**Client2**
|
||||
```bash
|
||||
```
|
||||
# note that this key.json file is a hardcoded demo for all chains, this will
|
||||
# be updated in a future release
|
||||
RELAY_KEY=${BCHOME}/../server/key.json
|
||||
|
@ -327,7 +327,7 @@ basecli query account $RELAY_ADDR
|
|||
```
|
||||
|
||||
**Relay**
|
||||
```bash
|
||||
```
|
||||
# lots of config...
|
||||
SERVER_1=~/.ibcdemo/chain1/server
|
||||
SERVER_2=~/.ibcdemo/chain2/server
|
||||
|
@ -358,7 +358,7 @@ a secure relay between them. Now we can enjoy the fruits of our labor...
|
|||
|
||||
**Client2**
|
||||
|
||||
```bash
|
||||
```
|
||||
# this should be empty
|
||||
basecli query account $YOU
|
||||
# now, we get the key to copy to the other terminal
|
||||
|
@ -367,14 +367,14 @@ echo $YOU
|
|||
|
||||
**Client1**
|
||||
|
||||
```bash
|
||||
```
|
||||
# set TARGET to be $YOU from the other chain
|
||||
basecli tx send --amount=12345mycoin --sequence=2 --to=test-chain-2/$TARGET --name=money
|
||||
```
|
||||
|
||||
**Client2**
|
||||
|
||||
```bash
|
||||
```
|
||||
# give it time to arrive...
|
||||
sleep 1
|
||||
# now you should see 12345 coins!
|
||||
|
|
|
@ -1,40 +1,18 @@
|
|||
#!/bin/bash
|
||||
|
||||
# these are two globals to control all scripts (can use eg. counter instead)
|
||||
# These global variables are required for common.sh
|
||||
SERVER_EXE=basecoin
|
||||
CLIENT_EXE=basecli
|
||||
ACCOUNTS=(jae ethan bucky rigel igor)
|
||||
RICH=${ACCOUNTS[0]}
|
||||
POOR=${ACCOUNTS[4]}
|
||||
|
||||
oneTimeSetUp() {
|
||||
# these are passed in as args
|
||||
BASE_DIR=$HOME/.basecoin_test_basictx
|
||||
CHAIN_ID=my-test-chain
|
||||
|
||||
rm -rf $BASE_DIR 2>/dev/null
|
||||
mkdir -p $BASE_DIR
|
||||
|
||||
# set up client - make sure you use the proper prefix if you set
|
||||
# a custom CLIENT_EXE
|
||||
export BC_HOME=${BASE_DIR}/client
|
||||
prepareClient
|
||||
|
||||
# start basecoin server (with counter)
|
||||
initServer $BASE_DIR $CHAIN_ID 3456
|
||||
if [ $? != 0 ]; then return 1; fi
|
||||
|
||||
initClient $CHAIN_ID 34567
|
||||
|
||||
echo "...Testing may begin!"
|
||||
echo
|
||||
echo
|
||||
echo
|
||||
quickSetup .basecoin_test_basictx basictx-chain
|
||||
}
|
||||
|
||||
oneTimeTearDown() {
|
||||
echo
|
||||
echo
|
||||
echo "stopping $SERVER_EXE test server..."
|
||||
kill -9 $PID_SERVER >/dev/null 2>&1
|
||||
sleep 1
|
||||
quickTearDown
|
||||
}
|
||||
|
||||
test00GetAccount() {
|
||||
|
@ -64,15 +42,11 @@ test01SendTx() {
|
|||
checkAccount $SENDER "1" "9007199254740000"
|
||||
checkAccount $RECV "0" "992"
|
||||
|
||||
# make sure tx is indexed
|
||||
# Make sure tx is indexed
|
||||
checkSendTx $HASH $TX_HEIGHT $SENDER "992"
|
||||
}
|
||||
|
||||
|
||||
# load and run these tests with shunit2!
|
||||
# Load common then run these tests with shunit2!
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #get this files directory
|
||||
|
||||
# load common helpers
|
||||
. $DIR/common.sh
|
||||
|
||||
. $DIR/shunit2
|
||||
|
|
|
@ -1,9 +1,46 @@
|
|||
# this is not executable, but helper functions for the other scripts
|
||||
# This is not executable, but helper functions for the other scripts
|
||||
|
||||
# these are general accounts to be prepared
|
||||
ACCOUNTS=(jae ethan bucky rigel igor)
|
||||
RICH=${ACCOUNTS[0]}
|
||||
POOR=${ACCOUNTS[4]}
|
||||
# XXX XXX XXX XXX XXX
|
||||
# The following global variables must be defined before calling common functions:
|
||||
# SERVER_EXE=foobar # Server binary name
|
||||
# CLIENT_EXE=foobarcli # Client binary name
|
||||
# ACCOUNTS=(foo bar) # List of accounts for initialization
|
||||
# RICH=${ACCOUNTS[0]} # Account to assign genesis balance
|
||||
|
||||
# XXX Ex Usage: quickSetup $WORK_NAME $CHAIN_ID
|
||||
# Desc: Start the program, use with shunit2 OneTimeSetUp()
|
||||
quickSetup() {
|
||||
# These are passed in as args
|
||||
BASE_DIR=$HOME/$1
|
||||
CHAIN_ID=$2
|
||||
|
||||
rm -rf $BASE_DIR 2>/dev/null
|
||||
mkdir -p $BASE_DIR
|
||||
|
||||
# Set up client - make sure you use the proper prefix if you set
|
||||
# a custom CLIENT_EXE
|
||||
export BC_HOME=${BASE_DIR}/client
|
||||
prepareClient
|
||||
|
||||
# start basecoin server (with counter)
|
||||
initServer $BASE_DIR $CHAIN_ID
|
||||
if [ $? != 0 ]; then return 1; fi
|
||||
|
||||
initClient $CHAIN_ID
|
||||
if [ $? != 0 ]; then return 1; fi
|
||||
|
||||
printf "...Testing may begin!\n\n\n"
|
||||
}
|
||||
|
||||
# XXX Ex Usage: quickTearDown
|
||||
# Desc: close the test server, use with shunit2 OneTimeTearDown()
|
||||
quickTearDown() {
|
||||
printf "\n\nstopping $SERVER_EXE test server..."
|
||||
kill -9 $PID_SERVER >/dev/null 2>&1
|
||||
sleep 1
|
||||
}
|
||||
|
||||
############################################################
|
||||
|
||||
prepareClient() {
|
||||
echo "Preparing client keys..."
|
||||
|
@ -15,9 +52,10 @@ prepareClient() {
|
|||
done
|
||||
}
|
||||
|
||||
# initServer takes two args - (root dir, chain_id)
|
||||
# and optionally port prefix as a third arg (default is 4665{6,7,8})
|
||||
# it grabs the first account to give it the money
|
||||
# XXX Ex Usage1: initServer $ROOTDIR $CHAINID
|
||||
# XXX Ex Usage2: initServer $ROOTDIR $CHAINID $PORTPREFIX
|
||||
# Desc: Grabs the Rich account and gives it all genesis money
|
||||
# port-prefix default is 4665{6,7,8}
|
||||
initServer() {
|
||||
echo "Setting up genesis..."
|
||||
SERVE_DIR=$1/server
|
||||
|
@ -46,7 +84,10 @@ initServer() {
|
|||
fi
|
||||
}
|
||||
|
||||
# initClient requires chain_id arg, port is optional (default 46657)
|
||||
# XXX Ex Usage1: initClient $CHAINID
|
||||
# XXX Ex Usage2: initClient $CHAINID $PORTPREFIX
|
||||
# Desc: Initialize the client program
|
||||
# port-prefix default is 46657
|
||||
initClient() {
|
||||
echo "Attaching ${CLIENT_EXE} client..."
|
||||
PORT=${2:-46657}
|
||||
|
@ -55,7 +96,9 @@ initClient() {
|
|||
assertTrue "initialized light-client" $?
|
||||
}
|
||||
|
||||
# newKeys makes a key for a given username, second arg optional password
|
||||
# XXX Ex Usage1: newKey $NAME
|
||||
# XXX Ex Usage2: newKey $NAME $PASSWORD
|
||||
# Desc: Generates key for given username and password
|
||||
newKey(){
|
||||
assertNotNull "keyname required" "$1"
|
||||
KEYPASS=${2:-qwertyuiop}
|
||||
|
@ -64,7 +107,8 @@ newKey(){
|
|||
assertTrue "$1 doesn't exist" "${CLIENT_EXE} keys get $1"
|
||||
}
|
||||
|
||||
# getAddr gets the address for a key name
|
||||
# XXX Ex Usage: getAddr $NAME
|
||||
# Desc: Gets the address for a key name
|
||||
getAddr() {
|
||||
assertNotNull "keyname required" "$1"
|
||||
RAW=$(${CLIENT_EXE} keys get $1)
|
||||
|
@ -73,8 +117,7 @@ getAddr() {
|
|||
echo $RAW | cut -d' ' -f2
|
||||
}
|
||||
|
||||
# checkAccount $ADDR $SEQUENCE $BALANCE
|
||||
# assumes just one coin, checks the balance of first coin in any case
|
||||
# Desc: Assumes just one coin, checks the balance of first coin in any case
|
||||
checkAccount() {
|
||||
# make sure sender goes down
|
||||
ACCT=$(${CLIENT_EXE} query account $1)
|
||||
|
@ -84,8 +127,8 @@ checkAccount() {
|
|||
return $?
|
||||
}
|
||||
|
||||
# txSucceeded $? "$RES"
|
||||
# must be called right after the `tx` command, makes sure it got a success response
|
||||
# XXX Ex Usage: txSucceeded $? "$RES"
|
||||
# Desc: Must be called right after the `tx` command, makes sure it got a success response
|
||||
txSucceeded() {
|
||||
if (assertTrue "sent tx: $2" $1); then
|
||||
TX=`echo $2 | cut -d: -f2-` # strip off first line asking for password
|
||||
|
@ -96,9 +139,9 @@ txSucceeded() {
|
|||
fi
|
||||
}
|
||||
|
||||
# checkSendTx $HASH $HEIGHT $SENDER $AMOUNT
|
||||
# this looks up the tx by hash, and makes sure the height and type match
|
||||
# and that the first input was from this sender for this amount
|
||||
# XXX Ex Usage: checkSendTx $HASH $HEIGHT $SENDER $AMOUNT
|
||||
# Desc: This looks up the tx by hash, and makes sure the height and type match
|
||||
# and that the first input was from this sender for this amount
|
||||
checkSendTx() {
|
||||
TX=$(${CLIENT_EXE} query tx $1)
|
||||
assertTrue "found tx" $?
|
||||
|
@ -109,8 +152,8 @@ checkSendTx() {
|
|||
return $?
|
||||
}
|
||||
|
||||
# waitForBlock $port
|
||||
# waits until the block height on that node increases by one
|
||||
# XXX Ex Usage: waitForBlock $port
|
||||
# Desc: Waits until the block height on that node increases by one
|
||||
waitForBlock() {
|
||||
addr=http://localhost:$1
|
||||
b1=`curl -s $addr/status | jq .result.latest_block_height`
|
||||
|
|
|
@ -1,44 +1,20 @@
|
|||
#!/bin/bash
|
||||
|
||||
# these are two globals to control all scripts (can use eg. counter instead)
|
||||
# These global variables are required for common.sh
|
||||
SERVER_EXE=counter
|
||||
CLIENT_EXE=countercli
|
||||
ACCOUNTS=(jae ethan bucky rigel igor)
|
||||
RICH=${ACCOUNTS[0]}
|
||||
POOR=${ACCOUNTS[4]}
|
||||
|
||||
oneTimeSetUp() {
|
||||
# these are passed in as args
|
||||
BASE_DIR=$HOME/.basecoin_test_counter
|
||||
CHAIN_ID="counter-chain"
|
||||
|
||||
rm -rf $BASE_DIR 2>/dev/null
|
||||
mkdir -p $BASE_DIR
|
||||
|
||||
# set up client - make sure you use the proper prefix if you set
|
||||
# a custom CLIENT_EXE
|
||||
export BC_HOME=${BASE_DIR}/client
|
||||
prepareClient
|
||||
|
||||
# start basecoin server (with counter)
|
||||
initServer $BASE_DIR $CHAIN_ID 1234
|
||||
if [ $? != 0 ]; then return 1; fi
|
||||
|
||||
initClient $CHAIN_ID 12347
|
||||
if [ $? != 0 ]; then return 1; fi
|
||||
|
||||
echo "...Testing may begin!"
|
||||
echo
|
||||
echo
|
||||
echo
|
||||
quickSetup .basecoin_test_counter counter-chain
|
||||
}
|
||||
|
||||
oneTimeTearDown() {
|
||||
echo
|
||||
echo
|
||||
echo "stopping $SERVER_EXE test server..."
|
||||
kill -9 $PID_SERVER >/dev/null 2>&1
|
||||
sleep 1
|
||||
quickTearDown
|
||||
}
|
||||
|
||||
|
||||
test00GetAccount() {
|
||||
SENDER=$(getAddr $RICH)
|
||||
RECV=$(getAddr $POOR)
|
||||
|
@ -75,8 +51,8 @@ test02GetCounter() {
|
|||
assertFalse "no default count" $?
|
||||
}
|
||||
|
||||
# checkAccount $COUNT $BALANCE
|
||||
# assumes just one coin, checks the balance of first coin in any case
|
||||
# checkCounter $COUNT $BALANCE
|
||||
# Assumes just one coin, checks the balance of first coin in any case
|
||||
checkCounter() {
|
||||
# make sure sender goes down
|
||||
ACCT=$(${CLIENT_EXE} query counter)
|
||||
|
@ -85,7 +61,7 @@ checkCounter() {
|
|||
assertEquals "proper money" "$2" $(echo $ACCT | jq .data.TotalFees[0].amount)
|
||||
}
|
||||
|
||||
test02AddCount() {
|
||||
test03AddCount() {
|
||||
SENDER=$(getAddr $RICH)
|
||||
assertFalse "bad password" "echo hi | ${CLIENT_EXE} tx counter --amount=1000mycoin --sequence=2 --name=${RICH} 2>/dev/null"
|
||||
|
||||
|
@ -114,10 +90,7 @@ test02AddCount() {
|
|||
# echo $TX
|
||||
}
|
||||
|
||||
# load and run these tests with shunit2!
|
||||
# Load common then run these tests with shunit2!
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #get this files directory
|
||||
|
||||
# load common helpers
|
||||
. $DIR/common.sh
|
||||
|
||||
. $DIR/shunit2
|
||||
|
|
|
@ -2,14 +2,18 @@
|
|||
|
||||
#!/bin/bash
|
||||
|
||||
# these are two globals to control all scripts (can use eg. counter instead)
|
||||
# These global variables are required for common.sh
|
||||
SERVER_EXE=basecoin
|
||||
CLIENT_EXE=basecli
|
||||
# just uncomment this line for full stack traces in error output
|
||||
ACCOUNTS=(jae ethan bucky rigel igor)
|
||||
RICH=${ACCOUNTS[0]}
|
||||
POOR=${ACCOUNTS[4]}
|
||||
|
||||
# Uncomment the following line for full stack traces in error output
|
||||
# CLIENT_EXE="basecli --trace"
|
||||
|
||||
oneTimeSetUp() {
|
||||
# these are passed in as args
|
||||
# These are passed in as args
|
||||
BASE_DIR_1=$HOME/.basecoin_test_ibc/chain1
|
||||
CHAIN_ID_1=test-chain-1
|
||||
CLIENT_1=${BASE_DIR_1}/client
|
||||
|
@ -22,41 +26,36 @@ oneTimeSetUp() {
|
|||
PREFIX_2=2345
|
||||
PORT_2=${PREFIX_2}7
|
||||
|
||||
# clean up and create the test dirs
|
||||
# Clean up and create the test dirs
|
||||
rm -rf $BASE_DIR_1 $BASE_DIR_2 2>/dev/null
|
||||
mkdir -p $BASE_DIR_1 $BASE_DIR_2
|
||||
|
||||
# set up client for chain 1- make sure you use the proper prefix if you set
|
||||
# a custom CLIENT_EXE
|
||||
# Set up client for chain 1- make sure you use the proper prefix if you set
|
||||
# a custom CLIENT_EXE
|
||||
BC_HOME=${CLIENT_1} prepareClient
|
||||
BC_HOME=${CLIENT_2} prepareClient
|
||||
|
||||
# start basecoin server, giving money to the key in the first client
|
||||
# Start basecoin server, giving money to the key in the first client
|
||||
BC_HOME=${CLIENT_1} initServer $BASE_DIR_1 $CHAIN_ID_1 $PREFIX_1
|
||||
if [ $? != 0 ]; then return 1; fi
|
||||
PID_SERVER_1=$PID_SERVER
|
||||
|
||||
# start second basecoin server, giving money to the key in the second client
|
||||
# Start second basecoin server, giving money to the key in the second client
|
||||
BC_HOME=${CLIENT_2} initServer $BASE_DIR_2 $CHAIN_ID_2 $PREFIX_2
|
||||
if [ $? != 0 ]; then return 1; fi
|
||||
PID_SERVER_2=$PID_SERVER
|
||||
|
||||
# connect both clients
|
||||
# Connect both clients
|
||||
BC_HOME=${CLIENT_1} initClient $CHAIN_ID_1 $PORT_1
|
||||
if [ $? != 0 ]; then return 1; fi
|
||||
BC_HOME=${CLIENT_2} initClient $CHAIN_ID_2 $PORT_2
|
||||
if [ $? != 0 ]; then return 1; fi
|
||||
|
||||
echo "...Testing may begin!"
|
||||
echo
|
||||
echo
|
||||
echo
|
||||
printf "...Testing may begin!\n\n\n"
|
||||
}
|
||||
|
||||
oneTimeTearDown() {
|
||||
echo
|
||||
echo
|
||||
echo "stopping both $SERVER_EXE test servers... $PID_SERVER_1 $PID_SERVER_2"
|
||||
printf "\n\nstopping both $SERVER_EXE test servers... $PID_SERVER_1 $PID_SERVER_2"
|
||||
kill -9 $PID_SERVER_1
|
||||
kill -9 $PID_SERVER_2
|
||||
sleep 1
|
||||
|
@ -79,20 +78,21 @@ test00GetAccount() {
|
|||
assertFalse "has no genesis account" "${CLIENT_EXE} query account $RECV_2"
|
||||
checkAccount $SENDER_2 "0" "9007199254740992"
|
||||
|
||||
# make sure that they have different addresses on both chains (they are random keys)
|
||||
# Make sure that they have different addresses on both chains (they are random keys)
|
||||
assertNotEquals "sender keys must be different" "$SENDER_1" "$SENDER_2"
|
||||
assertNotEquals "recipient keys must be different" "$RECV_1" "$RECV_2"
|
||||
}
|
||||
|
||||
test01SendIBCTx() {
|
||||
# trigger a cross-chain sendTx... from RICH on chain1 to POOR on chain2
|
||||
# we make sure the money was reduced, but nothing arrived
|
||||
# Trigger a cross-chain sendTx... from RICH on chain1 to POOR on chain2
|
||||
# we make sure the money was reduced, but nothing arrived
|
||||
SENDER=$(BC_HOME=${CLIENT_1} getAddr $RICH)
|
||||
RECV=$(BC_HOME=${CLIENT_2} getAddr $POOR)
|
||||
|
||||
# we have to remove the password request from stdout, to just get the json
|
||||
export BC_HOME=${CLIENT_1}
|
||||
RES=$(echo qwertyuiop | ${CLIENT_EXE} tx send --amount=20002mycoin --sequence=1 --to=${CHAIN_ID_2}/${RECV} --name=$RICH 2>/dev/null)
|
||||
RES=$(echo qwertyuiop | ${CLIENT_EXE} tx send --amount=20002mycoin \
|
||||
--sequence=1 --to=${CHAIN_ID_2}/${RECV} --name=$RICH 2>/dev/null)
|
||||
txSucceeded $? "$RES"
|
||||
# an example to quit early if there is no point in more tests
|
||||
if [ $? != 0 ]; then echo "aborting!"; return 1; fi
|
||||
|
@ -101,66 +101,67 @@ test01SendIBCTx() {
|
|||
HASH=$(echo $TX | jq .hash | tr -d \")
|
||||
TX_HEIGHT=$(echo $TX | jq .height)
|
||||
|
||||
# make sure balance went down and tx is indexed
|
||||
# Make sure balance went down and tx is indexed
|
||||
checkAccount $SENDER "1" "9007199254720990"
|
||||
checkSendTx $HASH $TX_HEIGHT $SENDER "20002"
|
||||
|
||||
# # make sure nothing arrived - yet
|
||||
# Make sure nothing arrived - yet
|
||||
waitForBlock ${PORT_1}
|
||||
assertFalse "no relay running" "BC_HOME=${CLIENT_2} ${CLIENT_EXE} query account $RECV"
|
||||
|
||||
# start the relay and wait a few blocks...
|
||||
# Start the relay and wait a few blocks...
|
||||
# (already sent a tx on chain1, so use higher sequence)
|
||||
startRelay 2 1
|
||||
if [ $? != 0 ]; then echo "can't start relay"; cat ${BASE_DIR_1}/../relay.log; return 1; fi
|
||||
|
||||
# give it a little time, then make sure the money arrived
|
||||
# Give it a little time, then make sure the money arrived
|
||||
echo "waiting for relay..."
|
||||
sleep 1
|
||||
waitForBlock ${PORT_1}
|
||||
waitForBlock ${PORT_2}
|
||||
|
||||
# check the new account
|
||||
# Check the new account
|
||||
echo "checking ibc recipient..."
|
||||
BC_HOME=${CLIENT_2} checkAccount $RECV "0" "20002"
|
||||
|
||||
# stop relay
|
||||
echo "stoping relay"
|
||||
echo
|
||||
# Stop relay
|
||||
printf "stoping relay\n"
|
||||
kill -9 $PID_RELAY
|
||||
}
|
||||
|
||||
# startRelay $seq1 $seq2
|
||||
# StartRelay $seq1 $seq2
|
||||
# startRelay hooks up a relay between chain1 and chain2
|
||||
# it needs the proper sequence number for $RICH on chain1 and chain2 as args
|
||||
startRelay() {
|
||||
# send some cash to the default key, so it can send messages
|
||||
# Send some cash to the default key, so it can send messages
|
||||
RELAY_KEY=${BASE_DIR_1}/server/key.json
|
||||
RELAY_ADDR=$(cat $RELAY_KEY | jq .address | tr -d \")
|
||||
echo starting relay $PID_RELAY ...
|
||||
|
||||
# get paid on chain1
|
||||
# Get paid on chain1
|
||||
export BC_HOME=${CLIENT_1}
|
||||
SENDER=$(getAddr $RICH)
|
||||
RES=$(echo qwertyuiop | ${CLIENT_EXE} tx send --amount=100000mycoin --sequence=$1 --to=$RELAY_ADDR --name=$RICH 2>/dev/null)
|
||||
RES=$(echo qwertyuiop | ${CLIENT_EXE} tx send --amount=100000mycoin \
|
||||
--sequence=$1 --to=$RELAY_ADDR --name=$RICH 2>/dev/null)
|
||||
txSucceeded $? "$RES"
|
||||
if [ $? != 0 ]; then echo "can't pay chain1!"; return 1; fi
|
||||
|
||||
# get paid on chain2
|
||||
# Get paid on chain2
|
||||
export BC_HOME=${CLIENT_2}
|
||||
SENDER=$(getAddr $RICH)
|
||||
RES=$(echo qwertyuiop | ${CLIENT_EXE} tx send --amount=100000mycoin --sequence=$2 --to=$RELAY_ADDR --name=$RICH 2>/dev/null)
|
||||
RES=$(echo qwertyuiop | ${CLIENT_EXE} tx send --amount=100000mycoin \
|
||||
--sequence=$2 --to=$RELAY_ADDR --name=$RICH 2>/dev/null)
|
||||
txSucceeded $? "$RES"
|
||||
if [ $? != 0 ]; then echo "can't pay chain2!"; return 1; fi
|
||||
|
||||
# initialize the relay (register both chains)
|
||||
# Initialize the relay (register both chains)
|
||||
${SERVER_EXE} relay init --chain1-id=$CHAIN_ID_1 --chain2-id=$CHAIN_ID_2 \
|
||||
--chain1-addr=tcp://localhost:${PORT_1} --chain2-addr=tcp://localhost:${PORT_2} \
|
||||
--genesis1=${BASE_DIR_1}/server/genesis.json --genesis2=${BASE_DIR_2}/server/genesis.json \
|
||||
--from=$RELAY_KEY > ${BASE_DIR_1}/../relay.log
|
||||
if [ $? != 0 ]; then echo "can't initialize relays"; cat ${BASE_DIR_1}/../relay.log; return 1; fi
|
||||
|
||||
# now start the relay (constantly send packets)
|
||||
# Now start the relay (constantly send packets)
|
||||
${SERVER_EXE} relay start --chain1-id=$CHAIN_ID_1 --chain2-id=$CHAIN_ID_2 \
|
||||
--chain1-addr=tcp://localhost:${PORT_1} --chain2-addr=tcp://localhost:${PORT_2} \
|
||||
--from=$RELAY_KEY >> ${BASE_DIR_1}/../relay.log &
|
||||
|
@ -168,15 +169,12 @@ startRelay() {
|
|||
PID_RELAY=$!
|
||||
disown
|
||||
|
||||
# return an error if it dies in the first two seconds to make sure it is running
|
||||
# Return an error if it dies in the first two seconds to make sure it is running
|
||||
ps $PID_RELAY >/dev/null
|
||||
return $?
|
||||
}
|
||||
|
||||
# load and run these tests with shunit2!
|
||||
# Load common then run these tests with shunit2!
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #get this files directory
|
||||
|
||||
# load common helpers
|
||||
. $DIR/common.sh
|
||||
|
||||
. $DIR/shunit2
|
||||
|
|
Loading…
Reference in New Issue