Skip to content

Commit a4fc9af

Browse files
authored
Extract each tx new command's integration tests to a dedicated file. (#2217)
1 parent fdec3ca commit a4fc9af

16 files changed

Lines changed: 2413 additions & 2373 deletions
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
use soroban_test::TestEnv;
2+
3+
use crate::integration::util::setup_accounts;
4+
5+
#[tokio::test]
6+
async fn account_merge() {
7+
let sandbox = &TestEnv::new();
8+
let client = sandbox.network.rpc_client().unwrap();
9+
let (test, test1) = setup_accounts(sandbox);
10+
let before = client.get_account(&test).await.unwrap();
11+
let before1 = client.get_account(&test1).await.unwrap();
12+
let fee = 100;
13+
sandbox
14+
.new_assert_cmd("tx")
15+
.args([
16+
"new",
17+
"account-merge",
18+
"--source",
19+
"test1",
20+
"--account",
21+
test.as_str(),
22+
"--fee",
23+
fee.to_string().as_str(),
24+
])
25+
.assert()
26+
.success();
27+
let after = client.get_account(&test).await.unwrap();
28+
assert!(client.get_account(&test1).await.is_err());
29+
assert_eq!(before.balance + before1.balance - fee, after.balance);
30+
}
31+
32+
#[tokio::test]
33+
async fn account_merge_with_alias() {
34+
let sandbox = &TestEnv::new();
35+
let client = sandbox.client();
36+
let (test, test1) = setup_accounts(sandbox);
37+
let before = client.get_account(&test).await.unwrap();
38+
let before1 = client.get_account(&test1).await.unwrap();
39+
let fee = 100;
40+
sandbox
41+
.new_assert_cmd("tx")
42+
.args([
43+
"new",
44+
"account-merge",
45+
"--source",
46+
"test1",
47+
"--account",
48+
"test",
49+
"--fee",
50+
fee.to_string().as_str(),
51+
])
52+
.assert()
53+
.success();
54+
let after = client.get_account(&test).await.unwrap();
55+
assert!(client.get_account(&test1).await.is_err());
56+
assert_eq!(before.balance + before1.balance - fee, after.balance);
57+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use crate::integration::util::test_address;
2+
use soroban_cli::xdr::SequenceNumber;
3+
use soroban_test::TestEnv;
4+
5+
#[tokio::test]
6+
async fn bump_sequence() {
7+
let sandbox = &TestEnv::new();
8+
let client = sandbox.network.rpc_client().unwrap();
9+
let test = test_address(sandbox);
10+
let before = client.get_account(&test).await.unwrap();
11+
let amount = 50;
12+
let seq = SequenceNumber(before.seq_num.0 + amount);
13+
// bump sequence tx new
14+
sandbox
15+
.new_assert_cmd("tx")
16+
.args([
17+
"new",
18+
"bump-sequence",
19+
"--bump-to",
20+
seq.0.to_string().as_str(),
21+
])
22+
.assert()
23+
.success();
24+
let after = client.get_account(&test).await.unwrap();
25+
assert_eq!(seq, after.seq_num);
26+
}
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
use soroban_cli::{config::locator, tx::builder, utils::contract_id_hash_from_asset};
2+
3+
use soroban_test::TestEnv;
4+
5+
use crate::integration::util::{issue_asset, new_account, setup_accounts};
6+
7+
#[tokio::test]
8+
async fn change_trust() {
9+
let sandbox = &TestEnv::new();
10+
let (test, issuer) = setup_accounts(sandbox);
11+
let asset = &format!("usdc:{issuer}");
12+
13+
let limit = 100_000_000;
14+
let half_limit = limit / 2;
15+
issue_asset(sandbox, &test, asset, limit, half_limit).await;
16+
sandbox
17+
.new_assert_cmd("contract")
18+
.arg("asset")
19+
.arg("deploy")
20+
.arg("--asset")
21+
.arg(asset)
22+
.assert()
23+
.success();
24+
25+
let id = contract_id_hash_from_asset(
26+
&asset
27+
.parse::<builder::Asset>()
28+
.unwrap()
29+
.resolve(&locator::Args::default())
30+
.unwrap(),
31+
&sandbox.network.network_passphrase,
32+
);
33+
sandbox
34+
.new_assert_cmd("contract")
35+
.args([
36+
"invoke",
37+
"--id",
38+
&id.to_string(),
39+
"--",
40+
"balance",
41+
"--id",
42+
&test,
43+
])
44+
.assert()
45+
.stdout(format!("\"{half_limit}\"\n"));
46+
47+
let bob = new_account(sandbox, "bob");
48+
let bobs_limit = half_limit / 2;
49+
sandbox
50+
.new_assert_cmd("tx")
51+
.args([
52+
"new",
53+
"change-trust",
54+
"--source=bob",
55+
"--line",
56+
asset,
57+
"--limit",
58+
bobs_limit.to_string().as_str(),
59+
])
60+
.assert()
61+
.success();
62+
sandbox
63+
.new_assert_cmd("tx")
64+
.args([
65+
"new",
66+
"payment",
67+
"--destination",
68+
&bob,
69+
"--asset",
70+
asset,
71+
"--amount",
72+
half_limit.to_string().as_str(),
73+
])
74+
.assert()
75+
.failure();
76+
sandbox
77+
.new_assert_cmd("tx")
78+
.args([
79+
"new",
80+
"payment",
81+
"--destination",
82+
&bob,
83+
"--asset",
84+
asset,
85+
"--amount",
86+
bobs_limit.to_string().as_str(),
87+
])
88+
.assert()
89+
.success();
90+
sandbox
91+
.new_assert_cmd("contract")
92+
.args([
93+
"invoke",
94+
"--id",
95+
&id.to_string(),
96+
"--",
97+
"balance",
98+
"--id",
99+
&bob,
100+
])
101+
.assert()
102+
.stdout(format!("\"{bobs_limit}\"\n"));
103+
}
104+
105+
#[tokio::test]
106+
async fn set_trustline_flags() {
107+
let sandbox = &TestEnv::new();
108+
let (test, test1_address) = setup_accounts(sandbox);
109+
let asset = "usdc:test1";
110+
issue_asset(sandbox, &test, asset, 100_000, 100).await;
111+
sandbox
112+
.new_assert_cmd("contract")
113+
.arg("asset")
114+
.arg("deploy")
115+
.arg("--asset")
116+
.arg(asset)
117+
.assert()
118+
.success();
119+
let id = contract_id_hash_from_asset(
120+
&format!("usdc:{test1_address}")
121+
.parse::<builder::Asset>()
122+
.unwrap()
123+
.resolve(&locator::Args::default())
124+
.unwrap(),
125+
&sandbox.network.network_passphrase,
126+
);
127+
128+
sandbox
129+
.new_assert_cmd("contract")
130+
.args([
131+
"invoke",
132+
"--id",
133+
&id.to_string(),
134+
"--",
135+
"authorized",
136+
"--id",
137+
&test,
138+
])
139+
.assert()
140+
.success()
141+
.stdout("true\n");
142+
}

0 commit comments

Comments
 (0)