Skip to content

Commit

Permalink
test: add workflow for ic-ref
Browse files Browse the repository at this point in the history
  • Loading branch information
hansl committed Aug 18, 2020
1 parent 579ecce commit 1be2629
Show file tree
Hide file tree
Showing 11 changed files with 175 additions and 13 deletions.
85 changes: 85 additions & 0 deletions .github/workflows/ic-ref.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: ic-ref

on: [push]

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
build: [ linux-0-8 ]
include:
- build: linux-0-8
ghc: '8.8.3'
spec: 'joachim/test-for-agent-rust'
os: ubuntu-latest
rust: stable

steps:
- uses: actions/checkout@v2
with:
path: main
- uses: actions/checkout@v2
with:
repository: 'dfinity-lab/ic-ref'
# Personal Read-only Access Token created by [email protected]
token: ${{ secrets.IC_REF_TOKEN }}
path: ic-ref
ref: ${{ matrix.spec }}

- name: Cache ~/.cabal/store
uses: actions/cache@v1
with:
path: ~/.cabal/store
key: ${{ runner.os }}-${{ matrix.ghc }}-cabal-store
- uses: actions/[email protected]
with:
ghc-version: ${{ matrix.ghc }}

- name: Cache Cargo registry
uses: actions/cache@v1
with:
path: ~/.cargo/registry
key: ${{ matrix.build }}-cargo-registry-${{ hashFiles('main/**/Cargo.lock') }}
restore-keys: |
${{ matrix.build }}-cargo-registry-
- name: Cache Cargo index
uses: actions/cache@v1
with:
path: ~/.cargo/git
key: ${{ matrix.build }}-cargo-index-${{ hashFiles('main/**/Cargo.lock') }}
restore-keys: |
${{ matrix.build }}-cargo-index-
- name: Cache Cargo build
uses: actions/cache@v1
with:
path: main/target
key: ${{ matrix.build }}-target-${{ hashFiles('main/**/Cargo.lock') }}
restore-keys: |
${{ matrix.build }}-target-
- name: Install Rust
run: |
rustup update ${{ matrix.rust }} --no-self-update
rustup default ${{ matrix.rust }}
- name: Build ic-ref
run: |
ls -l /opt/ghc/
export PATH=/opt/ghc/bin:$PATH
cabal --version
ghc --version
mkdir -p $HOME/bin
cd ic-ref/impl
cabal update
cabal install -w ghc-${{ matrix.ghc }} --overwrite-policy=always --installdir=$HOME/bin
- name: Run Tests
run: |
set -ex
$HOME/bin/ic-ref --pick-port --write-port-to $HOME/ic_ref_port &
sleep 1
export IC_REF_PORT=$(cat $HOME/ic_ref_port)
cd main/ic-agent
cargo test --features ic_ref_tests --test ic-ref
env:
RUST_BACKTRACE: 1
3 changes: 1 addition & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ on: [pull_request]

jobs:
test:
name: Lint

name: lint
runs-on: ubuntu-latest

steps:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
name: Tests

on: [pull_request]
on: [push]

jobs:
test:
name: Test

runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand Down Expand Up @@ -47,6 +45,8 @@ jobs:
rustup update ${{ matrix.rust }} --no-self-update
rustup default ${{ matrix.rust }}
- name: Run Tests
run: cargo test --all-features
run: |
# Do not test all features here.
cargo test
env:
RUST_BACKTRACE: 1
5 changes: 0 additions & 5 deletions .mergify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ pull_request_rules:
conditions:
- "#approved-reviews-by>=1"
- "#changes-requested-reviews-by=0"
- "-conflict"
- "-draft"
- status-success=conventional-pr-title
- "#status-success>=1"
- "#status-failure=0"
- base=master
- label=automerge-squash
actions:
merge:
Expand Down
8 changes: 7 additions & 1 deletion ic-agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@ rand = "0.7.2"
reqwest = "0.10.4"
serde = { version = "1.0.101", features = ["derive"] }
serde_bytes = "0.11.2"
serde_cbor = "0.10"
serde_cbor = "0.11.1"
url = "2.1.0"

