forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 4
/
test_decidable.go
50 lines (41 loc) · 990 Bytes
/
test_decidable.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
41
42
43
44
45
46
47
48
49
50
// Copyright (C) 2019-2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package choices
import (
"context"
"fmt"
"github.com/MetalBlockchain/metalgo/ids"
)
var _ Decidable = (*TestDecidable)(nil)
// TestDecidable is a test Decidable
type TestDecidable struct {
IDV ids.ID
AcceptV, RejectV error
StatusV Status
}
func (d *TestDecidable) ID() ids.ID {
return d.IDV
}
func (d *TestDecidable) Accept(context.Context) error {
switch d.StatusV {
case Unknown, Rejected:
return fmt.Errorf("invalid state transition from %s to %s",
d.StatusV, Accepted)
default:
d.StatusV = Accepted
return d.AcceptV
}
}
func (d *TestDecidable) Reject(context.Context) error {
switch d.StatusV {
case Unknown, Accepted:
return fmt.Errorf("invalid state transition from %s to %s",
d.StatusV, Rejected)
default:
d.StatusV = Rejected
return d.RejectV
}
}
func (d *TestDecidable) Status() Status {
return d.StatusV
}