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

Fix/sdk testing #218

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
2 changes: 2 additions & 0 deletions .github/workflows/general.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ jobs:
tests:
name: cargo-test
runs-on: ubuntu-latest
env:
CI: true
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ signed.tx

# testing files
*.feature
test-harness
tests/features
/test-harness
/tests/features

# editor
*.code-workspace
Expand Down
17 changes: 12 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,27 @@ gloo-timers = { version = "0.2.4", features = ["futures"] }
instant = { version = "0.1", features = ["now", "wasm-bindgen"] }

[dev-dependencies]
async-trait = "0.1.51"
cucumber = "0.19.0"
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"] }
cucumber = "0.19.0"
async-trait = "0.1.51"
insta = { version = "1.29.0", features = ["yaml"] }
rand = "0.8.3"
tokio = { version = "1.6.0", features = ["rt-multi-thread", "macros"] }

[profile.dev.package.insta]
opt-level = 3

[profile.dev.package.similar]
opt-level = 3

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

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

harness:
./test-harness.sh up
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 @@ -861,4 +861,4 @@ mod tests {
.is_err()
);
}
}
}
5 changes: 5 additions & 0 deletions src/constant.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// Application ID prefix when signing
pub const APPID_PREFIX: &[u8; 5] = b"appID";

/// how long addresses are in bytes
pub const KEN_LEN_BYTES: u64 = 32;
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ pub mod indexer;
pub mod kmd;

pub mod atomic_transaction_composer;
pub mod constant;

pub mod error;
pub use error::Error;

pub mod logic;

pub mod util;
27 changes: 27 additions & 0 deletions src/logic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use crate::constant::APPID_PREFIX;
use sha2::{Digest, Sha512};

pub fn get_application_address(app_id: u64) -> Vec<u8> {
let app_id: &[u8; 8] = &app_id.to_be_bytes();
let to_sign: Vec<u8> = APPID_PREFIX
.iter()
.copied()
.chain(app_id.iter().copied())
.collect();

let mut hasher = Sha512::new();
hasher.update(to_sign);

hasher.finalize()[..].to_vec()
}

