2020-03-10 12:20:34 -07:00
|
|
|
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
|
|
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
|
|
|
|
package snowman
|
|
|
|
|
|
|
|
import (
|
2020-05-26 10:25:34 -07:00
|
|
|
"errors"
|
2020-03-10 12:20:34 -07:00
|
|
|
"sort"
|
|
|
|
|
|
|
|
"github.com/ava-labs/gecko/ids"
|
|
|
|
"github.com/ava-labs/gecko/snow/choices"
|
|
|
|
)
|
|
|
|
|
2020-04-04 15:07:14 -07:00
|
|
|
type TestBlock struct {
|
2020-03-10 12:20:34 -07:00
|
|
|
parent Block
|
|
|
|
id ids.ID
|
|
|
|
height int
|
|
|
|
status choices.Status
|
|
|
|
bytes []byte
|
2020-06-21 18:26:50 -07:00
|
|
|
err error
|
2020-03-10 12:20:34 -07:00
|
|
|
}
|
|
|
|
|
2020-04-04 15:07:14 -07:00
|
|
|
func (b *TestBlock) Parent() Block { return b.parent }
|
|
|
|
func (b *TestBlock) ID() ids.ID { return b.id }
|
|
|
|
func (b *TestBlock) Status() choices.Status { return b.status }
|
2020-05-26 10:25:34 -07:00
|
|
|
func (b *TestBlock) Accept() error {
|
2020-03-10 12:20:34 -07:00
|
|
|
if b.status.Decided() && b.status != choices.Accepted {
|
2020-05-26 10:25:34 -07:00
|
|
|
return errors.New("Dis-agreement")
|
2020-03-10 12:20:34 -07:00
|
|
|
}
|
|
|
|
b.status = choices.Accepted
|
2020-06-21 18:26:50 -07:00
|
|
|
return b.err
|
2020-03-10 12:20:34 -07:00
|
|
|
}
|
2020-05-26 10:25:34 -07:00
|
|
|
func (b *TestBlock) Reject() error {
|
2020-03-10 12:20:34 -07:00
|
|
|
if b.status.Decided() && b.status != choices.Rejected {
|
2020-05-26 10:25:34 -07:00
|
|
|
return errors.New("Dis-agreement")
|
2020-03-10 12:20:34 -07:00
|
|
|
}
|
|
|
|
b.status = choices.Rejected
|
2020-06-21 18:26:50 -07:00
|
|
|
return b.err
|
2020-03-10 12:20:34 -07:00
|
|
|
}
|
2020-06-21 18:26:50 -07:00
|
|
|
func (b *TestBlock) Verify() error { return b.err }
|
2020-04-04 15:07:14 -07:00
|
|
|
func (b *TestBlock) Bytes() []byte { return b.bytes }
|
2020-03-10 12:20:34 -07:00
|
|
|
|
2020-04-04 15:07:14 -07:00
|
|
|
type sortBlocks []*TestBlock
|
2020-03-10 12:20:34 -07:00
|
|
|
|
2020-04-04 15:07:14 -07:00
|
|
|
func (sb sortBlocks) Less(i, j int) bool { return sb[i].height < sb[j].height }
|
|
|
|
func (sb sortBlocks) Len() int { return len(sb) }
|
|
|
|
func (sb sortBlocks) Swap(i, j int) { sb[j], sb[i] = sb[i], sb[j] }
|
2020-03-10 12:20:34 -07:00
|
|
|
|
2020-04-04 15:07:14 -07:00
|
|
|
func SortVts(blocks []*TestBlock) { sort.Sort(sortBlocks(blocks)) }
|