From 0c3abbecbb63d4ac11a9bf4e620f460d8d5aaf4c Mon Sep 17 00:00:00 2001 From: Ryan Staudt Date: Wed, 29 Jul 2020 05:34:16 -0500 Subject: [PATCH] rpcserver: Add handleGetCFilterV2 tests. --- internal/rpcserver/rpcserverhandlers_test.go | 55 ++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/internal/rpcserver/rpcserverhandlers_test.go b/internal/rpcserver/rpcserverhandlers_test.go index a3f086ba..6cf8f250 100644 --- a/internal/rpcserver/rpcserverhandlers_test.go +++ b/internal/rpcserver/rpcserverhandlers_test.go @@ -3356,6 +3356,61 @@ func TestHandleGetCFilterHeader(t *testing.T) { }}) } +func TestHandleGetCFilterV2(t *testing.T) { + t.Parallel() + + blkHashString := block432100.BlockHash().String() + filter := hex.EncodeToString(defaultMockFiltererV2().filterByBlockHash.Bytes()) + var noFilterErr blockchain.NoFilterError + testRPCServerHandler(t, []rpcTest{{ + name: "handleGetCFilterV2: ok", + handler: handleGetCFilterV2, + cmd: &types.GetCFilterV2Cmd{ + BlockHash: blkHashString, + }, + result: &types.GetCFilterV2Result{ + BlockHash: blkHashString, + Data: filter, + ProofIndex: blockchain.HeaderCmtFilterIndex, + ProofHashes: nil, + }, + }, { + name: "handleGetCFilterV2: invalid hash", + handler: handleGetCFilterV2, + cmd: &types.GetCFilterV2Cmd{ + BlockHash: "invalid", + }, + wantErr: true, + errCode: dcrjson.ErrRPCDecodeHexString, + }, { + name: "handleGetCFilterV2: block not found", + handler: handleGetCFilterV2, + cmd: &types.GetCFilterV2Cmd{ + BlockHash: blkHashString, + }, + mockFiltererV2: func() *testFiltererV2 { + testFiltererV2 := defaultMockFiltererV2() + testFiltererV2.filterByBlockHashErr = noFilterErr + return testFiltererV2 + }(), + wantErr: true, + errCode: dcrjson.ErrRPCBlockNotFound, + }, { + name: "handleGetCFilterV2: failed to load filter", + handler: handleGetCFilterV2, + cmd: &types.GetCFilterV2Cmd{ + BlockHash: blkHashString, + }, + mockFiltererV2: func() *testFiltererV2 { + testFiltererV2 := defaultMockFiltererV2() + testFiltererV2.filterByBlockHashErr = errors.New("failed to load filter") + return testFiltererV2 + }(), + wantErr: true, + errCode: dcrjson.ErrRPCInternal.Code, + }}) +} + func TestHandleGetChainTips(t *testing.T) { t.Parallel()