Skip to content

Commit

Permalink
Merge pull request #5324 from oasisprotocol/peternose/trivial/reorgan…
Browse files Browse the repository at this point in the history
…ize-e2e-tests

go/oasis-test-runner: Reorganize e2e tests
  • Loading branch information
peternose authored Jul 19, 2023
2 parents 457ee23 + 8f34ee2 commit c234001
Show file tree
Hide file tree
Showing 60 changed files with 2,683 additions and 2,471 deletions.
Empty file added .changelog/5324.trivial.md
Empty file.
70 changes: 35 additions & 35 deletions go/consensus/cometbft/full/full.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,40 +580,40 @@ func (t *fullService) lazyInit() error { // nolint: gocyclo
}

// Create CometBFT node.
tenderConfig := cmtconfig.DefaultConfig()
_ = viper.Unmarshal(&tenderConfig)
tenderConfig.SetRoot(cometbftDataDir)
cometConfig := cmtconfig.DefaultConfig()
_ = viper.Unmarshal(&cometConfig)
cometConfig.SetRoot(cometbftDataDir)
timeoutCommit := t.genesis.Consensus.Parameters.TimeoutCommit
emptyBlockInterval := t.genesis.Consensus.Parameters.EmptyBlockInterval
tenderConfig.Consensus.TimeoutCommit = timeoutCommit
tenderConfig.Consensus.SkipTimeoutCommit = t.genesis.Consensus.Parameters.SkipTimeoutCommit
tenderConfig.Consensus.CreateEmptyBlocks = true
tenderConfig.Consensus.CreateEmptyBlocksInterval = emptyBlockInterval
tenderConfig.Consensus.DebugUnsafeReplayRecoverCorruptedWAL = config.GlobalConfig.Consensus.Debug.UnsafeReplayRecoverCorruptedWAL && cmflags.DebugDontBlameOasis()
tenderConfig.Mempool.Version = cmtconfig.MempoolV1
tenderConfig.Instrumentation.Prometheus = true
tenderConfig.Instrumentation.PrometheusListenAddr = ""
tenderConfig.TxIndex.Indexer = "null"
tenderConfig.P2P.ListenAddress = config.GlobalConfig.Consensus.ListenAddress
tenderConfig.P2P.ExternalAddress = config.GlobalConfig.Consensus.ExternalAddress
tenderConfig.P2P.PexReactor = !config.GlobalConfig.Consensus.P2P.DisablePeerExchange
tenderConfig.P2P.MaxNumInboundPeers = config.GlobalConfig.Consensus.P2P.MaxNumInboundPeers
tenderConfig.P2P.MaxNumOutboundPeers = config.GlobalConfig.Consensus.P2P.MaxNumOutboundPeers
tenderConfig.P2P.SendRate = config.GlobalConfig.Consensus.P2P.SendRate
tenderConfig.P2P.RecvRate = config.GlobalConfig.Consensus.P2P.RecvRate
tenderConfig.P2P.PersistentPeers = strings.Join(persistentPeers, ",")
tenderConfig.P2P.PersistentPeersMaxDialPeriod = config.GlobalConfig.Consensus.P2P.PersistenPeersMaxDialPeriod
tenderConfig.P2P.UnconditionalPeerIDs = strings.Join(unconditionalPeers, ",")
tenderConfig.P2P.Seeds = strings.Join(seeds, ",")
tenderConfig.P2P.AddrBookStrict = !(config.GlobalConfig.Consensus.Debug.P2PAddrBookLenient && cmflags.DebugDontBlameOasis())
tenderConfig.P2P.AllowDuplicateIP = config.GlobalConfig.Consensus.Debug.P2PAllowDuplicateIP && cmflags.DebugDontBlameOasis()
tenderConfig.RPC.ListenAddress = ""
cometConfig.Consensus.TimeoutCommit = timeoutCommit
cometConfig.Consensus.SkipTimeoutCommit = t.genesis.Consensus.Parameters.SkipTimeoutCommit
cometConfig.Consensus.CreateEmptyBlocks = true
cometConfig.Consensus.CreateEmptyBlocksInterval = emptyBlockInterval
cometConfig.Consensus.DebugUnsafeReplayRecoverCorruptedWAL = config.GlobalConfig.Consensus.Debug.UnsafeReplayRecoverCorruptedWAL && cmflags.DebugDontBlameOasis()
cometConfig.Mempool.Version = cmtconfig.MempoolV1
cometConfig.Instrumentation.Prometheus = true
cometConfig.Instrumentation.PrometheusListenAddr = ""
cometConfig.TxIndex.Indexer = "null"
cometConfig.P2P.ListenAddress = config.GlobalConfig.Consensus.ListenAddress
cometConfig.P2P.ExternalAddress = config.GlobalConfig.Consensus.ExternalAddress
cometConfig.P2P.PexReactor = !config.GlobalConfig.Consensus.P2P.DisablePeerExchange
cometConfig.P2P.MaxNumInboundPeers = config.GlobalConfig.Consensus.P2P.MaxNumInboundPeers
cometConfig.P2P.MaxNumOutboundPeers = config.GlobalConfig.Consensus.P2P.MaxNumOutboundPeers
cometConfig.P2P.SendRate = config.GlobalConfig.Consensus.P2P.SendRate
cometConfig.P2P.RecvRate = config.GlobalConfig.Consensus.P2P.RecvRate
cometConfig.P2P.PersistentPeers = strings.Join(persistentPeers, ",")
cometConfig.P2P.PersistentPeersMaxDialPeriod = config.GlobalConfig.Consensus.P2P.PersistenPeersMaxDialPeriod
cometConfig.P2P.UnconditionalPeerIDs = strings.Join(unconditionalPeers, ",")
cometConfig.P2P.Seeds = strings.Join(seeds, ",")
cometConfig.P2P.AddrBookStrict = !(config.GlobalConfig.Consensus.Debug.P2PAddrBookLenient && cmflags.DebugDontBlameOasis())
cometConfig.P2P.AllowDuplicateIP = config.GlobalConfig.Consensus.Debug.P2PAllowDuplicateIP && cmflags.DebugDontBlameOasis()
cometConfig.RPC.ListenAddress = ""

