-
Notifications
You must be signed in to change notification settings - Fork 107
/
runtime_upgrade.go
72 lines (57 loc) · 1.87 KB
/
runtime_upgrade.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
package runtime
import (
"context"
"time"
"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/oasis/cli"
"github.com/oasisprotocol/oasis-core/go/oasis-test-runner/scenario"
)
// RuntimeUpgrade is the runtime upgrade scenario.
var RuntimeUpgrade scenario.Scenario = newRuntimeUpgradeImpl()
const versionActivationTimeout = 15 * time.Second
type runtimeUpgradeImpl struct {
Scenario
upgradedRuntimeIndex int
}
func newRuntimeUpgradeImpl() scenario.Scenario {
return &runtimeUpgradeImpl{
Scenario: *NewScenario(
"runtime-upgrade",
NewTestClient().WithScenario(InsertRemoveKeyValueEncScenario),
),
}
}
func (sc *runtimeUpgradeImpl) Fixture() (*oasis.NetworkFixture, error) {
f, err := sc.Scenario.Fixture()
if err != nil {
return nil, err
}
if sc.upgradedRuntimeIndex, err = sc.UpgradeComputeRuntimeFixture(f); err != nil {
return nil, err
}
return f, nil
}
func (sc *runtimeUpgradeImpl) Clone() scenario.Scenario {
return &runtimeUpgradeImpl{
Scenario: *sc.Scenario.Clone().(*Scenario),
}
}
func (sc *runtimeUpgradeImpl) Run(ctx context.Context, childEnv *env.Env) error {
cli := cli.New(childEnv, sc.Net, sc.Logger)
// Start the network and run the test client.
if err := sc.StartNetworkAndWaitForClientSync(ctx); err != nil {
return err
}
if err := sc.RunTestClientAndCheckLogs(ctx, childEnv); err != nil {
return err
}
// Upgrade the compute runtime.
if err := sc.UpgradeComputeRuntime(ctx, childEnv, cli, sc.upgradedRuntimeIndex, 0); err != nil {
return err
}
// Run client again.
sc.Logger.Info("starting a second client to check if runtime works")
sc.Scenario.TestClient = NewTestClient().WithSeed("seed2").WithScenario(InsertRemoveKeyValueEncScenarioV2)
return sc.RunTestClientAndCheckLogs(ctx, childEnv)
}