Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure Algorand SDKs tests + implement applications feature #115

Merged
merged 9 commits into from
Dec 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .github/workflows/quickstart.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
on: [push, pull_request]
on:
push:
pull_request:
types: [opened]

name: Continuous integration

Expand All @@ -17,7 +20,7 @@ jobs:
with:
command: check

unit:
tests:
name: Tests
runs-on: ubuntu-latest
steps:
Expand All @@ -31,7 +34,8 @@ jobs:
with:
command: test
args: --workspace --lib --examples --test test_account --test test_logic_signature

- run: make docker-test

fmt:
name: Rustfmt
runs-on: ubuntu-latest
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ Cargo.lock
/test.sh
signed.tx
**/.env

# ignore cucumber test resources
test-harness/
tests/features/
9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,24 @@ algonaut_encoding = {path = "algonaut_encoding", version = "0.3.0"}
algonaut_transaction = {path = "algonaut_transaction", version = "0.3.0"}
thiserror = "1.0.23"
rmp-serde = "0.15.5"
tokio = { version = "1.6.0", features = ["rt-multi-thread", "macros"] }

[dev-dependencies]
dotenv = "0.15.0"
tokio = { version = "1.6.0", features = ["rt-multi-thread", "macros"] }
rand = "0.8.3"
getrandom = { version = "0.2.2", features = ["js"] }
data-encoding = "2.3.1"
# Using main branch because of this issue: https://github.com/cucumber-rs/cucumber/issues/173
# TODO replace with v0.11 once released ("few days" from now, according to maintainer)
cucumber = { git = "https://github.com/cucumber-rs/cucumber.git" }
async-trait = "0.1.51"

[features]
default = ["native"]
native = ["algonaut_client/native"]
rustls = ["algonaut_client/rustls"]

[[test]]
name = "features_runner"
harness = false # Allows Cucumber to print output instead of libtest
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
integration:
cargo test --test features_runner --

