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

multi: Remove rpctest package #3028

Merged
merged 3 commits into from
Nov 30, 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
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ 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
github.com/decred/dcrd/hdkeychain/v3 v3.1.0
github.com/decred/dcrd/lru v1.1.1
github.com/decred/dcrd/math/uint256 v1.0.0
github.com/decred/dcrd/peer/v3 v3.0.0
github.com/decred/dcrd/rpc/jsonrpc/types/v4 v4.0.0
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 All @@ -46,6 +46,7 @@ require (
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412 // indirect
github.com/dchest/siphash v1.2.2 // indirect
github.com/decred/dcrd/dcrec/edwards/v2 v2.0.2 // indirect
github.com/decred/dcrd/hdkeychain/v3 v3.1.0 // indirect
github.com/golang/snappy v0.0.4 // indirect
)

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
23 changes: 23 additions & 0 deletions internal/integration/rpctests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
rpctests
====


[![Build Status](https://github.com/decred/dcrd/workflows/Build%20and%20Test/badge.svg)](https://github.com/decred/dcrd/actions)
[![ISC License](https://img.shields.io/badge/license-ISC-blue.svg)](http://copyfree.org)
[![Doc](https://img.shields.io/badge/doc-reference-blue.svg)](https://pkg.go.dev/github.com/decred/dcrd/internal/integration/rpctests)

Package rpctests provides integration-level tests for dcrd that rely on its RPC
service. The tests in this package exercise features and behaviors of the fully
compiled binary.

Most of the tests in this package are only executed if a corresponding `rpctest`
tag is specified during test execution. For example:

```shell
$ go test -tags rpctest .
```

## License

Package rpctests is licensed under the [copyfree](http://copyfree.org) ISC
License.
146 changes: 146 additions & 0 deletions internal/integration/rpctests/rpcserver_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
// Copyright (c) 2016 The btcsuite developers
// Copyright (c) 2017-2022 The Decred developers

// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

// This file is ignored during the regular tests due to the following build tag.
//go:build rpctest
// +build rpctest

package rpctests

import (
"bytes"
"context"
"testing"

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

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)
}

// Create a new block connecting to the current tip.
generatedBlockHashes, err := r.Node.Generate(ctx, 1)
if err != nil {
t.Fatalf("Unable to generate block: %v", err)
}

bestHash, bestHeight, err := r.Node.GetBestBlock(ctx)
if err != nil {
t.Fatalf("Call to `getbestblock` failed: %v", err)
}

// Hash should be the same as the newly submitted block.
if !bytes.Equal(bestHash[:], generatedBlockHashes[0][:]) {
t.Fatalf("Block hashes do not match. Returned hash %v, wanted "+
"hash %v", bestHash, generatedBlockHashes[0])
}

// Block height should now reflect newest height.
if bestHeight != prevbestHeight+1 {
t.Fatalf("Block heights do not match. Got %v, wanted %v",
bestHeight, prevbestHeight+1)
}
}

func testGetBlockCount(ctx context.Context, r *dcrdtest.Harness, t *testing.T) {
// Save the current count.
currentCount, err := r.Node.GetBlockCount(ctx)
if err != nil {
t.Fatalf("Unable to get block count: %v", err)
}

if _, err := r.Node.Generate(ctx, 1); err != nil {
t.Fatalf("Unable to generate block: %v", err)
}

// Count should have increased by one.
newCount, err := r.Node.GetBlockCount(ctx)
if err != nil {
t.Fatalf("Unable to get block count: %v", err)
}
if newCount != currentCount+1 {
t.Fatalf("Block count incorrect. Got %v should be %v",
newCount, currentCount+1)
}
}

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 {
t.Fatalf("Unable to generate block: %v", err)
}

info, err := r.Node.GetInfo(ctx)
if err != nil {
t.Fatalf("call to getinfo failed: %v", err)
}

blockHash, err := r.Node.GetBlockHash(ctx, info.Blocks)
if err != nil {
t.Fatalf("Call to `getblockhash` failed: %v", err)
}

// Block hashes should match newly created block.
if !bytes.Equal(generatedBlockHashes[0][:], blockHash[:]) {
t.Fatalf("Block hashes do not match. Returned hash %v, wanted "+
"hash %v", blockHash, generatedBlockHashes[0])
}
}

func TestRpcServer(t *testing.T) {
// In order to properly test scenarios on as if we were on mainnet,
// ensure that non-standard transactions aren't accepted into the
// mempool or relayed.
args := []string{"--rejectnonstd"}
harness, err := dcrdtest.New(t, chaincfg.RegNetParams(), nil, args)
if err != nil {
t.Fatalf("unable to create primary harness: %v", err)
}

// Initialize the primary mining node with a chain of length 125,
// providing 25 mature coinbases to allow spending from for testing
// purposes.
ctx := context.Background()
if err := harness.SetUp(ctx, true, 25); err != nil {
// Even though the harness was not fully setup, it still needs
// to be torn down to ensure all resources such as temp
// directories are cleaned up. The error is intentionally
// ignored since this is already an error path and nothing else
// could be done about it anyways.
_ = harness.TearDown()
t.Fatalf("unable to setup test chain: %v", err)
}
defer harness.TearDownInTest(t)

// Test cases.
tests := []struct {
name string
f func(context.Context, *dcrdtest.Harness, *testing.T)
}{
{
f: testGetBestBlock,
name: "testGetBestBlock",
},
{
f: testGetBlockCount,
name: "testGetBlockCount",
},
{
f: testGetBlockHash,
name: "testGetBlockHash",
},
}

for _, test := range tests {
test.f(ctx, harness, t)
t.Logf("=== Running test: %v ===", test.name)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

package rpcserver
// This file is ignored during the regular tests due to the following build tag.
//go:build rpctest
// +build rpctest

package rpctests

import (
"context"
Expand All @@ -22,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 @@ -228,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 @@ -243,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 @@ -261,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
17 changes: 17 additions & 0 deletions internal/integration/rpctests/util_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) 2022 The Decred developers

// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

package rpctests

import "github.com/decred/dcrd/wire"

// newTxOut returns a new transaction output with the given parameters.
func newTxOut(amount int64, pkScriptVer uint16, pkScript []byte) *wire.TxOut {
return &wire.TxOut{
Value: amount,
Version: pkScriptVer,
PkScript: pkScript,
}
}
Loading