Skip to content
Open
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
36 changes: 36 additions & 0 deletions integration/rpcserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ package integration

import (
"bytes"
"encoding/json"
"fmt"
"os"
"runtime/debug"
"testing"
"time"

"github.com/btcsuite/btcd/blockchain"
"github.com/btcsuite/btcd/btcjson"
"github.com/btcsuite/btcd/chaincfg/v2"
"github.com/btcsuite/btcd/chainhash/v2"
"github.com/btcsuite/btcd/integration/rpctest"
Expand Down Expand Up @@ -99,6 +101,39 @@ func testGetBlockHash(r *rpctest.Harness, t *testing.T) {
}
}

func testGetBlockNullVerbosity(r *rpctest.Harness, t *testing.T) {
hash, err := r.Client.GetBestBlockHash()
if err != nil {
t.Fatalf("Unable to get best block hash: %v", err)
}

hashJSON, err := json.Marshal(hash.String())
if err != nil {
t.Fatalf("Unable to marshal block hash: %v", err)
}

resultJSON, err := r.Client.RawRequest(
"getblock", []json.RawMessage{
hashJSON, json.RawMessage("null"),
},
)
if err != nil {
t.Fatalf("Unable to get block with null verbosity: %v", err)
}

var result btcjson.GetBlockVerboseResult
if err := json.Unmarshal(resultJSON, &result); err != nil {
t.Fatalf("Unable to unmarshal verbose block result: %v", err)
}
if result.Hash != hash.String() {
t.Fatalf("Block hashes do not match. Got %v, wanted %v",
result.Hash, hash)
}
if len(result.Tx) == 0 {
t.Fatal("Verbose block result contains no transactions")
}
}

func testBulkClient(r *rpctest.Harness, t *testing.T) {
// Create a new block connecting to the current tip.
generatedBlockHashes, err := r.Client.Generate(20)
Expand Down Expand Up @@ -293,6 +328,7 @@ var rpcTestCases = []rpctest.HarnessTestCase{
testGetBestBlock,
testGetBlockCount,
testGetBlockHash,
testGetBlockNullVerbosity,
testBulkClient,
testGetNetworkHashPS,
testGetNetworkHashPS2,
Expand Down
Loading