Skip to content

Commit

Permalink
pass core harness tests
Browse files Browse the repository at this point in the history
  • Loading branch information
buck54321 committed Jun 11, 2022
1 parent 6bab295 commit ccf546d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 18 deletions.
13 changes: 11 additions & 2 deletions client/cmd/simnet-trade-tests/run
Expand Up @@ -14,7 +14,7 @@ case $1 in
;;

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

Expand All @@ -31,20 +31,25 @@ case $1 in
./simnet-trade-tests --base1node trading1 --base2node trading2 --quote eth ${@:2}
;;

zecbtc)
./simnet-trade-tests --base zec --quote btc --regasset btc ${@: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.
The following pre-configured tests are available. Be sure to run the appropriate harnesses before starting 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
zecbtc - RPC wallets on ZEC-BTC market
---------------------
Expand All @@ -55,6 +60,10 @@ EOF
./simnet-trade-tests --list
;;

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

*)
echo -n "unknown program"
;;
Expand Down
43 changes: 29 additions & 14 deletions client/core/simnet_trade.go
@@ -1,4 +1,4 @@
//go:build harness && lgpl
// go:build harness && lgpl

package core

Expand Down Expand Up @@ -42,6 +42,7 @@ import (
"decred.org/dcrdex/client/asset/doge"
"decred.org/dcrdex/client/asset/eth"
"decred.org/dcrdex/client/asset/ltc"
"decred.org/dcrdex/client/asset/zec"
"decred.org/dcrdex/client/comms"
"decred.org/dcrdex/client/db"
"decred.org/dcrdex/dex"
Expand Down Expand Up @@ -89,11 +90,17 @@ var testLookup = map[string]func(s *simulationTest) error{
}

func SimTests() []string {
tests := make([]string, 0, len(testLookup))
for name := range testLookup {
tests = append(tests, name)
// Use this slice instead of the generating from the testLookup map so that
// the order doesn't change.
return []string{
"success",
"nomakerswap",
"notakerswap",
"nomakerredeem",
"makerghost",
"orderstatus",
"resendpending",
}
return tests
}

// SimulationConfig is the test configuration.
Expand Down Expand Up @@ -294,6 +301,11 @@ func (s *simulationTest) startClients() error {
}

mktCfg := dc.marketConfig(s.marketName)

if mktCfg == nil {
return fmt.Errorf("market %s not found", s.marketName)
}

s.lotSize = mktCfg.LotSize
s.rateStep = mktCfg.RateStep

Expand Down Expand Up @@ -512,7 +524,7 @@ func testOrderStatusReconciliation(s *simulationTest) error {
// will always be partially matched (3*lotSize matched or
// 1*lotSize matched, if Order 2 is matched first).
waiter.Go(func() error {
_, err := s.placeOrder(s.client1, 3*s.rateStep, rate, false)
_, err := s.placeOrder(s.client1, 3*s.lotSize, rate, false)
if err != nil {
return fmt.Errorf("client 1 place order error: %v", err)
}
Expand Down Expand Up @@ -1383,7 +1395,7 @@ func newHarnessCtrl(assetID uint32) *harnessCtrl {
blockMultiplier uint32 = 1
)
switch assetID {
case dcr.BipID, btc.BipID, ltc.BipID, bch.BipID, doge.BipID:
case dcr.BipID, btc.BipID, ltc.BipID, bch.BipID, doge.BipID, zec.BipID:
case eth.BipID:
// Sending with values of .1 eth.
fundStr = `attach_--exec personal.sendTransaction({from:eth.accounts[1],to:"%s",gasPrice:200e9,value:%de17},"abc")`
Expand Down Expand Up @@ -1449,15 +1461,12 @@ func btcCloneWallet(assetID uint32, useSPV bool, node string, rpcWalletType stri

parentNode := node
pass := []byte("abc")
switch node {
case "gamma":
pass = nil
case "delta":
if node == "gamma" || node == "delta" || assetID == zec.BipID {
pass = nil
}

switch assetID {
case doge.BipID: // , zec.BipID:
case doge.BipID, zec.BipID:
// dogecoind doesn't support > 1 wallet, so gamma and delta
// have their own nodes.
default:
Expand Down Expand Up @@ -1489,6 +1498,10 @@ func dogeWallet(node string) (*tWallet, error) {
return btcCloneWallet(doge.BipID, false, node, "dogecoindRPC")
}

func zecWallet(node string) (*tWallet, error) {
return btcCloneWallet(zec.BipID, false, node, "zcashdRPC")
}

func (s *simulationTest) newClient(name string, cl *SimClient) (*simulationClient, error) {
wallets := make(map[uint32]*tWallet, 2)
addWallet := func(assetID uint32, useSPV bool, node string) error {
Expand All @@ -1509,6 +1522,8 @@ func (s *simulationTest) newClient(name string, cl *SimClient) (*simulationClien
tw, err = bchWallet(useSPV, node)
case doge.BipID:
tw, err = dogeWallet(node)
case zec.BipID:
tw, err = zecWallet(node)
default:
return fmt.Errorf("no method to create wallet for asset %d", assetID)
}
Expand Down Expand Up @@ -1736,8 +1751,8 @@ func (s *simulationTest) placeOrder(client *simulationClient, qty, rate uint64,

r := calc.ConventionalRateAlt(rate, s.base.conversionFactor, s.quote.conversionFactor)

client.log.Infof("placed order %sing %s %s at %s %s (%s)", sellString(client.isSeller),
s.base.valFmt(qty), s.base.symbol, r, s.quote.symbol, ord.ID[:8])
client.log.Infof("placed order %sing %s %s at %f %s/%s (%s)", sellString(client.isSeller),
s.base.valFmt(qty), s.base.symbol, r, s.quote.symbol, s.base.symbol, ord.ID[:8])
return ord.ID.String(), nil
}

Expand Down
4 changes: 2 additions & 2 deletions dex/testing/zec/harness.sh
Expand Up @@ -307,8 +307,8 @@ DELTA_ADDR=`./delta getnewaddress`
GAMMA_ADDR=`./gamma getnewaddress`

# Send the lazy wallets some dough.
echo "Sending 84 ZEC to beta in 8 blocks"
for i in 10 18 5 7 1 15 3 25
echo "Sending 174 ZEC to beta in 8 blocks"
for i in 100 18 5 7 1 15 3 25
do
tmux send-keys -t $SESSION:4 "./alpha sendtoaddress ${BETA_ADDR} ${i}${DONE}" C-m\; ${WAIT}
tmux send-keys -t $SESSION:4 "./alpha sendtoaddress ${DELTA_ADDR} ${i}${DONE}" C-m\; ${WAIT}
Expand Down

0 comments on commit ccf546d

Please sign in to comment.