Skip to content
This repository has been archived by the owner on Apr 4, 2022. It is now read-only.

Commit

Permalink
problem: not updated signature, borked pagination condition
Browse files Browse the repository at this point in the history
solution: fix signatures, add a small test, and fix param condition
  • Loading branch information
whilei committed Jun 13, 2018
1 parent 02859c6 commit 08a5e61
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
8 changes: 4 additions & 4 deletions core/atxi.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,13 @@ func GetAddrTxs(db ethdb.Database, address common.Address, blockStartN uint64, b
err = errWithReason(errAtxiInvalidUse, "Address transactions list signature requires 'kind of' param to be empty string or [s|c] prefix (eg. both, standard, or contract)")
return
}
if paginationStart < 0 {
paginationStart = 0
}
if paginationStart > paginationEnd {
if paginationStart > 0 && paginationEnd > 0 && paginationStart > paginationEnd {
err = errWithReason(errAtxiInvalidUse, "Pagination start must be less than or equal to pagination end params")
return
}
if paginationStart < 0 {
paginationStart = 0
}

// Have to cast to LevelDB to use iterator. Yuck.
ldb, ok := db.(*ethdb.LDBDatabase)
Expand Down
27 changes: 17 additions & 10 deletions core/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -982,23 +982,30 @@ func TestFastVsFullChainsATXI(t *testing.T) {
}
}

out := GetAddrTxs(db, addr1, 0, 0, "", "", -1, -1, false)
out, _ := GetAddrTxs(db, addr1, 0, 0, "", "", -1, -1, false)
if len(out) != 3 {
t.Errorf("[%d] got: %v, want: %v", i, len(out), 3)
}
out = GetAddrTxs(db, addr1, 0, 0, "from", "", -1, -1, false)

// method should return an error if pagination params are invalid
_, err = GetAddrTxs(db, addr1, 0, 0, "", "", 2, 1, false)
if err == nil {
t.Errorf("[%d] got: %v, want: %v", i, err, errAtxiInvalidUse)
}

out, _ = GetAddrTxs(db, addr1, 0, 0, "from", "", -1, -1, false)
if len(out) != 2 {
t.Errorf("[%d] got: %v, want: %v", i, len(out), 2)
}
out = GetAddrTxs(db, addr1, 0, 0, "to", "", -1, -1, false)
out, _ = GetAddrTxs(db, addr1, 0, 0, "to", "", -1, -1, false)
if len(out) != 1 {
t.Errorf("[%d] got: %v, want: %v", i, len(out), 1)
}
out = GetAddrTxs(db, addr2, 0, 0, "", "", -1, -1, false)
out, _ = GetAddrTxs(db, addr2, 0, 0, "", "", -1, -1, false)
if len(out) != 3 {
t.Errorf("[%d] got: %v, want: %v", i, len(out), 3)
}
out = GetAddrTxs(db, addr2, 3, 3, "", "", -1, -1, false)
out, _ = GetAddrTxs(db, addr2, 3, 3, "", "", -1, -1, false)
if len(out) != 1 {
t.Errorf("[%d] got: %v, want: %v", i, len(out), 1)
}
Expand Down Expand Up @@ -1076,14 +1083,14 @@ func TestRmAddrTx(t *testing.T) {
t.Fatalf("failed to process block %d: %v", res.Index, res.Error)
}

