-
Notifications
You must be signed in to change notification settings - Fork 107
/
seed_api.go
201 lines (170 loc) · 6.45 KB
/
seed_api.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
package e2e
import (
"context"
"fmt"
beacon "github.com/oasisprotocol/oasis-core/go/beacon/api"
consensusAPI "github.com/oasisprotocol/oasis-core/go/consensus/api"
"github.com/oasisprotocol/oasis-core/go/consensus/api/transaction"
"github.com/oasisprotocol/oasis-core/go/control/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"
)
// SeedAPI is the scenario where seed node control and consensus APIs are tested.
var SeedAPI scenario.Scenario = &seedAPI{
Scenario: *NewScenario("seed-api"),
}
type seedAPI struct {
Scenario
}
func (sc *seedAPI) Fixture() (*oasis.NetworkFixture, error) {
f, err := sc.Scenario.Fixture()
if err != nil {
return nil, err
}
// Add a client which will connect to the seed.
f.Clients = append(f.Clients, oasis.ClientFixture{})
f.Network.SetInsecureBeacon()
return f, nil
}
func (sc *seedAPI) Clone() scenario.Scenario {
return &seedAPI{
Scenario: sc.Scenario.Clone(),
}
}
func (sc *seedAPI) Run(ctx context.Context, childEnv *env.Env) error { // nolint: gocyclo
if err := sc.Net.Start(); err != nil {
return fmt.Errorf("net Start: %w", err)
}
sc.Logger.Info("waiting for network to come up")
if err := sc.Net.Controller().WaitNodesRegistered(ctx, 3); err != nil {
return fmt.Errorf("WaitNodesRegistered: %w", err)
}
seedCtrl, err := oasis.NewController(sc.Net.Seeds()[0].SocketPath())
if err != nil {
return err
}
sc.Logger.Info("testing IsSynced")
isSynced, err := seedCtrl.IsSynced(ctx)
if err != nil {
return err
}
if !isSynced {
return fmt.Errorf("seed reports as not synced")
}
sc.Logger.Info("testing IsReady")
isReady, err := seedCtrl.IsReady(ctx)
if err != nil {
return err
}
if isReady {
return fmt.Errorf("seed reports as ready to accept runtime work")
}
sc.Logger.Info("testing GetStatus")
status, err := seedCtrl.GetStatus(ctx)
if err != nil {
return fmt.Errorf("failed to get status for node: %w", err)
}
if status.Consensus.Status != consensusAPI.StatusStateReady {
return fmt.Errorf("seed node consensus status should be '%s', got: '%s'", consensusAPI.StatusStateReady, status.Consensus.Status)
}
if status.Consensus.LatestHeight != int64(0) {
return fmt.Errorf("seed node latest height should be 0, got: %d", status.Consensus.LatestHeight)
}
if status.Consensus.IsValidator {
return fmt.Errorf("seed node reports itself to be a validator")
}
if status.Consensus.Features.Has(consensusAPI.FeatureServices) {
return fmt.Errorf("seed node reports feature services")
}
if len(status.Runtimes) != 0 {
return fmt.Errorf("seed node reports configured runtimes")
}
rs := api.RegistrationStatus{}
if status.Registration != rs {
return fmt.Errorf("seed reports as registered")
}
if len(status.Consensus.NodePeers) == 0 {
return fmt.Errorf("seed should be conencted at least to the client-0")
}
if p := status.PendingUpgrades; len(p) != 0 {
return fmt.Errorf("unexpected pending upgrades: %v", p)
}
sc.Logger.Info("testing SetEpoch")
if err = seedCtrl.SetEpoch(ctx, beacon.EpochTime(0)); err == nil {
return fmt.Errorf("seed node SetEpoch should fail")
}
sc.Logger.Info("testing GetGenesisDocument")
doc, err := seedCtrl.Consensus.GetGenesisDocument(ctx)
if err != nil {
return fmt.Errorf("seed node GetGenesisDocument should work")
}
if doc == nil {
return fmt.Errorf("seed node GetGenesisDocument should not be nil")
}
sc.Logger.Info("testing SubmitTx")
err = seedCtrl.Consensus.SubmitTx(ctx, &transaction.SignedTransaction{})
if err != consensusAPI.ErrUnsupported {
return fmt.Errorf("seed node SubmitTx should fail with unsupported")
}
sc.Logger.Info("testing SubmitTxNoWait")
err = seedCtrl.Consensus.SubmitTxNoWait(ctx, &transaction.SignedTransaction{})
if err != consensusAPI.ErrUnsupported {
return fmt.Errorf("seed node SubmitTxNoWait should fail with unsupported")
}
sc.Logger.Info("testing SubmitEvidence")
err = seedCtrl.Consensus.SubmitEvidence(ctx, &consensusAPI.Evidence{})
if err != consensusAPI.ErrUnsupported {
return fmt.Errorf("seed node SubmitEvidence should fail with unsupported")
}
sc.Logger.Info("testing StateToGenesis")
_, err = seedCtrl.Consensus.StateToGenesis(ctx, 0)
if err != consensusAPI.ErrUnsupported {
return fmt.Errorf("seed node StateToGenesis should fail with unsupported")
}
sc.Logger.Info("testing EstimateGas")
_, err = seedCtrl.Consensus.EstimateGas(ctx, &consensusAPI.EstimateGasRequest{})
if err != consensusAPI.ErrUnsupported {
return fmt.Errorf("seed node EstimateGas should fail with unsupported")
}
sc.Logger.Info("testing GetBlock")
_, err = seedCtrl.Consensus.GetBlock(ctx, consensusAPI.HeightLatest)
if err != consensusAPI.ErrUnsupported {
return fmt.Errorf("seed node GetBlock should fail with unsupported")
}
sc.Logger.Info("testing GetTransactions")
_, err = seedCtrl.Consensus.GetTransactions(ctx, consensusAPI.HeightLatest)
if err != consensusAPI.ErrUnsupported {
return fmt.Errorf("seed node GetTransactions should fail with unsupported")
}
sc.Logger.Info("testing GetTransactionsWithResults")
_, err = seedCtrl.Consensus.GetTransactionsWithResults(ctx, consensusAPI.HeightLatest)
if err != consensusAPI.ErrUnsupported {
return fmt.Errorf("seed node GetTransactionsWithResults should fail with unsupported")
}
sc.Logger.Info("testing GetUnconfirmedTransactions")
_, err = seedCtrl.Consensus.GetUnconfirmedTransactions(ctx)
if err != consensusAPI.ErrUnsupported {
return fmt.Errorf("seed node GetUnconfirmedTransactions should fail with unsupported")
}
sc.Logger.Info("testing GetSignerNonce")
_, err = seedCtrl.Consensus.GetSignerNonce(ctx, &consensusAPI.GetSignerNonceRequest{})
if err != consensusAPI.ErrUnsupported {
return fmt.Errorf("seed node GetSignerNonce should fail with unsupported")
}
sc.Logger.Info("testing GetLightBlock")
_, err = seedCtrl.Consensus.GetLightBlock(ctx, consensusAPI.HeightLatest)
if err != consensusAPI.ErrUnsupported {
return fmt.Errorf("seed node GetLightBlock should fail with unsupported")
}
sc.Logger.Info("testing GetParameters")
_, err = seedCtrl.Consensus.GetParameters(ctx, consensusAPI.HeightLatest)
if err != consensusAPI.ErrUnsupported {
return fmt.Errorf("seed node GetParameters should fail with unsupported")
}
sc.Logger.Info("testing RequestShutdown")
if err := seedCtrl.RequestShutdown(ctx, true); err != nil {
return fmt.Errorf("seed node request shutdown error: %w", err)
}
return nil
}