From 41f9f8f4921529593acddb96ba4a622627e074cb Mon Sep 17 00:00:00 2001 From: Tsachi Herman <24438559+tsachiherman@users.noreply.github.com> Date: Mon, 11 Sep 2023 15:33:02 -0400 Subject: [PATCH] soroban-cli: add tests for version + xdr decoding (#947) * add few cli test. * linter * cargo fmt * exclude test from windows. --- ...{invoke_sandbox.rs => contract_sandbox.rs} | 0 cmd/crates/soroban-test/tests/it/lab.rs | 27 ++++++++++ .../it/lab_test_transaction_envelope.txt | 54 +++++++++++++++++++ cmd/crates/soroban-test/tests/it/main.rs | 4 +- cmd/crates/soroban-test/tests/it/version.rs | 12 +++++ 5 files changed, 96 insertions(+), 1 deletion(-) rename cmd/crates/soroban-test/tests/it/{invoke_sandbox.rs => contract_sandbox.rs} (100%) create mode 100644 cmd/crates/soroban-test/tests/it/lab.rs create mode 100644 cmd/crates/soroban-test/tests/it/lab_test_transaction_envelope.txt create mode 100644 cmd/crates/soroban-test/tests/it/version.rs diff --git a/cmd/crates/soroban-test/tests/it/invoke_sandbox.rs b/cmd/crates/soroban-test/tests/it/contract_sandbox.rs similarity index 100% rename from cmd/crates/soroban-test/tests/it/invoke_sandbox.rs rename to cmd/crates/soroban-test/tests/it/contract_sandbox.rs diff --git a/cmd/crates/soroban-test/tests/it/lab.rs b/cmd/crates/soroban-test/tests/it/lab.rs new file mode 100644 index 000000000..85d8dc650 --- /dev/null +++ b/cmd/crates/soroban-test/tests/it/lab.rs @@ -0,0 +1,27 @@ +use soroban_test::TestEnv; +use std::path::PathBuf; + +#[test] +#[cfg_attr(target_os = "windows", ignore)] +fn lab_xdr_decode() { + let sandbox = TestEnv::default(); + let cargo_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + let ref_xdr_filename = cargo_dir.join("tests/it/lab_test_transaction_envelope.txt"); + let ref_xdr = std::fs::read_to_string(ref_xdr_filename.clone()).unwrap(); + + let cmd = sandbox + .new_assert_cmd("lab") + .arg("xdr") + .arg("dec") + .arg("--type") + .arg("TransactionEnvelope") + .arg("--xdr") + .arg("AAAAAgAAAABzdv3ojkzWHMD7KUoXhrPx0GH18vHKV0ZfqpMiEblG1gAAAGQAAAAAAAAAAQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAADRjwIQ/2zB8tzxMB+71MMO4RoHWCBoTUcd+J0PEBHqKAAAAOjUpRAAAAAAAAAAAAERuUbWAAAAQKAEpum2TGh/P2K0/eOxeXw1eGEG5fl/Ft2a/j7YUN+H3XNjkFAfYnJvfpmvTsNYqPsoHKufgRpDmJuAhd0xJgk=") + .assert() + .success(); + let stdout = String::from_utf8(cmd.get_output().clone().stdout).unwrap(); + if ref_xdr.is_empty() { + std::fs::write(ref_xdr_filename, stdout.clone()).unwrap(); + } + assert_eq!(stdout, ref_xdr); +} diff --git a/cmd/crates/soroban-test/tests/it/lab_test_transaction_envelope.txt b/cmd/crates/soroban-test/tests/it/lab_test_transaction_envelope.txt new file mode 100644 index 000000000..6cd597694 --- /dev/null +++ b/cmd/crates/soroban-test/tests/it/lab_test_transaction_envelope.txt @@ -0,0 +1,54 @@ +TransactionEnvelope( + Tx( + TransactionV1Envelope { + tx: Transaction { + source_account: Ed25519( + Uint256(7376fde88e4cd61cc0fb294a1786b3f1d061f5f2f1ca57465faa932211b946d6), + ), + fee: 100, + seq_num: SequenceNumber( + 1, + ), + cond: Time( + TimeBounds { + min_time: TimePoint( + 0, + ), + max_time: TimePoint( + 0, + ), + }, + ), + memo: None, + operations: VecM( + [ + Operation { + source_account: None, + body: CreateAccount( + CreateAccountOp { + destination: AccountId( + PublicKeyTypeEd25519( + Uint256(d18f0210ff6cc1f2dcf1301fbbd4c30ee11a075820684d471df89d0f1011ea28), + ), + ), + starting_balance: 1000000000000, + }, + ), + }, + ], + ), + ext: V0, + }, + signatures: VecM( + [ + DecoratedSignature { + hint: SignatureHint(11b946d6), + signature: Signature( + BytesM(a004a6e9b64c687f3f62b4fde3b1797c35786106e5f97f16dd9afe3ed850df87dd736390501f62726f7e99af4ec358a8fb281cab9f811a43989b8085dd312609), + ), + }, + ], + ), + }, + ), +) diff --git a/cmd/crates/soroban-test/tests/it/main.rs b/cmd/crates/soroban-test/tests/it/main.rs index 71683c4fa..1d3af2cb6 100644 --- a/cmd/crates/soroban-test/tests/it/main.rs +++ b/cmd/crates/soroban-test/tests/it/main.rs @@ -1,8 +1,10 @@ mod arg_parsing; mod config; +mod contract_sandbox; mod custom_types; mod dotenv; -mod invoke_sandbox; +mod lab; mod plugin; mod util; +mod version; diff --git a/cmd/crates/soroban-test/tests/it/version.rs b/cmd/crates/soroban-test/tests/it/version.rs new file mode 100644 index 000000000..cb7826fa4 --- /dev/null +++ b/cmd/crates/soroban-test/tests/it/version.rs @@ -0,0 +1,12 @@ +use soroban_cli::commands::version::long; +use soroban_test::TestEnv; + +#[test] +fn version() { + let sandbox = TestEnv::default(); + sandbox + .new_assert_cmd("version") + .assert() + .success() + .stdout(format!("soroban {}\n", long())); +}