Skip to content

Commit

Permalink
soroban-cli: add tests for version + xdr decoding (#947)
Browse files Browse the repository at this point in the history
* add few cli test.

* linter

* cargo fmt

* exclude test from windows.
  • Loading branch information
tsachiherman authored Sep 11, 2023
1 parent ec404da commit 41f9f8f
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 1 deletion.
27 changes: 27 additions & 0 deletions cmd/crates/soroban-test/tests/it/lab.rs
Original file line number Diff line number Diff line change
@@ -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);
}
54 changes: 54 additions & 0 deletions cmd/crates/soroban-test/tests/it/lab_test_transaction_envelope.txt
Original file line number Diff line number Diff line change
@@ -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),
),
},
],
),
},
),
)
4 changes: 3 additions & 1 deletion cmd/crates/soroban-test/tests/it/main.rs
Original file line number Diff line number Diff line change
@@ -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;
12 changes: 12 additions & 0 deletions cmd/crates/soroban-test/tests/it/version.rs
Original file line number Diff line number Diff line change
@@ -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()));
}

0 comments on commit 41f9f8f

Please sign in to comment.