|
| 1 | +use crate::integration::util::{deploy_contract, test_address, DeployOptions, HELLO_WORLD}; |
| 2 | + |
| 3 | +use soroban_test::{AssertExt, TestEnv}; |
| 4 | + |
| 5 | +#[tokio::test] |
| 6 | +async fn info_hash_with_wasm_file() { |
| 7 | + let sandbox = &TestEnv::new(); |
| 8 | + let expected = HELLO_WORLD.hash().unwrap().to_string(); |
| 9 | + |
| 10 | + let actual = sandbox |
| 11 | + .new_assert_cmd("contract") |
| 12 | + .arg("info") |
| 13 | + .arg("hash") |
| 14 | + .arg("--wasm") |
| 15 | + .arg(HELLO_WORLD.path()) |
| 16 | + .assert() |
| 17 | + .success() |
| 18 | + .stdout_as_str(); |
| 19 | + |
| 20 | + assert_eq!(actual, expected); |
| 21 | +} |
| 22 | + |
| 23 | +#[tokio::test] |
| 24 | +async fn info_hash_with_contract_id() { |
| 25 | + let sandbox = &TestEnv::new(); |
| 26 | + let expected = HELLO_WORLD.hash().unwrap().to_string(); |
| 27 | + let contract_id = deploy_contract(sandbox, HELLO_WORLD, DeployOptions::default()).await; |
| 28 | + |
| 29 | + let actual = sandbox |
| 30 | + .new_assert_cmd("contract") |
| 31 | + .arg("info") |
| 32 | + .arg("hash") |
| 33 | + .arg("--id") |
| 34 | + .arg(&contract_id) |
| 35 | + .assert() |
| 36 | + .success() |
| 37 | + .stdout_as_str(); |
| 38 | + |
| 39 | + assert_eq!(actual, expected); |
| 40 | +} |
| 41 | + |
| 42 | +#[tokio::test] |
| 43 | +async fn info_hash_with_contract_alias() { |
| 44 | + let sandbox = &TestEnv::new(); |
| 45 | + let expected = HELLO_WORLD.hash().unwrap().to_string(); |
| 46 | + let contract_id = deploy_contract(sandbox, HELLO_WORLD, DeployOptions::default()).await; |
| 47 | + |
| 48 | + sandbox |
| 49 | + .new_assert_cmd("contract") |
| 50 | + .arg("alias") |
| 51 | + .arg("add") |
| 52 | + .arg("hello") |
| 53 | + .arg("--id") |
| 54 | + .arg(&contract_id) |
| 55 | + .assert() |
| 56 | + .success(); |
| 57 | + |
| 58 | + let actual = sandbox |
| 59 | + .new_assert_cmd("contract") |
| 60 | + .arg("info") |
| 61 | + .arg("hash") |
| 62 | + .arg("--id") |
| 63 | + .arg("hello") |
| 64 | + .assert() |
| 65 | + .success() |
| 66 | + .stdout_as_str(); |
| 67 | + |
| 68 | + assert_eq!(actual, expected); |
| 69 | +} |
| 70 | + |
| 71 | +#[tokio::test] |
| 72 | +async fn info_hash_errors_on_stellar_asset_contract() { |
| 73 | + let sandbox = &TestEnv::new(); |
| 74 | + let issuer = test_address(sandbox); |
| 75 | + let sac_id = sandbox |
| 76 | + .new_assert_cmd("contract") |
| 77 | + .arg("asset") |
| 78 | + .arg("deploy") |
| 79 | + .arg(format!("--asset=USDC:{issuer}")) |
| 80 | + .assert() |
| 81 | + .success() |
| 82 | + .stdout_as_str(); |
| 83 | + |
| 84 | + sandbox |
| 85 | + .new_assert_cmd("contract") |
| 86 | + .arg("info") |
| 87 | + .arg("hash") |
| 88 | + .arg("--id") |
| 89 | + .arg(&sac_id) |
| 90 | + .assert() |
| 91 | + .failure(); |
| 92 | +} |
| 93 | + |
| 94 | +#[tokio::test] |
| 95 | +async fn info_hash_requires_one_source() { |
| 96 | + let sandbox = &TestEnv::new(); |
| 97 | + |
| 98 | + sandbox |
| 99 | + .new_assert_cmd("contract") |
| 100 | + .arg("info") |
| 101 | + .arg("hash") |
| 102 | + .assert() |
| 103 | + .failure(); |
| 104 | +} |
| 105 | + |
| 106 | +#[tokio::test] |
| 107 | +async fn info_hash_wasm_and_id_are_mutually_exclusive() { |
| 108 | + let sandbox = &TestEnv::new(); |
| 109 | + let contract_id = deploy_contract(sandbox, HELLO_WORLD, DeployOptions::default()).await; |
| 110 | + |
| 111 | + sandbox |
| 112 | + .new_assert_cmd("contract") |
| 113 | + .arg("info") |
| 114 | + .arg("hash") |
| 115 | + .arg("--wasm") |
| 116 | + .arg(HELLO_WORLD.path()) |
| 117 | + .arg("--id") |
| 118 | + .arg(&contract_id) |
| 119 | + .assert() |
| 120 | + .failure(); |
| 121 | +} |
0 commit comments