|
| 1 | +use predicates::prelude::predicate; |
| 2 | +use soroban_cli::tx::ONE_XLM; |
| 3 | +use soroban_test::{AssertExt, TestEnv}; |
| 4 | + |
| 5 | +fn secure_store_key(sandbox: &TestEnv, name: &str) -> String { |
| 6 | + sandbox |
| 7 | + .new_assert_cmd("keys") |
| 8 | + .args(["generate", "--fund", "--secure-store", name]) |
| 9 | + .assert() |
| 10 | + .success() |
| 11 | + .stdout_as_str(); |
| 12 | + |
| 13 | + sandbox |
| 14 | + .new_assert_cmd("keys") |
| 15 | + .args(["address", name]) |
| 16 | + .assert() |
| 17 | + .success() |
| 18 | + .stdout_as_str() |
| 19 | +} |
| 20 | + |
| 21 | +// test that we can create a create-account tx and sign it with a secure-store key |
| 22 | +#[tokio::test] |
| 23 | +async fn create_account() { |
| 24 | + let sandbox = &TestEnv::new(); |
| 25 | + let secure_store_address = secure_store_key(sandbox, "secure-store"); |
| 26 | + |
| 27 | + sandbox |
| 28 | + .new_assert_cmd("keys") |
| 29 | + .args(["generate", "--no-fund", "new"]) |
| 30 | + .assert() |
| 31 | + .success(); |
| 32 | + let new_address = sandbox |
| 33 | + .new_assert_cmd("keys") |
| 34 | + .args(["address", "new"]) |
| 35 | + .assert() |
| 36 | + .success() |
| 37 | + .stdout_as_str(); |
| 38 | + |
| 39 | + let client = sandbox.network.rpc_client().unwrap(); |
| 40 | + let secure_account = client.get_account(&secure_store_address).await.unwrap(); |
| 41 | + |
| 42 | + let starting_balance = ONE_XLM * 100; |
| 43 | + sandbox |
| 44 | + .new_assert_cmd("tx") |
| 45 | + .args([ |
| 46 | + "new", |
| 47 | + "create-account", |
| 48 | + "--destination", |
| 49 | + new_address.as_str(), |
| 50 | + "--starting-balance", |
| 51 | + starting_balance.to_string().as_str(), |
| 52 | + "--source", |
| 53 | + "secure-store", |
| 54 | + ]) |
| 55 | + .assert() |
| 56 | + .success() |
| 57 | + .stdout_as_str(); |
| 58 | + |
| 59 | + let secure_account_after = client.get_account(&secure_store_address).await.unwrap(); |
| 60 | + assert!(secure_account_after.balance < secure_account.balance); |
| 61 | + |
| 62 | + let new_account = client.get_account(&new_address).await.unwrap(); |
| 63 | + assert_eq!(new_account.balance, starting_balance); |
| 64 | +} |
| 65 | + |
| 66 | +#[tokio::test] |
| 67 | +async fn get_secret_key() { |
| 68 | + let sandbox = &TestEnv::new(); |
| 69 | + sandbox |
| 70 | + .new_assert_cmd("keys") |
| 71 | + .args(["generate", "secret-key-test", "--secure-store"]) |
| 72 | + .assert() |
| 73 | + .success(); |
| 74 | + sandbox |
| 75 | + .new_assert_cmd("keys") |
| 76 | + .arg("secret") |
| 77 | + .arg("secret-key-test") |
| 78 | + .assert() |
| 79 | + .stderr(predicate::str::contains("does not reveal secret key")) |
| 80 | + .failure(); |
| 81 | +} |
| 82 | + |
| 83 | +#[tokio::test] |
| 84 | +async fn public_key_with_secure_store() { |
| 85 | + let sandbox = &TestEnv::new(); |
| 86 | + sandbox |
| 87 | + .new_assert_cmd("keys") |
| 88 | + .args(["generate", "public-key-test", "--secure-store"]) |
| 89 | + .assert() |
| 90 | + .success(); |
| 91 | + sandbox |
| 92 | + .new_assert_cmd("keys") |
| 93 | + .arg("public-key") |
| 94 | + .arg("public-key-test") |
| 95 | + .assert() |
| 96 | + .stdout(predicate::str::contains("G")) |
| 97 | + .success(); |
| 98 | +} |
0 commit comments