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

Added tests for FutureGetBestBlockHashResult.Receive #2048

Merged
merged 1 commit into from
Nov 2, 2023
Merged
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
Added tests for FutureGetBestBlockHashResult.Receive
  • Loading branch information
ClaytonNorthey92 committed Oct 26, 2023
commit 74360900696e776d13b00bdac33a92f69398c854
41 changes: 40 additions & 1 deletion rpcclient/chain_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package rpcclient

import "testing"
import (
"errors"
"testing"
)

// TestUnmarshalGetBlockChainInfoResult ensures that the SoftForks and
// UnifiedSoftForks fields of GetBlockChainInfoResult are properly unmarshaled
Expand Down Expand Up @@ -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)
}
}
Loading