Skip to content

Commit

Permalink
go/oasis-test-runner/scenario/e2e/runtime: Add kv_enc test client
Browse files Browse the repository at this point in the history
  • Loading branch information
Yawning committed Jun 24, 2021
1 parent e73a1bc commit 8dfc641
Show file tree
Hide file tree
Showing 7 changed files with 349 additions and 121 deletions.
16 changes: 3 additions & 13 deletions go/oasis-test-runner/scenario/e2e/runtime/keymanager_restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,7 @@ func newKmRestartImpl() scenario.Scenario {
return &kmRestartImpl{
runtimeImpl: *newRuntimeImpl(
"keymanager-restart",
NewBinaryTestClient(
"simple-keyvalue-enc-client",
[]string{
"--key", "key1",
"--seed", "first_seed",
},
),
NewKeyValueEncTestClient().WithKey("key1").WithSeed("first_seed"),
),
}
}
Expand Down Expand Up @@ -69,12 +63,8 @@ func (sc *kmRestartImpl) Run(childEnv *env.Env) error {
// Run the second client on a different key so that it will require
// a second trip to the keymanager.
sc.Logger.Info("starting a second client to check if key manager works")
newTestClient := sc.testClient.Clone().(*BinaryTestClient)
newTestClient.args = []string{
"--key", "key2",
"--seed", "second_seed",
}
sc.runtimeImpl.testClient = newTestClient
newTestClient := sc.testClient.Clone().(*KeyValueEncTestClient)
sc.runtimeImpl.testClient = newTestClient.WithKey("key2").WithSeed("second_seed")

if err = sc.startTestClientOnly(ctx, childEnv); err != nil {
return err
Expand Down
16 changes: 3 additions & 13 deletions go/oasis-test-runner/scenario/e2e/runtime/keymanager_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,7 @@ func newKmUpgradeImpl() scenario.Scenario {
return &kmUpgradeImpl{
runtimeImpl: *newRuntimeImpl(
"keymanager-upgrade",
NewBinaryTestClient(
"simple-keyvalue-enc-client",
[]string{
"--key", "key1",
"--seed", "first_seed",
},
),
NewKeyValueEncTestClient().WithKey("key1").WithSeed("first_seed"),
),
}
}
Expand Down Expand Up @@ -281,12 +275,8 @@ func (sc *kmUpgradeImpl) Run(childEnv *env.Env) error {

// Run client again.
sc.Logger.Info("starting a second client to check if key manager works")
newTestClient := sc.testClient.Clone().(*BinaryTestClient)
newTestClient.args = []string{
"--key", "key2",
"--seed", "second_seed",
}
sc.runtimeImpl.testClient = newTestClient
newTestClient := sc.testClient.Clone().(*KeyValueEncTestClient)
sc.runtimeImpl.testClient = newTestClient.WithKey("key2").WithSeed("second_seed")
if err := sc.startTestClientOnly(ctx, childEnv); err != nil {
return err
}
Expand Down
83 changes: 0 additions & 83 deletions go/oasis-test-runner/scenario/e2e/runtime/runtime_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,9 @@ import (
"path/filepath"
"strings"

"github.com/oasisprotocol/oasis-core/go/common"
"github.com/oasisprotocol/oasis-core/go/common/cbor"
"github.com/oasisprotocol/oasis-core/go/oasis-test-runner/env"
)

var (
BasicKVTestClient = NewBinaryTestClient(
"simple-keyvalue-client",
nil,
)
BasicKVEncTestClient = NewBinaryTestClient(
"simple-keyvalue-enc-client",
nil,
)
)

// TestClient is the interface exposed to implement a runtime test
// client that executes a pre-determined workload against a given runtime.
type TestClient interface {
Expand All @@ -35,76 +22,6 @@ type TestClient interface {
Clone() TestClient
}

// KeyValueTestClient is a client that exercises the simple key-value
// test runtime.
type KeyValueTestClient struct {
sc *runtimeImpl
}

func (cli *KeyValueTestClient) Init(scenario *runtimeImpl) error {
cli.sc = scenario
return nil
}

func (cli *KeyValueTestClient) Start(ctx context.Context, childEnv *env.Env) error {
panic("not implemented")
}

func (cli *KeyValueTestClient) Wait() error {
panic("not implemented")
}

func (cli *KeyValueTestClient) Clone() TestClient {
panic("not implemented")
}

func NewKeyValueTestClient() *KeyValueTestClient {
panic("not implemented")
}

func (sc *runtimeImpl) submitKeyValueRuntimeInsertTx(
ctx context.Context,
id common.Namespace,
key, value string,
nonce uint64,
) error {
_, err := sc.submitRuntimeTx(ctx, id, "insert", struct {
Key string `json:"key"`
Value string `json:"value"`
Nonce uint64 `json:"nonce"`
}{
Key: key,
Value: value,
Nonce: nonce,
})
return err
}

func (sc *runtimeImpl) submitKeyValueRuntimeGetTx(
ctx context.Context,
id common.Namespace,
key string,
nonce uint64,
) (string, error) {
rawRsp, err := sc.submitRuntimeTx(ctx, runtimeID, "get", struct {
Key string `json:"key"`
Nonce uint64 `json:"nonce"`
}{
Key: key,
Nonce: nonce,
})
if err != nil {
return "", fmt.Errorf("failed to submit get tx to runtime: %w", err)
}

var rsp string
if err = cbor.Unmarshal(rawRsp, &rsp); err != nil {
return "", fmt.Errorf("failed to unmarshal response from runtime: %w", err)
}

return rsp, nil
}

// BinaryTestClient is a client that exercises an arbitrary runtime
// by fork/exec-ing another binary.
type BinaryTestClient struct {
Expand Down
85 changes: 85 additions & 0 deletions go/oasis-test-runner/scenario/e2e/runtime/runtime_client_kv.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package runtime

import (
"context"
"fmt"

"github.com/oasisprotocol/oasis-core/go/common"
"github.com/oasisprotocol/oasis-core/go/common/cbor"
"github.com/oasisprotocol/oasis-core/go/oasis-test-runner/env"
)

var BasicKVTestClient = NewBinaryTestClient(
"simple-keyvalue-client",
nil,
)

// KeyValueTestClient is a client that exercises the simple key-value
// test runtime.
type KeyValueTestClient struct {
sc *runtimeImpl
}

func (cli *KeyValueTestClient) Init(scenario *runtimeImpl) error {
cli.sc = scenario
return nil
}

func (cli *KeyValueTestClient) Start(ctx context.Context, childEnv *env.Env) error {
panic("not implemented")
}

func (cli *KeyValueTestClient) Wait() error {
panic("not implemented")
}

func (cli *KeyValueTestClient) Clone() TestClient {
panic("not implemented")
}

func NewKeyValueTestClient() *KeyValueTestClient {
panic("not implemented")
}

func (sc *runtimeImpl) submitKeyValueRuntimeInsertTx(
ctx context.Context,
id common.Namespace,
key, value string,
nonce uint64,
) error {
_, err := sc.submitRuntimeTx(ctx, id, "insert", struct {
Key string `json:"key"`
Value string `json:"value"`
Nonce uint64 `json:"nonce"`
}{
Key: key,
Value: value,
Nonce: nonce,
})
return err
}

func (sc *runtimeImpl) submitKeyValueRuntimeGetTx(
ctx context.Context,
id common.Namespace,
key string,
nonce uint64,
) (string, error) {
rawRsp, err := sc.submitRuntimeTx(ctx, runtimeID, "get", struct {
Key string `json:"key"`
Nonce uint64 `json:"nonce"`
}{
Key: key,
Nonce: nonce,
})
if err != nil {
return "", fmt.Errorf("failed to submit get tx to runtime: %w", err)
}

var rsp string
if err = cbor.Unmarshal(rawRsp, &rsp); err != nil {
return "", fmt.Errorf("failed to unmarshal response from runtime: %w", err)
}

return rsp, nil
}
Loading

0 comments on commit 8dfc641

Please sign in to comment.