Skip to content

Commit

Permalink
contracts: expand sector roots test to cover edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
n8maninger committed Jan 7, 2024
1 parent 4721312 commit 6403c8e
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions host/contracts/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1078,4 +1078,36 @@ func TestSectorRoots(t *testing.T) {
t.Fatalf("expected sector root %v to be %v, got %v", i, roots[i], check[i])
}
}

// try random offsets and lengths
for i := 0; i < 200; i++ {
offset, limit := frand.Intn(len(roots)), frand.Intn(len(roots))

check, err = c.SectorRoots(rev.Revision.ParentID, limit, offset)
if err != nil {
t.Fatal(err)
}

// handle special case
if limit == 0 {
limit = len(roots)
}

// handle case where offset+limit > len(roots)
n := limit
if offset+limit > len(roots) {
n = len(roots) - offset
}

if len(check) != n {
t.Fatalf("expected %v sector roots, got %v (offset %d, limit %d, len %d)", n, len(check), offset, limit, len(roots))
}

for i := range check {
j := offset + i
if check[i] != roots[j] {
t.Fatalf("expected sector root %v to be %v, got %v", j, roots[j], check[i])
}
}
}
}

0 comments on commit 6403c8e

Please sign in to comment.