[dev-dependencies]
actix-rt = "1.1.1"
mockito = "0.27.0"
proptest = "0.9.5"
tokio = "0.2.6"

[features]
default = []

ic_ref_tests = ['default'] # Used to separate integration tests for ic-ref which need a server running.
32 changes: 31 additions & 1 deletion ic-agent/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,35 @@ This library contains typings and utility functions dealing with the public spec
client. It might be shared in the future but for now is separated for the purpose of testing and
development.

== Running Tests
Regular tests can be run by anyone using `cargo test`. This will not run a special version of the
tests that runs against a server implementation of the public specification, though those
tests can be run against a compatible Replica.

=== Public Spec Tests
The `ic-ref` integration tests have to have a locally available server (cannot be run accross
a network). To run those locally, one must set the `IC_REF_PORT` environment variable to the
network port the server listens to.

If you know a replica is compatible with the ic_api version supported in the code, you can run
the replica (for example, using `dfx replica`) locally and set the environment variable to the
port the replica will listen to.

Once you have a replica and the environment variable, change the current directory to the
`ic-agent` package, and run the `ic-ref` test suite, using:

[sources, bash]
----
cd ic-agent
cargo test --features=ic_ref_tests --test ic-ref
----

Alternatively, removing the `--test ic-ref` argument will run ALL tests, including the `ic-ref`
test suite.

On CI, we use a reference implementation which the Replica follows as well. This ensures
compatibility with the latest version.

== References
The latest version of the https://hydra.dfinity.systems/latest/dfinity-ci-build/dfinity/dfinity.docs.x86_64-linux/dfinity/spec/public/index.html[public spec] is available internally on hydra.
The public specification of the Internet Computer is, at this moment, privately shared. When it
is made public a reference to the version supported will be available here.
6 changes: 6 additions & 0 deletions ic-agent/src/agent/agent_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,9 @@ impl From<TextualCanisterIdError> for AgentError {
Self::CanisterIdTextError(err)
}
}

impl From<AgentError> for String {
fn from(err: AgentError) -> Self {
format!("{:?}", err)
}
}
2 changes: 2 additions & 0 deletions ic-agent/tests/ic-ref.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#![cfg(feature = "ic_ref_tests")]
mod ic_ref;
2 changes: 2 additions & 0 deletions ic-agent/tests/ic_ref/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod status;
mod utils;
25 changes: 25 additions & 0 deletions ic-agent/tests/ic_ref/status.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use super::utils::create_agent;

#[actix_rt::test]
async fn status_endpoint_works() -> Result<(), String> {
let agent = create_agent().await?;
agent.ping_once().await?;

Ok(())
}

#[actix_rt::test]
async fn status_endpoint_is_expected() -> Result<(), String> {
let agent = create_agent().await?;
let status = agent.ping_once().await?;

match status {
serde_cbor::Value::Map(map) => {
let key = serde_cbor::Value::from("ic_api_version".to_string());
assert_eq!(map.get( &key), Some(&serde_cbor::Value::from("0.8.2".to_string())));
},
x => assert!(false, "Invalid status return: {:?}", x),
}

Ok(())
}
12 changes: 12 additions & 0 deletions ic-agent/tests/ic_ref/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use ic_agent::{Agent, AgentConfig};

pub async fn create_agent() -> Result<Agent, String>
{
let port_env = std::env::var("IC_REF_PORT").expect("Need to specify the IC_REF_PORT environment variable.");
let port = port_env.parse::<u32>().expect("Could not parse the IC_REF_PORT environment variable as an integer.");

Ok(ic_agent::Agent::new(AgentConfig {
url: &format!("http://127.0.0.1:{}", port),
..AgentConfig::default()
})?)
}

0 comments on commit 1be2629

Please sign in to comment.