Skip to content

Commit

Permalink
tbc: BlockHeadersBest -> BlockHeaderBest in rpc_test
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuasing committed Jun 3, 2024
1 parent a039a52 commit aefa232
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions service/tbc/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"nhooyr.io/websocket"
"nhooyr.io/websocket/wsjson"

"github.com/hemilabs/heminetwork/api"
"github.com/hemilabs/heminetwork/api/protocol"
"github.com/hemilabs/heminetwork/api/tbcapi"
"github.com/hemilabs/heminetwork/bitcoin"
Expand Down Expand Up @@ -259,7 +260,7 @@ func TestBlockHeadersByHeightDoesNotExist(t *testing.T) {
}
}

func TestBlockHeadersBestRaw(t *testing.T) {
func TestBlockHeaderBestRaw(t *testing.T) {
skipIfNoDocker(t)

ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
Expand Down Expand Up @@ -287,15 +288,15 @@ func TestBlockHeadersBestRaw(t *testing.T) {
}

var lastErr error
var response tbcapi.BlockHeadersBestRawResponse
var response tbcapi.BlockHeaderBestRawResponse
for {
select {
case <-time.After(1 * time.Second):
case <-ctx.Done():
t.Fatal(ctx.Err())
}
lastErr = nil
err = tbcapi.Write(ctx, tws.conn, "someid", tbcapi.BlockHeadersBestRawRequest{})
err = tbcapi.Write(ctx, tws.conn, "someid", tbcapi.BlockHeaderBestRawRequest{})
if err != nil {
lastErr = err
continue
Expand All @@ -308,7 +309,7 @@ func TestBlockHeadersBestRaw(t *testing.T) {
continue
}

if v.Header.Command == tbcapi.CmdBlockHeadersBestRawResponse {
if v.Header.Command == tbcapi.CmdBlockHeaderBestRawResponse {
if err := json.Unmarshal(v.Payload, &response); err != nil {
t.Fatal(err)
}
Expand All @@ -322,7 +323,7 @@ func TestBlockHeadersBestRaw(t *testing.T) {
t.Fatal(lastErr)
}

bh, err := bytes2Header(response.BlockHeaders[0])
bh, err := bytes2Header(response.BlockHeader)
if err != nil {
t.Fatal(err)
}
Expand All @@ -335,12 +336,12 @@ func TestBlockHeadersBestRaw(t *testing.T) {

cliBlockHeader := bitcoindBestBlock(ctx, t, bitcoindContainer)
expected := cliBlockHeaderToRaw(t, cliBlockHeader)
if diff := deep.Equal(expected, response.BlockHeaders); len(diff) > 0 {
if diff := deep.Equal(expected, []api.ByteSlice{response.BlockHeader}); len(diff) > 0 {
t.Errorf("unexpected diff: %s", diff)
}
}

func TestBtcBlockHeadersBest(t *testing.T) {
func TestBtcBlockHeaderBest(t *testing.T) {
skipIfNoDocker(t)

ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
Expand Down Expand Up @@ -368,15 +369,15 @@ func TestBtcBlockHeadersBest(t *testing.T) {
}

var lastErr error
var response tbcapi.BlockHeadersBestResponse
var response tbcapi.BlockHeaderBestResponse
for {
select {
case <-time.After(1 * time.Second):
case <-ctx.Done():
t.Fatal(ctx.Err())
}
lastErr = nil
err = tbcapi.Write(ctx, tws.conn, "someid", tbcapi.BlockHeadersBestRequest{})
err = tbcapi.Write(ctx, tws.conn, "someid", tbcapi.BlockHeaderBestRequest{})
if err != nil {
lastErr = err
continue
Expand All @@ -389,7 +390,7 @@ func TestBtcBlockHeadersBest(t *testing.T) {
continue
}

if v.Header.Command == tbcapi.CmdBlockHeadersBestResponse {
if v.Header.Command == tbcapi.CmdBlockHeaderBestResponse {
if err := json.Unmarshal(v.Payload, &response); err != nil {
t.Fatal(err)
}
Expand All @@ -410,7 +411,7 @@ func TestBtcBlockHeadersBest(t *testing.T) {

cliBlockHeader := bitcoindBestBlock(ctx, t, bitcoindContainer)
expected := cliBlockHeaderToTBC(t, cliBlockHeader)
if diff := deep.Equal(expected, response.BlockHeaders); len(diff) > 0 {
if diff := deep.Equal(expected, []*tbcapi.BlockHeader{response.BlockHeader}); len(diff) > 0 {
t.Errorf("unexpected diff: %s", diff)
}
}
Expand Down

0 comments on commit aefa232

Please sign in to comment.