changed 5 years ago
Linked with GitHub

(Generic) Swap Test Guide

Instructions

1. Start the client of your choice

This guide should work with any ethereum client provided that it has accounts and has its first account prefunded and unlocked. For specific clients there are some instructions below.

2. Run the deploy script

You can download and pipe directly into bash using:

curl https://gist.githubusercontent.com/ralph-pichler/dc0386f81ffa09c220271d4389b4a139/raw/71e39e39152e18f06107f6af91d2069d85148abd/deploy.sh | bash | tee test-env

Alternatively download first, then run with bash:

curl https://gist.githubusercontent.com/ralph-pichler/dc0386f81ffa09c220271d4389b4a139/raw/71e39e39152e18f06107f6af91d2069d85148abd/deploy.sh -o deploy.sh
bash deploy.sh | tee test-env # or ./deploy.sh after chmod +x deploy.sh

Notes:

  • This script requires jq and curl to be installed
  • This script only works with bash, and not necessarily other sh implementations
  • You only need to do this once per blockchain or whenever the contracts change.

If the rpc port of the ethereum backend is not 8545 you can specify it manually using the BACKEND environment variable. (e.g. BACKEND=http://localhost:4444 bash deploy.sh for rskj). If you use different bzzaccounts than in the guide you can specify the prefunded accounts using the BZZACCOUNTS variable.

If you want to read the deployment script, follow this link.

This guide uses the SWARM_SWAP_BACKEND_URL and SWARM_SWAP_CHEQUEBOOK_FACTORY_ADDR environment variables to set the backend and factory. This allows using the same swarm commands regardless of which client is used. The necessary export commands are printed as the result of the script and stored in a file called test-env using tee. This file is then sourced prior to executing swarm.

3. Run the swarm nodes

This will populate the datadirs of the swarm nodes with the accounts already prefunded both with ether and tokens. It will also use predefined nodekeys. If you want to reset balances to 0 simply execute the entire code again. If you want the datadir to persist only execute the last line (in that case make sure DATADIR1 and/or DATADIR2 is defined).

Start the first node (with syncing disabled) with

DATADIR="/tmp/s1" && 
rm -rf "$DATADIR" && mkdir "$DATADIR" &&
source test-env && make && ./build/bin/swarm --bzznetworkid 5 --datadir "$DATADIR" --swap --ws --wsaddr=0.0.0.0 --wsapi=accounting,bzz,swap --wsorigins='*' --no-sync --bzzkeyhex 40b3e576b606d4580ad3c875e9fda07ba3e4d99a40534c5bf1bc72226451adb1 --nodekeyhex 2eae3526db799cb5f1ab6ab64255ba8182cdaeb4f773a0ae1244f4ca59978dc2 --swap-deposit-amount 50000000000000000

and the second node with this:

DATADIR="/tmp/s2" && 
rm -rf "$DATADIR" && mkdir "$DATADIR" &&
source test-env && ./build/bin/swarm --bzznetworkid 5 --datadir "$DATADIR" --port 40400 --swap --bzzport 9100 --bootnodes "enode://9b7571c26d50bed78f614be5bf3b2d661176fdfeb546f100b84dd03545f4bc98e42e640286ac92fe110ec5f4995141743e47d8f642aa49ac05bd5f2cab2e881a@127.0.0.1:30399" --ws --wsaddr=0.0.0.0 --wsapi=accounting,bzz,swap --wsport 8556 --wsorigins='*' --no-sync --bzzkeyhex 73f0f0e024f09059acb267f836ba7924e0a02fe9dd8089293e7ca3b7a1c14a67 --swap-deposit-amount 50000000000000000

4. Generate a random file and upload

This continously generates files and pushes them to one node and then retrieves them one the other one.

while true; do dd if=/dev/urandom of=output bs=500k count=1 && hash="$(./build/bin/swarm --bzzapi http://localhost:9100 up output)" && ./build/bin/swarm --bzzapi http://localhost:8500 down "bzz://$hash" && rm "$hash"; sleep 1; done

6. Query Balances

Query all balances:

echo swap_balances | websocat "ws://127.0.0.1:8546" --origin localhost --jsonrpc -n --one-message &&
echo swap_balances | websocat "ws://127.0.0.1:8556" --origin localhost --jsonrpc -n --one-message

Query a specific balance:

ADDRESS=02a4c0fafcf4ad9b189b5d9fda216968c8268e07c25a7ac235d643c521682de7 # example
echo swap_peerBalance \"$ADDRESS\" | websocat "ws://127.0.0.1:8546" --origin localhost --jsonrpc -n --one-message

Client Specific Instructions

Ganache

ganache does not need any specific flags

ganache-cli

Geth

geth in dev mode starts with its first account unlocked. rpc needs to be enabled by flag.

geth --dev --dev.period 5 --rpc

Parity

parity in dev mode does not unlock its prefunded account by default. The password is the empty string (that is what the <(echo) is for).

parity --chain dev --password <(echo) --unlock 0x00a329c0648769a73afac7f9381e08fb43dbea72

This starts with a premined address (0x00a329c0648769a73afac7f9381e08fb43dbea72).

rskj

Download the rskj node with the event data field fix from here. If you don't want to login to google you can also download it from swarm here.

rm -rf datadir # cleanup previous directory
java -jar rskj-core-unformatted-log-all.jar co.rsk.Start --regtest -base-path datadir

This starts with a premined address (0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826).

Note: rskj has its rpc on port 4444 by default. Specify BACKEND=http://localhost:4444.

Observed issues with specific clients

suggest gas price issues with rskj

  • Cashing cheques does not work
ERROR[11-26|16:29:40.620] error cashing cheque                     
swaplog=* base=d79b7346431a6112 err="failed to suggest gas price: Post http://localhost:4444: EOF"
  • Chequebook deploying requires multiple tries
INFO [11-26|16:32:48.728] Deploying new swap                       swaplog=* base=d79b7346431a6112 owner=0xc45D64d8F9642a604Db93C59FD38492b262391CA deposit=500000000000
WARN [11-26|16:32:48.733] chequebook deploy error, retrying...     swaplog=* base=d79b7346431a6112 try=0 error="failed to suggest gas price: Post http://localhost:4444: EOF"
INFO [11-26|16:32:51.780] Deployed chequebook                      swaplog=* base=d79b7346431a6112 contract address=0x8e9a2a73BCA088852de1b6b510D9d9673cc09e90 deposit=500000000000 owner=0xc45D64d8F9642a604Db93C59FD38492b262391CA

Under the hood suggest gas price uses eth_gasPrice for rpc connections. This call works on rksj as verified with curl:

curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_gasPrice","params":[], "id":1 }' http://localhost:4444 

It is unknown if this is problem with swap or rsk. Most likely the problem is not in swap but lower in the http stack. Connecting through a mitmproxy mitigates this. This and the fact that swap works with all other clients indicates that the issue might be with rskj (However capturing and manually resending the requests using curl leads to rskj responding correctly).

Select a repo