-
Notifications
You must be signed in to change notification settings - Fork 107
/
debond.go
143 lines (128 loc) · 4.17 KB
/
debond.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package e2e
import (
"context"
"fmt"
"github.com/oasisprotocol/oasis-core/go/common/quantity"
consensus "github.com/oasisprotocol/oasis-core/go/consensus/api"
"github.com/oasisprotocol/oasis-core/go/oasis-test-runner/env"
"github.com/oasisprotocol/oasis-core/go/oasis-test-runner/oasis"
"github.com/oasisprotocol/oasis-core/go/oasis-test-runner/scenario"
staking "github.com/oasisprotocol/oasis-core/go/staking/api"
)
// Debond tests debonding records created in the genesis document.
var Debond scenario.Scenario = &debondImpl{
Scenario: *NewScenario("debond"),
}
type debondImpl struct {
Scenario
}
func (s *debondImpl) Clone() scenario.Scenario {
return &debondImpl{
Scenario: s.Scenario.Clone(),
}
}
func (s *debondImpl) Fixture() (*oasis.NetworkFixture, error) {
f, err := s.Scenario.Fixture()
if err != nil {
return nil, err
}
// We will mock epochs for reclaiming the escrow.
f.Network.SetMockEpoch()
f.Network.SetInsecureBeacon()
// Enable some features in the staking system that we'll test.
f.Network.StakingGenesis = &staking.Genesis{
Parameters: staking.ConsensusParameters{
CommissionScheduleRules: staking.CommissionScheduleRules{
RateChangeInterval: 10,
RateBoundLead: 30,
MaxRateSteps: 4,
MaxBoundSteps: 12,
},
},
TotalSupply: *quantity.NewFromUint64(1000),
Ledger: map[staking.Address]*staking.Account{
TestEntityAccount: {
Escrow: staking.EscrowAccount{
Debonding: staking.SharePool{
Balance: *quantity.NewFromUint64(1000),
TotalShares: *quantity.NewFromUint64(1000),
},
},
},
},
DebondingDelegations: map[staking.Address]map[staking.Address][]*staking.DebondingDelegation{
TestEntityAccount: {
DeterministicValidator0: {
{
Shares: *quantity.NewFromUint64(500),
DebondEndTime: 1,
},
{
Shares: *quantity.NewFromUint64(500),
DebondEndTime: 2,
},
},
},
},
}
return f, nil
}
func (s *debondImpl) Run(ctx context.Context, childEnv *env.Env) error {
if err := s.Net.Start(); err != nil {
return fmt.Errorf("net Start: %w", err)
}
s.Logger.Info("waiting for network to come up")
if err := s.Net.Controller().WaitNodesRegistered(ctx, 3); err != nil {
return fmt.Errorf("WaitNodesRegistered: %w", err)
}
// Beginning: lockup account has no funds.
lockupQuery := staking.OwnerQuery{
Owner: DeterministicValidator0,
Height: consensus.HeightLatest,
}
s.Logger.Info("checking balance at beginning")
acct, err := s.Net.Controller().Staking.Account(ctx, &lockupQuery)
if err != nil {
return fmt.Errorf("beginning Account: %w", err)
}
if !acct.General.Balance.IsZero() {
return fmt.Errorf("beginning balance %v should be zero", acct.General.Balance)
}
s.Logger.Info("balance ok")
// First debonding: 500 base units at epoch 1.
s.Logger.Info("advancing to first debonding")
if err = s.Net.Controller().SetEpoch(ctx, 1); err != nil {
return fmt.Errorf("first SetEpoch: %w", err)
}
var expected quantity.Quantity
if err = expected.FromInt64(500); err != nil {
return fmt.Errorf("import first debonding expected balance: %w", err)
}
s.Logger.Info("checking balance at first debonding")
acct, err = s.Net.Controller().Staking.Account(ctx, &lockupQuery)
if err != nil {
return fmt.Errorf("first debonding Account: %w", err)
}
if acct.General.Balance.Cmp(&expected) != 0 {
return fmt.Errorf("first debonding balance %v should be %v", acct.General.Balance, expected)
}
s.Logger.Info("balance ok")
// Second debonding: 500 more base units at epoch 2.
s.Logger.Info("advancing to second debonding")
if err = s.Net.Controller().SetEpoch(ctx, 2); err != nil {
return fmt.Errorf("second SetEpoch: %w", err)
}
if err = expected.FromInt64(1000); err != nil {
return fmt.Errorf("import second debonding expected balance: %w", err)
}
s.Logger.Info("checking balance at second debonding")
acct, err = s.Net.Controller().Staking.Account(ctx, &lockupQuery)
if err != nil {
return fmt.Errorf("second debonding Account: %w", err)
}
if acct.General.Balance.Cmp(&expected) != 0 {
return fmt.Errorf("second debonding balance %v should be %v", acct.General.Balance, expected)
}
s.Logger.Info("balance ok")
return nil
}