Skip to content

Simnet Testing

Jonathan Chappelow edited this page Jul 6, 2020 · 16 revisions

Simnet Harnesses

Start the DCR and BTC simnet harnesses

The harness are used by both server (dcrdex) and client (dexc).

From the source repository root, run each command in a separate terminal:

DCR harness terminal

./dex/testing/dcr/harness.sh

BTC harness terminal

./dex/testing/btc/harness.sh

When a harness is ready, it will be at a command prompt in a tmux session (green bar at the bottom).

tmux harness

When done with a harness, use ./quit to shutdown all the processes and tmux sessions started by the harness.

Automatic mining

For convenience, the harnesses may continually mine blocks with the watch command. To generate a new Bitcoin block every 5 seconds:

~  dextest  btc  harness-ctl  $  watch -n 25 ./mine-alpha 1

Decred is similar, but under the dcr folder:

~  dextest  dcr  harness-ctl  $  watch -n 30 ./mine-alpha 1

WARNING: Decred's harness can't mine indefinitely so stop the watch when you have completed your current test. The harness config has a ticket buyer, but not enough tickets are purchased on a long enough time line because automatic buying is not allowed before price change. This needs tweaking.

Server (dcrdex) Setup

Configure dcrdex markets for simnet

dcrdex will start markets configured in ~/.dcrdex/markets.json:

{
    "markets": [
        {
            "base": "DCR_simnet",
            "quote": "BTC_simnet",
            "epochDuration": 6000,
            "marketBuyBuffer": 1.2
        }
    ],
    "assets": {
        "DCR_simnet": {
            "bip44symbol": "dcr",
            "network": "simnet",
            "lotSize": 100000000,
            "rateStep": 100000,
            "maxFeeRate": 26,
            "swapConf": 1,
            "configPath": "/home/dcrd/.dcrd/simnet.conf"
        },
        "BTC_simnet": {
            "bip44symbol": "btc",
            "network": "simnet",
            "lotSize": 100000,
            "rateStep": 100,
            "maxFeeRate": 122,
            "swapConf": 1,
            "configPath": "/home/bitcoin/.bitcoin/simnet.conf"
        }
    }
}

For the DCR config file, this might be similar to ~/dextest/dcr/alpha/w-alpha.conf but with username/password vs rpcuser/rpcpass.

For the BTC config file, this could be ~/dextest/btc/harness-ctl/alpha.conf.

Prepare the PostgreSQL DB

First delete any old swap state files:

rm -rf ~/.dcrdex/data/simnet/swapState*

Wipe any old PostgreSQL DB, and create a new simnet PostgreSQL DB:

DROP DATABASE dcrdex_simnet;
CREATE DATABASE dcrdex_simnet OWNER dcrdex;

If necessary, first create the dcrdex PostgreSQL user with CREATE USER dcrdex;

Start dcrdex

Start dcrdex for simnet, with trace-level logging, a regfeexpub corresponding to a simnet wallet, 1 registration fee confirmation required, and the dcrdex_simnet PostgreSQL database created above:

./dcrdex -d trace --simnet --regfeexpub \
  spubVWHTkHRefqHpw3qMN2VTWqnT9rMuqDZrbdgxp8QzGBvXCYfdUuk2VKFnsPHE1CBBNSZjrwHTx2LrM9LbXbGH7gb9qLCYc3JUkLW883SeQ2H \
  --regfeeconfirms=1 --pgdbname=dcrdex_simnet

Client (dexc) Setup

The wallet config files for dexc

Bitcoin:

  • Config file: ~/dextest/btc/harness-ctl/alpha.conf (also applies the gamma wallet process), but you might want to create ~/.dexc/btc-simnet-w.conf file.
  • Account/wallet: "gamma"
  • Wallet password: "abc"

Decred:

  • Config file: ~/dextest/dcr/alpha/w-alpha.conf, but you might want to create ~/.dexc/dcr-simnet-w.conf.
  • Account: default
  • Wallet password: 123

Start dexc

Clear any existing client DB files from previous setups:

rm ~/.dexc/simnet/dexc.db ~/.dexc/simnet/backup/dexc.db

Start dexc with the web UI and RPC server in simnet mode and trace level logging:

./dexc --simnet --rpc --log=trace

The client can be configured via the browser interface or with dexcctl on the command line.

Setup the client via the browser interface

