Skip to content
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
1 change: 1 addition & 0 deletions crates/contracts/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "stellaraid-core"
version = "0.1.0"
edition = "2021"
license = "MIT"

[lib]
crate-type = ["cdylib"]
Expand Down
3 changes: 2 additions & 1 deletion crates/contracts/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ impl CoreContract {
#[cfg(test)]
mod tests {
use super::*;
use soroban_sdk::testutils::Address as _;
use soroban_sdk::Env;

#[test]
Expand All @@ -24,7 +25,7 @@ mod tests {
let contract_id = env.register_contract(None, CoreContract);
let client = CoreContractClient::new(&env, &contract_id);

let admin = env.current_contract_address();
let admin = Address::generate(&env);
client.init(&admin);

let result = client.ping();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"generators": {
"address": 1,
"address": 2,
"nonce": 0
},
"auth": [],
"auth": [
[],
[]
],
"ledger": {
"protocol_version": 21,
"sequence_number": 0,
Expand Down Expand Up @@ -79,22 +82,44 @@
"v0": {
"topics": [
{
"symbol": "error"
"symbol": "fn_call"
},
{
"error": {
"context": "internal_error"
}
"bytes": "0000000000000000000000000000000000000000000000000000000000000001"
},
{
"symbol": "init"
}
],
"data": {
"string": "Current context has no contract ID"
"address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFCT4"
}
}
}
},
"failed_call": false
},
{
"event": {
"ext": "v0",
"contract_id": "0000000000000000000000000000000000000000000000000000000000000001",
"type_": "diagnostic",
"body": {
"v0": {
"topics": [
{
"symbol": "fn_return"
},
{
"symbol": "init"
}
],
"data": "void"
}
}
},
"failed_call": false
},
{
"event": {
"ext": "v0",
Expand All @@ -104,16 +129,38 @@
"v0": {
"topics": [
{
"symbol": "error"
"symbol": "fn_call"
},
{
"error": {
"context": "internal_error"
}
"bytes": "0000000000000000000000000000000000000000000000000000000000000001"
},
{
"symbol": "ping"
}
],
"data": "void"
}
}
},
"failed_call": false
},
{
"event": {
"ext": "v0",
"contract_id": "0000000000000000000000000000000000000000000000000000000000000001",
"type_": "diagnostic",
"body": {
"v0": {
"topics": [
{
"symbol": "fn_return"
},
{
"symbol": "ping"
}
],
"data": {
"string": "escalating error to panic"
"u32": 1
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "stellaraid-tools"
version = "0.1.0"
edition = "2021"
license = "MIT"

[[bin]]
name = "stellaraid-cli"
Expand All @@ -17,6 +18,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
toml = "0.7"
thiserror = "1.0"
stellar-baselib = "0.5.6"

[dev-dependencies]
tempfile = "3"
99 changes: 58 additions & 41 deletions crates/tools/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ mod tests {
use super::*;
use std::fs::File;
use std::io::Write;
use std::sync::{Mutex, OnceLock};
use tempfile::tempdir;

fn write_toml(dir: &Path, content: &str) -> PathBuf {
Expand All @@ -192,83 +193,99 @@ mod tests {
env::remove_var("SOROBAN_NETWORK_PASSPHRASE");
}

fn env_lock() -> &'static Mutex<()> {
static LOCK: OnceLock<Mutex<()>> = OnceLock::new();
LOCK.get_or_init(|| Mutex::new(()))
}

fn with_isolated_env<F: FnOnce()>(f: F) {
let _guard = env_lock().lock().expect("env lock poisoned");
clear_env_vars();
f();
clear_env_vars();
}

#[test]
fn loads_profile_by_name() {
let d = tempdir().unwrap();
let toml = r#"
with_isolated_env(|| {
let d = tempdir().unwrap();
let toml = r#"
[profile.testnet]
network = "testnet"
rpc_url = "https://soroban-testnet.stellar.org"
network_passphrase = "Test SDF Network ; September 2015"
"#;
clear_env_vars();
let p = write_toml(d.path(), toml);
env::set_var("SOROBAN_NETWORK", "testnet");

let cfg = Config::load(Some(&p)).expect("should load");
assert_eq!(cfg.profile, "testnet");
assert_eq!(cfg.rpc_url, "https://soroban-testnet.stellar.org");
assert_eq!(cfg.network_passphrase, "Test SDF Network ; September 2015");
match cfg.network {
Network::Testnet => {},
_ => panic!("expected testnet"),
}
let p = write_toml(d.path(), toml);
env::set_var("SOROBAN_NETWORK", "testnet");

let cfg = Config::load(Some(&p)).expect("should load");
assert_eq!(cfg.profile, "testnet");
assert_eq!(cfg.rpc_url, "https://soroban-testnet.stellar.org");
assert_eq!(cfg.network_passphrase, "Test SDF Network ; September 2015");
match cfg.network {
Network::Testnet => {},
_ => panic!("expected testnet"),
}
});
}

#[test]
fn env_overrides_profile_values() {
let d = tempdir().unwrap();
let toml = r#"
with_isolated_env(|| {
let d = tempdir().unwrap();
let toml = r#"
[profile.testnet]
network = "testnet"
rpc_url = "https://soroban-testnet.stellar.org"
network_passphrase = "Test SDF Network ; September 2015"
"#;
clear_env_vars();
let p = write_toml(d.path(), toml);
env::set_var("SOROBAN_NETWORK", "testnet");
env::set_var("SOROBAN_RPC_URL", "https://override.local");
env::set_var("SOROBAN_NETWORK_PASSPHRASE", "override pass");

let cfg = Config::load(Some(&p)).expect("should load with overrides");
assert_eq!(cfg.rpc_url, "https://override.local");
assert_eq!(cfg.network_passphrase, "override pass");
let p = write_toml(d.path(), toml);
env::set_var("SOROBAN_NETWORK", "testnet");
env::set_var("SOROBAN_RPC_URL", "https://override.local");
env::set_var("SOROBAN_NETWORK_PASSPHRASE", "override pass");

let cfg = Config::load(Some(&p)).expect("should load with overrides");
assert_eq!(cfg.rpc_url, "https://override.local");
assert_eq!(cfg.network_passphrase, "override pass");
});
}

#[test]
fn missing_required_values_returns_error() {
let d = tempdir().unwrap();
// create a profile with empty values
let toml = r#"
with_isolated_env(|| {
let d = tempdir().unwrap();
// create a profile with empty values
let toml = r#"
[profile.empty]
network = ""
rpc_url = ""
network_passphrase = ""
"#;
clear_env_vars();
let p = write_toml(d.path(), toml);
let p = write_toml(d.path(), toml);

// ensure defaulting behavior picks testnet is not present -> should error
let res = Config::load(Some(&p));
assert!(res.is_err());
// ensure defaulting behavior picks testnet is not present -> should error
let res = Config::load(Some(&p));
assert!(res.is_err());
});
}

#[test]
fn loads_sandbox_profile() {
let d = tempdir().unwrap();
let toml = r#"
with_isolated_env(|| {
let d = tempdir().unwrap();
let toml = r#"
[profile.sandbox]
network = "sandbox"
rpc_url = "http://localhost:8000"
network_passphrase = "Standalone Network ; February 2017"
"#;
clear_env_vars();
let p = write_toml(d.path(), toml);
let p = write_toml(d.path(), toml);

env::set_var("SOROBAN_NETWORK", "sandbox");
env::set_var("SOROBAN_NETWORK", "sandbox");

let cfg = Config::load(Some(&p)).expect("should load sandbox");
assert_eq!(cfg.profile, "sandbox");
assert_eq!(cfg.rpc_url, "http://localhost:8000");
let cfg = Config::load(Some(&p)).expect("should load sandbox");
assert_eq!(cfg.profile, "sandbox");
assert_eq!(cfg.rpc_url, "http://localhost:8000");
});
}
}
Loading
Loading