#[cfg(test)]
mod tests {
use super::get_application_address;

#[test]
fn get_application_address_snapshots() {
let a = get_application_address(13);
insta::assert_yaml_snapshot!(a);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
source: src/logic.rs
expression: a
---
- 174
- 108
- 145
- 15
- 43
- 99
- 36
- 10
- 139
- 82
- 201
- 202
- 142
- 242
- 99
- 74
- 61
- 193
- 187
- 44
- 151
- 217
- 248
- 206
- 180
- 209
- 90
- 215
- 232
- 66
- 175
- 204
- 169
- 225
- 82
- 128
- 30
- 94
- 110
- 70
- 3
- 59
- 48
- 108
- 176
- 169
- 159
- 62
- 187
- 88
- 65
- 125
- 161
- 12
- 43
- 23
- 172
- 246
- 74
- 228
- 121
- 195
- 177
- 111

33 changes: 33 additions & 0 deletions tests/cucumber.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use cucumber::World;
use step_defs::world;

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)
// assets feature: omitted (algod v1)

// TODO use tags - so we don't have to create a new config per file (until the tests are complete)

world::World::cucumber()
.max_concurrent_scenarios(1)
.fail_on_skipped()
.run_and_exit("tests/features/integration/applications.feature")
.await;

world::World::cucumber()
.max_concurrent_scenarios(1)
.fail_on_skipped()
.run_and_exit("tests/features/integration/abi.feature")
.await;

world::World::cucumber()
.max_concurrent_scenarios(1)
.fail_on_skipped()
.run_and_exit("tests/features/integration/c2c.feature")
.await;
}
36 changes: 0 additions & 36 deletions tests/features_runner.rs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::step_defs::{
integration::world::World,
util::{read_teal, wait_for_pending_transaction},
world::World,
};
use algonaut::atomic_transaction_composer::{
transaction_signer::TransactionSigner, AbiArgValue, AbiMethodReturnValue, AbiReturnDecodeError,
Expand Down
10 changes: 10 additions & 0 deletions tests/step_defs/account.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use crate::step_defs::world::World;
use cucumber::then;

#[then(
"I get the account address for the current application and see that it matches the app id's hash"
)]
async fn assert_app_account_is_the_hash(w: &mut World) {
let _app_id = w.app_id;
// TODO
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::step_defs::integration::world::World;
use crate::step_defs::util::{parse_app_args, read_teal, split_addresses, split_uint64};
use crate::step_defs::util::{
read_teal, split_addresses, split_and_process_app_args, split_uint64,
};
use crate::step_defs::world::World;
use algonaut_algod::models::{Application, ApplicationLocalState};
use algonaut_transaction::builder::{
CallApplication, ClearApplication, CloseApplication, DeleteApplication, OptInApplication,
Expand All @@ -12,13 +14,13 @@ use data_encoding::BASE64;
use std::error::Error;

#[given(
regex = r#"^I build an application transaction with the transient account, the current application, suggested params, operation "([^"]*)", approval-program "([^"]*)", clear-program "([^"]*)", global-bytes (\d+), global-ints (\d+), local-bytes (\d+), local-ints (\d+), app-args "([^"]*)", foreign-apps "([^"]*)", foreign-assets "([^"]*)", app-accounts "([^"]*)", extra-pages (\d+)$"#
regex = r#"^I build an application transaction with the transient account, the current application, suggested params, operation "([^"]*)", approval-program "([^"]*)", clear-program "([^"]*)", global-bytes (\d+), global-ints (\d+), local-bytes (\d+), local-ints (\d+), app-args "([^"]*)", foreign-apps "([^"]*)", foreign-assets "([^"]*)", app-accounts "([^"]*)", extra-pages (\d+), boxes "([^"]*)"$"#
)]
#[then(
regex = r#"^I build an application transaction with the transient account, the current application, suggested params, operation "([^"]*)", approval-program "([^"]*)", clear-program "([^"]*)", global-bytes (\d+), global-ints (\d+), local-bytes (\d+), local-ints (\d+), app-args "([^"]*)", foreign-apps "([^"]*)", foreign-assets "([^"]*)", app-accounts "([^"]*)", extra-pages (\d+)$"#
regex = r#"^I build an application transaction with the transient account, the current application, suggested params, operation "([^"]*)", approval-program "([^"]*)", clear-program "([^"]*)", global-bytes (\d+), global-ints (\d+), local-bytes (\d+), local-ints (\d+), app-args "([^"]*)", foreign-apps "([^"]*)", foreign-assets "([^"]*)", app-accounts "([^"]*)", extra-pages (\d+), boxes "([^"]*)"$"#
)]
#[when(
regex = r#"^I build an application transaction with the transient account, the current application, suggested params, operation "([^"]*)", approval-program "([^"]*)", clear-program "([^"]*)", global-bytes (\d+), global-ints (\d+), local-bytes (\d+), local-ints (\d+), app-args "([^"]*)", foreign-apps "([^"]*)", foreign-assets "([^"]*)", app-accounts "([^"]*)", extra-pages (\d+)$"#
regex = r#"^I build an application transaction with the transient account, the current application, suggested params, operation "([^"]*)", approval-program "([^"]*)", clear-program "([^"]*)", global-bytes (\d+), global-ints (\d+), local-bytes (\d+), local-ints (\d+), app-args "([^"]*)", foreign-apps "([^"]*)", foreign-assets "([^"]*)", app-accounts "([^"]*)", extra-pages (\d+), boxes "([^"]*)"$"#
)]
async fn i_build_an_application_transaction(
w: &mut World,
Expand All @@ -34,11 +36,12 @@ async fn i_build_an_application_transaction(
foreign_assets: String,
app_accounts: String,
extra_pages: u32,
_boxes: String, // TODO implement boxes
) -> Result<(), Box<dyn Error>> {
let algod = w.algod.as_ref().unwrap();
let transient_account = w.transient_account.as_ref().unwrap();

let args = parse_app_args(app_args)?;
let args = split_and_process_app_args(app_args);

let accounts = split_addresses(app_accounts)?;

Expand Down Expand Up @@ -283,3 +286,28 @@ async fn the_transient_account_should_have(

Ok(())
}

#[then(
regex = r#"according to "([^"]*)", the contents of the box with name "([^"]*)" in the current application should be "([^"]*)". If there is an error it is "([^"]*)"."#
)]
async fn check_box_contents(
_w: &mut World,
_context: String,
_from_client: String,
box_name: String,
_box_value: String,
_error_string: String,
) {
let _box_name = split_and_process_app_args(box_name);

// TODO
// if from_client == "algod" {
// let box_response = w
// .algod
// .as_ref()
// .unwrap()
// .app_box(w.app_id.unwrap(), &box_name)
// .await
// .ok();
// }
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use crate::step_defs::{
integration::world::World,
util::{account_from_kmd_response, wait_for_pending_transaction},
world::World,
};
use algonaut::{algod::v2::Algod, kmd::v1::Kmd};
use algonaut::{algod::v2::Algod, indexer::v2::Indexer, kmd::v1::Kmd};
use algonaut_core::MicroAlgos;
use algonaut_transaction::{Pay, TxnBuilder};
use cucumber::{given, then, when};
use rand::Rng;
use std::error::Error;

#[given(regex = "an algod v2 client")]
#[given("an algod v2 client")]
async fn an_algod_v2_client(w: &mut World) -> Result<(), Box<dyn Error>> {
let algod = Algod::new(
"http://localhost:60000",
Expand All @@ -23,6 +23,15 @@ async fn an_algod_v2_client(w: &mut World) -> Result<(), Box<dyn Error>> {
Ok(())
}

#[given("an indexer v2 client")]
async fn an_indexer_v2_client(w: &mut World) -> Result<(), Box<dyn Error>> {
let indexer = Indexer::new("http://localhost:59999", "").unwrap();

w.indexer = Some(indexer);

Ok(())
}

#[given(regex = r#"^an algod v2 client connected to "([^"]*)" port (\d+) with token "([^"]*)"$"#)]
async fn an_algod_v2_client_connected_to(w: &mut World, host: String, port: String, token: String) {
let algod = Algod::new(&format!("http://{}:{}", host, port), &token).unwrap();
Expand Down
4 changes: 0 additions & 4 deletions tests/step_defs/integration/mod.rs

This file was deleted.

8 changes: 6 additions & 2 deletions tests/step_defs/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
pub mod integration;
mod util;
pub mod abi;
pub mod account;
pub mod applications;
pub mod general;
pub mod util;
pub mod world;
Loading
Loading