-
Notifications
You must be signed in to change notification settings - Fork 670
/
test_block.go
40 lines (30 loc) · 1.12 KB
/
test_block.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package snowman
import (
"sort"
"time"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow/choices"
)
var _ Block = &TestBlock{}
// TestBlock is a useful test block
type TestBlock struct {
choices.TestDecidable
ParentV ids.ID
HeightV uint64
TimestampV time.Time
VerifyV error
BytesV []byte
}
func (b *TestBlock) Parent() ids.ID { return b.ParentV }
func (b *TestBlock) Height() uint64 { return b.HeightV }
func (b *TestBlock) Timestamp() time.Time { return b.TimestampV }
func (b *TestBlock) Verify() error { return b.VerifyV }
func (b *TestBlock) Bytes() []byte { return b.BytesV }
type sortBlocks []*TestBlock
func (sb sortBlocks) Less(i, j int) bool { return sb[i].HeightV < sb[j].HeightV }
func (sb sortBlocks) Len() int { return len(sb) }
func (sb sortBlocks) Swap(i, j int) { sb[j], sb[i] = sb[i], sb[j] }
// SortTestBlocks sorts the array of blocks by height
func SortTestBlocks(blocks []*TestBlock) { sort.Sort(sortBlocks(blocks)) }