Skip to content

Commit

Permalink
chore: add xfer test
Browse files Browse the repository at this point in the history
fixes #995
  • Loading branch information
willemneal committed Nov 8, 2023
1 parent 5398c06 commit 24a12c8
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 37 deletions.
2 changes: 2 additions & 0 deletions cmd/crates/soroban-test/tests/it/integration/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
std::env::var("SOROBAN_RPC_URL").ok()
}
Expand Down
90 changes: 53 additions & 37 deletions cmd/crates/soroban-test/tests/it/integration/wrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

0 comments on commit 24a12c8

Please sign in to comment.