out := GetAddrTxs(db, addr1, 0, 0, "", "", -1, -1, false)
out, _ := GetAddrTxs(db, addr1, 0, 0, "", "", -1, -1, false)
if len(out) != 3 {
t.Errorf("got: %v, want: %v", len(out), 3)
}
if err := RmAddrTx(db, t1); err != nil {
t.Fatal(err)
}
out = GetAddrTxs(db, addr1, 0, 0, "", "", -1, -1, false)
out, _ = GetAddrTxs(db, addr1, 0, 0, "", "", -1, -1, false)
if len(out) != 2 {
t.Errorf("got: %v, want: %v", len(out), 2)
}
Expand Down Expand Up @@ -1363,9 +1370,9 @@ func testChainTxReorgs(t *testing.T, db ethdb.Database, withATXI bool) {
if !withATXI {
return
}
txsh1 := GetAddrTxs(db, addr1, 0, 0, "", "", -1, -1, false)
txsh2 := GetAddrTxs(db, addr2, 0, 0, "", "", -1, -1, false)
txsh3 := GetAddrTxs(db, addr3, 0, 0, "", "", -1, -1, false)
txsh1, _ := GetAddrTxs(db, addr1, 0, 0, "", "", -1, -1, false)
txsh2, _ := GetAddrTxs(db, addr2, 0, 0, "", "", -1, -1, false)
txsh3, _ := GetAddrTxs(db, addr3, 0, 0, "", "", -1, -1, false)

allAtxis := txsh1
allAtxis = append(allAtxis, txsh2...)
Expand Down
16 changes: 8 additions & 8 deletions core/database_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,13 +395,13 @@ func TestAddrTxStorage(t *testing.T) {
t.Errorf("want: %v, got: %v", 7, count)
}

out := GetAddrTxs(db, from2, 0, 0, "", "", -1, -1, false)
out, _ := GetAddrTxs(db, from2, 0, 0, "", "", -1, -1, false)
if len(out) != 3 {
t.Errorf("want: %v, got: %v", 3, len(out))
}

// Test pagination and reverse
outReverse := GetAddrTxs(db, from2, 0, 0, "", "", -1, -1, true)
outReverse, _ := GetAddrTxs(db, from2, 0, 0, "", "", -1, -1, true)
if len(outReverse) != 3 {
t.Errorf("want: %v, got: %v", 3, len(outReverse))
}
Expand All @@ -410,21 +410,21 @@ func TestAddrTxStorage(t *testing.T) {
t.Errorf("got: %v, want: %v", outReverse, out)
}
// pagination
outPag := GetAddrTxs(db, from2, 0, 0, "", "", 1, -1, false)
outPag, _ := GetAddrTxs(db, from2, 0, 0, "", "", 1, -1, false)
if len(outPag) != 2 {
t.Errorf("got: %v, want: %v", len(outPag), 2)
}

out = GetAddrTxs(db, from2, 0, 0, "", "c", -1, -1, false)
out, _ = GetAddrTxs(db, from2, 0, 0, "", "c", -1, -1, false)
if len(out) != 1 {
t.Errorf("got: %v, want: %v", len(out), 1)
}
out = GetAddrTxs(db, common.Address{}, 0, 0, "", "", -1, -1, false)
out, _ = GetAddrTxs(db, common.Address{}, 0, 0, "", "", -1, -1, false)
if len(out) != 1 {
t.Errorf("got: %v, want: %v", len(out), 1)
}

out = GetAddrTxs(db, from1, 314, 314, "", "", -1, -1, false)
out, _ = GetAddrTxs(db, from1, 314, 314, "", "", -1, -1, false)
if len(out) != 1 {
t.Errorf("want: %v, got: %v", 1, len(out))
} else {
Expand All @@ -447,7 +447,7 @@ func TestAddrTxStorage(t *testing.T) {
}
}

out = GetAddrTxs(db, from2to, 314, 314, "to", "", -1, -1, false)
out, _ = GetAddrTxs(db, from2to, 314, 314, "to", "", -1, -1, false)
if len(out) != 1 {
t.Errorf("want: %v, got: %v", 1, len(out))
} else {
Expand All @@ -474,7 +474,7 @@ func TestAddrTxStorage(t *testing.T) {
t.Errorf("got: %v, want: %v", f, from2)
}
}
out = GetAddrTxs(db, from2to, 314, 314, "from", "", -1, -1, false)
out, _ = GetAddrTxs(db, from2to, 314, 314, "from", "", -1, -1, false)
if len(out) != 0 {
t.Errorf("want: %v, got: %v", 0, len(out))
}
Expand Down

0 comments on commit 08a5e61

Please sign in to comment.