Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ test_snapshots
local.sh
.stellar
.zed
node_modules/
.DS_Store
761 changes: 302 additions & 459 deletions FULL_HELP_DOCS.md

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions cmd/crates/soroban-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ impl TestEnv {
sign_with_lab: false,
sign_with_ledger: false,
},
fee: None,
inclusion_fee: None,
}
}

Expand Down
113 changes: 113 additions & 0 deletions cmd/crates/soroban-test/tests/it/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,47 @@ fn set_default_identity() {
.success();
}

#[test]
fn warns_if_default_identity_will_be_ignored() {
let sandbox = TestEnv::default();

sandbox
.new_assert_cmd("keys")
.env(
"SOROBAN_SECRET_KEY",
"SC4ZPYELVR7S7EE7KZDZN3ETFTNQHHLTUL34NUAAWZG5OK2RGJ4V2U3Z",
)
.arg("add")
.arg("alice")
.assert()
.success();

sandbox
.new_assert_cmd("keys")
.env(
"SOROBAN_SECRET_KEY",
"SDIY6AQQ75WMD4W46EYB7O6UYMHOCGQHLAQGQTKHDX4J2DYQCHVCQYFD",
)
.arg("add")
.arg("bob")
.assert()
.success();

sandbox
.new_assert_cmd("keys")
.env("STELLAR_ACCOUNT", "bob")
.arg("use")
.arg("alice")
.assert()
.stderr(predicate::str::contains(
"Environment variable STELLAR_ACCOUNT is set, which will override this default source account.",
))
.success();

let config_contents = fs::read_to_string(sandbox.config_dir().join("config.toml")).unwrap();
assert!(config_contents.contains("identity = \"alice\""));
}