In a browser, navigate to http://127.0.0.1:5758/, and be sure JavaScript is enabled. This should redirect to http://127.0.0.1:5758/register.

  1. Setup the app pass.

  2. Configure the DCR wallet (default, 123, /home/jon/dextest/dcr/alpha/w-alpha.conf, app pass from 1.).

  3. In the next step, specify the server URL http://localhost:7232. Upload the TLS certificate from ~/.dcrdex/rpc.cert.

  4. Pay fee (type in app pass to authorize payment from DCR wallet).

  5. If auto-mining is not setup, mine a few blocks on Decred simnet. How many depends on the regfeeconfirms setting used with `dcrdex.

    ~  dextest  dcr  harness-ctl  $  ./mine-alpha 4
    
  6. Place a couple orders that match.

  7. If needed, mine a few blocks on each chain. And another few on each chain. How many depends on the "swapConf" values in markets.json.

Setup the client via dexcctl

If this is the first time starting dexc, the application must be initialized with a new "app password". For example, initializing with the password "asdf":

$   ./dexcctl -u u -P p init
Set new app password:  <asdf>
app initialized

Setting up a Decred wallet (DCR coin ID is 42):

$   ./dexcctl -u u -P p newwallet 42 default ~/dextest/dcr/alpha/w-alpha.conf
App password:       <asdf>
Wallet password:    <123>
dcr wallet created and unlocked

The dexc console should log something similar to the following:

[INF] CORE: Created dcr wallet. Account "default" balance available = 5227016557638 / locked = 0, Deposit address = SsfWraUBDUtU2dKAhBAYcb8HVTEupAnj9ta
[INF] CORE: Connected to and unlocked dcr wallet. Account "default" balance available = 5227016557638 / locked = 0, Deposit address = SsfWraUBDUtU2dKAhBAYcb8HVTEupAnj9ta

Setting up a Bitcoin wallet (BT coin ID is 0):

$   ./dexcctl -u u -P p newwallet 0 "gamma" ~/dextest/btc/harness-ctl/alpha.conf
App password:      <asdf>
Wallet password:   <abc>
btc wallet created and unlocked

Note that Bitcoin's coin ID is always 0, even on testnet and simnet. Do not use coin ID 1 for BTC testnet.

Now both Decred and Bitcoin wallets are available. Query their status with the wallets command:

$   ./dexcctl -u u -P p wallets
[
  {
    "symbol": "dcr",
    "assetID": 42,
    "open": true,
    "running": true,
    "updated": 0,
    "balance": 5227016557638,
    "address": "SsfWraUBDUtU2dKAhBAYcb8HVTEupAnj9ta",
    "feerate": 10,
    "units": "atoms"
  },
  {
    "symbol": "btc",
    "assetID": 0,
    "open": true,
    "running": true,
    "updated": 0,
    "balance": 8400000000,
    "address": "mig9X7iDprqwnDMR6FyakQpdJo18u7PCLq",
    "feerate": 2,
    "units": "Satoshis"
  }
]

Now that a Decred wallet is configured, you can register with a DEX server. First query for the registration fee with the getfee command:

$   ./dexcctl -u u -P p getfee "http://127.0.0.1:7232" ~/.dcrdex/rpc.cert 
{
  "fee": 100000000
}

Note that the fee is in atoms, the smallest unit of value in Decred, where 1 DCR == 1e8 atoms.

If the fee is acceptable, use the register command to pay the fee:

$   ./dexcctl -u u -P p register "http://127.0.0.1:7232" 100000000 ~/.dcrdex/rpc.cert 
App password:    <asdf>
the DEX fee of 100000000 has been paid

After the required number of confirmations, the newly created account will be able to trade on that DEX server. During this process, dexc should log messages similar to the following:

[INF] CORE: Connected to DEX http://127.0.0.1:7232 and listening for messages.
[INF] CORE: Attempting registration fee payment for SsfWraUBDUtU2dKAhBAYcb8HVTEupAnj9ta of 100000000 units of dcr
[DBG] CORE[dcr]: 1 signature cycles to converge on fees for tx 4992afa0eaa92bfe82f977466c28fa9cc944c32f43ddad8d7e8c8329e62daa2f
[INF] CORE: notify: |SUCCESS| (fee payment) Fee paid - Waiting for 1 confirmations before trading at http://127.0.0.1:7232
...
[TRC] CORE: processing tip change for dcr
[DBG] CORE: Registration fee txn 326661613264653632393833386337653864616464643433326663333434633939636661323836633436373766393832666532626139656161306166393234393030303030303030 now has 1 confirmations.
[INF] CORE: Notifying dex http://127.0.0.1:7232 of fee payment.
[DBG] CORE: authenticated connection to http://127.0.0.1:7232
[INF] CORE: notify: |SUCCESS| (fee payment) Account registered - You may now trade at http://127.0.0.1:7232