Skip to content

Commit

Permalink
add MinTimestamp to tipset and test
Browse files Browse the repository at this point in the history
  • Loading branch information
frrist committed Jun 12, 2019
1 parent ebd469b commit 30da7c3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
13 changes: 13 additions & 0 deletions types/tipset.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,19 @@ func (ts TipSet) MinTicket() (Signature, error) {
return ts.blocks[0].Ticket, nil
}

func (ts TipSet) MinTimestamp() (Uint64, error) {
if len(ts.blocks) == 0 {
return 0, errUndefTipSet
}
min := ts.blocks[0].Timestamp
for i := 0; i < len(ts.blocks[0:]); i++ {
if ts.blocks[i].Timestamp < min {
min = ts.blocks[i].Timestamp
}
}
return min, nil
}

// Height returns the height of a tipset.
func (ts TipSet) Height() (uint64, error) {
if len(ts.blocks) == 0 {
Expand Down
5 changes: 5 additions & 0 deletions types/tipset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ func TestTipSet(t *testing.T) {
assert.Equal(t, b1.Ticket, tsTicket)
})

t.Run("min timestamp", func(t *testing.T) {
tsTime, _ := RequireNewTipSet(t, b1, b2, b3).MinTimestamp()
assert.Equal(t, b1.Timestamp, tsTime)
})

t.Run("equality", func(t *testing.T) {
ts1a := RequireNewTipSet(t, b3, b2, b1)
ts1b := RequireNewTipSet(t, b1, b2, b3)
Expand Down

0 comments on commit 30da7c3

Please sign in to comment.