From 74360900696e776d13b00bdac33a92f69398c854 Mon Sep 17 00:00:00 2001 From: ClaytonNorthey92 Date: Thu, 26 Oct 2023 09:21:30 -0400 Subject: [PATCH] Added tests for FutureGetBestBlockHashResult.Receive --- rpcclient/chain_test.go | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/rpcclient/chain_test.go b/rpcclient/chain_test.go index e32d547ce3..16344ff9c0 100644 --- a/rpcclient/chain_test.go +++ b/rpcclient/chain_test.go @@ -1,6 +1,9 @@ package rpcclient -import "testing" +import ( + "errors" + "testing" +) // TestUnmarshalGetBlockChainInfoResult ensures that the SoftForks and // UnifiedSoftForks fields of GetBlockChainInfoResult are properly unmarshaled @@ -90,3 +93,39 @@ func TestUnmarshalGetBlockChainInfoResultSoftForks(t *testing.T) { } } } + +func TestFutureGetBlockCountResultReceiveErrors(t *testing.T) { + responseChan := FutureGetBlockCountResult(make(chan *Response)) + response := Response{ + result: []byte{}, + err: errors.New("blah blah something bad happened"), + } + go func() { + responseChan <- &response + }() + + _, err := responseChan.Receive() + if err == nil || err.Error() != "blah blah something bad happened" { + t.Fatalf("unexpected error: %s", err.Error()) + } +} + +func TestFutureGetBlockCountResultReceiveMarshalsResponseCorrectly(t *testing.T) { + responseChan := FutureGetBlockCountResult(make(chan *Response)) + response := Response{ + result: []byte{0x36, 0x36}, + err: nil, + } + go func() { + responseChan <- &response + }() + + res, err := responseChan.Receive() + if err != nil { + t.Fatalf("unexpected error: %s", err.Error()) + } + + if res != 66 { + t.Fatalf("unexpected response: %d (0x%X)", res, res) + } +}