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

chore: add xfer test #1072

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
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()
}
Loading