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

feat: add tx::builder module and initial classic commands #1551

Merged
merged 65 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
95503a9
feat: add `tx::builder` and initial classic cmds createAccount/payment
willemneal Aug 19, 2024
a78d7ab
Merge remote-tracking branch 'origin/main' into feat/tx_builder
willemneal Aug 19, 2024
7d92aa0
feat: add payment command
willemneal Aug 19, 2024
b279976
fix: clean up interface
willemneal Aug 19, 2024
5a54a8d
feat: add more operation builders
willemneal Aug 20, 2024
1f4baa3
feat: add the rest of the commands
willemneal Aug 20, 2024
bb16dc8
fix: clippy
willemneal Aug 20, 2024
1ade782
Merge branch 'main' into feat/tx_builder
willemneal Aug 22, 2024
8b98ed6
fix: add conflicts to args
willemneal Aug 22, 2024
2d64c4a
feat: add begin sponsoring future reserves
willemneal Aug 27, 2024
c7c3b41
Merge remote-tracking branch 'origin/main' into feat/tx_builder
willemneal Aug 27, 2024
456e5b2
fix: begin_sponsoring_future_reserves
willemneal Aug 28, 2024
ccbee4c
Merge remote-tracking branch 'origin/main' into feat/tx_builder
willemneal Aug 28, 2024
b06dc75
Merge remote-tracking branch 'origin/main' into feat/tx_builder
willemneal Aug 30, 2024
5898a01
fix: fmt and tests
willemneal Aug 30, 2024
e4af37c
fix: tests
willemneal Aug 30, 2024
a67ac00
fix: tests
willemneal Aug 30, 2024
3566ca2
fix: tests use name and not public key
willemneal Aug 30, 2024
b0274b7
fix: assert error
willemneal Aug 30, 2024
1ddb33a
Merge branch 'main' into feat/tx_builder
willemneal Aug 30, 2024
4346282
Merge remote-tracking branch 'origin/main' into feat/tx_builder
willemneal Aug 31, 2024
d6cbf73
Merge remote-tracking branch 'origin/main' into feat/tx_builder
willemneal Sep 9, 2024
38f58ac
fix: merge test
willemneal Sep 9, 2024
a498805
fix: remove sponsor operation since it requires multi ops
willemneal Sep 9, 2024
97052a7
chore: more tests
willemneal Sep 9, 2024
5f43658
fix: add test and fix two
willemneal Sep 9, 2024
50bee37
Merge remote-tracking branch 'origin/main' into feat/tx_builder
willemneal Sep 9, 2024
7e1490c
fix: tests
willemneal Sep 10, 2024
301cdcb
fix: assets and hex
willemneal Sep 10, 2024
ccc9777
fix: remove bad source
willemneal Sep 10, 2024
8262ed7
Merge remote-tracking branch 'origin/main' into feat/tx_builder
willemneal Sep 10, 2024
cfe127e
chore: check response
willemneal Sep 10, 2024
d2fcf22
fix: tests
willemneal Sep 10, 2024
47a805c
fix: encode bytes to hex correctly
willemneal Sep 10, 2024
11f2174
fix: tx::manage_data actually use hex to encode bytes
willemneal Sep 10, 2024
77d7933
chore: add set-trustline-flags test
willemneal Sep 10, 2024
f183d84
chore: sp
willemneal Sep 10, 2024
d2dda83
feat: see resulting transactions
willemneal Sep 10, 2024
f443268
fix: actually return `--build-only`
willemneal Sep 10, 2024
0fe3748
chore: clean up imports
willemneal Sep 10, 2024
167e3ba
fix: actually output tx_env
willemneal Sep 10, 2024
e72f01f
Merge remote-tracking branch 'origin/main' into feat/tx_builder
willemneal Sep 12, 2024
a67772e
Merge remote-tracking branch 'origin/main' into feat/tx_builder
willemneal Sep 18, 2024
c5f3c84
fix: use separate issuer for change_trust
willemneal Sep 18, 2024
5a22a8d
fix: add back feature flag
willemneal Sep 18, 2024
6978b2c
fix: add tests
willemneal Sep 18, 2024
628ca62
feat: add Address type and clean up errors
willemneal Sep 23, 2024
9287ce1
Merge remote-tracking branch 'origin/main' into feat/tx_builder
willemneal Sep 24, 2024
bca01e6
fix: test error
willemneal Sep 24, 2024
37616e3
Merge remote-tracking branch 'origin/main' into feat/tx_builder
willemneal Sep 25, 2024
15994d9
fix: remove unneeded builder types and simplify commands
willemneal Sep 25, 2024
dcb61a5
Merge remote-tracking branch 'ElliotFriend/main' into feat/tx_builder
willemneal Sep 25, 2024
30a76c8
fix: cargo fmt
willemneal Sep 25, 2024
0766d31
Update cmd/crates/soroban-test/Cargo.toml
willemneal Sep 25, 2024
c2ed093
fix: used MuxedAccount Directly
willemneal Sep 26, 2024
fde0a16
Merge remote-tracking branch 'origin/main' into feat/tx_builder
willemneal Sep 30, 2024
91217df
fix: remove most builder types in favor of xdr types directly
willemneal Sep 30, 2024
f69d41a
Merge remote-tracking branch 'origin/main' into feat/tx_builder
willemneal Sep 30, 2024
1d9968b
fix: try adding test for set_trust_line
willemneal Sep 30, 2024
408e079
Merge remote-tracking branch 'AhaLabs-PR1311/feat/tx_builder' into fe…
willemneal Sep 30, 2024
c5afff8
Update cmd/soroban-cli/src/tx/builder/transaction.rs
willemneal Sep 30, 2024
0556060
fix: fmt
willemneal Sep 30, 2024
f30761c
fix: actually test trustline
willemneal Oct 1, 2024
27b34fd
fix: links and feedback about docs
willemneal Oct 1, 2024
0028e68
fix test failure
leighmcculloch Oct 2, 2024
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
8 changes: 8 additions & 0 deletions Cargo.lock

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