if len(sentryUpstreamAddrs) > 0 {
t.Logger.Info("Acting as a cometbft sentry", "addrs", sentryUpstreamAddrs)

// Append upstream addresses to persistent, private and unconditional peers.
tenderConfig.P2P.PersistentPeers += "," + strings.Join(sentryUpstreamAddrs, ",")
cometConfig.P2P.PersistentPeers += "," + strings.Join(sentryUpstreamAddrs, ",")

var sentryUpstreamIDs []string
for _, addr := range sentryUpstreamAddrs {
Expand All @@ -625,11 +625,11 @@ func (t *fullService) lazyInit() error { // nolint: gocyclo
}

sentryUpstreamIDsStr := strings.Join(sentryUpstreamIDs, ",")
tenderConfig.P2P.PrivatePeerIDs += "," + sentryUpstreamIDsStr
tenderConfig.P2P.UnconditionalPeerIDs += "," + sentryUpstreamIDsStr
cometConfig.P2P.PrivatePeerIDs += "," + sentryUpstreamIDsStr
cometConfig.P2P.UnconditionalPeerIDs += "," + sentryUpstreamIDsStr
}

if !tenderConfig.P2P.PexReactor {
if !cometConfig.P2P.PexReactor {
t.Logger.Info("pex reactor disabled",
logging.LogEvent, api.LogEventPeerExchangeDisabled,
)
Expand Down Expand Up @@ -717,16 +717,16 @@ func (t *fullService) lazyInit() error { // nolint: gocyclo
t.Unlock()

// Enable state sync in the configuration.
tenderConfig.StateSync.Enable = true
tenderConfig.StateSync.TrustHash = config.GlobalConfig.Consensus.StateSync.TrustHash
cometConfig.StateSync.Enable = true
cometConfig.StateSync.TrustHash = config.GlobalConfig.Consensus.StateSync.TrustHash

// Create new state sync state provider.
cfg := lightAPI.ClientConfig{
GenesisDocument: tmGenDoc,
TrustOptions: cmtlight.TrustOptions{
Period: config.GlobalConfig.Consensus.StateSync.TrustPeriod,
Height: int64(config.GlobalConfig.Consensus.StateSync.TrustHeight),
Hash: tenderConfig.StateSync.TrustHashBytes(),
Hash: cometConfig.StateSync.TrustHashBytes(),
},
}
if stateProvider, err = newStateProvider(t.ctx, t.genesis.ChainContext(), cfg, t.p2p); err != nil {
Expand All @@ -737,13 +737,13 @@ func (t *fullService) lazyInit() error { // nolint: gocyclo
}
}

t.node, err = cmtnode.NewNode(tenderConfig,
t.node, err = cmtnode.NewNode(cometConfig,
cometbftPV,
&cmtp2p.NodeKey{PrivKey: crypto.SignerToCometBFT(t.identity.P2PSigner)},
cmtproxy.NewLocalClientCreator(t.mux.Mux()),
cometbftGenesisProvider,
wrapDbProvider,
cmtnode.DefaultMetricsProvider(tenderConfig.Instrumentation),
cmtnode.DefaultMetricsProvider(cometConfig.Instrumentation),
tmcommon.NewLogAdapter(!config.GlobalConfig.Consensus.LogDebug),
cmtnode.StateProvider(stateProvider),
)
Expand Down
7 changes: 4 additions & 3 deletions go/oasis-node/cmd/debug/fixgenesis/fixgenesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import (
staking "github.com/oasisprotocol/oasis-core/go/staking/api"
)

const cfgNewGenesis = "genesis.new_file"
// CfgNewGenesisFile is the flag used to specify a new genesis file.
const CfgNewGenesisFile = "genesis.new_file"

var (
fixGenesisCmd = &cobra.Command{
Expand Down Expand Up @@ -83,7 +84,7 @@ func doFixGenesis(cmd *cobra.Command, args []string) {
}

// Write out the new genesis document.
w, shouldClose, err := cmdCommon.GetOutputWriter(cmd, cfgNewGenesis)
w, shouldClose, err := cmdCommon.GetOutputWriter(cmd, CfgNewGenesisFile)
if err != nil {
logger.Error("failed to get writer for fixed genesis file",
"err", err,
Expand Down Expand Up @@ -449,6 +450,6 @@ func Register(parentCmd *cobra.Command) {
}

func init() {
newGenesisFlag.String(cfgNewGenesis, "genesis_fixed.json", "path to fixed genesis document")
newGenesisFlag.String(CfgNewGenesisFile, "genesis_fixed.json", "path to fixed genesis document")
_ = viper.BindPFlags(newGenesisFlag)
}
16 changes: 8 additions & 8 deletions go/oasis-node/cmd/debug/txsource/workload/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func (r *runtime) validateEvents(ctx context.Context, rtc runtimeClient.RuntimeC
return nil
}

func (r *runtime) submitRuntimeRquest(ctx context.Context, rtc runtimeClient.RuntimeClient, req *TxnCall) (*TxnOutput, uint64, error) {
func (r *runtime) submitRuntimeRequest(ctx context.Context, rtc runtimeClient.RuntimeClient, req *TxnCall) (*TxnOutput, uint64, error) {
var rsp TxnOutput
rtx := &runtimeClient.SubmitTxRequest{
RuntimeID: r.runtimeID,
Expand Down Expand Up @@ -243,7 +243,7 @@ func (r *runtime) doInsertRequest(ctx context.Context, rng *rand.Rand, rtc runti
Value: value,
},
}
rsp, round, err := r.submitRuntimeRquest(ctx, rtc, req)
rsp, round, err := r.submitRuntimeRequest(ctx, rtc, req)
if err != nil {
r.Logger.Error("Submit insert request failure",
"request", req,
Expand Down Expand Up @@ -293,7 +293,7 @@ func (r *runtime) doGetRequest(ctx context.Context, rng *rand.Rand, rtc runtimeC
Key: key,
},
}
rsp, round, err := r.submitRuntimeRquest(ctx, rtc, req)
rsp, round, err := r.submitRuntimeRequest(ctx, rtc, req)
if err != nil {
r.Logger.Error("Submit get request failure",
"request", req,
Expand Down Expand Up @@ -340,7 +340,7 @@ func (r *runtime) doRemoveRequest(ctx context.Context, rng *rand.Rand, rtc runti
Key: key,
},
}
rsp, round, err := r.submitRuntimeRquest(ctx, rtc, req)
rsp, round, err := r.submitRuntimeRequest(ctx, rtc, req)
if err != nil {
r.Logger.Error("Submit remove request failure",
"request", req,
Expand Down Expand Up @@ -577,7 +577,7 @@ func (r *runtime) doWithdrawRequest(ctx context.Context, rng *rand.Rand, rtc run
},
},
}
rsp, round, err := r.submitRuntimeRquest(ctx, rtc, req)
rsp, round, err := r.submitRuntimeRequest(ctx, rtc, req)
if err != nil {
r.Logger.Error("Submit withdraw request failure",
"request", req,
Expand Down Expand Up @@ -621,7 +621,7 @@ func (r *runtime) doTransferRequest(ctx context.Context, rng *rand.Rand, rtc run
},
},
}
rsp, round, err := r.submitRuntimeRquest(ctx, rtc, req)
rsp, round, err := r.submitRuntimeRequest(ctx, rtc, req)
if err != nil {
r.Logger.Error("Submit transfer request failure",
"request", req,
Expand Down Expand Up @@ -665,7 +665,7 @@ func (r *runtime) doAddEscrowRequest(ctx context.Context, rng *rand.Rand, rtc ru
},
},
}
rsp, round, err := r.submitRuntimeRquest(ctx, rtc, req)
rsp, round, err := r.submitRuntimeRequest(ctx, rtc, req)
if err != nil {
r.Logger.Error("Submit add escrow request failure",
"request", req,
Expand Down Expand Up @@ -711,7 +711,7 @@ func (r *runtime) doReclaimEscrowRequest(ctx context.Context, rng *rand.Rand, rt
},
},
}
rsp, round, err := r.submitRuntimeRquest(ctx, rtc, req)
rsp, round, err := r.submitRuntimeRequest(ctx, rtc, req)
if err != nil {
r.Logger.Error("Submit reclaim escrow request failure",
"request", req,
Expand Down
9 changes: 9 additions & 0 deletions go/oasis-test-runner/oasis/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ type Helpers struct {
Consensus *ConsensusHelpers
Registry *RegistryHelpers
Keymanager *KeymanagerHelpers
Debug *DebugHelpers
Genesis *GenesisHelpers
}

// New creates new oasis-node cli helpers.
Expand All @@ -68,9 +70,16 @@ func New(env *env.Env, factory Factory, logger *logging.Logger) *Helpers {
Consensus: &ConsensusHelpers{base},
Registry: &RegistryHelpers{base},
Keymanager: &KeymanagerHelpers{base},
Debug: &DebugHelpers{base},
Genesis: &GenesisHelpers{base},
}
}

// SetConfig sets the configuration for the oasis-node cli helpers.
func (h *Helpers) SetConfig(cfg Config) {
h.cfg = cfg
}

// UnsafeReset launches the unsafe-reset subcommand, clearing all consensus and (optionally)
// runtime state.
func (h *Helpers) UnsafeReset(dataDir string, preserveRuntimeStorage, preserveLocalStorage, force bool) error {
Expand Down
36 changes: 36 additions & 0 deletions go/oasis-test-runner/oasis/cli/debug.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package cli

import (
"fmt"

"github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common"
"github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common/flags"
"github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/debug/fixgenesis"
)

// DebugHelpers contains the oasis-node debug CLI helpers.
type DebugHelpers struct {
*helpersBase
}

// FixGenesis is a wrapper for "debug fix-genesis" subcommand.
func (d *DebugHelpers) FixGenesis(
genesisFilePath string,
fixedGenesisFilePath string,
) error {
d.logger.Info("fixing genesis file")

args := []string{
"debug", "fix-genesis",
"--" + flags.CfgGenesisFile, genesisFilePath,
"--" + fixgenesis.CfgNewGenesisFile, fixedGenesisFilePath,
"--" + flags.CfgDebugDontBlameOasis,
"--" + common.CfgDebugAllowTestKeys,
}

if out, err := d.runSubCommandWithOutput("debug-fix-genesis", args); err != nil {
return fmt.Errorf("failed to run 'debug fix-genesis': error: %w output: %s", err, out.String())
}

return nil
}
56 changes: 56 additions & 0 deletions go/oasis-test-runner/oasis/cli/genesis.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package cli

import (
"fmt"

"github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common"
"github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common/flags"
"github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common/grpc"
"github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/stake"
)

// GenesisHelpers contains the oasis-node genesis CLI helpers.
type GenesisHelpers struct {
*helpersBase
}

// Check is a wrapper for "genesis check" subcommand.
func (g *GenesisHelpers) Check(
genesisFilePath string,
) (string, error) {
g.logger.Info("checking genesis file")

args := []string{
"genesis", "check",
"--" + flags.CfgGenesisFile, genesisFilePath,
"--" + flags.CfgDebugDontBlameOasis,
"--" + common.CfgDebugAllowTestKeys,
}

out, err := g.runSubCommandWithOutput("genesis-check", args)
if err != nil {
return "", fmt.Errorf("failed to run 'genesis check': error: %w output: %s", err, out.String())
}

return out.String(), nil
}

// Dump is a wrapper for "genesis dump" subcommand.
func (g *GenesisHelpers) Dump(
genesisFilePath string,
) error {
g.logger.Info("dumping network state to genesis file")

args := []string{
"genesis", "dump",
"--" + stake.CfgHeight, "0",
"--" + flags.CfgGenesisFile, genesisFilePath,
"--" + grpc.CfgAddress, "unix:" + g.cfg.NodeSocketPath,
}

if out, err := g.runSubCommandWithOutput("genesis-dump", args); err != nil {
return fmt.Errorf("failed to run 'genesis dump': error: %w output: %s", err, out.String())
}

return nil
}
39 changes: 28 additions & 11 deletions go/oasis-test-runner/oasis/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,25 +149,38 @@ func (rt *Runtime) BundlePaths() []string {
return paths
}

// RefreshRuntimeBundles makes sure the generated runtime bundles are refreshed.
func (rt *Runtime) RefreshRuntimeBundles() error {
for i, deployCfg := range rt.cfgSave.deployments {
fn := rt.bundlePath(i)
// RefreshRuntimeBundle makes sure the generated runtime bundle is refreshed.
func (rt *Runtime) RefreshRuntimeBundle(deploymentIndex int) error {
if deploymentIndex < 0 || deploymentIndex >= len(rt.cfgSave.deployments) {
return fmt.Errorf("invalid deployment index")
}

// Remove the generated bundle (if any).
if err := os.Remove(fn); err != nil && !errors.Is(err, os.ErrNotExist) {
return err
}
fn := rt.bundlePath(deploymentIndex)

deployCfg.bundle = nil
deployCfg.mrEnclave = nil
// Remove the generated bundle (if any).
if err := os.Remove(fn); err != nil && !errors.Is(err, os.ErrNotExist) {
return err
}

deployCfg := rt.cfgSave.deployments[deploymentIndex]
deployCfg.bundle = nil
deployCfg.mrEnclave = nil

// Generate a fresh bundle.
_, err := rt.ToRuntimeBundles()
_, err := rt.toRuntimeBundle(deploymentIndex)
return err
}

// RefreshRuntimeBundles makes sure the generated runtime bundles are refreshed.
func (rt *Runtime) RefreshRuntimeBundles() error {
for i := range rt.cfgSave.deployments {
if err := rt.RefreshRuntimeBundle(i); err != nil {
return err
}
}
return nil
}

// ToRuntimeBundles serializes the runtime to disk and returns the bundle.
func (rt *Runtime) ToRuntimeBundles() ([]*bundle.Bundle, error) {
var bundles []*bundle.Bundle
Expand All @@ -183,6 +196,10 @@ func (rt *Runtime) ToRuntimeBundles() ([]*bundle.Bundle, error) {
}

func (rt *Runtime) toRuntimeBundle(deploymentIndex int) (*bundle.Bundle, error) {
if deploymentIndex < 0 || deploymentIndex >= len(rt.cfgSave.deployments) {
return nil, fmt.Errorf("invalid deployment index")
}

deployCfg := rt.cfgSave.deployments[deploymentIndex]
fn := rt.bundlePath(deploymentIndex)
switch _, err := os.Stat(fn); err {
Expand Down
Loading

0 comments on commit c234001

Please sign in to comment.