Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utility for running core harness tests #1632

Merged
merged 5 commits into from
Jun 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ node_modules/
client/cmd/dexc/dexc
client/cmd/dexcctl/dexcctl
client/cmd/assetseed/assetseed
client/cmd/simnet-trade-tests/simnet-trade-tests
docs/examples/rpcclient/rpcclient
wiki
dex/testing/loadbot/loadbot
Expand Down
92 changes: 92 additions & 0 deletions client/cmd/simnet-trade-tests/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
//go:build harness && lgpl

package main

import (
"flag"
"fmt"

"decred.org/dcrdex/client/core"
"decred.org/dcrdex/dex"
)

func main() {
var baseSymbol, quoteSymbol, base1Node, quote1Node, base2Node, quote2Node, regAsset string
var base1SPV, quote1SPV, base2SPV, quote2SPV, debug, trace, list bool
var tests flagArray
flag.Var(&tests, "t", "the test(s) to run. multiple --t flags OK")
flag.StringVar(&baseSymbol, "base", "dcr", "the bot program to run")
flag.StringVar(&quoteSymbol, "quote", "btc", "the bot program to run")
flag.StringVar(&base1Node, "base1node", "beta", "the harness node to connect to for the first client's base asset. only RPC wallets")
flag.StringVar(&quote1Node, "quote1node", "beta", "the harness node to connect to for the first client's quote asset. only RPC wallets")
flag.StringVar(&base2Node, "base2node", "gamma", "the harness node to connect to for the second client's base asset. only RPC wallets")
flag.StringVar(&quote2Node, "quote2node", "gamma", "the harness node to connect to for the second client's quote asset. only RPC wallets")
flag.StringVar(&regAsset, "regasset", "", "the asset to use for registration. default is base asset")
flag.BoolVar(&base1SPV, "base1spv", false, "use SPV wallet for the first client's base asset")
flag.BoolVar(&quote1SPV, "quote1spv", false, "use SPV wallet for the first client's quote asset")
flag.BoolVar(&base2SPV, "base2spv", false, "use SPV wallet for the second client's base asset")
flag.BoolVar(&quote2SPV, "quote2spv", false, "use SPV wallet for the second client's quote asset")
flag.BoolVar(&list, "list", false, "list available tests")
flag.BoolVar(&debug, "debug", false, "log at logging level debug")
flag.BoolVar(&trace, "trace", false, "log at logging level trace")
flag.Parse()

if list {
for _, s := range core.SimTests() {
fmt.Println(s)
}
return
}

logLevel := dex.LevelInfo
switch {
case trace:
logLevel = dex.LevelTrace
case debug:
logLevel = dex.LevelDebug
}

if len(tests) == 0 {
tests = []string{"success"}
}

if regAsset == "" {
regAsset = baseSymbol
}

err := core.RunSimulationTest(&core.SimulationConfig{
BaseSymbol: baseSymbol,
QuoteSymbol: quoteSymbol,
RegistrationAsset: regAsset,
Client1: &core.SimClient{
BaseSPV: base1SPV,
QuoteSPV: quote1SPV,
BaseNode: base1Node,
QuoteNode: quote1Node,
},
Client2: &core.SimClient{
BaseSPV: base2SPV,
QuoteSPV: quote2SPV,
BaseNode: base2Node,
QuoteNode: quote2Node,
},
Tests: tests,
Logger: dex.StdOutLogger("T", logLevel),
})
if err != nil {
fmt.Println("ERROR:", err)
} else {
fmt.Println("SUCCESS!")
}
}

type flagArray []string

func (f *flagArray) String() string {
return "my string representation"
}

func (f *flagArray) Set(value string) error {
*f = append(*f, value)
return nil
}
61 changes: 61 additions & 0 deletions client/cmd/simnet-trade-tests/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file needs the chmod +x. Also can it be named run.sh?

set -e

go build -tags lgpl,harness

case $1 in

dcrbtc)
./simnet-trade-tests --base1node trading1 --base2node trading2 ${@:2}
;;

dcrbtcspv)
./simnet-trade-tests --base1node trading1 --base2node trading2 --quote1spv ${@:2}
;;

bchdcr)
./simnet-trade-tests --base bch --quote dcr --quote1node trading1 --quote2node trading2 \
--regasset dcr ${@:2}
;;

ltcdcr)
./simnet-trade-tests --base ltc --quote dcr --quote1node trading1 --quote2node trading2 \
--regasset dcr ${@:2}
;;

dcrdoge)
./simnet-trade-tests --base1node trading1 --base2node trading2 --quote doge ${@:2}
;;

dcreth)
./simnet-trade-tests --base1node trading1 --base2node trading2 --quote eth ${@:2}
;;

help|--help|-h)
./simnet-trade-tests --help
cat <<EOF

---------------------

The following pre-configured tests are available. Be sure to run the appropriate harnesses before running the dcrdex server harness.

dcrbtc - RPC wallets on DCR-BTC market
dcrbtcspv - Decred RPC wallet and Bitcoin SPV wallet on DCR-BTC market
bchdcr - RPC wallets on BCH-DCR market
ltcdcr - RPC wallets on LTC-DCR market
dcrdoge - RPC wallets on DCR-DOGE market
dcreth - Decred RPC wallet and Ethereum native wallet on DCR-ETH market

---------------------

One or more of the following tests can be run by specifying one or more -t flags. Default is ['success'].

EOF

./simnet-trade-tests --list
;;

*)
echo -n "unknown program"
;;
esac
Loading