Skip to content

Commit

Permalink
move all params_tests to dex/networks
Browse files Browse the repository at this point in the history
  • Loading branch information
chappjc committed Jan 19, 2023
1 parent 5cb7904 commit c960d55
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 34 deletions.
11 changes: 5 additions & 6 deletions server/asset/bch/bch_test.go → dex/networks/bch/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import (
"encoding/hex"
"testing"

dexbch "decred.org/dcrdex/dex/networks/bch"
"decred.org/dcrdex/server/asset/btc"
btctest "decred.org/dcrdex/dex/networks/btc/test"
)

func TestCompatibility(t *testing.T) {
Expand All @@ -18,24 +17,24 @@ func TestCompatibility(t *testing.T) {
}

// 2b381efec176b72da70e894a6dbba1fc1ba18a1d573af898e6f92915c0ca8209:1
p2pkhAddr, err := dexbch.DecodeCashAddress("bitcoincash:qznf2drgsapgsejd95yp9nw0qzhw9mrcxsez7d78uv", dexbch.MainNetParams)
p2pkhAddr, err := DecodeCashAddress("bitcoincash:qznf2drgsapgsejd95yp9nw0qzhw9mrcxsez7d78uv", MainNetParams)
if err != nil {
t.Fatalf("error p2pkh decoding CashAddr address: %v", err)
}

// b63e8090fe7140328d5d6ecdd6045b123e3f05742d9a749f2550fba7d0a6879f:1
p2shAddr, err := dexbch.DecodeCashAddress("bitcoincash:pqugctqhj096cufywe32rktfu5dpmnnrjgsznuudl2", dexbch.MainNetParams)
p2shAddr, err := DecodeCashAddress("bitcoincash:pqugctqhj096cufywe32rktfu5dpmnnrjgsznuudl2", MainNetParams)
if err != nil {
t.Fatalf("error decoding p2sh CashAddr address: %v", err)
}

// These scripts and addresses are just copy-pasted from random
// getrawtransaction output.
items := &btc.CompatibilityItems{
items := &btctest.CompatibilityItems{
P2PKHScript: fromHex("76a914a6953468874288664d2d0812cdcf00aee2ec783488ac"),
PKHAddr: p2pkhAddr.String(),
P2SHScript: fromHex("a914388c2c1793cbac71247662a1d969e51a1dce639287"),
SHAddr: p2shAddr.String(),
}
btc.CompatibilityCheck(items, dexbch.MainNetParams, t)
btctest.CompatibilityCheck(t, items, MainNetParams)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import (
"encoding/hex"
"testing"

dexdoge "decred.org/dcrdex/dex/networks/doge"
"decred.org/dcrdex/server/asset/btc"
btctest "decred.org/dcrdex/dex/networks/btc/test"
)

func TestCompatibility(t *testing.T) {
Expand All @@ -18,11 +17,11 @@ func TestCompatibility(t *testing.T) {
}
// These scripts and addresses are just copy-pasted from random
// getrawtransaction output.
items := &btc.CompatibilityItems{
items := &btctest.CompatibilityItems{
P2PKHScript: fromHex("76a914f8f0813eb71c0c5c0a8677b6e8f1e4bb870935fc88ac"),
PKHAddr: "DTqNEQLjhn2hf8vK46py9nDohkci2BeAt1",
P2SHScript: fromHex("a9140aa26a002d22f88c1f83d35298dc64769fe6e81a87"),
SHAddr: "9sQVz2zRbhCAMdXb4NtoLRYzi84qAkGD5r",
}
btc.CompatibilityCheck(items, dexdoge.MainNetParams, t)
btctest.CompatibilityCheck(t, items, MainNetParams)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import (
"encoding/hex"
"testing"

dexltc "decred.org/dcrdex/dex/networks/ltc"
"decred.org/dcrdex/server/asset/btc"
btctest "decred.org/dcrdex/dex/networks/btc/test"
)

func TestCompatibility(t *testing.T) {
Expand All @@ -18,7 +17,7 @@ func TestCompatibility(t *testing.T) {
}
// These scripts and addresses are just copy-pasted from random
// getrawtransaction output.
items := &btc.CompatibilityItems{
items := &btctest.CompatibilityItems{
P2PKHScript: fromHex("76a9146e137cab355e7a35d7546470dc6db403b7bd47ea88ac"),
PKHAddr: "LVFywJ1DHYbN2uYjWNCJGcLJJhL3boaiSy",
P2WPKHScript: fromHex("00144820955c5ecf2fd7a0864d8ae7572f17b1e8fb91"),
Expand All @@ -28,5 +27,5 @@ func TestCompatibility(t *testing.T) {
P2WSHScript: fromHex("0020adb044cf4da15506e73c6d3928737229e64227f29cd86dcc34b7353c1f5560eb"),
WSHAddr: "ltc1q4kcyfn6d592sdeeud5ujsumj98nyyfljnnvxmnp5ku6nc864vr4sawj2gw",
}
btc.CompatibilityCheck(items, dexltc.MainNetParams, t)
btctest.CompatibilityCheck(t, items, MainNetParams)
}
13 changes: 5 additions & 8 deletions server/asset/zec/zec_test.go → dex/networks/zec/params_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
//go:build !zeclive

package zec

import (
"encoding/hex"
"testing"

dexzec "decred.org/dcrdex/dex/networks/zec"
"decred.org/dcrdex/server/asset/btc"
btctest "decred.org/dcrdex/dex/networks/btc/test"
)

func TestCompatibility(t *testing.T) {
Expand All @@ -20,22 +17,22 @@ func TestCompatibility(t *testing.T) {
}

pkhAddr := "t1SqYLhzHyGoWwatRNGrTt4ueqivKdJpFY4"
btcPkhAddr, err := dexzec.DecodeAddress(pkhAddr, dexzec.MainNetAddressParams, dexzec.MainNetParams)
btcPkhAddr, err := DecodeAddress(pkhAddr, MainNetAddressParams, MainNetParams)
if err != nil {
t.Fatalf("error decoding p2pkh address: %v", err)
}

shAddr := "t3ZJCdehVh9MTm6BaKWZmWy5Hsw7PhJxmTc"
btcShAddr, err := dexzec.DecodeAddress(shAddr, dexzec.MainNetAddressParams, dexzec.MainNetParams)
btcShAddr, err := DecodeAddress(shAddr, MainNetAddressParams, MainNetParams)
if err != nil {
t.Fatalf("error decoding p2sh address: %v", err)
}

items := &btc.CompatibilityItems{
items := &btctest.CompatibilityItems{
P2PKHScript: fromHex("76a91462553d6a85afe7753cbe8dc57c7f34f6a8efd79f88ac"),
PKHAddr: btcPkhAddr.String(),
P2SHScript: fromHex("a914a19f5d7d23bbbff0695363f932c8d67c0169963f87"),
SHAddr: btcShAddr.String(),
}
btc.CompatibilityCheck(items, dexzec.MainNetParams, t)
btctest.CompatibilityCheck(t, items, MainNetParams)
}
12 changes: 0 additions & 12 deletions server/asset/btc/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import (
"testing"

dexbtc "decred.org/dcrdex/dex/networks/btc"
btctest "decred.org/dcrdex/dex/networks/btc/test"
"decred.org/dcrdex/server/asset"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/txscript"
)
Expand Down Expand Up @@ -380,16 +378,6 @@ func isEscrowScript(script []byte) bool {
return false
}

// CompatibilityItems is an alias for the type in dex/networks/btc/test, which
// should be used instead of this type to test a clone's chain parameters.
type CompatibilityItems = btctest.CompatibilityItems

// CompatibilityCheck is an alias for the type in dex/networks/btc/test, which
// should be used instead of this type to test a clone's chain parameters.
func CompatibilityCheck(items *CompatibilityItems, chainParams *chaincfg.Params, t *testing.T) {
btctest.CompatibilityCheck(t, items, chainParams)
}

func TestMedianFees(btc *Backend, t *testing.T) {
// The easy way.
medianFees, err := btc.node.medianFeeRate()
Expand Down

0 comments on commit c960d55

Please sign in to comment.