Skip to content

Commit

Permalink
Add integration test for place order and time-locked token contract (s…
Browse files Browse the repository at this point in the history
…ei-protocol#836)

* Add integration test for place order and register contracts

* Fix some comments

* Add aws region

* Add AWS keys and secret

* Add integration test for token claim contract

* Fix the workflow build file

* Add more integration tests

* Extend timeout

* Fix migration testing logic

* Change vote period to be 2

---------

Co-authored-by: Yiming Zang <yzang@twitter.com>
  • Loading branch information
yzang2019 and Yiming Zang authored Jun 8, 2023
1 parent bef71a4 commit 0674823
Show file tree
Hide file tree
Showing 18 changed files with 552 additions and 36 deletions.
20 changes: 17 additions & 3 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ defaults:
shell: bash

jobs:

build:
runs-on: ubuntu-latest
timeout-minutes: 15
timeout-minutes: 20
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
steps:
- uses: actions/checkout@v3

Expand All @@ -38,4 +40,16 @@ jobs:
sleep 5
- name: Verify Sei Chain is able to start up
run: ./docker/integration_test/startup_test.sh
run: docker exec -i sei-node-0 integration_test/startup/startup_test.sh

- name: Testing Dex Module
run: docker exec -i sei-node-0 integration_test/dex_module/place_order_test.sh

- name: Testing Wasm Module
run: |
docker exec -i sei-node-0 integration_test/contracts/deploy_timelocked_token_contract.sh
docker exec -i sei-node-0 integration_test/wasm_module/timelocked_token_test_1.sh
docker exec -i sei-node-0 integration_test/contracts/deploy_timelocked_token_contract.sh
docker exec -i sei-node-0 integration_test/wasm_module/timelocked_token_test_2.sh
docker exec -i sei-node-0 integration_test/contracts/deploy_timelocked_token_contract.sh migration
docker exec -i sei-node-0 integration_test/wasm_module/timelocked_token_test_3.sh
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ parallelization/**/artifacts/
parallelization/**/target/
parallelization/**/Cargo.lock

# integration test resources
integration_test/**/*.txt
integration_test/**/*.json

# Coverage Files
coverage.html
coverage.out
coverage.out
8 changes: 4 additions & 4 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: '3.3'
services:
node0:
platform: linux/amd64
container_name: sei-node0
container_name: sei-node-0
image: "sei-chain/localnode"
ports:
- "26656-26658:26656-26658"
Expand All @@ -24,7 +24,7 @@ services:

node1:
platform: linux/amd64
container_name: sei-node1
container_name: sei-node-1
image: "sei-chain/localnode"
ports:
- "26659-26661:26656-26658"
Expand All @@ -45,7 +45,7 @@ services:

node2:
platform: linux/amd64
container_name: sei-node2
container_name: sei-node-2
image: "sei-chain/localnode"
environment:
- ID=2
Expand All @@ -66,7 +66,7 @@ services:

node3:
platform: linux/amd64
container_name: sei-node3
container_name: sei-node-3
image: "sei-chain/localnode"
environment:
- ID=3
Expand Down
21 changes: 0 additions & 21 deletions docker/integration_test/startup_test.sh

This file was deleted.

14 changes: 7 additions & 7 deletions docker/localnode/scripts/step2_genesis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ override_genesis() {
override_genesis '.app_state["crisis"]["constant_fee"]["denom"]="usei"'
override_genesis '.app_state["mint"]["params"]["mint_denom"]="usei"'
override_genesis '.app_state["staking"]["params"]["bond_denom"]="usei"'
override_genesis '.app_state["oracle"]["params"]["vote_period"]="1"'
override_genesis '.app_state["oracle"]["params"]["vote_period"]="2"'
override_genesis '.app_state["slashing"]["params"]["signed_blocks_window"]="10000"'
override_genesis '.app_state["slashing"]["params"]["min_signed_per_window"]="0.050000000000000000"'
override_genesis '.app_state["staking"]["params"]["max_validators"]="50"'
override_genesis '.consensus_params["block"]["max_gas"]="5000000000"'
override_genesis '.app_state["staking"]["params"]["unbonding_time"]="86400s"'
override_genesis '.app_state["staking"]["params"]["unbonding_time"]="10s"'

# We already added node0's genesis account in configure_init, remove it here since we're going to re-add it in the "add genesis accounts" step
override_genesis '.app_state["auth"]["accounts"]=[]'
Expand All @@ -30,14 +30,14 @@ override_genesis '.app_state["genutil"]["gen_txs"]=[]'

# gov parameters
override_genesis '.app_state["gov"]["deposit_params"]["min_deposit"][0]["denom"]="usei"'
#override_genesis '.app_state["gov"]["deposit_params"]["min_expedited_deposit"][0]["denom"]="usei"'
#override_genesis '.app_state["gov"]["deposit_params"]["max_deposit_period"]="300s"'
override_genesis '.app_state["gov"]["deposit_params"]["min_expedited_deposit"][0]["denom"]="usei"'
override_genesis '.app_state["gov"]["deposit_params"]["max_deposit_period"]="300s"'
override_genesis '.app_state["gov"]["voting_params"]["voting_period"]="300s"'
#override_genesis '.app_state["gov"]["voting_params"]["expedited_voting_period"]="120s"'
override_genesis '.app_state["gov"]["voting_params"]["expedited_voting_period"]="120s"'
override_genesis '.app_state["gov"]["tally_params"]["quorum"]="0.5"'
override_genesis '.app_state["gov"]["tally_params"]["threshold"]="0.5"'
#override_genesis '.app_state["gov"]["tally_params"]["expedited_quorum"]="0.9"'
#override_genesis '.app_state["gov"]["tally_params"]["expedited_threshold"]="0.9"'
override_genesis '.app_state["gov"]["tally_params"]["expedited_quorum"]="0.9"'
override_genesis '.app_state["gov"]["tally_params"]["expedited_threshold"]="0.9"'

# add genesis accounts for each node
while read account; do
Expand Down
41 changes: 41 additions & 0 deletions integration_test/contracts/deploy_dex_contract.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

seidbin=$(which ~/go/bin/seid | tr -d '"')
keyname=$(printf "12345678\n" | $seidbin keys list --output json | jq ".[0].name" | tr -d '"')
chainid=$($seidbin status | jq ".NodeInfo.network" | tr -d '"')
seihome=$(git rev-parse --show-toplevel | tr -d '"')
contract_name=$1
if [[ $# -ne 1 ]];
then
echo "Need to provide a contract name (mars,saturn,venus)"
exit 1
fi

cd $seihome || exit
echo "Deploying $contract_name contract..."

# store
echo "Storing contract..."
store_result=$(printf "12345678\n" | $seidbin tx wasm store integration_test/contracts/"$contract_name".wasm -y --from="$keyname" --chain-id="$chainid" --gas=5000000 --fees=1000000usei --broadcast-mode=block --output=json)
contract_id=$(echo "$store_result" | jq -r '.logs[].events[].attributes[] | select(.key == "code_id").value')
echo "Got contract id $contract_id"

# instantiate
echo "Instantiating contract..."
instantiate_result=$(printf "12345678\n" | $seidbin tx wasm instantiate "$contract_id" '{}' -y --no-admin --from="$keyname" --chain-id="$chainid" --gas=5000000 --fees=1000000usei --broadcast-mode=block --label=dex --output=json)
contract_addr=$(echo "$instantiate_result" |jq -r '.logs[].events[].attributes[] | select(.key == "_contract_address").value')

# register
echo "Registering contract..."
printf "12345678\n" | $seidbin tx dex register-contract "$contract_addr" "$contract_id" false true 100000000000 -y --from="$keyname" --chain-id="$chainid" --fees=100000000000usei --gas=500000 --broadcast-mode=block

echo '{"batch_contract_pair":[{"contract_addr":"'$contract_addr'","pairs":[{"price_denom":"SEI","asset_denom":"ATOM","price_tick_size":"0.0000001", "quantity_tick_size":"0.0000001"}]}]}' > integration_test/contracts/"$contract_name"-pair.json
contract_pair=$(printf "12345678\n" | $seidbin tx dex register-pairs integration_test/contracts/"$contract_name"-pair.json -y --from=$keyname --chain-id=$chainid --fees=10000000usei --gas=500000 --broadcast-mode=block --output=json)

sleep 15s

echo "Deployed contracts:"
echo "$contract_addr"
echo "$contract_addr" > $seihome/integration_test/contracts/"$contract_name"-addr.txt

exit 0
90 changes: 90 additions & 0 deletions integration_test/contracts/deploy_timelocked_token_contract.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/bin/bash

seidbin=$(which ~/go/bin/seid | tr -d '"')
keyname=$(printf "12345678\n" | $seidbin keys list --output json | jq ".[0].name" | tr -d '"')
chainid=$($seidbin status | jq ".NodeInfo.network" | tr -d '"')
seihome=$(git rev-parse --show-toplevel | tr -d '"')
migration=$1

# Prepare admin accounts
echo "Preparing admin accounts..."
printf "12345678\n" | $seidbin keys add admin1
printf "12345678\n" | $seidbin keys add admin2
printf "12345678\n" | $seidbin keys add admin3
printf "12345678\n" | $seidbin keys add admin4
printf "12345678\n" | $seidbin keys add op
printf "12345678\n" | $seidbin keys add staking_reward_dest
printf "12345678\n" | $seidbin keys add unlocked_dest
key_admin1=$(printf "12345678\n" |$seidbin keys show admin1 -a)
key_admin2=$(printf "12345678\n" |$seidbin keys show admin2 -a)
key_admin3=$(printf "12345678\n" |$seidbin keys show admin3 -a)
key_admin4=$(printf "12345678\n" |$seidbin keys show admin4 -a)
key_op=$(printf "12345678\n" |$seidbin keys show op -a)
key_staking=$(printf "12345678\n" |$seidbin keys show staking_reward_dest -a)
key_unlock=$(printf "12345678\n" |$seidbin keys show unlocked_dest -a)
printf "12345678\n" | $seidbin tx bank send admin "$key_admin1" 10000000usei -y --chain-id=$chainid --gas=5000000 --fees=1000000usei --broadcast-mode=block
printf "12345678\n" | $seidbin tx bank send admin "$key_admin2" 10000000usei -y --chain-id=$chainid --gas=5000000 --fees=1000000usei --broadcast-mode=block
printf "12345678\n" | $seidbin tx bank send admin "$key_admin3" 10000000usei -y --chain-id=$chainid --gas=5000000 --fees=1000000usei --broadcast-mode=block
printf "12345678\n" | $seidbin tx bank send admin "$key_admin4" 10000000usei -y --chain-id=$chainid --gas=5000000 --fees=1000000usei --broadcast-mode=block
printf "12345678\n" | $seidbin tx bank send admin "$key_op" 10000000usei -y --chain-id=$chainid --gas=5000000 --fees=1000000usei --broadcast-mode=block
printf "12345678\n" | $seidbin tx bank send admin "$key_staking" 10000000usei -y --chain-id=$chainid --gas=5000000 --fees=1000000usei --broadcast-mode=block
printf "12345678\n" | $seidbin tx bank send admin "$key_unlock" 10000000usei -y --chain-id=$chainid --gas=5000000 --fees=1000000usei --broadcast-mode=block


# Deploy goblin contract
contract_name=goblin
cd $seihome || exit
echo "Deploying $contract_name contract..."

# store
echo "Storing contract..."
store_result=$(printf "12345678\n" | $seidbin tx wasm store integration_test/contracts/"$contract_name".wasm -y --from="$keyname" --chain-id="$chainid" --gas=5000000 --fees=1000000usei --broadcast-mode=block --output=json)
contract_id=$(echo "$store_result" | jq -r '.logs[].events[].attributes[] | select(.key == "code_id").value')
echo "Got $contract_name contract id: $contract_id"

# instantiate
echo "Instantiating contract..."
params='{"admins":["'$key_admin1'", "'$key_admin2'", "'$key_admin3'", "'$key_admin4'"], "max_voting_period": {"time":1800}, "admin_voting_threshold_percentage": 75}'
instantiate_result=$(printf "12345678\n" | $seidbin tx wasm instantiate "$contract_id" "$params" -y --no-admin --amount=1500000usei --from="$keyname" --chain-id="$chainid" --gas=5000000 --fees=1000000usei --broadcast-mode=block --label=$contract_name --output=json)
contract_addr=$(echo "$instantiate_result" |jq -r '.logs[].events[].attributes[] | select(.key == "_contract_address").value')
echo "Instantiated $contract_name contract address: $contract_addr"
echo "$contract_addr,$contract_id" > $seihome/integration_test/contracts/"$contract_name"-contract-addr.txt
if [ -z "$contract_addr" ]
then
echo "Failed to deploy contract $contract_name"
exit 1
fi

# Deploy gringotts contract
goblin_addr=$contract_addr
if [ -z "$migration" ]
then
contract_name=gringotts
else
contract_name=gringotts_migrate
fi
cd $seihome || exit
echo "Deploying $contract_name contract..."

# store
echo "Storing contract..."
store_result=$(printf "12345678\n" | $seidbin tx wasm store integration_test/contracts/"$contract_name".wasm -y --from="$keyname" --chain-id="$chainid" --gas=5000000 --fees=1000000usei --broadcast-mode=block --output=json)
contract_id=$(echo "$store_result" | jq -r '.logs[].events[].attributes[] | select(.key == "code_id").value')
echo "Got $contract_name contract id: $contract_id"

# instantiate
echo "Instantiating contract..."
VESTING_TIMESTAMPS='["1685480400000000000", "1685505600000000000"]' # nanoseconds since unix epoch
VESTING_AMOUNTS='["1000000", "500000"]' # in usei
params='{"admins":["'$key_admin1'", "'$key_admin2'", "'$key_admin3'", "'$key_admin4'"], "ops": ["'$key_op'"], "tranche": {"denom":"usei", "vesting_timestamps":'$VESTING_TIMESTAMPS', "vesting_amounts":'$VESTING_AMOUNTS', "unlocked_token_distribution_address": "'$key_unlock'", "staking_reward_distribution_address": "'$key_staking'"}, "max_voting_period": {"time":1800}, "admin_voting_threshold_percentage": 75}'
instantiate_result=$(printf "12345678\n" | $seidbin tx wasm instantiate "$contract_id" "$params" -y --admin="$goblin_addr" --amount=1500000usei --from="$keyname" --chain-id="$chainid" --gas=5000000 --fees=1000000usei --broadcast-mode=block --label=$contract_name --output=json)
contract_addr=$(echo "$instantiate_result" |jq -r '.logs[].events[].attributes[] | select(.key == "_contract_address").value')
echo "Instantiated $contract_name contract address: $contract_addr"
echo "$contract_addr,$contract_id" > $seihome/integration_test/contracts/"$contract_name"-contract-addr.txt
if [ -z "$contract_addr" ]
then
echo "Failed to deploy contract $contract_name"
exit 1
fi

exit 0
Binary file added integration_test/contracts/goblin.wasm
Binary file not shown.
Binary file added integration_test/contracts/gringotts.wasm
Binary file not shown.
Binary file not shown.
Binary file added integration_test/contracts/mars.wasm
Binary file not shown.
Binary file added integration_test/contracts/saturn.wasm
Binary file not shown.
Binary file added integration_test/contracts/venus.wasm
Binary file not shown.
25 changes: 25 additions & 0 deletions integration_test/dex_module/place_order_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

# Deploy mars contract
./integration_test/contracts/deploy_dex_contract.sh mars
contract_addr=$(tail -1 integration_test/contracts/mars-addr.txt)
if [ -z "$contract_addr" ]
then
echo "Failed to deploy contract"
exit 1
fi

# Place orders
echo "Place a new order"
printf "12345678\n" | build/seid tx dex place-orders "$contract_addr" 'LONG?1.01?5?SEI?ATOM?LIMIT?{"leverage":"1","position_effect":"Open"}' --amount=1000000000usei -y --from=admin --chain-id=sei --fees=1000000usei --gas=50000000 --broadcast-mode=block
sleep 15
echo "Verify order is placed successfully"
result=$(build/seid q dex get-orders-by-id "$contract_addr" SEI ATOM 0 |grep "status:" |awk '{print $2}')
if [ "$result" = "PLACED" ]
then
echo "Successfully placed an order"
else
echo "Failed to place an order"
exit 1
fi
exit 0
23 changes: 23 additions & 0 deletions integration_test/startup/startup_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# Verify there are 4 validators
NUM_VALIDATORS=$(build/seid q tendermint-validator-set |grep address |wc -l)
if [[ "$NUM_VALIDATORS" -eq 4 ]];
then
echo "Number validators is correct: $NUM_VALIDATORS"
else
exit 1
fi

# Verify block height is keep increasing
HEIGHT_1=$(build/seid status |jq -r .SyncInfo.latest_block_height)
echo "Current height: $HEIGHT_1"
sleep 15
HEIGHT_2=$(build/seid status |jq -r .SyncInfo.latest_block_height)
echo "Current height: $HEIGHT_2"
if [ "$HEIGHT_1" -ge "$HEIGHT_2" ];
then
exit 1
fi
echo "Startup test passed"
exit 0
Loading

0 comments on commit 0674823

Please sign in to comment.