docker-test:
./tests/docker/run_docker.sh
1 change: 1 addition & 0 deletions algonaut_client/src/algod/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use algonaut_model::algod::v2::{
use reqwest::header::HeaderMap;
use reqwest::Url;

#[derive(Debug)]
/// Client for interacting with the Algorand protocol daemon
pub struct Client {
url: String,
Expand Down
1 change: 1 addition & 0 deletions algonaut_client/src/indexer/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use reqwest::header::HeaderMap;
use reqwest::Url;

/// Client interacting with the Algorand's indexer
#[derive(Debug)]
pub struct Client {
pub(super) url: String,
pub(super) headers: HeaderMap,
Expand Down
5 changes: 3 additions & 2 deletions algonaut_client/src/kmd/v1/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::extensions::reqwest::ResponseExt;
use crate::Headers;
use crate::{error::ClientError, extensions::reqwest::to_header_map};
use algonaut_core::MultisigSignature;
use algonaut_core::{Address, MultisigSignature};
use algonaut_crypto::{Ed25519PublicKey, MasterDerivationKey};
use algonaut_model::kmd::v1::{
CreateWalletRequest, CreateWalletResponse, DeleteKeyRequest, DeleteKeyResponse,
Expand All @@ -19,6 +19,7 @@ use algonaut_model::kmd::v1::{
use reqwest::header::HeaderMap;
use reqwest::Url;

#[derive(Debug)]
/// Client for interacting with the key management daemon
pub struct Client {
pub(super) address: String,
Expand Down Expand Up @@ -262,7 +263,7 @@ impl Client {
&self,
wallet_handle: &str,
wallet_password: &str,
address: &str,
address: &Address,
) -> Result<ExportKeyResponse, ClientError> {
let req = ExportKeyRequest {
wallet_handle_token: wallet_handle.to_string(),
Expand Down
2 changes: 1 addition & 1 deletion algonaut_model/src/algod/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ pub struct BlockHeader {
pub rwd: String,
pub seed: String,
pub ts: u64,
pub txn: String,
pub txn: Option<String>,
}

/// Catchup
Expand Down
1 change: 1 addition & 0 deletions algonaut_transaction/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use rand::Rng;
use ring::signature::{Ed25519KeyPair, KeyPair};
use serde::{Deserialize, Serialize};

#[derive(Debug)]
pub struct Account {
seed: [u8; 32],
address: Address,
Expand Down
2 changes: 1 addition & 1 deletion algonaut_transaction/src/api_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ impl From<Transaction> for ApiTransaction {
api_t.app_id = call.app_id.and_then(num_as_api_option);
api_t.on_complete =
num_as_api_option(application_call_on_complete_to_int(&call.on_complete));
api_t.accounts = call.accounts.to_owned();
api_t.accounts = call.accounts.clone().and_then(vec_as_api_option);
api_t.approval_program = call
.approval_program
.to_owned()
Expand Down
1 change: 1 addition & 0 deletions src/algod/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use algonaut_transaction::SignedTransaction;

use crate::error::AlgonautError;

#[derive(Debug)]
pub struct Algod {
pub(crate) client: Client,
}
Expand Down
1 change: 1 addition & 0 deletions src/indexer/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use algonaut_model::indexer::v2::{

use crate::error::AlgonautError;

#[derive(Debug)]
pub struct Indexer {
pub(super) client: Client,
}
Expand Down
5 changes: 3 additions & 2 deletions src/kmd/v1/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use algonaut_client::kmd::v1::Client;
use algonaut_core::{MultisigSignature, ToMsgPack};
use algonaut_core::{Address, MultisigSignature, ToMsgPack};
use algonaut_crypto::{Ed25519PublicKey, MasterDerivationKey};
use algonaut_model::kmd::v1::{
CreateWalletResponse, DeleteKeyResponse, DeleteMultisigResponse, ExportKeyResponse,
Expand All @@ -13,6 +13,7 @@ use algonaut_transaction::Transaction;

use crate::error::AlgonautError;

#[derive(Debug)]
pub struct Kmd {
pub(crate) client: Client,
}
Expand Down Expand Up @@ -133,7 +134,7 @@ impl Kmd {
&self,
wallet_handle: &str,
wallet_password: &str,
address: &str,
address: &Address,
) -> Result<ExportKeyResponse, AlgonautError> {
Ok(self
.client
Expand Down
13 changes: 13 additions & 0 deletions tests/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# ARG GO_IMAGE=golang:1.13-stretch
# FROM $GO_IMAGE
FROM rust:1.57.0
RUN apt-get update && apt-get install -y make

# Copy SDK code into the container
RUN mkdir -p $HOME/algonaut
COPY . $HOME/algonaut
WORKDIR $HOME/algonaut

# Run integration tests
# CMD ["/bin/bash", "-c", "make unit && make integration"]
CMD ["/bin/bash", "-c", "make integration"]
26 changes: 26 additions & 0 deletions tests/docker/run_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

set -e

# reset test harness
rm -rf test-harness
rm -rf tests/features
# fork with modified features, as cucumber-rs doesn't understand some syntax:
# https://github.com/cucumber-rs/cucumber/issues/174
# https://github.com/cucumber-rs/cucumber/issues/175
# git clone --single-branch --branch master https://github.com/algorand/algorand-sdk-testing.git test-harness
git clone --single-branch --branch master https://github.com/ivanschuetz/algorand-sdk-testing.git test-harness
# copy feature files into project
mv test-harness/features tests/features

RUST_IMAGE=rust:1.57.0

echo "Building docker image from base \"$RUST_IMAGE\""

#build test environment
docker build -t rust-sdk-testing -f tests/docker/Dockerfile "$(pwd)"

# Start test harness environment
./test-harness/scripts/up.sh -p

docker run --network host rust-sdk-testing:latest
25 changes: 25 additions & 0 deletions tests/features_runner.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use cucumber::WorldInit;
use step_defs::integration;

mod step_defs;

#[tokio::main]
async fn main() {
// NOTE: we don't support algod v1 anymore
// features which depend completely on algod v1 are omitted

// algod feature: omitted (algod v1)

// TODO abi feature: ABI not supported yet

integration::applications::World::cucumber()
.max_concurrent_scenarios(1)
.run(integration_path("applications"))
.await;

// assets feature: omitted (algod v1)
}

fn integration_path(feature_name: &str) -> String {
format!("tests/features/integration/{}.feature", feature_name)
}
Loading