|
| 1 | +use serde_json::Value; |
| 2 | +use soroban_test::{AssertExt, TestEnv}; |
| 3 | + |
| 4 | +use crate::integration::{ |
| 5 | + token::{add_trustline, deploy_sac, sac_balance, sac_id}, |
| 6 | + util::{new_account, test_address}, |
| 7 | +}; |
| 8 | + |
| 9 | +#[tokio::test] |
| 10 | +async fn set_admin_transfers_control_and_returns_receipt() { |
| 11 | + let sandbox = &TestEnv::new(); |
| 12 | + let test = test_address(sandbox); |
| 13 | + let issuer = new_account(sandbox, "issuer"); |
| 14 | + let new_admin = new_account(sandbox, "newadmin"); |
| 15 | + let asset = format!("USDC:{issuer}"); |
| 16 | + |
| 17 | + add_trustline(sandbox, "test", &asset); |
| 18 | + deploy_sac(sandbox, &asset, "issuer"); |
| 19 | + |
| 20 | + let stdout = sandbox |
| 21 | + .new_assert_cmd("token") |
| 22 | + .args([ |
| 23 | + "set-admin", |
| 24 | + "--id", |
| 25 | + &asset, |
| 26 | + "--admin", |
| 27 | + "issuer", |
| 28 | + "--new-admin", |
| 29 | + &new_admin, |
| 30 | + "--output", |
| 31 | + "json", |
| 32 | + ]) |
| 33 | + .assert() |
| 34 | + .success() |
| 35 | + .stdout_as_str(); |
| 36 | + let receipt: Value = serde_json::from_str(&stdout).unwrap(); |
| 37 | + assert!( |
| 38 | + receipt["tx_hash"].as_str().is_some(), |
| 39 | + "expected a tx hash, got: {receipt}" |
| 40 | + ); |
| 41 | + |
| 42 | + // Control has transferred: the new admin can now mint, proving the change |
| 43 | + // took effect. |
| 44 | + sandbox |
| 45 | + .new_assert_cmd("token") |
| 46 | + .args([ |
| 47 | + "mint", "--id", &asset, "--admin", "newadmin", "--to", &test, "--amount", "9000000", |
| 48 | + ]) |
| 49 | + .assert() |
| 50 | + .success(); |
| 51 | + let sac = sac_id(sandbox, &asset); |
| 52 | + assert_eq!( |
| 53 | + sac_balance(sandbox, &sac, &test), |
| 54 | + 9_000_000, |
| 55 | + "the new admin should be able to mint" |
| 56 | + ); |
| 57 | +} |
| 58 | + |
| 59 | +#[tokio::test] |
| 60 | +async fn set_admin_fails_when_sac_not_deployed() { |
| 61 | + let sandbox = &TestEnv::new(); |
| 62 | + let issuer = new_account(sandbox, "issuer"); |
| 63 | + let new_admin = new_account(sandbox, "newadmin"); |
| 64 | + let asset = format!("USDC:{issuer}"); |
| 65 | + |
| 66 | + // No SAC deployed → structured deploy-pointer error with a typed discriminator. |
| 67 | + let stdout = sandbox |
| 68 | + .new_assert_cmd("token") |
| 69 | + .args([ |
| 70 | + "set-admin", |
| 71 | + "--id", |
| 72 | + &asset, |
| 73 | + "--admin", |
| 74 | + "issuer", |
| 75 | + "--new-admin", |
| 76 | + &new_admin, |
| 77 | + "--output", |
| 78 | + "json", |
| 79 | + ]) |
| 80 | + .assert() |
| 81 | + .failure() |
| 82 | + .stdout_as_str(); |
| 83 | + let value: Value = serde_json::from_str(&stdout).unwrap(); |
| 84 | + assert_eq!( |
| 85 | + value["error"]["type"], "sac_not_deployed", |
| 86 | + "expected a typed error, got: {stdout}" |
| 87 | + ); |
| 88 | +} |
| 89 | + |
| 90 | +#[tokio::test] |
| 91 | +async fn set_admin_rejects_muxed_source_with_clear_error() { |
| 92 | + let sandbox = &TestEnv::new(); |
| 93 | + let new_admin = new_account(sandbox, "newadmin"); |
| 94 | + |
| 95 | + // Muxed (M…) source accounts aren't supported by the invoke pipeline yet |
| 96 | + // (see #2645). Until then the command must reject them up front with a clear |
| 97 | + // message rather than a raw strkey decode error deep in the pipeline. |
| 98 | + let muxed = "MA3D5KRYM6CB7OWQ6TWYRR3Z4T7GNZLKERYNZGGA5SOAOPIFY6YQGAAAAAAAAAPCICBKU"; |
| 99 | + sandbox |
| 100 | + .new_assert_cmd("token") |
| 101 | + .args([ |
| 102 | + "set-admin", |
| 103 | + "--id", |
| 104 | + "native", |
| 105 | + "--admin", |
| 106 | + muxed, |
| 107 | + "--new-admin", |
| 108 | + &new_admin, |
| 109 | + ]) |
| 110 | + .assert() |
| 111 | + .failure() |
| 112 | + .stderr(predicates::str::contains( |
| 113 | + "muxed (M…) source accounts are not yet supported", |
| 114 | + )); |
| 115 | +} |
0 commit comments