Skip to content

Commit

Permalink
Add peggy e2e tests (#352)
Browse files Browse the repository at this point in the history
Co-authored-by: James Moore <[email protected]>
  • Loading branch information
banshee and banshee authored Dec 9, 2020
1 parent 51c7b05 commit e3201b2
Show file tree
Hide file tree
Showing 14 changed files with 358 additions and 192 deletions.
5 changes: 2 additions & 3 deletions test/integration/Dockerfile.testrunner
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ COPY --from=build /go/bin/sifnodecli /usr/bin/sifnodecli
COPY --from=build /go/bin/ebrelayer /usr/bin/ebrelayer

# extras for test suite
RUN apk add python3 vim bash
RUN apk add python3 vim bash yarn npm socat busybox-extras
RUN \
# update packages
apk update && apk upgrade && \
Expand All @@ -50,5 +50,4 @@ RUN \
rm -rf /var/cache/apk/*
RUN gem install rake
RUN wget https://github.com/mikefarah/yq/releases/download/3.4.0/yq_linux_amd64 -O /usr/bin/yq &&\
chmod +x /usr/bin/yq

chmod +x /usr/bin/yq
11 changes: 11 additions & 0 deletions test/integration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@

The [setup-linux-environment.sh](./setup-linux-environment.sh) script will install all the tools you need to run in a fresh Linux environment (go, make, etc). This is the script that github actions use to set up that environment.

## Execute in test environment

Run `make` in test/integration/vagrant. That uses [vagrant](https://www.vagrantup.com/docs/installation) to set up a fresh Linux environment with all the tools necessary for building and running the tests. It will:

1. Create a new Linux machine (using virtualbox).
2. Install the tools (using setup-linux-environment.sh)
3. Run the tests.
4. Leave a virtual machine running with the full test environment available for use.

Running `make` again will run the tests again in the existing environment.

## Execute

[start-integration-env.sh](./start-integration-env.sh) starts docker instances and runs the integration tests. The tests are scripts that exit with a non-zero status if they fail.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
#!/bin/bash

# sends $1 rowan to account $2

amount=$1
destination=$2
set -x

BASEDIR=$(pwd)
PASSWORD=$(yq r network-definition.yml "(*==$MONIKER).password")
ADDR=$(yq r network-definition.yml "(*==$MONIKER).address")

yes $PASSWORD | sifnodecli tx send $ADDR $(yes $PASSWORD | sifnodecli keys show user1 -a) "10000000rowan" -y
yes $PASSWORD | sifnodecli tx send $ADDR $(yes $PASSWORD | sifnodecli keys show $destination -a) "${amount}rowan" -y

4 changes: 4 additions & 0 deletions test/integration/integration-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ start_rest_server() {
#
start_relayer() {
wait_for_rpc
echo ETHEREUM_WEBSOCKET_ADDRESS $ETHEREUM_WEBSOCKET_ADDRESS
echo ETHEREUM_CONTRACT_ADDRESS $ETHEREUM_CONTRACT_ADDRESS
echo MONIKER $MONIKER
echo MNEMONIC $MNEMONIC
ebrelayer init tcp://0.0.0.0:26657 "$ETHEREUM_WEBSOCKET_ADDRESS" \
"$ETHEREUM_CONTRACT_ADDRESS" \
"$MONIKER" \
Expand Down
144 changes: 63 additions & 81 deletions test/integration/peggy-basic-test-docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
import json
import time
import sys
from test_utilities import print_error_message, get_user_account, get_password, get_balance, get_shell_output_json, \
network_password, amount_in_wei
from test_utilities import get_shell_output
from test_utilities import test_log_line

# define users
USER = "user1"
Expand All @@ -10,189 +14,167 @@
PEGGYROWAN = "erwn"
ETH = "eth"
SLEEPTIME = 5
AMOUNT = 100000
CLAIMLOCK = "lock"
CLAIMBURN = "burn"
ETHEREUM_SENDER_ADDRESS='0x11111111262b236c9ac9a9a8c8e4276b5cf6b2c9'
ETHEREUM_NULL_ADDRESS='0x0000000000000000000000000000000000000000'
ETHEREUM_CHAIN_ID='5777'
def print_error_message(error_message):
print("#################################")
print("!!!!Error: ", error_message)
print("#################################")
sys.exit(error_message)

def get_shell_output(command_line):
sub = subprocess.Popen(command_line, shell=True, stdout=subprocess.PIPE)
subprocess_return = sub.stdout.read()
return subprocess_return.rstrip()

def get_password():
command_line = "yq r network-definition.yml \"(*==$MONIKER).password\""
output = get_shell_output(command_line).decode("utf-8")
return f"{output}"


def get_moniker():
command_line = "echo $MONIKER"
return get_shell_output(command_line).decode("utf-8")
return get_shell_output(command_line)


def get_ethereum_contract_address():
command_line = "echo $ETHEREUM_CONTRACT_ADDRESS"
return get_shell_output(command_line).decode("utf-8")
return get_shell_output(command_line)


VALIDATOR = get_moniker()
ETHEREUM_CONTRACT_ADDRESS = get_ethereum_contract_address()

def get_user_account(user):
password = get_password()
command_line = "yes " + password + " | sifnodecli keys show " + user + " -a"
return get_shell_output(command_line).decode("utf-8")


def get_operator_account(user):
password = get_password()
password = network_password
command_line = "yes " + password + " | sifnodecli keys show " + user + " -a --bech val"
return get_shell_output(command_line).decode("utf-8")
return get_shell_output(command_line)


def get_account_nonce(user):
command_line = "sifnodecli q auth account " + get_user_account(user) + ' -o json'
output = get_shell_output(command_line).decode("utf-8")
json_str = json.loads(output)
return json_str["value"]["sequence"]


def get_balance(user, denom):
command_line = "sifnodecli q auth account " + get_user_account(user) + ' -o json'
output = get_shell_output(command_line).decode("utf-8")
json_str = json.loads(output)
coins = json_str["value"]["coins"]
for coin in coins:
if coin["denom"] == denom:
return coin["amount"]
return 0
command_line = "sifnodecli q auth account " + get_user_account(user, network_password) + ' -o json'
return get_shell_output_json(command_line)["value"]["sequence"]


# sifnodecli tx ethbridge create-claim
# claim_type is lock | burn
def create_claim(user, validator, amount, denom, claim_type):
print(amount)
print('----- params')
password = get_password()
password = network_password
print(password)
print(validator)
print(get_account_nonce(validator))
print(get_user_account(user))
print(get_user_account(user, network_password))
print(get_operator_account(validator))
print(get_ethereum_contract_address())
print('----- params')
print(get_password())
command_line = f""" yes {get_password()} | sifnodecli tx ethbridge create-claim \
print(network_password)
command_line = f""" yes {network_password} | sifnodecli tx ethbridge create-claim \
{ETHEREUM_CONTRACT_ADDRESS} {get_account_nonce(validator)} {denom} \
{ETHEREUM_SENDER_ADDRESS} {get_user_account(user)} {get_operator_account(validator)} \
{ETHEREUM_SENDER_ADDRESS} {get_user_account(user, network_password)} {get_operator_account(validator)} \
{amount} {claim_type} --token-contract-address={ETHEREUM_NULL_ADDRESS} \
--ethereum-chain-id={ETHEREUM_CHAIN_ID} --from={validator} --yes"""
--ethereum-chain-id={ETHEREUM_CHAIN_ID} --from={validator} --yes -o json"""
print(command_line)
#command_line = """yes | sifnodecli tx ethbridge create-claim $ETHEREUM_CONTRACT_ADDRESS {} {} \
#0x11111111262b236c9ac9a9a8c8e4276b5cf6b2c9 {} {} {} {} \
#--token-contract-address=0x0000000000000000000000000000000000000000 \
#--ethereum-chain-id=3 --from={} \
#--yes""".format(get_account_nonce(validator), denom, get_user_account(user),
# get_operator_account(validator), amount, claim_type, validator)
# print(command_line)
return get_shell_output(command_line)


def burn_peggy_coin(user, validator, amount):
command_line = """yes {} | sifnodecli tx ethbridge burn {} \
0x11111111262b236c9ac9a9a8c8e4276b5cf6b2c9 {} {} \
--ethereum-chain-id=5777 --from={} \
--yes""".format(get_password(), get_user_account(user),
--yes -o json""".format(network_password, get_user_account(user, network_password),
amount, PEGGYETH, user)
# print(command_line)
return get_shell_output(command_line)


def lock_rowan(user, amount):
print('lock')
command_line = """yes {} |sifnodecli tx ethbridge lock {} \
0x11111111262b236c9ac9a9a8c8e4276b5cf6b2c9 {} rowan \
--ethereum-chain-id=5777 --from={} --yes
""".format(get_password(), get_user_account(user), amount, user)
# print(command_line)
--ethereum-chain-id=5777 --from={} --yes -o json
""".format(network_password, get_user_account(user, network_password), amount, user)
return get_shell_output(command_line)


def test_case_1():
test_log_line("########## Test Case One Start: lock eth in ethereum then mint ceth in sifchain\n")
print(
"########## Test Case One Start: lock eth in ethereum then mint ceth in sifchain"
f"########## Test Case One Start: lock eth in ethereum then mint ceth in sifchain {network_password}"
)
balance_before_tx = int(get_balance(USER, PEGGYETH))
print("Before lock transaction {}'s balance of {} is {}".format(
USER, PEGGYETH, balance_before_tx))
balance_before_tx = int(get_balance(USER, PEGGYETH, network_password))
print(f"Before lock transaction {USER}'s balance of {PEGGYETH} is {balance_before_tx}")

print("Send lock claim to Sifchain...")
amount = amount_in_wei(5)
print(create_claim(USER, VALIDATOR, amount, ETH, CLAIMLOCK))

print(create_claim(USER, VALIDATOR, AMOUNT, ETH, CLAIMLOCK))
time.sleep(SLEEPTIME)
balance_after_tx = int(get_balance(USER, PEGGYETH))
print("After lock transaction {}'s balance of {} is {}".format(
USER, PEGGYETH, balance_after_tx))
if balance_after_tx != balance_before_tx + AMOUNT:

balance_after_tx = int(get_balance(USER, PEGGYETH, network_password))

print(f"After lock transaction {USER}'s balance of {PEGGYETH} is {balance_after_tx}")

if balance_after_tx != balance_before_tx + amount:
print_error_message("balance is wrong after send eth lock claim")

print("########## Test Case One Over ##########")
test_log_line("########## Test Case One Over ##########\n")


def test_case_2():
print(
"########## Test Case Two Start: burn ceth in sifchain then eth back to ethereum"
)
balance_before_tx = int(get_balance(USER, PEGGYETH))
balance_before_tx = int(get_balance(USER, PEGGYETH, network_password))
print('before_tx', balance_before_tx)
print("Before burn transaction {}'s balance of {} is {}".format(
USER, PEGGYETH, balance_before_tx))
if balance_before_tx < AMOUNT:
amount = amount_in_wei(7)
if balance_before_tx < amount:
print_error_message("No enough ceth to burn")
return
print("Send burn claim to Sifchain...")
burn_peggy_coin(USER, VALIDATOR, AMOUNT)
burn_peggy_coin(USER, VALIDATOR, amount)
time.sleep(SLEEPTIME)
balance_after_tx = int(get_balance(USER, PEGGYETH))
balance_after_tx = int(get_balance(USER, PEGGYETH, network_password))
print("After burn transaction {}'s balance of {} is {}".format(
USER, PEGGYETH, balance_after_tx))
if balance_after_tx != balance_before_tx - AMOUNT:
if balance_after_tx != balance_before_tx - amount:
print_error_message("balance is wrong after send eth lock claim")
print("########## Test Case Two Over ##########")


def test_case_3():
print(
"########## Test Case Three Start: lock rowan in sifchain transfer to ethereum"
)
balance_before_tx = int(get_balance(USER, ROWAN))
balance_before_tx = int(get_balance(USER, ROWAN, network_password))
print("Before lock transaction {}'s balance of {} is {}".format(
USER, ROWAN, balance_before_tx))
if balance_before_tx < AMOUNT:
amount = 12
if balance_before_tx < amount:
print_error_message("No enough rowan to lock")
print("Send lock claim to Sifchain...")
lock_rowan(USER, AMOUNT)
lock_rowan(USER, amount)
time.sleep(SLEEPTIME)
balance_after_tx = int(get_balance(USER, ROWAN))
balance_after_tx = int(get_balance(USER, ROWAN, network_password))
print("After lock transaction {}'s balance of {} is {}".format(
USER, ROWAN, balance_after_tx))
if balance_after_tx != balance_before_tx - AMOUNT:
if balance_after_tx != balance_before_tx - amount:
print_error_message("balance is wrong after send eth lock claim")
print("########## Test Case Three Over ##########")


def test_case_4():
print(
"########## Test Case Four Start: burn erwn in ethereum then transfer rwn back to sifchain"
)
balance_before_tx = int(get_balance(USER, ROWAN))
balance_before_tx = int(get_balance(USER, ROWAN, network_password))
print("Before lock transaction {}'s balance of {} is {}".format(
USER, ROWAN, balance_before_tx))
print("Send burn claim to Sifchain...")
create_claim(USER, VALIDATOR, AMOUNT, ROWAN, CLAIMBURN)
amount = 13
create_claim(USER, VALIDATOR, amount, ROWAN, CLAIMBURN)
time.sleep(SLEEPTIME)
balance_after_tx = int(get_balance(USER, ROWAN))
balance_after_tx = int(get_balance(USER, ROWAN, network_password))
print("After lock transaction {}'s balance of {} is {}".format(
USER, ROWAN, balance_after_tx))
if balance_after_tx != balance_before_tx + AMOUNT:
if balance_after_tx != balance_before_tx + amount:
print_error_message("balance is wrong after send eth lock claim")
print("########## Test Case Four Over ##########")


test_case_1()
test_case_2()
test_case_3()
Expand Down
Loading

0 comments on commit e3201b2

Please sign in to comment.