Skip to content

Commit 92c5238

Browse files
committed
Add support for calling sifnoded add-genesis-validators to integration tests
1 parent 3830b86 commit 92c5238

7 files changed

+111
-61
lines changed

Diff for: test/integration/docker-compose-integration.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ services:
2828
- ${BASEDIR}:/sifnode
2929
- yarncache:/yarncache
3030

31-
entrypoint: /test/integration/integration-entrypoint.sh
31+
entrypoint: /test/integration/integration-entrypoint.sh ${ADD_VALIDATOR_TO_WHITELIST}
3232
networks:
3333
genesis_sifchain:
3434
ipv4_address: ${IPV4_ADDRESS1}

Diff for: test/integration/integration-entrypoint.sh

+18-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,24 @@
33
# Sifnode entrypoint.
44
#
55

6-
#
7-
# Daemon.
8-
#
6+
set -x
7+
8+
ADD_VALIDATOR_TO_WHITELIST=$1
9+
shift
10+
11+
NETDEF=/network-definition.yml
12+
PASSWORD=$(cat $NETDEF | yq r - ".password")
13+
14+
if [ -z "${ADD_VALIDATOR_TO_WHITELIST}" ]
15+
then
16+
# no whitelist validator requested; mostly useful for testing validator whitelisting
17+
echo $0: no whitelisted validators
18+
else
19+
whitelisted_validator=$(yes $PASSWORD | sifnodecli keys show -a --bech val $MONIKER)
20+
echo $0: whitelisted validator $whitelisted_validator
21+
sifnoded add-genesis-validators $whitelisted_validator
22+
fi
23+
924
start_daemon() {
1025
sifnoded start --rpc.laddr tcp://0.0.0.0:26657
1126
}

Diff for: test/integration/no_whitelisted_validators.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from test_utilities import owner_addr, amount_in_wei, transact_ethereum_currency_to_sifchain_addr, print_error_message
2+
3+
4+
def no_whitelisted_validators():
5+
print(f"adding eth to {owner_addr}, expect to fail")
6+
try:
7+
transact_ethereum_currency_to_sifchain_addr(owner_addr, "eth", amount_in_wei(10))
8+
print("did not fail")
9+
transferred = True
10+
except:
11+
# this is the good path; we don't want the transfer to happen
12+
transferred = False
13+
print("did fail")
14+
if transferred:
15+
print_error_message("balance should not have tranferred, we should have no validators")
16+
17+
18+
no_whitelisted_validators()

Diff for: test/integration/peggy-e2e-test.py

-4
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@
1919
CLAIMLOCK = "lock"
2020
CLAIMBURN = "burn"
2121

22-
ETH_OPERATOR = "0x627306090abaB3A6e1400e9345bC60c78a8BEf57"
23-
ETH_ACCOUNT = os.environ.get("USER1ADDR")
24-
user1EthAddress = "0x4Bbb1BB825003eC701545524AaBDDCa1B970502C"
2522
operatorAddress = "0xf17f52151EbEF6C7334FAD080c5704D77216b732"
26-
ROWAN_CONTRACT = "0x409Ba3dd291bb5D48D5B4404F5EFa207441F6CbA"
2723