#[test]
fn set_default_network() {
let sandbox = TestEnv::default();
Expand All @@ -272,6 +313,78 @@ fn set_default_network() {
.success();
}

#[test]
fn warns_if_default_network_will_be_ignored() {
let sandbox = TestEnv::default();

sandbox
.new_assert_cmd("network")
.env("STELLAR_NETWORK", "custom_network")
.arg("use")
.arg("testnet")
.assert()
.stderr(predicate::str::contains(
"Environment variable STELLAR_NETWORK is set, which will override this default network.",
))
.success();

let config_contents = fs::read_to_string(sandbox.config_dir().join("config.toml")).unwrap();
assert!(config_contents.contains("network = \"testnet\""));
}

#[test]
fn set_default_inclusion_fee() {
let sandbox = TestEnv::default();

sandbox
.new_assert_cmd("fees")
.arg("use")
.args(["--amount", "150"])
.assert()
.stderr(predicate::str::contains(
"The default inclusion fee is set to `150`",
))
.success();

let config_contents = fs::read_to_string(sandbox.config_dir().join("config.toml")).unwrap();
assert!(config_contents.contains("inclusion_fee = 150"));
}

#[test]
fn warns_if_default_inclusion_fee_will_be_ignored() {
let sandbox = TestEnv::default();

sandbox
.new_assert_cmd("fees")
.env("STELLAR_INCLUSION_FEE", "200")
.arg("use")
.args(["--amount", "150"])
.assert()
.stderr(predicate::str::contains(
"Environment variable STELLAR_INCLUSION_FEE is set, which will override this default inclusion fee.",
))
.success();

let config_contents = fs::read_to_string(sandbox.config_dir().join("config.toml")).unwrap();
assert!(config_contents.contains("inclusion_fee = 150"));
}

#[test]
fn cannot_set_default_inclusion_fee_below_100() {
let sandbox = TestEnv::default();

sandbox
.new_assert_cmd("fees")
.arg("use")
.args(["--amount", "99"])
.assert()
.stderr(predicate::str::contains(
"Fee amount must be at least 100 stroops, but got 99",
))
.failure();
assert!(fs::read_to_string(sandbox.config_dir().join("config.toml")).is_err());
}

#[test]
fn cannot_create_contract_with_test_name() {
let sandbox = TestEnv::default();
Expand Down
1 change: 1 addition & 0 deletions cmd/crates/soroban-test/tests/it/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mod contract;
mod cookbook;
mod custom_types;
mod dotenv;
mod fee_args;
mod fee_stats;
mod hello_world;
mod init;
Expand Down
95 changes: 95 additions & 0 deletions cmd/crates/soroban-test/tests/it/integration/fee_args.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
use predicates::prelude::predicate;
use soroban_cli::xdr::{self, Limits, ReadXdr};
use soroban_test::{AssertExt, TestEnv};

use super::util::deploy_hello;

fn get_inclusion_fee_from_xdr(tx_xdr: &str) -> u32 {
let tx = xdr::TransactionEnvelope::from_xdr_base64(tx_xdr, Limits::none()).unwrap();
match tx {
xdr::TransactionEnvelope::TxV0(te) => te.tx.fee,
xdr::TransactionEnvelope::Tx(te) => te.tx.fee,
xdr::TransactionEnvelope::TxFeeBump(te) => te.tx.fee.try_into().unwrap(),
}
}

#[tokio::test]
async fn inclusion_fee_arg() {
let sandbox = &TestEnv::new();
let id = deploy_hello(sandbox).await;

// Defaults to 100
let tx_xdr = sandbox
.new_assert_cmd("contract")
.arg("invoke")
.args(["--id", &id.to_string()])
.arg("--build-only")
.arg("--")
.arg("inc")
.assert()
.success()
.stdout_as_str();
assert_eq!(get_inclusion_fee_from_xdr(&tx_xdr), 100u32);

// Update manually to 200
sandbox
.new_assert_cmd("fees")
.arg("use")
.args(["--amount", "200"])
.assert()
.stderr(predicate::str::contains(
"The default inclusion fee is set to `200`",
))
.success();

let tx_xdr = sandbox
.new_assert_cmd("contract")
.arg("invoke")
.args(["--id", &id.to_string()])
.arg("--build-only")
.arg("--")
.arg("inc")
.assert()
.success()
.stdout_as_str();
assert_eq!(get_inclusion_fee_from_xdr(&tx_xdr), 200u32);

// Arg overrides config
let tx_xdr = sandbox
.new_assert_cmd("contract")
.arg("invoke")
.args(["--id", &id.to_string()])
.args(["--inclusion-fee", "300"])
.arg("--build-only")
.arg("--")
.arg("inc")
.assert()
.success()
.stdout_as_str();
assert_eq!(get_inclusion_fee_from_xdr(&tx_xdr), 300u32);

// Update from fee stats (going to be 100 since sandbox)
sandbox
.new_assert_cmd("fees")
.arg("use")
.args(["--fee-metric", "p50"])
.assert()
.stderr(predicate::str::contains(
"The default inclusion fee is set to `100`",
))
.success();

// Deprecated fee arg ignored if inclusion-fee config exists
let tx_xdr = sandbox
.new_assert_cmd("contract")
.arg("invoke")
.args(["--id", &id.to_string()])
.args(["--fee", "300"])
.arg("--build-only")
.arg("--")
.arg("inc")
.assert()
.success()
.stdout_as_str();
assert_eq!(get_inclusion_fee_from_xdr(&tx_xdr), 100u32);
}
6 changes: 4 additions & 2 deletions cmd/crates/soroban-test/tests/it/integration/fee_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use soroban_test::{AssertExt, TestEnv};
async fn fee_stats_text_output() {
let sandbox = &TestEnv::new();
sandbox
.new_assert_cmd("fee-stats")
.new_assert_cmd("fees")
.arg("stats")
.arg("--output")
.arg("text")
.assert()
Expand All @@ -19,7 +20,8 @@ async fn fee_stats_text_output() {
async fn fee_stats_json_output() {
let sandbox = &TestEnv::new();
let output = sandbox
.new_assert_cmd("fee-stats")
.new_assert_cmd("fees")
.arg("stats")
.arg("--output")
.arg("json")
.assert()
Expand Down
2 changes: 1 addition & 1 deletion cmd/crates/soroban-test/tests/it/integration/tx/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async fn simulate() {
.assert()
.success()
.stdout_as_str();
let assembled = simulate_and_assemble_transaction(&sandbox.client(), &tx, None)
let assembled = simulate_and_assemble_transaction(&sandbox.client(), &tx, None, None)
.await
.unwrap();
let txn_env: TransactionEnvelope = assembled.transaction().clone().into();
Expand Down
Loading