Skip to content

Commit

Permalink
rpctests: Switch to dcrtest/dcrdtest package
Browse files Browse the repository at this point in the history
This switches the tests in the rpctests package to use the recently
introduced dcrtest/dcrdtest package.

Given the rpctests package is inside the main dcrd module, the main dcrd
module version is built for use in tests by default.
  • Loading branch information
matheusd committed Nov 29, 2022
1 parent 4021711 commit 82052d2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 40 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
github.com/decred/dcrd/crypto/ripemd160 v1.0.1
github.com/decred/dcrd/database/v3 v3.0.0
github.com/decred/dcrd/dcrec v1.0.0
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0
github.com/decred/dcrd/dcrjson/v4 v4.0.0
github.com/decred/dcrd/dcrutil/v4 v4.0.0
github.com/decred/dcrd/gcs/v4 v4.0.0
Expand All @@ -31,6 +31,7 @@ require (
github.com/decred/dcrd/rpcclient/v8 v8.0.0
github.com/decred/dcrd/txscript/v4 v4.0.0
github.com/decred/dcrd/wire v1.5.0
github.com/decred/dcrtest/dcrdtest v0.0.0-20221125134442-85f922c0880e
github.com/decred/go-socks v1.1.0
github.com/decred/slog v1.2.0
github.com/gorilla/websocket v1.5.0
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ github.com/dchest/siphash v1.2.2/go.mod h1:q+IRvb2gOSrUnYoPqHiyHXS0FOBBOdl6tONBl
github.com/decred/base58 v1.0.3/go.mod h1:pXP9cXCfM2sFLb2viz2FNIdeMWmZDBKG3ZBYbiSM78E=
github.com/decred/base58 v1.0.4 h1:QJC6B0E0rXOPA8U/kw2rP+qiRJsUaE2Er+pYb3siUeA=
github.com/decred/base58 v1.0.4/go.mod h1:jJswKPEdvpFpvf7dsDvFZyLT22xZ9lWqEByX38oGd9E=
github.com/decred/dcrd v1.2.1-0.20221123192607-fc017ce3bb3b/go.mod h1:9MS9DQkbDZGj2yT6znvK4srKr3ZlAm4UTsJTFHgW7Ng=
github.com/decred/dcrd/dcrec/edwards/v2 v2.0.2 h1:bX7rtGTMBDJxujZ29GNqtn7YCAdINjHKnA6J6tBBv6s=
github.com/decred/dcrd/dcrec/edwards/v2 v2.0.2/go.mod h1:d0H8xGMWbiIQP7gN3v2rByWUcuZPm9YsgmnfoxgbINc=
github.com/decred/dcrtest/dcrdtest v0.0.0-20221125134442-85f922c0880e h1:QKtZ4/aNVRzMbW/dllhAiLJhXxswhaGGZgnu5Z9YtiM=
github.com/decred/dcrtest/dcrdtest v0.0.0-20221125134442-85f922c0880e/go.mod h1:9QDaNncc0bWuMeZcbbPhLqUIeE+IBYLAsHio8+2++JI=
github.com/decred/go-socks v1.1.0 h1:dnENcc0KIqQo3HSXdgboXAHgqsCIutkqq6ntQjYtm2U=
github.com/decred/go-socks v1.1.0/go.mod h1:sDhHqkZH0X4JjSa02oYOGhcGHYp12FsY1jQ/meV8md0=
github.com/decred/slog v1.2.0 h1:soHAxV52B54Di3WtKLfPum9OFfWqwtf/ygf9njdfnPM=
Expand Down
40 changes: 7 additions & 33 deletions internal/integration/rpctests/rpcserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@ package rpctests
import (
"bytes"
"context"
"fmt"
"runtime/debug"
"testing"

"github.com/decred/dcrd/chaincfg/v3"
"github.com/decred/dcrd/rpctest"
"github.com/decred/dcrtest/dcrdtest"
)

func testGetBestBlock(ctx context.Context, r *rpctest.Harness, t *testing.T) {
func testGetBestBlock(ctx context.Context, r *dcrdtest.Harness, t *testing.T) {
_, prevbestHeight, err := r.Node.GetBestBlock(ctx)
if err != nil {
t.Fatalf("Call to `getbestblock` failed: %v", err)
Expand Down Expand Up @@ -51,7 +49,7 @@ func testGetBestBlock(ctx context.Context, r *rpctest.Harness, t *testing.T) {
}
}

func testGetBlockCount(ctx context.Context, r *rpctest.Harness, t *testing.T) {
func testGetBlockCount(ctx context.Context, r *dcrdtest.Harness, t *testing.T) {
// Save the current count.
currentCount, err := r.Node.GetBlockCount(ctx)
if err != nil {
Expand All @@ -73,7 +71,7 @@ func testGetBlockCount(ctx context.Context, r *rpctest.Harness, t *testing.T) {
}
}

func testGetBlockHash(ctx context.Context, r *rpctest.Harness, t *testing.T) {
func testGetBlockHash(ctx context.Context, r *dcrdtest.Harness, t *testing.T) {
// Create a new block connecting to the current tip.
generatedBlockHashes, err := r.Node.Generate(ctx, 1)
if err != nil {
Expand Down Expand Up @@ -102,7 +100,7 @@ func TestRpcServer(t *testing.T) {
// ensure that non-standard transactions aren't accepted into the
// mempool or relayed.
args := []string{"--rejectnonstd"}
harness, err := rpctest.New(t, chaincfg.RegNetParams(), nil, args)
harness, err := dcrdtest.New(t, chaincfg.RegNetParams(), nil, args)
if err != nil {
t.Fatalf("unable to create primary harness: %v", err)
}
Expand All @@ -120,34 +118,12 @@ func TestRpcServer(t *testing.T) {
_ = harness.TearDown()
t.Fatalf("unable to setup test chain: %v", err)
}

defer func() {
// Clean up any active harnesses that are still currently
// running.This includes removing all temporary directories,
// and shutting down any created processes.
if err := rpctest.TearDownAll(); err != nil {
t.Fatalf("unable to tear down all harnesses: %v", err)
}
}()

var currentTestNum int
defer func() {
// If one of the integration tests caused a panic within the
// main goroutine, then tear down all the harnesses in order to
// avoid any leaked dcrd processes.
if r := recover(); r != nil {
fmt.Println("recovering from test panic: ", r)
if err := rpctest.TearDownAll(); err != nil {
fmt.Println("unable to tear down all harnesses: ", err)
}
t.Fatalf("test #%v panicked: %s", currentTestNum, debug.Stack())
}
}()
defer harness.TearDownInTest(t)

// Test cases.
tests := []struct {
name string
f func(context.Context, *rpctest.Harness, *testing.T)
f func(context.Context, *dcrdtest.Harness, *testing.T)
}{
{
f: testGetBestBlock,
Expand All @@ -166,7 +142,5 @@ func TestRpcServer(t *testing.T) {
for _, test := range tests {
test.f(ctx, harness, t)
t.Logf("=== Running test: %v ===", test.name)

currentTestNum++
}
}
12 changes: 6 additions & 6 deletions internal/integration/rpctests/treasury_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ import (
"github.com/decred/dcrd/dcrec/secp256k1/v4"
"github.com/decred/dcrd/dcrutil/v4"
"github.com/decred/dcrd/rpcclient/v8"
"github.com/decred/dcrd/rpctest"
"github.com/decred/dcrd/txscript/v4"
"github.com/decred/dcrd/txscript/v4/sign"
"github.com/decred/dcrd/txscript/v4/stdaddr"
"github.com/decred/dcrd/wire"
"github.com/decred/dcrtest/dcrdtest"
)

// timeoutCtx returns a context with the given timeout and automatically calls
Expand Down Expand Up @@ -232,9 +232,9 @@ func TestTreasury(t *testing.T) {
}
}

// Create the rpctest harness and mine outputs for the voting wallet to
// Create the dcrdtest harness and mine outputs for the voting wallet to
// use.
hn, err := rpctest.New(t, net, handlers, extraArgs)
hn, err := dcrdtest.New(t, net, handlers, extraArgs)
if err != nil {
t.Fatal(err)
}
Expand All @@ -247,13 +247,13 @@ func TestTreasury(t *testing.T) {
t.Fatal(err)
}
defer hn.TearDown()
_, err = rpctest.AdjustedSimnetMiner(timeoutCtx(t, time.Minute), hn.Node, 64)
_, err = dcrdtest.AdjustedSimnetMiner(timeoutCtx(t, time.Minute), hn.Node, 64)
if err != nil {
t.Fatal(err)
}

// Create the voting wallet.
vw, err := rpctest.NewVotingWallet(ctx, hn)
vw, err := dcrdtest.NewVotingWallet(ctx, hn)
if err != nil {
t.Fatalf("unable to create voting wallet for test: %v", err)
}
Expand All @@ -265,7 +265,7 @@ func TestTreasury(t *testing.T) {
t.Fatalf("voting wallet errored: %v", vwerr)
})
vw.SetMiner(func(ctx context.Context, nb uint32) ([]*chainhash.Hash, error) {
return rpctest.AdjustedSimnetMiner(ctx, hn.Node, nb)
return dcrdtest.AdjustedSimnetMiner(ctx, hn.Node, nb)
})

// Create a privkey and p2pkh addr we control for use in the tests.
Expand Down

0 comments on commit 82052d2

Please sign in to comment.