2824
def get_eth_balance(account, symbol):
2925
command_line = cd_smart_contracts_dir + "yarn peggy:getTokenBalance {} {}".format(

Diff for: test/integration/setup_sifchain.sh

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
3+
set -x
4+
set -e
5+
6+
. $(dirname $0)/vagrantenv.sh
7+
. ${BASEDIR}/test/integration/shell_utilities.sh
8+
9+
#
10+
# scaffold and boot the dockerized localnet
11+
#
12+
BASEDIR=${BASEDIR} rake genesis:network:scaffold['localnet']
13+
# see deploy/rake/genesis.rake for the description of the args to genesis:network:boot
14+
# :chainnet, :eth_bridge_registry_address, :eth_keys, :eth_websocket
15+
BASEDIR=${BASEDIR} rake genesis:network:boot["localnet,${ETHEREUM_CONTRACT_ADDRESS},c87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3,ws://192.168.2.6:7545/"]
16+
17+
sleep 15
18+
19+
#
20+
# Wait for the Websocket subscriptions to be initialized (like 10 seconds)
21+
#
22+
docker logs -f ${CONTAINER_NAME} | grep -m 1 "Subscribed"
23+
24+
# We need to forward the port used by ganache, since adding new network didn't allow
25+
# using the cli
26+
docker exec ${CONTAINER_NAME} bash -c "bash /test/integration/start-ganache-port-forwarding.sh"
27+
28+
# those rake commands generate yaml that provides useful usernames and passwords
29+
# wait for it to appear
30+
31+
NETDEF=$NETWORKDIR/network-definition.yml
32+
echo "export NETDEF=$NETDEF" >> $envexportfile
33+
while [ ! -f $NETWORKDIR/network-definition.yml ]
34+
do
35+
sleep 2
36+
done
37+
38+
export MONIKER=$(cat ${NETWORKDIR}/network-definition.yml | to_json | jq '.[0].moniker')
39+
echo "export MONIKER=$MONIKER" >> $envexportfile
40+
export MONIKER_ADDR=$(cat ${NETWORKDIR}/network-definition.yml | to_json | jq '.[0].moniker')
41+
echo "export MONIKER=$MONIKER" >> $envexportfile
42+
43+
OWNER_PASSWORD=$(cat $NETDEF | yq r - ".password")
44+
echo "export OWNER_PASSWORD=$OWNER_PASSWORD" >> $envexportfile
45+
46+
OWNER_ADDR=$(cat $NETDEF | yq r - ".address")
47+
echo "export OWNER_ADDR=$OWNER_ADDR" >> $envexportfile

Diff for: test/integration/shell_utilities.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
# must run from the root directory of the sifnode tree
3+
4+
set -e # exit on any failure
5+
6+
# add 18 zeros to a number
7+
to_wei () { echo "${1}000000000000000000" ; }
8+
to_json () { ruby -ryaml -rjson -e "puts YAML::load(STDIN.read).to_json"; }

Diff for: test/integration/start-integration-env.sh

+19-53
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,25 @@
33

44
set -e # exit on any failure
55

6-
# add 18 zeros to a number
7-
to_wei () { echo "${1}000000000000000000" ; }
8-
to_json () { ruby -ryaml -rjson -e "puts YAML::load(STDIN.read).to_json"; }
9-
106
BASEDIR=$(pwd)/$(dirname $0)/../..
11-
NETWORKDIR=$BASEDIR/deploy/networks
127

13-
envexportfile=$BASEDIR/test/integration/vagrantenv.sh
8+
. ${BASEDIR}/test/integration/shell_utilities.sh
9+
10+
export envexportfile=$BASEDIR/test/integration/vagrantenv.sh
1411
rm -f $envexportfile
1512

1613
export CONTAINER_NAME="integration_sifnode1_1"
1714
echo "export CONTAINER_NAME=$CONTAINER_NAME" >> $envexportfile
1815

1916
echo "export BASEDIR=$BASEDIR" >> $envexportfile
2017

18+
NETWORKDIR=$BASEDIR/deploy/networks
19+
echo "export NETWORKDIR=$NETWORKDIR" >> $envexportfile
20+
2121
#
2222
# Remove prior generations Config
2323
#
24-
echo "apologies for this sudo, it is to delete non-persisent cryptographic keys that usually has enhanced permissions"
25-
sudo rm -rf $NETWORKDIR && mkdir $NETWORKDIR
24+
rm -rf $NETWORKDIR && mkdir $NETWORKDIR
2625
rm -rf ${BASEDIR}/smart-contracts/build ${BASEDIR}/smart-contracts/.openzeppelin
2726
make -C ${BASEDIR} install
2827

@@ -31,15 +30,14 @@ cd $BASEDIR/smart-contracts
3130

3231
# Startup ganache-cli (https://github.com/trufflesuite/ganache)
3332

33+
cp $BASEDIR/test/integration/.env.ciExample .env
34+
3435
yarn --cwd $BASEDIR/smart-contracts install
3536
export YARN_CACHE_DIR=$(yarn cache dir)
3637
echo "export YARN_CACHE_DIR=$YARN_CACHE_DIR" >> $envexportfile
3738

38-
3939
docker-compose --project-name genesis -f $BASEDIR/test/integration/docker-compose-ganache.yml up -d --force-recreate
4040

41-
cp $BASEDIR/test/integration/.env.ciExample .env
42-
4341
# https://www.trufflesuite.com/docs/truffle/overview
4442
# and note that truffle migrate and truffle deploy are the same command
4543
truffle compile
@@ -63,47 +61,10 @@ if [ -z "BRIDGE_BANK_ADDRESS" ]; then
6361
fi
6462
echo "export BRIDGE_BANK_ADDRESS=$BRIDGE_BANK_ADDRESS" >> $envexportfile
6563

66-
#
67-
# scaffold and boot the dockerized localnet
68-
#
69-
BASEDIR=${BASEDIR} rake genesis:network:scaffold['localnet']
70-
# see deploy/rake/genesis.rake for the description of the args to genesis:network:boot
71-
# :chainnet, :eth_bridge_registry_address, :eth_keys, :eth_websocket
72-
BASEDIR=${BASEDIR} rake genesis:network:boot["localnet,${ETHEREUM_CONTRACT_ADDRESS},c87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3,ws://192.168.2.6:7545/"]
73-
74-
sleep 15
75-
76-
#
77-
# Wait for the Websocket subscriptions to be initialized (like 10 seconds)
78-
#
79-
docker logs -f ${CONTAINER_NAME} | grep -m 1 "Subscribed"
64+
ADD_VALIDATOR_TO_WHITELIST=1 bash ${BASEDIR}/test/integration/setup_sifchain.sh && . $envexportfile
8065

81-
# We need to forward the port used by ganache, since adding new network didn't allow
82-
# using the cli
83-
docker exec ${CONTAINER_NAME} bash -c "bash /test/integration/start-ganache-port-forwarding.sh"
8466
docker exec ${CONTAINER_NAME} bash -c "cd /smart-contracts && yarn install"
8567

86-
# those rake commands generate yaml that provides useful usernames and passwords
87-
# wait for it to appear
88-
89-
NETDEF=$NETWORKDIR/network-definition.yml
90-
echo "export NETDEF=$NETDEF" >> $envexportfile
91-
while [ ! -f $NETWORKDIR/network-definition.yml ]
92-
do
93-
sleep 2
94-
done
95-
96-
export MONIKER=$(cat ${NETWORKDIR}/network-definition.yml | to_json | jq '.[0].moniker')
97-
echo "export MONIKER=$MONIKER" >> $envexportfile
98-
export MONIKER_ADDR=$(cat ${NETWORKDIR}/network-definition.yml | to_json | jq '.[0].moniker')
99-
echo "export MONIKER=$MONIKER" >> $envexportfile
100-
101-
OWNER_PASSWORD=$(cat $NETDEF | yq r - ".password")
102-
echo "export OWNER_PASSWORD=$OWNER_PASSWORD" >> $envexportfile
103-
104-
OWNER_ADDR=$(cat $NETDEF | yq r - ".address")
105-
echo "export OWNER_ADDR=$OWNER_ADDR" >> $envexportfile
106-
10768
#
10869
# Add keys for a second account to test functions against
10970
#
@@ -116,11 +77,16 @@ echo "export USER1ADDR=$USER1ADDR" >> $envexportfile
11677
# Run the python tests
11778
#
11879
echo run python tests
80+
11981
docker exec ${CONTAINER_NAME} bash -c ". /test/integration/vagrantenv.sh; cd /sifnode; SMART_CONTRACTS_DIR=/smart-contracts python3 /test/integration/initial_test_balances.py /network-definition.yml"
120-
sleep 15
82+
sleep 5
12183
docker exec ${CONTAINER_NAME} bash -c ". /test/integration/vagrantenv.sh; cd /sifnode; SMART_CONTRACTS_DIR=/smart-contracts python3 /test/integration/peggy-basic-test-docker.py /network-definition.yml"
12284
docker exec ${CONTAINER_NAME} bash -c '. /test/integration/vagrantenv.sh; cd /sifnode; SMART_CONTRACTS_DIR=/smart-contracts python3 /test/integration/peggy-e2e-test.py /network-definition.yml'
12385

124-
# killing script will not end network use stop-integration-env.sh for that
125-
# and note that we just allow the github actions environment to be cleaned
126-
# up by their scripts
86+
# Uncomment these tests in PR 378
87+
# Rebuild sifchain, but this time don't use validators
88+
89+
#sudo rm -rf $NETWORKDIR && mkdir $NETWORKDIR
90+
#ADD_VALIDATOR_TO_WHITELIST= bash ${BASEDIR}/test/integration/setup_sifchain.sh && . $envexportfile
91+
#
92+
#docker exec ${CONTAINER_NAME} bash -c ". /test/integration/vagrantenv.sh; cd /sifnode; SMART_CONTRACTS_DIR=/smart-contracts python3 /test/integration/no_whitelisted_validators.py /network-definition.yml"

0 commit comments

Comments
 (0)