Skip to content

Commit

Permalink
updated indexing in tests to use best block + hash
Browse files Browse the repository at this point in the history
  • Loading branch information
ClaytonNorthey92 committed Jun 21, 2024
1 parent 77b53e7 commit a2affc7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 54 deletions.
84 changes: 30 additions & 54 deletions service/tbc/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,12 +557,7 @@ func TestBalanceByAddress(t *testing.T) {
case <-ctx.Done():
t.Fatal(ctx.Err())
}
// err = tbcServer.UtxoIndexer(ctx, 0, 1000)
_ = tbcServer
err = fmt.Errorf("fixme clayton")
if err != nil {
t.Fatal(err)
}
indexAll(ctx, t, tbcServer)
lastErr = nil
err = tbcapi.Write(ctx, tws.conn, "someid", tbcapi.BalanceByAddressRequest{
Address: tti.address(),
Expand Down Expand Up @@ -794,12 +789,7 @@ func TestUtxosByAddressRaw(t *testing.T) {
case <-ctx.Done():
t.Fatal(ctx.Err())
}
// err = tbcServer.UtxoIndexer(ctx, 0, 1000)
_ = tbcServer
err = fmt.Errorf("fixme clayton")
if err != nil {
t.Fatal(err)
}
indexAll(ctx, t, tbcServer)
lastErr = nil
err = tbcapi.Write(ctx, tws.conn, "someid", tbcapi.UtxosByAddressRawRequest{
Address: tti.address(),
Expand Down Expand Up @@ -1024,12 +1014,7 @@ func TestUtxosByAddress(t *testing.T) {
case <-ctx.Done():
t.Fatal(ctx.Err())
}
// err = tbcServer.UtxoIndexer(ctx, 0, 1000)
_ = tbcServer
err = fmt.Errorf("fixme clayton")
if err != nil {
t.Fatal(err)
}
indexAll(ctx, t, tbcServer)
lastErr = nil
err = tbcapi.Write(ctx, tws.conn, "someid", tbcapi.UtxosByAddressRequest{
Address: tti.address(),
Expand Down Expand Up @@ -1121,12 +1106,7 @@ func TestTxByIdRaw(t *testing.T) {
case <-ctx.Done():
t.Fatal(ctx.Err())
}
// err = tbcServer.TxIndexer(ctx, 0, 1000)
_ = tbcServer
err = fmt.Errorf("fixme clayton")
if err != nil {
t.Fatal(err)
}
indexAll(ctx, t, tbcServer)
lastErr = nil
txId := getRandomTxId(ctx, t, bitcoindContainer)
txIdBytes, err := hex.DecodeString(txId)
Expand Down Expand Up @@ -1227,12 +1207,7 @@ func TestTxByIdRawInvalid(t *testing.T) {
case <-ctx.Done():
t.Fatal(ctx.Err())
}
// err = tbcServer.TxIndexer(ctx, 0, 1000)
_ = tbcServer
err = fmt.Errorf("fixme clayton")
if err != nil {
t.Fatal(err)
}
indexAll(ctx, t, tbcServer)
lastErr = nil
txId := getRandomTxId(ctx, t, bitcoindContainer)
txIdBytes, err := hex.DecodeString(txId)
Expand Down Expand Up @@ -1342,12 +1317,7 @@ func TestTxByIdRawNotFound(t *testing.T) {
case <-ctx.Done():
t.Fatal(ctx.Err())
}
// err = tbcServer.TxIndexer(ctx, 0, 1000)
_ = tbcServer
err = fmt.Errorf("fixme clayton")
if err != nil {
t.Fatal(err)
}
indexAll(ctx, t, tbcServer)
lastErr = nil
txId := getRandomTxId(ctx, t, bitcoindContainer)
txIdBytes, err := hex.DecodeString(txId)
Expand Down Expand Up @@ -1443,12 +1413,9 @@ func TestTxById(t *testing.T) {
case <-ctx.Done():
t.Fatal(ctx.Err())
}
// err = tbcServer.TxIndexer(ctx, 0, 1000)
_ = tbcServer
err = fmt.Errorf("fixme clayton")
if err != nil {
t.Fatal(err)
}

indexAll(ctx, t, tbcServer)

lastErr = nil
txId := getRandomTxId(ctx, t, bitcoindContainer)
txIdBytes, err := hex.DecodeString(txId)
Expand Down Expand Up @@ -1544,12 +1511,7 @@ func TestTxByIdInvalid(t *testing.T) {
case <-ctx.Done():
t.Fatal(ctx.Err())
}
// err = tbcServer.TxIndexer(ctx, 0, 1000)
_ = tbcServer
err = fmt.Errorf("fixme clayton")
if err != nil {
t.Fatal(err)
}
indexAll(ctx, t, tbcServer)
lastErr = nil
txId := getRandomTxId(ctx, t, bitcoindContainer)
txIdBytes, err := hex.DecodeString(txId)
Expand Down Expand Up @@ -1657,12 +1619,9 @@ func TestTxByIdNotFound(t *testing.T) {
case <-ctx.Done():
t.Fatal(ctx.Err())
}
// err = tbcServer.TxIndexer(ctx, 0, 1000)
_ = tbcServer
err = fmt.Errorf("fixme clayton")
if err != nil {
t.Fatal(err)
}

indexAll(ctx, t, tbcServer)

lastErr = nil
txId := getRandomTxId(ctx, t, bitcoindContainer)
txIdBytes, err := hex.DecodeString(txId)
Expand Down Expand Up @@ -1725,3 +1684,20 @@ func assertPing(ctx context.Context, t *testing.T, c *websocket.Conn, cmd protoc
t.Fatalf("unexpected command: %s", v.Header.Command)
}
}

func indexAll(ctx context.Context, t *testing.T, tbcServer *Server) {
_, bh, err := tbcServer.BlockHeaderBest(ctx)
if err != nil {
t.Fatal(err)
}

hash := bh.BlockHash()

if err := tbcServer.TxIndexer(ctx, &hash); err != nil {
t.Fatal(err)
}

if err := tbcServer.UtxoIndexer(ctx, &hash); err != nil {
t.Fatal(err)
}
}
2 changes: 2 additions & 0 deletions service/tbc/tbcfork_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,8 @@ func TestFork(t *testing.T) {
if err != nil {
t.Fatal(err)
}

// XXX - this is fragile, audit. we sometimes get a length of 1
if len(bhsAt11) != 2 {
t.Fatalf("expected 2 best blocks, got %v", len(bhsAt11))
}
Expand Down

0 comments on commit a2affc7

Please sign in to comment.