Skip to content

Commit

Permalink
updated error handling to be single line
Browse files Browse the repository at this point in the history
  • Loading branch information
ClaytonNorthey92 committed Aug 6, 2024
1 parent 9704eca commit bbd95e2
Showing 1 changed file with 29 additions and 24 deletions.
53 changes: 29 additions & 24 deletions e2e/e2e_ext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2301,21 +2301,21 @@ func TestPopPayoutsMultiplePages(t *testing.T) {
Height: 99,
}

err := db.BtcBlockInsert(ctx, &btcBlock)
if err != nil {
if err := db.BtcBlockInsert(ctx, &btcBlock); err != nil {
t.Fatal(err)
}

// insert 151 pop payouts to different miners, get the first 3 pages,
// we expect result counts like so : 100, 51, 0
var txIndex uint64 = 1

for i := 0; i < 151; i++ {
for range 151 {

privateKey, err := dcrsecp256k1.GeneratePrivateKeyFromRand(rand.Reader)
if err != nil {
t.Fatal(err)
}

publicKey := privateKey.PubKey()
publicKeyUncompressed := publicKey.SerializeUncompressed()

Expand All @@ -2330,8 +2330,7 @@ func TestPopPayoutsMultiplePages(t *testing.T) {
BtcTxIndex: &txIndex,
}

err = db.PopBasisInsertFull(ctx, &popBasis)
if err != nil {
if err := db.PopBasisInsertFull(ctx, &popBasis); err != nil {
t.Fatal(err)
}
}
Expand All @@ -2358,14 +2357,14 @@ func TestPopPayoutsMultiplePages(t *testing.T) {
L2BlockForPayout: serializedL2Keystone[:],
}

err = bssapi.Write(ctx, bws.conn, "someid", popPayoutsRequest)
if err != nil {
if err := bssapi.Write(
ctx, bws.conn, "someid", popPayoutsRequest,
); err != nil {
t.Fatal(err)
}

var v protocol.Message
err = wsjson.Read(ctx, c, &v)
if err != nil {
if err := wsjson.Read(ctx, c, &v); err != nil {
t.Fatal(err)
}

Expand All @@ -2374,23 +2373,25 @@ func TestPopPayoutsMultiplePages(t *testing.T) {
}

popPayoutsResponse := bssapi.PopPayoutsResponse{}
err = json.Unmarshal(v.Payload, &popPayoutsResponse)
if err != nil {
if err := json.Unmarshal(v.Payload, &popPayoutsResponse); err != nil {
t.Fatal(err)
}

if len(popPayoutsResponse.PopPayouts) != 100 {
t.Fatalf("expected first page to have 100 results, received %d", len(popPayoutsResponse.PopPayouts))
t.Fatalf(
"expected first page to have 100 results, received %d",
len(popPayoutsResponse.PopPayouts),
)
}

popPayoutsRequest.Page = 1
err = bssapi.Write(ctx, bws.conn, "someid", popPayoutsRequest)
if err != nil {
if err := bssapi.Write(
ctx, bws.conn, "someid", popPayoutsRequest,
); err != nil {
t.Fatal(err)
}

err = wsjson.Read(ctx, c, &v)
if err != nil {
if err := wsjson.Read(ctx, c, &v); err != nil {
t.Fatal(err)
}

Expand All @@ -2404,31 +2405,35 @@ func TestPopPayoutsMultiplePages(t *testing.T) {
}

if len(popPayoutsResponse.PopPayouts) != 51 {
t.Fatalf("expected first page to have 51 results, received %d", len(popPayoutsResponse.PopPayouts))
t.Fatalf(
"expected first page to have 51 results, received %d",
len(popPayoutsResponse.PopPayouts),
)
}

popPayoutsRequest.Page = 2
err = bssapi.Write(ctx, bws.conn, "someid", popPayoutsRequest)
if err != nil {
if err := bssapi.Write(
ctx, bws.conn, "someid", popPayoutsRequest,
); err != nil {
t.Fatal(err)
}

err = wsjson.Read(ctx, c, &v)
if err != nil {
if err := wsjson.Read(ctx, c, &v); err != nil {
t.Fatal(err)
}

if v.Header.Command != bssapi.CmdPopPayoutResponse {
t.Fatalf("received unexpected command: %s", v.Header.Command)
}

err = json.Unmarshal(v.Payload, &popPayoutsResponse)
if err != nil {
if err := json.Unmarshal(v.Payload, &popPayoutsResponse); err != nil {
t.Fatal(err)
}

if len(popPayoutsResponse.PopPayouts) != 0 {
t.Fatalf("expected first page to have 0 results, received %d", len(popPayoutsResponse.PopPayouts))
t.Fatalf(
"expected first page to have 0 results, received %d",
len(popPayoutsResponse.PopPayouts))
}
}

Expand Down

0 comments on commit bbd95e2

Please sign in to comment.