Skip to content

Commit

Permalink
Merge branch 'main' into ORB-260-fund-your-own-station-cycles
Browse files Browse the repository at this point in the history
  • Loading branch information
olaszakos authored Aug 8, 2024
2 parents 562e699 + a9e8411 commit e4e294e
Show file tree
Hide file tree
Showing 19 changed files with 697 additions and 365 deletions.
85 changes: 69 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,22 @@ candid = "0.10.3"
candid_parser = "0.1.3"
cap-std = "3.1.0"
clap = { version = "4.5.7", features = ["derive"] }
dfx-core = { git = "https://github.com/dfinity/sdk.git", tag = "0.20.2-beta.0" }
dfx-core = { git = "https://github.com/dfinity/sdk.git", tag = "0.22.0" }
convert_case = "0.6"
futures = "0.3"
getrandom = { version = "0.2", features = ["custom"] }
hex = "0.4"
# The ic-agent matches the one sed by bthe
ic-agent = { git = "https://github.com/dfinity/agent-rs.git", rev = "8273d321e9a09fd8373bd4e38b0676ec6ad9c260" }
ic-asset = { git = "https://github.com/dfinity/sdk.git", rev = "ae10a96b381cfce3d8ac5a6cb940d19224ea6d2e" }
ic-certified-assets = { git = "https://github.com/dfinity/sdk.git", rev = "ae10a96b381cfce3d8ac5a6cb940d19224ea6d2e" }
ic-agent = { git = "https://github.com/dfinity/agent-rs.git", rev = "be929fd7967249c879f48f2f494cbfc5805a7d98" }
ic-asset = { git = "https://github.com/dfinity/sdk.git", rev = "75c080ebae22a70578c06ddf1eda0b18ef091845" }
ic-certified-assets = { git = "https://github.com/dfinity/sdk.git", rev = "75c080ebae22a70578c06ddf1eda0b18ef091845" }
ic-cdk = "0.13.2"
ic-cdk-macros = "0.9"
ic-cdk-timers = "0.7.0"
ic-ledger-types = "0.10.0"
ic-stable-structures = "0.6.4"
ic-utils = { git = "https://github.com/dfinity/agent-rs.git", rev = "8273d321e9a09fd8373bd4e38b0676ec6ad9c260" }
ic-utils = { git = "https://github.com/dfinity/agent-rs.git", rev = "be929fd7967249c879f48f2f494cbfc5805a7d98" }
itertools = "0.13.0"
lazy_static = "1.4.0"
mockall = "0.12.1"
num-bigint = "0.4"
Expand Down
1 change: 1 addition & 0 deletions tests/integration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ hex = { workspace = true }
orbit-essentials = { path = '../../libs/orbit-essentials', version = '0.0.2-alpha.3' }
ic-cdk = { workspace = true }
ic-ledger-types = { workspace = true }
itertools = { workspace = true }
lazy_static = { workspace = true }
num-bigint = { workspace = true }
pocket-ic = { workspace = true }
Expand Down
51 changes: 44 additions & 7 deletions tests/integration/src/dfx_orbit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ use crate::{
};
use candid::Principal;
use dfx_orbit::{dfx_extension_api::OrbitExtensionAgent, station_agent::StationConfig, DfxOrbit};
use itertools::Itertools;
use pocket_ic::PocketIc;
use rand::Rng;
use rand_chacha::{rand_core::SeedableRng, ChaCha8Rng};
use station_api::UserDTO;
use std::{
cell::RefCell,
collections::BTreeMap,
future::Future,
hash::{DefaultHasher, Hash, Hasher},
path::Path,
Expand Down Expand Up @@ -43,7 +45,17 @@ const IDENTITY_JSON: &str = "
\"default\": \"default\"
}";

fn dfx_orbit_test<F>(env: &mut PocketIc, test_func: F) -> F::Output
/// The test setup needs to be configurable
///
/// This struct allows to gradually introduce configurations into the `dfx_orbit` tests
/// to allow testing more fine grained controls
#[derive(Debug, Clone, Default)]
struct DfxOrbitTestConfig {
/// Sets the asset canisters to be defined in the dfx.json, maps name tp list of paths
asset_canisters: BTreeMap<String, Vec<String>>,
}

fn dfx_orbit_test<F>(env: &mut PocketIc, config: DfxOrbitTestConfig, test_func: F) -> F::Output
where
F: Future,
{
Expand Down Expand Up @@ -90,7 +102,7 @@ where
*port.borrow()
});

setup_test_dfx_json(tmp_dir.path());
setup_test_dfx_json(tmp_dir.path(), config);
setup_identity(tmp_dir.path());

// Start the live environment
Expand Down Expand Up @@ -123,15 +135,37 @@ fn setup_identity(dfx_root: &Path) {
std::fs::write(default_id_path.join("identity.pem"), TEST_KEY).unwrap();
}

fn setup_test_dfx_json(dfx_root: &Path) {
/// Sets up a custom `dfx.json` from the provided `config`
fn setup_test_dfx_json(dfx_root: &Path, config: DfxOrbitTestConfig) {
let port = PORT.with(|port| *port.borrow());
let dfx_json = test_dfx_json_from_template(port);
let dfx_json = test_dfx_json_from_template(config, port);
std::fs::write(dfx_root.join("dfx.json"), dfx_json).unwrap();
}

fn test_dfx_json_from_template(port: u16) -> String {
/// Generate a custom `dfx.json` from the provided `config`
fn test_dfx_json_from_template(config: DfxOrbitTestConfig, port: u16) -> String {
let asset_canisters = config
.asset_canisters
.iter()
.map(|(name, sources)| {
(
name,
sources
.iter()
.map(|source| format!("\"{source}\""))
.join(","),
)
})
.map(|(name, sources)| {
format!("\"{name}\": {{ \"source\": [{sources}], \"type\": \"assets\"}}")
})
.join(",");

format!(
"{{
\"canisters\": {{
{asset_canisters}
}},
\"networks\": {{
\"test\": {{
\"providers\": [
Expand Down Expand Up @@ -175,6 +209,7 @@ fn setup_dfx_user(env: &PocketIc, canister_ids: &CanisterIds) -> (Principal, Use
(dfx_principal, dfx_user)
}

/// Install the counter canister under given `canister_id` into the running IC
fn setup_counter_canister(env: &mut PocketIc, canister_ids: &CanisterIds) -> Principal {
// create and install the counter canister
let canister_id = create_canister(env, canister_ids.station);
Expand All @@ -192,6 +227,10 @@ fn setup_counter_canister(env: &mut PocketIc, canister_ids: &CanisterIds) -> Pri
canister_id
}

/// Fetches an asset from the local host and port
///
/// This is a bit tricky, as the boundary node uses the `Referer` header to determine the
/// resource being fetched.
async fn fetch_asset(canister_id: Principal, path: &str) -> Vec<u8> {
let port = PORT.with(|port| *port.borrow());
let local_url = format!("http://localhost:{}{}", port, path);
Expand All @@ -208,5 +247,3 @@ async fn fetch_asset(canister_id: Principal, path: &str) -> Vec<u8> {
.unwrap()
.into()
}

// TODO: Test canister update
Loading

0 comments on commit e4e294e

Please sign in to comment.