From d3d0682dd3d5743048430b296f534a93033689e1 Mon Sep 17 00:00:00 2001 From: Calvin Kim Date: Thu, 12 Oct 2023 15:24:42 +0900 Subject: [PATCH 1/2] integration: add test to check prune status Adds a check to make sure that prune status on getblockchaininfo returns true for pruned nodes. --- integration/prune_test.go | 41 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 integration/prune_test.go diff --git a/integration/prune_test.go b/integration/prune_test.go new file mode 100644 index 00000000..884862ff --- /dev/null +++ b/integration/prune_test.go @@ -0,0 +1,41 @@ +// Copyright (c) 2023 The btcsuite 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 integration + +import ( + "testing" + + "github.com/btcsuite/btcd/chaincfg" + "github.com/btcsuite/btcd/integration/rpctest" +) + +func TestPrune(t *testing.T) { + t.Parallel() + + // Boilerplate code to make a pruned node. + btcdCfg := []string{"--prune=1536"} + r, err := rpctest.New(&chaincfg.SimNetParams, nil, btcdCfg, "") + if err != nil { + t.Fatal("unable to create primary harness: ", err) + } + if err := r.SetUp(false, 0); err != nil { + t.Fatalf("unable to setup chain: %v", err) + } + defer r.TearDown() + + // Check that the rpc call for block chain info comes back correctly. + chainInfo, err := r.Client.GetBlockChainInfo() + if err != nil { + t.Fatalf("unable to query for chain info: %v", err) + } + if !chainInfo.Pruned { + t.Fatalf("expected the node to be pruned but the pruned "+ + "boolean was %v", chainInfo.Pruned) + } +} From 520d45e3b19c3533a946fbb6ef1761d496eb6b59 Mon Sep 17 00:00:00 2001 From: Calvin Kim Date: Mon, 16 Oct 2023 16:34:49 +0900 Subject: [PATCH 2/2] fixup! integration: add test to check prune status --- integration/prune_test.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/integration/prune_test.go b/integration/prune_test.go index 884862ff..ac363cb8 100644 --- a/integration/prune_test.go +++ b/integration/prune_test.go @@ -13,6 +13,7 @@ import ( "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/integration/rpctest" + "github.com/stretchr/testify/require" ) func TestPrune(t *testing.T) { @@ -21,19 +22,17 @@ func TestPrune(t *testing.T) { // Boilerplate code to make a pruned node. btcdCfg := []string{"--prune=1536"} r, err := rpctest.New(&chaincfg.SimNetParams, nil, btcdCfg, "") - if err != nil { - t.Fatal("unable to create primary harness: ", err) - } + require.NoError(t, err) + if err := r.SetUp(false, 0); err != nil { - t.Fatalf("unable to setup chain: %v", err) + require.NoError(t, err) } - defer r.TearDown() + t.Cleanup(func() { r.TearDown() }) // Check that the rpc call for block chain info comes back correctly. chainInfo, err := r.Client.GetBlockChainInfo() - if err != nil { - t.Fatalf("unable to query for chain info: %v", err) - } + require.NoError(t, err) + if !chainInfo.Pruned { t.Fatalf("expected the node to be pruned but the pruned "+ "boolean was %v", chainInfo.Pruned)