Skip to content

Commit

Permalink
go/oasis-net-runner: default fixture support staking genesis
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrus committed May 3, 2021
1 parent 468e059 commit 6080a38
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions .changelog/3914.feature.2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
go/oasis-net-runner: default fixture support staking genesis
22 changes: 18 additions & 4 deletions go/oasis-net-runner/fixtures/default.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package fixtures

import (
"encoding/json"
"fmt"
"io/ioutil"
"math"
"time"

Expand Down Expand Up @@ -33,11 +35,10 @@ const (
cfgSetupRuntimes = "fixture.default.setup_runtimes"
cfgTEEHardware = "fixture.default.tee_hardware"
cfgInitialHeight = "fixture.default.initial_height"
cfgStakingGenesis = "fixture.default.staking_genesis"
)

var (
keymanagerID common.Namespace
)
var keymanagerID common.Namespace

// newDefaultFixture returns a default network fixture.
func newDefaultFixture() (*oasis.NetworkFixture, error) {
Expand All @@ -51,6 +52,18 @@ func newDefaultFixture() (*oasis.NetworkFixture, error) {
mrSigner = &sgx.FortanixDummyMrSigner
}

var stakingGenesis staking.Genesis
if genesis := viper.GetString(cfgStakingGenesis); genesis != "" {
var raw []byte
raw, err = ioutil.ReadFile(genesis)
if err != nil {
return nil, fmt.Errorf("loading staking genesis file: %w", err)
}
if err = json.Unmarshal(raw, &stakingGenesis); err != nil {
return nil, fmt.Errorf("loading staking genesis: %w", err)
}
}

fixture := &oasis.NetworkFixture{
TEE: oasis.TEEFixture{
Hardware: tee,
Expand All @@ -74,7 +87,7 @@ func newDefaultFixture() (*oasis.NetworkFixture, error) {
},
DeterministicIdentities: viper.GetBool(cfgDeterministicIdentities),
FundEntities: viper.GetBool(cfgFundEntities),
StakingGenesis: &staking.Genesis{},
StakingGenesis: &stakingGenesis,
},
Entities: []oasis.EntityCfg{
{IsDebugTestEntity: true},
Expand Down Expand Up @@ -207,6 +220,7 @@ func init() {
DefaultFixtureFlags.String(cfgTEEHardware, "", "TEE hardware to use")
DefaultFixtureFlags.Uint64(cfgHaltEpoch, math.MaxUint64, "halt epoch height")
DefaultFixtureFlags.Int64(cfgInitialHeight, 1, "initial block height")
DefaultFixtureFlags.String(cfgStakingGenesis, "", "path to the staking genesis to use")

_ = viper.BindPFlags(DefaultFixtureFlags)

Expand Down

0 comments on commit 6080a38

Please sign in to comment.