decred.org/dcrdex@v1.0.5/docs/wiki/Simnet-Testing.md (about)

     1  # Simnet Testing
     2  
     3  - [Simnet Harnesses](#simnet-harnesses)
     4    - [Start the DCR and BTC simnet harnesses](#start-the-dcr-and-btc-simnet-harnesses)
     5    - [Automatic mining](#automatic-mining)
     6  - [Server (`dcrdex`) Setup](#server-dcrdex-setup)
     7    - [Configure dcrdex markets for simnet](#configure-dcrdex-markets-for-simnet)
     8    - [Prepare the PostgreSQL DB](#prepare-the-postgresql-db)
     9    - [Start dcrdex](#start-dcrdex)
    10  - [Wallet (`bisonw`) Setup](#wallet-bisonw-setup)
    11    - [The wallet config files for bisonw](#the-wallet-config-files-for-bisonw)
    12    - [Start `bisonw`](#start-bisonw)
    13    - [Setup the wallet via the browser interface](#setup-the-wallet-via-the-browser-interface)
    14    - [Setup the wallet via bwctl](#setup-the-wallet-via-bwctl)
    15  
    16  ## Simnet Harnesses
    17  
    18  ### Start the DCR and BTC simnet harnesses
    19  
    20  The harnesses are used by both server (dcrdex) and wallet (bisonw).
    21  
    22  From the source repository root, run each command in a separate terminal:
    23  
    24  DCR harness terminal
    25  
    26  ```sh
    27  ./dex/testing/dcr/harness.sh
    28  ```
    29  
    30  BTC harness terminal
    31  
    32  ```sh
    33  ./dex/testing/btc/harness.sh
    34  ```
    35  
    36  When a harness is ready, it will be at a command prompt in a tmux session (green bar at the bottom).
    37  
    38  ![tmux harness](https://user-images.githubusercontent.com/9373513/79356467-9f740900-7f04-11ea-80d7-6473eae24411.png)
    39  
    40  When done with a harness, use `./quit` to shutdown all the processes and tmux sessions started by the harness.
    41  
    42  ### Automatic mining
    43  
    44  For convenience, the harnesses may continually mine blocks with the `watch` command. To generate a new Bitcoin block every 5 seconds:
    45  
    46  ```sh
    47  ~/dextest/btc/harness-ctl $ watch -n 25 ./mine-alpha 1
    48  ```
    49  
    50  Decred is similar, but under the `dcr` folder:
    51  
    52  ```sh
    53  ~/dextest/dcr/harness-ctl $ watch -n 30 ./mine-alpha 1
    54  ```
    55  
    56  **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 timeline because automatic buying is not allowed before a price change.  This needs tweaking.
    57  
    58  ## Server (`dcrdex`) Setup
    59  
    60  ### Harness option
    61  
    62  There is a dcrdex harness that will set up everything for you, although with a very short contract lock time set of 1 min maker and 30 sec taker.
    63  
    64  ```sh
    65  /[repo root]/dex/testing/dcrdex $ ./harness.sh
    66  ```
    67  
    68  To setup the dcrdex server manually, and with the regular contract lock times, follow the steps in the following subsections.
    69  
    70  ### Configure dcrdex markets for simnet
    71  
    72  NOTE: If using the harness option described in the previous section, this and other server setup is not required.
    73  
    74  `dcrdex` will start running the markets configured in `~/.dcrdex/markets.json`:
    75  
    76  ```json
    77  {
    78      "markets": [
    79          {
    80              "base": "DCR_simnet",
    81              "quote": "BTC_simnet",
    82              "epochDuration": 6000,
    83              "marketBuyBuffer": 1.2,
    84              "lotSize": 100000000,
    85              "rateStep": 100
    86          }
    87      ],
    88      "assets": {
    89          "DCR_simnet": {
    90              "bip44symbol": "dcr",
    91              "network": "simnet",
    92              "maxFeeRate": 26,
    93              "swapConf": 1,
    94              "configPath": "/home/dcrd/.dcrd/simnet.conf",
    95              "regConfs": 1,
    96              "regFee": 100000000,
    97              "regXPub": "spubVWKGn9TGzyo7M4b5xubB5UV4joZ5HBMNBmMyGvYEaoZMkSxVG4opckpmQ26E85iHg8KQxrSVTdex56biddqtXBerG9xMN8Dvb3eNQVFFwpE"
    98          },
    99          "BTC_simnet": {
   100              "bip44symbol": "btc",
   101              "network": "simnet",
   102              "maxFeeRate": 122,
   103              "swapConf": 1,
   104              "configPath": "/home/bitcoin/.bitcoin/simnet.conf",
   105              "regConfs": 2,
   106              "regFee": 20000000,
   107              "regXPub": "vpub5SLqN2bLY4WeZJ9SmNJHsyzqVKreTXD4ZnPC22MugDNcjhKX5xNX9QiQWcE4SSRzVWyHWUihpKRT7hckDGNzVc69wSX2JPcfGeNiT5c2XZy"
   108          }
   109      }
   110  }
   111  ```
   112  
   113  For the DCR config file, this could be `~/dextest/btc/alpha/alpha.conf` to use the Decred simnet harness' setup.
   114  
   115  For the BTC config file, this could be `~/dextest/btc/alpha/alpha.conf` to use the Bitcoin simnet harness' setup.
   116  
   117  ### Prepare the PostgreSQL DB
   118  
   119  If necessary, first create the `dcrdex` PostgreSQL user with `CREATE USER dcrdex;`.
   120  
   121  Wipe any old PostgreSQL DB, and create a new simnet database:
   122  
   123  ```sql
   124  DROP DATABASE dcrdex_simnet;
   125  CREATE DATABASE dcrdex_simnet OWNER dcrdex;
   126  ```
   127  
   128  ### Start dcrdex
   129  
   130  Start `dcrdex` for simnet, with trace-level logging, and the `dcrdex_simnet` PostgreSQL database created [above](#prepare-the-postgresql-db):
   131  
   132  ```sh
   133  ./dcrdex -d trace --simnet --pgdbname=dcrdex_simnet
   134  ```
   135  
   136  Note that the registration fee xpub, amount, and required confirmations are set in markets.json now.
   137  
   138  ## Wallet (`bisonw`) Setup
   139  
   140  ### The wallet config files for bisonw
   141  
   142  Bitcoin:
   143  
   144  - Config file: `~/dextest/btc/alpha/alpha.conf` or `~/dextest/btc/beta/beta.conf` (also applies the gamma wallet process), but you could want to create for example `~/.dexc/btc-simnet-w.conf` file and select that during wallet setup below.
   145  - Account/wallet: For the alpha node's wallet, "" (empty string) or "gamma". For the beta node's wallet, "" (empty string) or "delta".
   146  - Wallet password: "abc"
   147  
   148  Decred:
   149  
   150  - Config file: `~/dextest/dcr/alpha/alpha.conf` or `~/dextest/dcr/beta/beta.conf`, but you might want to create `~/.dexc/dcr-simnet-w.conf`.
   151  - Account: default
   152  - Wallet password: "abc"
   153  
   154  ### Start `bisonw`
   155  
   156  Clear any existing wallet simnet files from previous setups:
   157  
   158  ```sh
   159  rm -fr ~/.dexc/simnet/
   160  ```
   161  
   162  Start `bisonw` with the web UI and RPC server in simnet mode and trace level logging. IMPORTANT: On the `release-0.1` branch you should also specify different HTTP and RPC listen addresses (e.g. To change the RPC port to 6757, and the HTTP IP address to 127.0.0.3: `--rpcaddr=localhost:6757 --webaddr=127.0.0.3:5758`). The following command does not change these, so modify it as necessary:
   163  
   164  ```sh
   165  ./bisonw --simnet --rpc --log=trace
   166  ```
   167  
   168  The wallet can be configured [via the browser interface](#setup-the-wallet-via-the-browser-interface) or with bwctl on the command line.
   169  
   170  ### Setup the wallet via the browser interface
   171  
   172  In a browser, navigate to <http://127.0.0.3:5758/> (or whatever bisonw was configured to use with `--webaddr`), and be sure JavaScript is
   173  enabled. This should redirect to <http://127.0.0.3:5758/register.>
   174  
   175  1. Setup the app pass.
   176  2. Configure the DCR wallet (default, abc, /home/jon/dextest/dcr/alpha/w-alpha.conf, app pass from 1.).
   177  3. In the next step, specify the server address `localhost:17273` (for the harness, or whatever you manually configured dcrdex to use). Upload the TLS certificate from `~/dextest/dcrdex/rpc.cert` (for the dcrdex harness) or if running the server manually `~/.dcrdex/rpc.cert`.
   178  4. Pay fee (type in app pass to authorize payment from DCR wallet).
   179  5. If auto-mining is not setup, mine a few blocks on Decred simnet. How many depends on the `regfeeconfirms` setting used with `dcrdex.
   180  
   181      ```none
   182      ~/dextest/dcr/harness-ctl $ ./mine-alpha 1 # mine one block
   183      ```
   184  
   185  6. Place a couple orders that match.
   186  7. Mine a few blocks on each chain, alternating chains. How many depends on the `"swapConf"` values in markets.json.
   187  
   188  ### Setup the wallet via bwctl
   189  
   190  IMPORTANT: The example `bwctl` commands in this section use the `--simnet` flag to change the default bisonw ports to which it will attempt to connect.  On the `release-0.1` branch where this is not supported, you will need to specify the `-a, --rpcaddr=` option to match bisonw. For example, if bisonw was started with `--rpcaddr=localhost:6757`, then `bwctl` would need to use `--rpcaddr=localhost:6757` as well.
   191  
   192  If this is the first time starting `bisonw`, the application must be initialized with a new "app password".
   193  For example, initializing with the password "asdf":
   194  
   195  ```none
   196  $  ./bwctl --simnet -u u -P p init
   197  Set new app password:  <asdf>
   198  app initialized
   199  ```
   200  
   201  Setting up a Decred wallet (DCR coin ID is 42):
   202  
   203  ```none
   204  $  ./bwctl --simnet -u u -P p newwallet 42 ~/dextest/dcr/alpha/alpha.conf '{"account":"default"}'
   205  App password:       <asdf>
   206  Wallet password:    <abc>
   207  dcr wallet created and unlocked
   208  ```
   209  
   210  The `bw` console should log something similar to the following:
   211  
   212  ```none
   213  [INF] CORE: Created dcr wallet. Account "default" balance available = 5227016557638 / locked = 0, Deposit address = SsfWraUBDUtU2dKAhBAYcb8HVTEupAnj9ta
   214  [INF] CORE: Connected to and unlocked dcr wallet. Account "default" balance available = 5227016557638 / locked = 0, Deposit address = SsfWraUBDUtU2dKAhBAYcb8HVTEupAnj9ta
   215  ```
   216  
   217  Setting up a Bitcoin wallet (BT coin ID is 0):
   218  
   219  ```none
   220  $  ./bwctl --simnet -u u -P p newwallet 0 ~/dextest/btc/alpha/alpha.conf '{"walletname":"gamma"}'
   221  App password:      <asdf>
   222  Wallet password:   <abc>
   223  btc wallet created and unlocked
   224  ```
   225  
   226  Note that Bitcoin's coin ID is always 0, even on testnet and simnet. Do not use coin ID 1 for BTC testnet.
   227  
   228  Now both Decred and Bitcoin wallets are available. Query their status with the `wallets` command:
   229  
   230  ```none
   231  $  ./bwctl --simnet -u u -P p wallets
   232  [
   233    {
   234      "symbol": "dcr",
   235      "assetID": 42,
   236      "open": true,
   237      "running": true,
   238      "updated": 0,
   239      "balance": 5227016557638,
   240      "address": "SsfWraUBDUtU2dKAhBAYcb8HVTEupAnj9ta",
   241      "feerate": 10,
   242      "units": "atoms"
   243    },
   244    {
   245      "symbol": "btc",
   246      "assetID": 0,
   247      "open": true,
   248      "running": true,
   249      "updated": 0,
   250      "balance": 8400000000,
   251      "address": "mig9X7iDprqwnDMR6FyakQpdJo18u7PCLq",
   252      "feerate": 2,
   253      "units": "Satoshis"
   254    }
   255  ]
   256  ```
   257  
   258  Now that a Decred wallet is configured, you can register with a DEX server.  First query for the registration fee with the `getfee` command:
   259  
   260  ```none
   261  $  ./bwctl --simnet -u u -P p getfee "http://127.0.0.1:7232" ~/.dcrdex/rpc.cert 
   262  {
   263    "fee": 100000000
   264  }
   265  ```
   266  
   267  Note that the fee is in atoms, the smallest unit of value in Decred, where 1 DCR == 1e8 atoms.
   268  
   269  If the fee is acceptable, use the `register` command to pay the fee:
   270  
   271  ```none
   272  $  ./bwctl --simnet -u u -P p register "http://127.0.0.1:7232" 100000000 ~/.dcrdex/rpc.cert 
   273  App password:    <asdf>
   274  the DEX fee of 100000000 has been paid
   275  ```
   276  
   277  After the required number of confirmations, the newly created account will be able to trade on that DEX server.
   278  During this process, `bisonw` should log messages similar to the following:
   279  
   280  ```none
   281  [INF] CORE: Connected to DEX http://127.0.0.1:17273 and listening for messages.
   282  [INF] CORE: Attempting registration fee payment for SsfWraUBDUtU2dKAhBAYcb8HVTEupAnj9ta of 100000000 units of dcr
   283  [DBG] CORE[dcr]: 1 signature cycles to converge on fees for tx 4992afa0eaa92bfe82f977466c28fa9cc944c32f43ddad8d7e8c8329e62daa2f
   284  [INF] CORE: notify: |SUCCESS| (fee payment) Fee paid - Waiting for 1 confirmations before trading at http://127.0.0.1:7232
   285  ...
   286  [TRC] CORE: processing tip change for dcr
   287  [DBG] CORE: Registration fee txn 326661613264653632393833386337653864616464643433326663333434633939636661323836633436373766393832666532626139656161306166393234393030303030303030 now has 1 confirmations.
   288  [DBG] CORE: Notifying dex http://127.0.0.1:17273 of fee payment.
   289  [DBG] CORE: authenticated connection to http://127.0.0.1:17273
   290  [INF] CORE: notify: |SUCCESS| (fee payment) Account registered - You may now trade at http://127.0.0.1:17273
   291  ```
   292  
   293  For rapid setup, there is a script at `[repo root]/client/cmd/bwctl/simnet-setup.sh` that has a reasonable default. You may also use this script as a template.
   294  
   295  ### Acquire DCR and BTC Simnet Funds
   296  
   297  You can generate a deposit address for your wallet through the wallets view in the
   298  wallet.
   299  
   300  Take the generated address to it's respective harness terminal and send funds to it using:
   301  
   302  `./alpha sendtoaddress {address} {amount}`
   303  
   304  Note: If you're using an `SPV` wallet, run `./mine-alpha 1` after sending or the SPV wallets won't see it.