From fb86bbc501c8beb27664cd32d7716d8751023de8 Mon Sep 17 00:00:00 2001 From: Yawning Angel Date: Wed, 23 Jun 2021 15:30:12 +0000 Subject: [PATCH] build: Remove the old clients --- .buildkite/benchmarks.pipeline.yml | 7 - .buildkite/code.pipeline.yml | 7 - .buildkite/longtests.pipeline.yml | 7 - .buildkite/rust/coverage.sh | 3 - .../scripts/download_e2e_test_artifacts.sh | 6 +- .buildkite/scripts/test_consim.sh | 48 --- .buildkite/scripts/test_e2e.sh | 1 - .changelog/4038.internal.md | 1 + Cargo.lock | 44 --- Cargo.toml | 5 - tests/clients/simple-keyvalue-enc/Cargo.toml | 18 -- tests/clients/simple-keyvalue-enc/src/main.rs | 143 --------- tests/clients/simple-keyvalue/Cargo.toml | 18 -- tests/clients/simple-keyvalue/src/main.rs | 295 ------------------ tests/clients/test-long-term/Cargo.toml | 16 - tests/clients/test-long-term/src/main.rs | 127 -------- 16 files changed, 2 insertions(+), 744 deletions(-) delete mode 100755 .buildkite/scripts/test_consim.sh create mode 100644 .changelog/4038.internal.md delete mode 100644 tests/clients/simple-keyvalue-enc/Cargo.toml delete mode 100644 tests/clients/simple-keyvalue-enc/src/main.rs delete mode 100644 tests/clients/simple-keyvalue/Cargo.toml delete mode 100644 tests/clients/simple-keyvalue/src/main.rs delete mode 100644 tests/clients/test-long-term/Cargo.toml delete mode 100644 tests/clients/test-long-term/src/main.rs diff --git a/.buildkite/benchmarks.pipeline.yml b/.buildkite/benchmarks.pipeline.yml index 7cdb4e3ba54..6abfe395e6d 100644 --- a/.buildkite/benchmarks.pipeline.yml +++ b/.buildkite/benchmarks.pipeline.yml @@ -62,17 +62,10 @@ steps: - label: Build Rust runtime loader command: - .buildkite/rust/build_generic.sh /workdir -p oasis-core-runtime-loader - - .buildkite/rust/build_generic.sh /workdir -p test-long-term-client - - .buildkite/rust/build_generic.sh /workdir -p simple-keyvalue-client - - .buildkite/rust/build_generic.sh /workdir -p simple-keyvalue-enc-client # Upload the built artifacts. - cd /var/tmp/artifacts/default/debug - buildkite-agent artifact upload oasis-core-runtime-loader - # Clients for E2E tests. - - buildkite-agent artifact upload test-long-term-client - - buildkite-agent artifact upload simple-keyvalue-client - - buildkite-agent artifact upload simple-keyvalue-enc-client plugins: <<: *docker_plugin diff --git a/.buildkite/code.pipeline.yml b/.buildkite/code.pipeline.yml index 7ef88eac456..a1f600d9c16 100644 --- a/.buildkite/code.pipeline.yml +++ b/.buildkite/code.pipeline.yml @@ -129,17 +129,10 @@ steps: - label: Build Rust runtime loader command: - .buildkite/rust/build_generic.sh /workdir -p oasis-core-runtime-loader - - .buildkite/rust/build_generic.sh /workdir -p test-long-term-client - - .buildkite/rust/build_generic.sh /workdir -p simple-keyvalue-client - - .buildkite/rust/build_generic.sh /workdir -p simple-keyvalue-enc-client # Upload the built artifacts. - cd /var/tmp/artifacts/default/debug - buildkite-agent artifact upload oasis-core-runtime-loader - # Clients for E2E tests. - - buildkite-agent artifact upload test-long-term-client - - buildkite-agent artifact upload simple-keyvalue-client - - buildkite-agent artifact upload simple-keyvalue-enc-client retry: <<: *retry_agent_failure plugins: diff --git a/.buildkite/longtests.pipeline.yml b/.buildkite/longtests.pipeline.yml index 18c207e468f..7353f615e36 100644 --- a/.buildkite/longtests.pipeline.yml +++ b/.buildkite/longtests.pipeline.yml @@ -52,17 +52,10 @@ steps: - label: Build Rust runtime loader command: - .buildkite/rust/build_generic.sh /workdir -p oasis-core-runtime-loader - - .buildkite/rust/build_generic.sh /workdir -p test-long-term-client - - .buildkite/rust/build_generic.sh /workdir -p simple-keyvalue-client - - .buildkite/rust/build_generic.sh /workdir -p simple-keyvalue-enc-client # Upload the built artifacts. - cd /var/tmp/artifacts/default/debug - buildkite-agent artifact upload oasis-core-runtime-loader - # Clients for E2E tests. - - buildkite-agent artifact upload test-long-term-client - - buildkite-agent artifact upload simple-keyvalue-client - - buildkite-agent artifact upload simple-keyvalue-enc-client plugins: <<: *docker_plugin diff --git a/.buildkite/rust/coverage.sh b/.buildkite/rust/coverage.sh index 433d6646e6d..84143959a4f 100755 --- a/.buildkite/rust/coverage.sh +++ b/.buildkite/rust/coverage.sh @@ -49,9 +49,6 @@ cargo tarpaulin \ --out Xml \ --all \ --exclude simple-keyvalue \ - --exclude simple-keyvalue-client \ - --exclude simple-keyvalue-enc-client \ - --exclude test-long-term-client \ --exclude-files '*generated*' \ --exclude-files tests \ --exclude-files runtime/src/storage/mkvs/interop \ diff --git a/.buildkite/scripts/download_e2e_test_artifacts.sh b/.buildkite/scripts/download_e2e_test_artifacts.sh index e4ed6018a63..6ddc017a0ad 100755 --- a/.buildkite/scripts/download_e2e_test_artifacts.sh +++ b/.buildkite/scripts/download_e2e_test_artifacts.sh @@ -29,11 +29,7 @@ download_artifact simple-keymanager target/default/debug 755 download_artifact simple-keymanager-upgrade.sgxs target/sgx/x86_64-fortanix-unknown-sgx/debug 755 download_artifact simple-keymanager-upgrade target/default/debug 755 -# Test simple-keyvalue runtime and clients. -download_artifact test-long-term-client target/default/debug 755 -download_artifact simple-keyvalue-client target/default/debug 755 -download_artifact simple-keyvalue-enc-client target/default/debug 755 - +# Test simple-keyvalue runtime. download_artifact simple-keyvalue.sgxs target/sgx/x86_64-fortanix-unknown-sgx/debug 755 download_artifact simple-keyvalue target/default/debug 755 download_artifact simple-keyvalue-upgrade.sgxs target/sgx/x86_64-fortanix-unknown-sgx/debug 755 diff --git a/.buildkite/scripts/test_consim.sh b/.buildkite/scripts/test_consim.sh deleted file mode 100755 index cc5e3e47fdb..00000000000 --- a/.buildkite/scripts/test_consim.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/bash - -############################################################ -# This script tests the Oasis Core project with the consensus -# simulator. -# -# Usage: -# test_consim.sh -############################################################ - -# Helpful tips on writing build scripts: -# https://buildkite.com/docs/pipelines/writing-build-scripts -set -euxo pipefail - -# Working directory. -WORKDIR=$PWD - -################# -# Run test suite. -################# - -echo ${WORKDIR} - -CONSIM_GENESIS=/tmp/consim-genesis.json - -# Generate the consensus sim genesis document. -${WORKDIR}/go/oasis-node/oasis-node \ - genesis init \ - --debug.test_entity \ - --debug.dont_blame_oasis \ - --chain.id test \ - --debug.allow_test_keys \ - --staking.token_symbol BUF \ - -g ${CONSIM_GENESIS} - -# Run the consensus simulator. -${WORKDIR}/go/oasis-node/oasis-node \ - debug consim \ - --datadir /tmp/consim-datadir \ - --log.level DEBUG \ - --log.file /tmp/consim-datadir/consim.log \ - -g ${CONSIM_GENESIS} \ - --debug.dont_blame_oasis \ - --debug.allow_test_keys \ - --consim.workload xfer \ - --consim.workload.xfer.iterations 10000 \ - --consim.num_kept 1 \ - --consim.memdb diff --git a/.buildkite/scripts/test_e2e.sh b/.buildkite/scripts/test_e2e.sh index bde9c967e2e..065ca9d23b2 100755 --- a/.buildkite/scripts/test_e2e.sh +++ b/.buildkite/scripts/test_e2e.sh @@ -48,7 +48,6 @@ ${test_runner_binary} \ ${BUILDKITE:+--basedir ${TEST_BASE_DIR:-$PWD}/e2e} \ --basedir.no_cleanup \ --e2e.node.binary ${node_binary} \ - --e2e/runtime.client.binary_dir ${WORKDIR}/target/default/debug \ --e2e/runtime.runtime.binary_dir.default ${WORKDIR}/target/default/debug \ --e2e/runtime.runtime.binary_dir.intel-sgx ${WORKDIR}/target/sgx/x86_64-fortanix-unknown-sgx/debug \ --e2e/runtime.runtime.loader ${WORKDIR}/target/default/debug/oasis-core-runtime-loader \ diff --git a/.changelog/4038.internal.md b/.changelog/4038.internal.md new file mode 100644 index 00000000000..c797214f8f0 --- /dev/null +++ b/.changelog/4038.internal.md @@ -0,0 +1 @@ +build: Stuff to make CI faster diff --git a/Cargo.lock b/Cargo.lock index 4a837e596e5..bf226b37dca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2271,36 +2271,6 @@ dependencies = [ "serde", ] -[[package]] -name = "simple-keyvalue-client" -version = "0.0.0" -dependencies = [ - "clap", - "grpcio", - "io-context", - "oasis-core-client", - "oasis-core-runtime", - "rand 0.7.3", - "serde_bytes", - "simple-keyvalue-api", - "tokio 1.6.1", -] - -[[package]] -name = "simple-keyvalue-enc-client" -version = "0.0.0" -dependencies = [ - "clap", - "grpcio", - "io-context", - "oasis-core-client", - "oasis-core-keymanager-client", - "oasis-core-runtime", - "rand 0.7.3", - "simple-keyvalue-api", - "tokio 1.6.1", -] - [[package]] name = "simple_asn1" version = "0.5.3" @@ -2519,19 +2489,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "test-long-term-client" -version = "0.0.0" -dependencies = [ - "clap", - "grpcio", - "oasis-core-client", - "oasis-core-runtime", - "rand 0.7.3", - "simple-keyvalue-api", - "tokio 1.6.1", -] - [[package]] name = "textwrap" version = "0.11.0" @@ -2636,7 +2593,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0a38d31d7831c6ed7aad00aa4c12d9375fd225a6dd77da1d25b707346319a975" dependencies = [ "autocfg 1.0.1", - "num_cpus", "pin-project-lite 0.2.6", ] diff --git a/Cargo.toml b/Cargo.toml index 8ffcf314f47..a6678df1842 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,11 +11,6 @@ members = [ # Test runtimes. "tests/runtimes/simple-keyvalue", "tests/runtimes/simple-keymanager", - - # Test clients. - "tests/clients/simple-keyvalue", - "tests/clients/simple-keyvalue-enc", - "tests/clients/test-long-term", ] [profile.release] diff --git a/tests/clients/simple-keyvalue-enc/Cargo.toml b/tests/clients/simple-keyvalue-enc/Cargo.toml deleted file mode 100644 index 9a83c8821a3..00000000000 --- a/tests/clients/simple-keyvalue-enc/Cargo.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -name = "simple-keyvalue-enc-client" -version = "0.0.0" -authors = ["Oasis Protocol Foundation "] -description = "Encrypted key value test client" -edition = "2018" - -[dependencies] -oasis-core-client = { path = "../../../client" } -oasis-core-keymanager-client = { path = "../../../keymanager-client" } -oasis-core-runtime = { path = "../../../runtime" } -simple-keyvalue-api = { path = "../../runtimes/simple-keyvalue/api" } - -clap = "2.29.1" -grpcio = "0.9.0" -io-context = "0.2.0" -rand = "0.7.3" -tokio = { version = "1", features = ["rt-multi-thread"] } diff --git a/tests/clients/simple-keyvalue-enc/src/main.rs b/tests/clients/simple-keyvalue-enc/src/main.rs deleted file mode 100644 index 498bf873a45..00000000000 --- a/tests/clients/simple-keyvalue-enc/src/main.rs +++ /dev/null @@ -1,143 +0,0 @@ -// Allow until oasis-core#3572. -#![allow(deprecated)] - -use std::{collections::BTreeMap, sync::Arc}; - -use clap::{value_t_or_exit, App, Arg}; -use grpcio::EnvBuilder; -use io_context::Context; -use rand::{rngs::StdRng, Rng, SeedableRng}; -use tokio::runtime::Runtime; - -use oasis_core_client::{create_txn_api_client, Node, TxnClient}; -use oasis_core_keymanager_client::{self, KeyManagerClient, KeyPairId}; -use oasis_core_runtime::{ - common::{crypto::hash::Hash, namespace::Namespace}, - consensus::{ - address::Address, - staking::{Account, Delegation}, - }, -}; - -use simple_keyvalue_api::{ - with_api, AddEscrow, Key, KeyValue, ReclaimEscrow, Transfer, UpdateRuntime, Withdraw, -}; - -with_api! { - create_txn_api_client!(SimpleKeyValueClient, api); -} - -fn main() { - let matches = App::new("Simple key/value runtime test client (with encryption)") - .arg( - Arg::with_name("runtime-id") - .long("runtime-id") - .takes_value(true) - .required(true), - ) - .arg( - Arg::with_name("node-address") - .long("node-address") - .takes_value(true) - .required(true), - ) - .arg( - Arg::with_name("key") - .long("key") - .takes_value(true) - .default_value("hello_key") - .required(true), - ) - .arg(Arg::with_name("seed").long("seed").takes_value(true)) - .get_matches(); - - let node_address = matches.value_of("node-address").unwrap(); - let runtime_id = value_t_or_exit!(matches, "runtime-id", Namespace); - let k = matches.value_of("key").unwrap(); - let nonce_seed = matches - .value_of("seed") - .unwrap_or("seeeeeeeeeeeeeeeeeeeeeeeeeeeeeed") - .as_bytes(); - - let h = Hash::digest_bytes(&nonce_seed); - let mut rng: StdRng = SeedableRng::from_seed(h.into()); - - println!("Initializing simple key/value runtime client!"); - let rt = Runtime::new().unwrap(); - let env = Arc::new(EnvBuilder::new().build()); - let node = Node::new(env, node_address); - let txn_client = TxnClient::new(node.channel(), runtime_id, None); - let kv_client = SimpleKeyValueClient::new(txn_client); - - let kv = KeyValue { - key: k.to_owned(), - value: String::from("hello_value"), - nonce: rng.gen(), - }; - let mut key = Key { - key: k.to_owned(), - nonce: rng.gen(), - }; - println!( - "Storing \"{}\" as key and \"{}\" as value to database...", - kv.key, kv.value - ); - let r: Option = rt.block_on(kv_client.enc_insert(kv)).unwrap(); - assert_eq!(r, None); // key should not exist in db before - - println!("Getting \"{}\"...", key.key); - let r = rt.block_on(kv_client.enc_get(key.clone())).unwrap(); - match r { - Some(val) => { - println!("Got \"{}\"", val); - assert_eq!(val, "hello_value") - } // key should exist in db - None => { - println!("Key not found"); - panic!("Key \"{}\" not found, but it should be.", key.key) - } - } - key.nonce = rng.gen(); - - println!("Removing \"{}\" record from database...", key.key); - let r = rt.block_on(kv_client.enc_remove(key.clone())).unwrap(); - assert_eq!(r, Some("hello_value".to_string())); // key should exist in db while removing it - key.nonce = rng.gen(); - - println!( - "Getting \"{}\" to check whether it still exists...", - key.key - ); - let r = rt.block_on(kv_client.enc_get(key.clone())).unwrap(); - match r { - Some(_) => println!("Key still exists."), - None => println!("Key not found anymore"), - } - assert_eq!(r, None, "key should not exist anymore"); - key.nonce = rng.gen(); - - // Test that key manager connection via EnclaveRPC works. - println!("Testing key manager connection via gRPC transport..."); - // TODO: Key manager MRENCLAVE. - let km_client = Arc::new(oasis_core_keymanager_client::RemoteClient::new_grpc( - runtime_id, - None, - node.channel(), - 1024, - )); - - // Request public key for some "key pair id". - let key_pair_id = KeyPairId::from(Hash::empty_hash().as_ref()); - let r = rt - .block_on(km_client.get_public_key(Context::background(), key_pair_id)) - .unwrap(); - assert!(r.is_some(), "get_public_key should return a public key"); - let pkey = r; - - let r = rt - .block_on(km_client.get_public_key(Context::background(), key_pair_id)) - .unwrap(); - assert_eq!(r, pkey, "get_public_key should return the same public key"); - - println!("Simple key/value client finished."); -} diff --git a/tests/clients/simple-keyvalue/Cargo.toml b/tests/clients/simple-keyvalue/Cargo.toml deleted file mode 100644 index a35602e29e0..00000000000 --- a/tests/clients/simple-keyvalue/Cargo.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -name = "simple-keyvalue-client" -version = "0.0.0" -authors = ["Oasis Protocol Foundation "] -description = "Key value test client" -edition = "2018" - -[dependencies] -oasis-core-client = { path = "../../../client" } -oasis-core-runtime = { path = "../../../runtime" } -simple-keyvalue-api = { path = "../../runtimes/simple-keyvalue/api" } - -clap = "2.29.1" -grpcio = "0.9.0" -io-context = "0.2.0" -rand = "0.7.3" -tokio = { version = "1", features = ["rt-multi-thread"] } -serde_bytes = "0.11.5" diff --git a/tests/clients/simple-keyvalue/src/main.rs b/tests/clients/simple-keyvalue/src/main.rs deleted file mode 100644 index 82c1a053f86..00000000000 --- a/tests/clients/simple-keyvalue/src/main.rs +++ /dev/null @@ -1,295 +0,0 @@ -// Allow until oasis-core#3572. -#![allow(deprecated)] - -#[macro_use] -extern crate clap; -extern crate grpcio; -extern crate io_context; -extern crate oasis_core_client; -extern crate oasis_core_runtime; -extern crate simple_keyvalue_api; -extern crate tokio; - -use std::{collections::BTreeMap, sync::Arc}; - -use clap::{App, Arg}; -use grpcio::EnvBuilder; -use io_context::Context; -use rand::{rngs::StdRng, Rng, SeedableRng}; -use serde_bytes::ByteBuf; -use tokio::runtime::Runtime; - -use oasis_core_client::{ - create_txn_api_client, - transaction::{Query, QueryCondition}, - Node, TxnClient, -}; -use oasis_core_runtime::{ - common::{crypto::hash::Hash, namespace::Namespace}, - consensus::{ - address::Address, - staking::{Account, Delegation}, - }, - storage::MKVS, -}; -use simple_keyvalue_api::{ - with_api, AddEscrow, Key, KeyValue, ReclaimEscrow, Transfer, UpdateRuntime, Withdraw, -}; - -with_api! { - create_txn_api_client!(SimpleKeyValueClient, api); -} - -fn main() { - let matches = App::new("Simple key/value runtime test client") - .arg( - Arg::with_name("runtime-id") - .long("runtime-id") - .takes_value(true) - .required(true), - ) - .arg( - Arg::with_name("node-address") - .long("node-address") - .takes_value(true) - .required(true), - ) - .arg(Arg::with_name("seed").long("seed").takes_value(true)) - .arg(Arg::with_name("repeat").long("repeat")) - .get_matches(); - - let node_address = matches.value_of("node-address").unwrap(); - let runtime_id = value_t_or_exit!(matches, "runtime-id", Namespace); - let nonce_seed = matches - .value_of("seed") - .unwrap_or("seeeeeeeeeeeeeeeeeeeeeeeeeeeeeed") - .as_bytes(); - let repeat = matches.is_present("repeat"); - - let h = Hash::digest_bytes(&nonce_seed); - let mut rng: StdRng = SeedableRng::from_seed(h.into()); - - println!("Initializing simple key/value runtime client!"); - let rt = Runtime::new().unwrap(); - let env = Arc::new(EnvBuilder::new().build()); - let node = Node::new(env, node_address); - let txn_client = TxnClient::new(node.channel(), runtime_id, None); - let kv_client = SimpleKeyValueClient::new(txn_client); - - // Check whether Runtime ID is also set remotely. - let r: Option = rt.block_on(kv_client.get_runtime_id(())).unwrap(); - assert_eq!(runtime_id.to_string(), r.expect("runtime_id")); - - let mut iteration = 0; - while iteration < 1 || repeat { - println!("Beginning client loop iteration..."); - iteration += 1; - - // Test simple [set,get] key calls - let mut kv = KeyValue { - key: String::from("hello_key"), - value: String::from("hello_value_from_") + &runtime_id.to_string(), - nonce: Some(rng.gen()), - }; - let mut k = Key { - key: kv.key.clone(), - nonce: Some(rng.gen()), - }; - println!( - "Storing \"{}\" as key and \"{}\" as value to database...", - kv.key, kv.value - ); - let r: Option = rt.block_on(kv_client.insert(kv.clone())).unwrap(); - if !repeat { - assert_eq!(r, None); // key should not exist in db before - } - kv.nonce = Some(rng.gen()); - - println!("Getting \"{}\"...", k.key); - let r = rt.block_on(kv_client.get(k.clone())).unwrap(); - match r { - Some(val) => { - println!("Got \"{}\"", val); - assert_eq!(val, kv.value) - } // key should exist in db - None => { - println!("Key not found"); - panic!("Key \"{}\" not found, but it should be.", kv.value) - } - } - k.nonce = Some(rng.gen()); - - // Test [set, get] long key calls - let mut long_kv = KeyValue { - key: String::from("Unlock the potential of your data without compromising security or privacy"), - value: String::from("The platform that puts data privacy first. From sharing medical records, to analyzing personal financial information etc."), - nonce: Some(rng.gen()), - }; - let mut long_k = Key { - key: long_kv.key.clone(), - nonce: Some(rng.gen()), - }; - println!("Storing long key and value to database..."); - let r: Option = rt.block_on(kv_client.insert(long_kv.clone())).unwrap(); - if !repeat { - assert_eq!(r, None); // key should not exist in db before - } - long_kv.nonce = Some(rng.gen()); - - println!("Testing runtime message emission..."); - rt.block_on(kv_client.consensus_transfer(Transfer { - nonce: rng.gen(), - transfer: Default::default(), - })) - .unwrap(); - - println!("Getting long key..."); - let r = rt.block_on(kv_client.get(long_k.clone())).unwrap(); - match r { - Some(val) => { - println!("Got correct long value"); - assert_eq!(val, long_kv.value) - } // key should exist in db - None => { - println!("Key not found"); - panic!("Long key not found, but it should be.") - } - } - long_k.nonce = Some(rng.gen()); - - // Test get_latest_block call. - println!("Getting latest block..."); - let snapshot = rt - .block_on(kv_client.txn_client().get_latest_block()) - .expect("get latest block snapshot"); - println!("Retrieved block: {:?}", snapshot.block); - println!("Accessing read-only state snapshot..."); - let r = snapshot - .get(Context::background(), kv.key.as_bytes()) - .expect("read-only state get"); - println!( - "Got \"{}\" ({:?})", - String::from_utf8(r.clone()).unwrap(), - r - ); - assert_eq!(&r[..], kv.value.as_bytes()); - - // Test get_block call. - for round in 0..=snapshot.block.header.round { - println!("Getting indexed block {}...", round); - let snapshot = rt - .block_on(kv_client.txn_client().get_block(round)) - .expect("get block snapshot") - .expect("block must exist"); - - println!("Retrieved block: {:?}", snapshot.block); - assert_eq!(snapshot.block.header.round, round); - } - - let latest_snapshot = snapshot; - let snapshot = rt - .block_on(kv_client.txn_client().get_block(100000)) - .expect("non-existent block must return None"); - assert!(snapshot.is_none(), "non-existent block must return None"); - - println!("Removing \"{}\" record from database...", k.key); - let r = rt.block_on(kv_client.remove(k.clone())).unwrap(); - if !repeat { - assert_eq!(r, Some(kv.value)); // key should exist in db while removing it - } - k.nonce = Some(rng.gen()); - - println!("Getting \"{}\" to check whether it still exists...", kv.key); - let r = rt.block_on(kv_client.get(k.clone())).unwrap(); - match r { - Some(_) => println!("Key still exists."), - None => println!("Key not found anymore"), - } - assert_eq!(r, None, "key should not exist anymore"); - k.nonce = Some(rng.gen()); - - // Test wait_block_indexed call. - println!("Waiting for block to be indexed..."); - let latest_round = latest_snapshot.block.header.round; - rt.block_on(kv_client.txn_client().wait_block_indexed(latest_round)) - .expect("wait block indexed"); - - // Test get_block_by_hash call. - println!( - "Querying block by hash ({:?})...", - latest_snapshot.block_hash - ); - let snapshot = rt - .block_on( - kv_client - .txn_client() - .get_block_by_hash(latest_snapshot.block_hash), - ) - .expect("query block snapshot") - .expect("block must exist"); - println!("Found block: {:?}", snapshot.block); - - // Test get_txs call. - println!("Fetching transaction inputs..."); - let txns = rt - .block_on( - kv_client - .txn_client() - .get_txs(snapshot.block.header.round, snapshot.block.header.io_root), - ) - .expect("get transactions"); - println!("Found transactions: {:?}", txns); - assert_eq!(txns.len(), 1); - - // Test query_tx call. - println!("Querying transaction tags (kv_op=insert)..."); - let snapshot = rt - .block_on(kv_client.txn_client().query_tx(b"kv_op", b"insert")) - .expect("query transaction snapshot") - .expect("transaction must exist"); - println!( - "Found transaction: index={} input={:?} output={:?}", - snapshot.index, snapshot.input, snapshot.output - ); - - // Test query_txs call. - println!("Querying transaction tags (kv_op=insert)..."); - let query = Query { - round_min: 0, - round_max: latest_round, - conditions: vec![QueryCondition { - key: b"kv_op".to_vec(), - values: vec![ByteBuf::from(b"insert".to_vec())], - }], - limit: 0, - }; - let txns = rt - .block_on(kv_client.txn_client().query_txs(query)) - .expect("query transactions"); - println!("Found transactions:"); - for txn in txns { - println!( - "round={} index={} input={:?} output={:?}", - txn.block_snapshot.block.header.round, txn.index, txn.input, txn.output - ); - } - } - - println!("Testing consensus queries:"); - let (accounts, delegations) = rt - .block_on(kv_client.consensus_accounts(())) - .expect("query consensus account"); - - for (addr, acc) in accounts { - println!("Account: {:?}: {:?}", addr, acc); - } - - println!("Delegations:"); - for (addr, dels) in delegations { - for (addr2, del) in dels { - println!("Escrow: {:?}: Delegator: {:?}: {:?}", addr, addr2, del); - } - } - - println!("Simple key/value client finished."); -} diff --git a/tests/clients/test-long-term/Cargo.toml b/tests/clients/test-long-term/Cargo.toml deleted file mode 100644 index 3624344f3e5..00000000000 --- a/tests/clients/test-long-term/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "test-long-term-client" -version = "0.0.0" -authors = ["Oasis Protocol Foundation "] -description = "Key value test client" -edition = "2018" - -[dependencies] -oasis-core-client = { path = "../../../client" } -oasis-core-runtime = { path = "../../../runtime" } -simple-keyvalue-api = { path = "../../runtimes/simple-keyvalue/api" } - -clap = "2.29.1" -grpcio = "0.9.0" -rand = "0.7.3" -tokio = { version = "1", features = ["rt-multi-thread"] } diff --git a/tests/clients/test-long-term/src/main.rs b/tests/clients/test-long-term/src/main.rs deleted file mode 100644 index d201878ce26..00000000000 --- a/tests/clients/test-long-term/src/main.rs +++ /dev/null @@ -1,127 +0,0 @@ -// Allow until oasis-core#3572. -#![allow(deprecated)] - -use std::{collections::BTreeMap, sync::Arc, thread, time}; - -use clap::{value_t_or_exit, App, Arg}; -use grpcio::EnvBuilder; -use rand::{rngs::StdRng, Rng, SeedableRng}; -use tokio::runtime::Runtime; - -use oasis_core_client::{create_txn_api_client, Node, TxnClient}; -use oasis_core_runtime::{ - common::{crypto::hash::Hash, namespace::Namespace}, - consensus::{ - address::Address, - staking::{Account, Delegation}, - }, -}; - -use simple_keyvalue_api::{ - with_api, AddEscrow, Key, KeyValue, ReclaimEscrow, Transfer, UpdateRuntime, Withdraw, -}; - -with_api! { - create_txn_api_client!(SimpleKeyValueClient, api); -} - -fn main() { - let matches = App::new("Simple key/value runtime test client") - .arg( - Arg::with_name("runtime-id") - .long("runtime-id") - .takes_value(true) - .required(true), - ) - .arg( - Arg::with_name("node-address") - .long("node-address") - .takes_value(true) - .required(true), - ) - .arg( - Arg::with_name("mode") - .long("mode") - .help("client operation mode") - .takes_value(true) - .possible_values(&["sleep", "part1", "part1-nomsg", "part2"]) - .default_value("sleep"), - ) - .arg( - Arg::with_name("sleep-for") - .long("sleep-for") - .help("amount of seconds to sleep for in sleep mode") - .takes_value(true) - .default_value("60"), - ) - .arg(Arg::with_name("seed").long("seed").takes_value(true)) - .get_matches(); - - let node_address = matches.value_of("node-address").unwrap(); - let runtime_id = value_t_or_exit!(matches, "runtime-id", Namespace); - let mode = matches.value_of("mode").unwrap(); - let nonce_seed = matches - .value_of("seed") - .unwrap_or("seeeeeeeeeeeeeeeeeeeeeeeeeeeeeed") - .as_bytes(); - - let h = Hash::digest_bytes(&nonce_seed); - let mut rng: StdRng = SeedableRng::from_seed(h.into()); - - println!("Initializing simple key/value runtime!"); - let rt = Runtime::new().unwrap(); - let env = Arc::new(EnvBuilder::new().build()); - let node = Node::new(env, node_address); - let txn_client = TxnClient::new(node.channel(), runtime_id, None); - let kv_client = SimpleKeyValueClient::new(txn_client); - - let mut kv = KeyValue { - key: String::from("my_key"), - value: String::from("my_value"), - nonce: rng.gen(), - }; - let mut key = Key { - key: kv.key.to_owned(), - nonce: rng.gen(), - }; - - if mode == "sleep" || mode == "part1" || mode == "part1-nomsg" { - println!("Inserting key/value pair"); - let r = rt.block_on(kv_client.insert(kv.clone())).unwrap(); - assert_eq!(r, None); // key should not exist in db before - kv.nonce = rng.gen(); - - // Check value. - println!("Checking if key exists and has the correct value"); - let r = rt.block_on(kv_client.get(key.clone())).unwrap(); - assert_eq!(r.unwrap(), kv.value); // key should exist in db - key.nonce = rng.gen(); - - if mode != "part1-nomsg" { - // Emit message so emitted messages will be pending before epoch transition. - println!("Testing runtime message emission..."); - rt.block_on(kv_client.consensus_transfer(Transfer { - nonce: rng.gen(), - transfer: Default::default(), - })) - .unwrap(); - } - } - - if mode == "sleep" { - let sleep_for = value_t_or_exit!(matches, "sleep-for", u64); - - // Sleep to allow for epoch to advance. - println!("Sleeping for {} seconds", sleep_for); - thread::sleep(time::Duration::from_secs(sleep_for)); - } - - if mode == "sleep" || mode == "part2" { - // Check value again. - println!("Checking (again) if key exists and has the correct value"); - let r = rt.block_on(kv_client.get(key.clone())).unwrap(); - assert_eq!(r.unwrap(), "my_value".to_string()); // key should still exist in db - } - - println!("All done"); -}