283 changes: 272 additions & 11 deletions FULL_HELP_DOCS.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions cmd/crates/soroban-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ tokio = "1.28.1"
walkdir = "2.4.0"
ulid.workspace = true
ed25519-dalek = { workspace = true }
hex = { workspace = true }

[features]
it = []
19 changes: 15 additions & 4 deletions cmd/crates/soroban-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pub enum Error {
pub struct TestEnv {
pub temp_dir: TempDir,
pub rpc_url: String,
pub network_passphrase: String,
}

impl Default for TestEnv {
Expand All @@ -67,6 +68,7 @@ impl Default for TestEnv {
Self {
temp_dir,
rpc_url: "http://localhost:8889/soroban/rpc".to_string(),
network_passphrase: LOCAL_NETWORK_PASSPHRASE.to_string(),
}
}
}
Expand Down Expand Up @@ -100,10 +102,13 @@ impl TestEnv {
}

pub fn with_rpc_url(rpc_url: &str) -> TestEnv {
let env = TestEnv {
let mut env = TestEnv {
rpc_url: rpc_url.to_string(),
..Default::default()
};
if let Ok(network_passphrase) = std::env::var("STELLAR_NETWORK_PASSPHRASE") {
env.network_passphrase = network_passphrase;
};
env.generate_account("test", None).assert().success();
env
}
Expand All @@ -112,6 +117,9 @@ impl TestEnv {
if let Ok(rpc_url) = std::env::var("SOROBAN_RPC_URL") {
return Self::with_rpc_url(&rpc_url);
}
if let Ok(rpc_url) = std::env::var("STELLAR_RPC_URL") {
return Self::with_rpc_url(&rpc_url);
}
let host_port = std::env::var("SOROBAN_PORT")
.as_deref()
.ok()
Expand Down Expand Up @@ -193,7 +201,7 @@ impl TestEnv {
command_str: &[I],
source: &str,
) -> Result<String, invoke::Error> {
let cmd = self.cmd_with_config::<I, invoke::Cmd>(command_str);
let cmd = self.cmd_with_config::<I, invoke::Cmd>(command_str, None);
self.run_cmd_with(cmd, source)
.await
.map(|r| r.into_result().unwrap())
Expand All @@ -203,12 +211,15 @@ impl TestEnv {
pub fn cmd_with_config<I: AsRef<str>, T: CommandParser<T> + NetworkRunnable>(
&self,
command_str: &[I],
source_account: Option<&str>,
) -> T {
let source = source_account.unwrap_or("test");
let source_str = format!("--source-account={source}");
let mut arg = vec![
"--network=local",
"--rpc-url=http",
"--network-passphrase=AA",
"--source-account=test",
source_str.as_str(),
];
let input = command_str
.iter()
Expand All @@ -227,7 +238,7 @@ impl TestEnv {
network_passphrase: Some(LOCAL_NETWORK_PASSPHRASE.to_string()),
network: None,
},
source_account: account.to_string(),
source_account: account.parse().unwrap(),
locator: config::locator::Args {
global: false,
config_dir,
Expand Down
29 changes: 13 additions & 16 deletions cmd/crates/soroban-test/tests/it/integration/cookbook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ fn parse_command(command: &str) -> Vec<String> {
.collect()
}

async fn run_command(
#[allow(clippy::too_many_lines, clippy::too_many_arguments)]
fn run_command(
sandbox: &TestEnv,
command: &str,
wasm_path: &str,
Expand Down Expand Up @@ -133,7 +134,8 @@ async fn run_command(
Ok(())
}

async fn test_mdx_file(
#[allow(clippy::too_many_arguments)]
fn test_mdx_file(
sandbox: &TestEnv,
file_path: &str,
wasm_path: &str,
Expand All @@ -145,15 +147,15 @@ async fn test_mdx_file(
key_xdr: &str,
) -> Result<(), String> {
let content = fs::read_to_string(file_path)
.map_err(|e| format!("Failed to read file {}: {}", file_path, e))?;
.map_err(|e| format!("Failed to read file {file_path}: {e}"))?;

let commands: Vec<&str> = content
.split("```bash")
.skip(1)
.filter_map(|block| block.split("```").next())
.collect();

println!("Testing commands from file: {}", file_path);
println!("Testing commands from file: {file_path}");

for (i, command) in commands.iter().enumerate() {
println!("Running command {}: {}", i + 1, command);
Expand All @@ -167,8 +169,7 @@ async fn test_mdx_file(
bob_id,
native_id,
key_xdr,
)
.await?;
)?;
}

Ok(())
Expand Down Expand Up @@ -260,9 +261,7 @@ mod tests {
let key_xdr = read_xdr.split(',').next().unwrap_or("").trim();
let repo_root = get_repo_root();
let docs_dir = repo_root.join("cookbook");
if !docs_dir.is_dir() {
panic!("docs directory not found");
}
assert!(docs_dir.is_dir(), "docs directory not found");

for entry in fs::read_dir(docs_dir).expect("Failed to read docs directory") {
let entry = entry.expect("Failed to read directory entry");
Expand All @@ -273,18 +272,16 @@ mod tests {
match test_mdx_file(
&sandbox,
file_path,
&wasm_path.to_str().unwrap(),
wasm_path.to_str().unwrap(),
&wasm_hash,
source,
&contract_id,
&bob_id,
&native_id,
&key_xdr,
)
.await
{
Ok(_) => println!("Successfully tested all commands in {}", file_path),
Err(e) => panic!("Error testing {}: {}", file_path, e),
key_xdr,
) {
Ok(()) => println!("Successfully tested all commands in {file_path}"),
Err(e) => panic!("Error testing {file_path}: {e}"),
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/crates/soroban-test/tests/it/integration/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use soroban_cli::{
contract::{self, fetch},
txn_result::TxnResult,
},
config::{locator, secret},
config::{address::Address, locator, secret},
};
use soroban_rpc::GetLatestLedgerResponse;
use soroban_test::{AssertExt, TestEnv, LOCAL_NETWORK_PASSPHRASE};
Expand All @@ -20,7 +20,7 @@ async fn invoke_view_with_non_existent_source_account() {
let id = deploy_hello(sandbox).await;
let world = "world";
let mut cmd = hello_world_cmd(&id, world);
cmd.config.source_account = String::new();
cmd.config.source_account = Address::default();
cmd.is_view = true;
let res = sandbox.run_cmd_with(cmd, "test").await.unwrap();
assert_eq!(res, TxnResult::Res(format!(r#"["Hello",{world:?}]"#)));
Expand Down Expand Up @@ -94,7 +94,7 @@ async fn invoke() {
sandbox
.new_assert_cmd("events")
.arg("--start-ledger")
.arg(&sequence.to_string())
.arg(sequence.to_string())
.arg("--id")
.arg(id)
.assert()
Expand Down Expand Up @@ -144,7 +144,7 @@ async fn invoke() {
invoke_log(sandbox, id);
}

fn invoke_hello_world(sandbox: &TestEnv, id: &str) {
pub(crate) fn invoke_hello_world(sandbox: &TestEnv, id: &str) {
sandbox
.new_assert_cmd("contract")
.arg("invoke")
Expand Down Expand Up @@ -324,7 +324,7 @@ async fn half_max_instructions() {
.arg("--fee")
.arg("1000000")
.arg("--instructions")
.arg(&(u32::MAX / 2).to_string())
.arg((u32::MAX / 2).to_string())
.arg("--wasm")
.arg(wasm.path())
.arg("--ignore-checks")
Expand Down
10 changes: 7 additions & 3 deletions cmd/crates/soroban-test/tests/it/integration/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ use soroban_test::{AssertExt, TestEnv};

use crate::integration::util::{deploy_contract, DeployKind, HELLO_WORLD};

mod operations;

#[tokio::test]
async fn simulate() {
let sandbox = &TestEnv::new();
let xdr_base64_build_only = deploy_contract(sandbox, HELLO_WORLD, DeployKind::BuildOnly).await;
let xdr_base64_sim_only = deploy_contract(sandbox, HELLO_WORLD, DeployKind::SimOnly).await;
let xdr_base64_build_only =
deploy_contract(sandbox, HELLO_WORLD, DeployKind::BuildOnly, None).await;
let xdr_base64_sim_only =
deploy_contract(sandbox, HELLO_WORLD, DeployKind::SimOnly, None).await;
let tx_env =
TransactionEnvelope::from_xdr_base64(&xdr_base64_build_only, Limits::none()).unwrap();
let tx = soroban_cli::commands::tx::xdr::unwrap_envelope_v1(tx_env).unwrap();
Expand Down Expand Up @@ -60,7 +64,7 @@ async fn build_simulate_sign_send() {
.assert()
.success();

let tx_simulated = deploy_contract(sandbox, HELLO_WORLD, DeployKind::SimOnly).await;
let tx_simulated = deploy_contract(sandbox, HELLO_WORLD, DeployKind::SimOnly, None).await;
dbg!("{tx_simulated}");

let tx_signed = sandbox
Expand Down
Loading
Loading