From 0cd747846d86094cc513aae0d4a7428cba5bc147 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Wed, 8 Nov 2023 13:45:21 -0500 Subject: [PATCH] chore: add xfer test fixes #995 --- .../soroban-test/tests/it/integration/util.rs | 2 + .../soroban-test/tests/it/integration/wrap.rs | 90 +++++++++++-------- 2 files changed, 55 insertions(+), 37 deletions(-) diff --git a/cmd/crates/soroban-test/tests/it/integration/util.rs b/cmd/crates/soroban-test/tests/it/integration/util.rs index 4cc41474f..c4b18efec 100644 --- a/cmd/crates/soroban-test/tests/it/integration/util.rs +++ b/cmd/crates/soroban-test/tests/it/integration/util.rs @@ -38,6 +38,8 @@ pub const DEFAULT_PUB_KEY_1: &str = "GCKZUJVUNEFGD4HLFBUNVYM2QY2P5WQQZMGRA3DDL4H pub const TEST_SALT: &str = "f55ff16f66f43360266b95db6f8fec01d76031054306ae4a4b380598f6cfd114"; pub const TEST_CONTRACT_ID: &str = "CBVTIVBYWAO2HNPNGKDCZW4OZYYESTKNGD7IPRTDGQSFJS4QBDQQJX3T"; +pub const ROOT_ACCOUNT_RPC_TEST: &str = "GD5KD2KEZJIGTC63IGW6UMUSMVUVG5IHG64HUTFWCHVZH2N2IBOQN7PS"; + pub fn rpc_url() -> Option { std::env::var("SOROBAN_RPC_URL").ok() } diff --git a/cmd/crates/soroban-test/tests/it/integration/wrap.rs b/cmd/crates/soroban-test/tests/it/integration/wrap.rs index f1a453e7a..89e74e867 100644 --- a/cmd/crates/soroban-test/tests/it/integration/wrap.rs +++ b/cmd/crates/soroban-test/tests/it/integration/wrap.rs @@ -8,72 +8,88 @@ use soroban_cli::{ }; use soroban_test::TestEnv; -use super::util::network_passphrase; +use super::util::{network_passphrase, ROOT_ACCOUNT_RPC_TEST}; #[tokio::test] #[ignore] -async fn burn() { +async fn xfer_and_burn() { let sandbox = &TestEnv::default(); - let address = config::identity::address::Cmd::parse("--hd-path=0") - .unwrap() - .public_key() - .unwrap(); - let asset = format!("native:{address}"); - wrap_cmd(&asset).run().await.unwrap(); - let asset = soroban_cli::utils::parsing::parse_asset(&asset).unwrap(); - let hash = contract_id_hash_from_asset(&asset, &network_passphrase().unwrap()).unwrap(); - let id = stellar_strkey::Contract(hash.0).to_string(); + let (address, id) = &deploy().await; + assert!(authorize(sandbox, id, address).await); assert_eq!( - "CAMTHSPKXZJIRTUXQP5QWJIFH3XIDMKLFAWVQOFOXPTKAW5GKV37ZC4N", - id + "\"9223372036854775807\"", + balance(sandbox, id, address).await, ); - assert_eq!( - "true", + + println!( + "{}", sandbox .invoke(&[ "--id", &id, "--", - "authorized", - "--id", - &address.to_string() + "xfer", + "--from", + address, + "--to", + ROOT_ACCOUNT_RPC_TEST, + "--amount=100" ]) .await .unwrap() ); + assert_eq!( - "\"9223372036854775807\"", - sandbox - .invoke(&["--id", &id, "--", "balance", "--id", &address.to_string()]) - .await - .unwrap(), + "\"9223372036854775707\"", + balance(sandbox, id, address).await, ); println!( "{}", sandbox - .invoke(&[ - "--id", - &id, - "--", - "burn", - "--id", - &address.to_string(), - "--amount=100" - ]) + .invoke(&["--id", id, "--", "burn", "--id", address, "--amount=100"]) .await .unwrap() ); assert_eq!( - "\"9223372036854775707\"", - sandbox - .invoke(&["--id", &id, "--", "balance", "--id", &address.to_string()]) - .await - .unwrap(), + "\"9223372036854775607\"", + balance(sandbox, id, address).await, ); } +pub async fn deploy() -> (String, String) { + let address = config::identity::address::Cmd::parse("--hd-path=0") + .unwrap() + .public_key() + .unwrap(); + let asset = format!("native:{address}"); + wrap_cmd(&asset).run().await.unwrap(); + let asset = soroban_cli::utils::parsing::parse_asset(&asset).unwrap(); + let hash = contract_id_hash_from_asset(&asset, &network_passphrase().unwrap()).unwrap(); + let id = stellar_strkey::Contract(hash.0).to_string(); + assert_eq!( + "CAMTHSPKXZJIRTUXQP5QWJIFH3XIDMKLFAWVQOFOXPTKAW5GKV37ZC4N", + id + ); + (address.to_string(), id) +} + fn wrap_cmd(asset: &str) -> wrap::Cmd { wrap::Cmd::parse_arg_vec(&[&format!("--asset={asset}")]).unwrap() } + +async fn authorize(sandbox: &TestEnv, id: &str, address: &str) -> bool { + sandbox + .invoke(&["--id", id, "--", "authorized", "--id", address]) + .await + .unwrap() + == "true" +} + +async fn balance(sandbox: &TestEnv, id: &str, address: &str) -> String { + sandbox + .invoke(&["--id", id, "--", "balance", "--id", address]) + .await + .unwrap() +}