1- use soroban_test:: AssertExt ;
2- use soroban_test:: TestEnv ;
3- use soroban_rpc:: FullLedgerEntries ;
4- use soroban_cli:: xdr:: { LedgerKey , LedgerKeyTrustLine , LedgerKeyAccount , PublicKey , Uint256 , AccountId , LedgerKeyData , LedgerEntryData , AssetCode4 , AlphaNum4 , TrustLineAsset , LedgerKeyContractData , ScVal , ScAddress , StringM , String64 , Hash , ContractDataDurability , WriteXdr , Limits , LedgerKeyContractCode , ConfigSettingId , LedgerKeyConfigSetting } ;
5- use stellar_strkey:: {
6- ed25519:: PublicKey as StrkeyPublicKeyEd25519 ,
7- Contract
1+ use soroban_cli:: xdr:: {
2+ AccountId , AlphaNum4 , AssetCode4 , ConfigSettingId , ContractDataDurability , Hash ,
3+ LedgerEntryData , LedgerKey , LedgerKeyAccount , LedgerKeyConfigSetting , LedgerKeyContractCode ,
4+ LedgerKeyContractData , LedgerKeyData , LedgerKeyTrustLine , Limits , PublicKey , ScAddress , ScVal ,
5+ String64 , StringM , TrustLineAsset , Uint256 , WriteXdr ,
86} ;
7+ use soroban_rpc:: FullLedgerEntries ;
98use soroban_spec_tools:: utils:: padded_hex_from_str;
9+ use soroban_test:: AssertExt ;
10+ use soroban_test:: TestEnv ;
11+ use stellar_strkey:: { ed25519:: PublicKey as StrkeyPublicKeyEd25519 , Contract } ;
1012
11- use crate :: integration:: util:: { deploy_contract, test_address, HELLO_WORLD , DeployOptions } ;
12-
13+ use crate :: integration:: util:: { deploy_contract, test_address, DeployOptions , HELLO_WORLD } ;
1314
1415// account data tests
1516// todo: test with--offer,
1617#[ tokio:: test]
17- async fn ledger_entry_account_only ( ) {
18+ async fn ledger_entry_account_only ( ) {
1819 let sandbox = & TestEnv :: new ( ) ;
1920 let account_alias = "new_account" ;
2021 let new_account_addr = new_account ( sandbox, account_alias) ;
@@ -35,11 +36,14 @@ async fn ledger_entry_account_only(){
3536
3637 assert ! ( !parsed. entries. is_empty( ) ) ;
3738 assert_eq ! ( parsed. entries[ 0 ] . key, expected_key) ;
38- assert ! ( matches!( parsed. entries[ 0 ] . val, LedgerEntryData :: Account { .. } ) ) ;
39+ assert ! ( matches!(
40+ parsed. entries[ 0 ] . val,
41+ LedgerEntryData :: Account { .. }
42+ ) ) ;
3943}
4044
4145#[ tokio:: test]
42- async fn ledger_entry_account_asset_xlm ( ) {
46+ async fn ledger_entry_account_asset_xlm ( ) {
4347 let sandbox = & TestEnv :: new ( ) ;
4448 let account_alias = "new_account" ;
4549 let new_account_addr = new_account ( sandbox, account_alias) ;
@@ -53,7 +57,7 @@ async fn ledger_entry_account_asset_xlm(){
5357 . arg ( account_alias)
5458 . arg ( "--asset" )
5559 // though xlm does not have, nor need, a trustline, "xlm" is a valid argument to `--asset`
56- // this test is including it to make sure that the account ledger entry is still included in the output
60+ // this test is including it to make sure that the account ledger entry is still included in the output
5761 . arg ( "xlm" )
5862 . assert ( )
5963 . success ( )
@@ -64,11 +68,14 @@ async fn ledger_entry_account_asset_xlm(){
6468 let parsed: FullLedgerEntries = serde_json:: from_str ( & output) . expect ( "Failed to parse JSON" ) ;
6569 assert ! ( !parsed. entries. is_empty( ) ) ;
6670 assert_eq ! ( parsed. entries[ 0 ] . key, expected_key) ;
67- assert ! ( matches!( parsed. entries[ 0 ] . val, LedgerEntryData :: Account { .. } ) ) ;
71+ assert ! ( matches!(
72+ parsed. entries[ 0 ] . val,
73+ LedgerEntryData :: Account { .. }
74+ ) ) ;
6875}
6976
7077#[ tokio:: test]
71- async fn ledger_entry_account_asset_usdc ( ) {
78+ async fn ledger_entry_account_asset_usdc ( ) {
7279 let sandbox = & TestEnv :: new ( ) ;
7380 let test_account_alias = "test" ;
7481 let test_account_address = test_address ( sandbox) ;
@@ -77,7 +84,14 @@ async fn ledger_entry_account_asset_usdc(){
7784 let asset = & format ! ( "usdc:{issuer_address}" ) ;
7885 let limit = 100_000 ;
7986 let initial_balance = 100 ;
80- issue_asset ( sandbox, & test_account_address, asset, limit, initial_balance) . await ;
87+ issue_asset (
88+ sandbox,
89+ & test_account_address,
90+ asset,
91+ limit,
92+ initial_balance,
93+ )
94+ . await ;
8195
8296 let output = sandbox
8397 . new_assert_cmd ( "ledger" )
@@ -93,7 +107,8 @@ async fn ledger_entry_account_asset_usdc(){
93107 . success ( )
94108 . stdout_as_str ( ) ;
95109
96- let ( account_id, expected_account_key) = expected_account_ledger_key ( & test_account_address) . await ;
110+ let ( account_id, expected_account_key) =
111+ expected_account_ledger_key ( & test_account_address) . await ;
97112 let ( issuer_account_id, _) = expected_account_ledger_key ( & issuer_address) . await ;
98113
99114 let trustline_asset = TrustLineAsset :: CreditAlphanum4 ( AlphaNum4 {
@@ -110,7 +125,10 @@ async fn ledger_entry_account_asset_usdc(){
110125
111126 let trustline_entry = & parsed. entries [ 0 ] ;
112127 assert_eq ! ( trustline_entry. key, expected_trustline_key) ;
113- assert ! ( matches!( trustline_entry. val, LedgerEntryData :: Trustline { .. } ) ) ;
128+ assert ! ( matches!(
129+ trustline_entry. val,
130+ LedgerEntryData :: Trustline { .. }
131+ ) ) ;
114132
115133 let account_entry = & parsed. entries [ 1 ] ;
116134 assert_eq ! ( account_entry. key, expected_account_key) ;
@@ -124,7 +142,7 @@ async fn ledger_entry_account_data() {
124142 let new_account_addr = new_account ( sandbox, account_alias) ;
125143 let data_name = "test_data_key" ;
126144 add_account_data ( sandbox, account_alias, data_name, "abcdef" ) . await ;
127-
145+
128146 let output = sandbox
129147 . new_assert_cmd ( "ledger" )
130148 . arg ( "entry" )
@@ -170,10 +188,13 @@ async fn ledger_entry_contract_data() {
170188 deployer : Some ( test_account_alias. to_string ( ) ) ,
171189 ..Default :: default ( )
172190 } ,
173- ) . await ;
191+ )
192+ . await ;
174193
175194 let storage_key = "COUNTER" ;
176- let storage_key_xdr = ScVal :: Symbol ( storage_key. try_into ( ) . unwrap ( ) ) . to_xdr_base64 ( Limits :: none ( ) ) . unwrap ( ) ;
195+ let storage_key_xdr = ScVal :: Symbol ( storage_key. try_into ( ) . unwrap ( ) )
196+ . to_xdr_base64 ( Limits :: none ( ) )
197+ . unwrap ( ) ;
177198
178199 // update contract storage
179200 sandbox
@@ -195,9 +216,10 @@ async fn ledger_entry_contract_data() {
195216 . assert ( )
196217 . success ( )
197218 . stdout_as_str ( ) ;
198- let parsed_key_output: FullLedgerEntries = serde_json:: from_str ( & key_output) . expect ( "Failed to parse JSON" ) ;
219+ let parsed_key_output: FullLedgerEntries =
220+ serde_json:: from_str ( & key_output) . expect ( "Failed to parse JSON" ) ;
199221 assert ! ( !parsed_key_output. entries. is_empty( ) ) ;
200-
222+
201223 // get entry by key xdr
202224 let key_xdr_output = sandbox
203225 . new_assert_cmd ( "ledger" )
@@ -213,22 +235,31 @@ async fn ledger_entry_contract_data() {
213235 . success ( )
214236 . stdout_as_str ( ) ;
215237
216- let parsed_key_xdr_output: FullLedgerEntries = serde_json:: from_str ( & key_xdr_output) . expect ( "Failed to parse JSON" ) ;
238+ let parsed_key_xdr_output: FullLedgerEntries =
239+ serde_json:: from_str ( & key_xdr_output) . expect ( "Failed to parse JSON" ) ;
217240 assert ! ( !parsed_key_xdr_output. entries. is_empty( ) ) ;
218241
219242 let expected_contract_data_key = expected_contract_ledger_key ( & contract_id, storage_key) . await ;
220243
221244 assert_eq ! ( parsed_key_output. entries[ 0 ] . key, expected_contract_data_key) ;
222- assert ! ( matches!( parsed_key_output. entries[ 0 ] . val, LedgerEntryData :: ContractData { .. } ) ) ;
245+ assert ! ( matches!(
246+ parsed_key_output. entries[ 0 ] . val,
247+ LedgerEntryData :: ContractData { .. }
248+ ) ) ;
249+
250+ assert_eq ! (
251+ parsed_key_xdr_output. entries[ 0 ] . key,
252+ expected_contract_data_key
253+ ) ;
254+ assert ! ( matches!(
255+ parsed_key_xdr_output. entries[ 0 ] . val,
256+ LedgerEntryData :: ContractData { .. }
257+ ) ) ;
223258
224- assert_eq ! ( parsed_key_xdr_output. entries[ 0 ] . key, expected_contract_data_key) ;
225- assert ! ( matches!( parsed_key_xdr_output. entries[ 0 ] . val, LedgerEntryData :: ContractData { .. } ) ) ;
226-
227259 // the output should be the same regardless of key format
228260 assert_eq ! ( parsed_key_output. entries, parsed_key_xdr_output. entries) ;
229261}
230262
231-
232263// top level test
233264// todo: test --ttl, --claimable-id, --pool-id,
234265#[ tokio:: test]
@@ -237,7 +268,8 @@ async fn ledger_entry_wasm_hash() {
237268 let test_account_alias = "test" ;
238269 let wasm = HELLO_WORLD ;
239270 let wasm_path = wasm. path ( ) ;
240- let contract_wasm_hash = sandbox. new_assert_cmd ( "contract" )
271+ let contract_wasm_hash = sandbox
272+ . new_assert_cmd ( "contract" )
241273 . arg ( "upload" )
242274 . arg ( "--wasm" )
243275 . arg ( wasm_path)
@@ -252,7 +284,8 @@ async fn ledger_entry_wasm_hash() {
252284 deployer : Some ( test_account_alias. to_string ( ) ) ,
253285 ..Default :: default ( )
254286 } ,
255- ) . await ;
287+ )
288+ . await ;
256289
257290 // get the contract's wasm bytecode
258291 let output = sandbox
@@ -266,21 +299,28 @@ async fn ledger_entry_wasm_hash() {
266299 . assert ( )
267300 . success ( )
268301 . stdout_as_str ( ) ;
269- let parsed_output: FullLedgerEntries = serde_json:: from_str ( & output) . expect ( "Failed to parse JSON" ) ;
302+ let parsed_output: FullLedgerEntries =
303+ serde_json:: from_str ( & output) . expect ( "Failed to parse JSON" ) ;
270304 assert ! ( !parsed_output. entries. is_empty( ) ) ;
271-
272- let hash = Hash ( padded_hex_from_str ( & contract_wasm_hash, 32 ) . unwrap ( ) . try_into ( ) . unwrap ( ) ) ;
273- let expected_contract_key = LedgerKey :: ContractCode ( LedgerKeyContractCode {
274- hash
275- } ) ;
305+
306+ let hash = Hash (
307+ padded_hex_from_str ( & contract_wasm_hash, 32 )
308+ . unwrap ( )
309+ . try_into ( )
310+ . unwrap ( ) ,
311+ ) ;
312+ let expected_contract_key = LedgerKey :: ContractCode ( LedgerKeyContractCode { hash } ) ;
276313
277314 assert_eq ! ( parsed_output. entries[ 0 ] . key, expected_contract_key) ;
278- assert ! ( matches!( parsed_output. entries[ 0 ] . val, LedgerEntryData :: ContractCode { .. } ) ) ;
315+ assert ! ( matches!(
316+ parsed_output. entries[ 0 ] . val,
317+ LedgerEntryData :: ContractCode { .. }
318+ ) ) ;
279319 // key: ContractCode(LedgerKeyContractCode { hash: Hash(74a0a58bee2730d38dfaa547c0f3e64b1b76cf7d7e430373a9bf7aad122aff9f) }
280320
281321 // assert_eq!(parsed_key_xdr_output.entries[0].key, expected_contract_data_key);
282322 // assert!(matches!(parsed_key_xdr_output.entries[0].val, LedgerEntryData::ContractData{ .. }));
283-
323+
284324 // // the output should be the same regardless of key format
285325 // assert_eq!(parsed_key_output.entries, parsed_key_xdr_output.entries);
286326}
@@ -301,21 +341,22 @@ async fn ledger_entry_config_setting_id() {
301341 . arg ( ( config_setting_variant as i32 ) . to_string ( ) )
302342 . assert ( )
303343 . success ( )
304- . stdout_as_str ( ) ;
305- let parsed_output: FullLedgerEntries = serde_json:: from_str ( & output) . expect ( "Failed to parse JSON" ) ;
344+ . stdout_as_str ( ) ;
345+ let parsed_output: FullLedgerEntries =
346+ serde_json:: from_str ( & output) . expect ( "Failed to parse JSON" ) ;
306347 assert ! ( !parsed_output. entries. is_empty( ) ) ;
307348
308- let expected_key = LedgerKey :: ConfigSetting (
309- LedgerKeyConfigSetting {
310- config_setting_id : config_setting_variant,
311- }
312- ) ;
349+ let expected_key = LedgerKey :: ConfigSetting ( LedgerKeyConfigSetting {
350+ config_setting_id : config_setting_variant,
351+ } ) ;
313352 assert_eq ! ( parsed_output. entries[ 0 ] . key, expected_key) ;
314- assert ! ( matches!( parsed_output. entries[ 0 ] . val, LedgerEntryData :: ConfigSetting { .. } ) ) ;
353+ assert ! ( matches!(
354+ parsed_output. entries[ 0 ] . val,
355+ LedgerEntryData :: ConfigSetting { .. }
356+ ) ) ;
315357 }
316358}
317359
318-
319360#[ ignore]
320361#[ tokio:: test]
321362async fn ledger_entry_ttl ( ) {
@@ -328,10 +369,13 @@ async fn ledger_entry_ttl() {
328369 deployer : Some ( test_account_alias. to_string ( ) ) ,
329370 ..Default :: default ( )
330371 } ,
331- ) . await ;
372+ )
373+ . await ;
332374
333375 let storage_key = "COUNTER" ;
334- let storage_key_xdr = ScVal :: Symbol ( storage_key. try_into ( ) . unwrap ( ) ) . to_xdr_base64 ( Limits :: none ( ) ) . unwrap ( ) ;
376+ let storage_key_xdr = ScVal :: Symbol ( storage_key. try_into ( ) . unwrap ( ) )
377+ . to_xdr_base64 ( Limits :: none ( ) )
378+ . unwrap ( ) ;
335379 println ! ( "storage key: {}" , storage_key_xdr) ;
336380
337381 // update contract storage
@@ -352,9 +396,10 @@ async fn ledger_entry_ttl() {
352396 . assert ( )
353397 . success ( )
354398 . stdout_as_str ( ) ;
355- let parsed_output: FullLedgerEntries = serde_json:: from_str ( & output) . expect ( "Failed to parse JSON" ) ;
399+ let parsed_output: FullLedgerEntries =
400+ serde_json:: from_str ( & output) . expect ( "Failed to parse JSON" ) ;
356401 assert ! ( !parsed_output. entries. is_empty( ) ) ;
357-
402+
358403 // let parsed_key_xdr_output: FullLedgerEntries = serde_json::from_str(&key_xdr_output).expect("Failed to parse JSON");
359404 // assert!(!parsed_key_xdr_output.entries.is_empty());
360405
@@ -365,7 +410,7 @@ async fn ledger_entry_ttl() {
365410
366411 // assert_eq!(parsed_key_xdr_output.entries[0].key, expected_contract_data_key);
367412 // assert!(matches!(parsed_key_xdr_output.entries[0].val, LedgerEntryData::ContractData{ .. }));
368-
413+
369414 // // the output should be the same regardless of key format
370415 // assert_eq!(parsed_key_output.entries, parsed_key_xdr_output.entries);
371416}
@@ -374,7 +419,7 @@ async fn ledger_entry_ttl() {
374419fn new_account ( sandbox : & TestEnv , name : & str ) -> String {
375420 sandbox. generate_account ( name, None ) . assert ( ) . success ( ) ;
376421 sandbox. fund_account ( name) . success ( ) ;
377-
422+
378423 sandbox
379424 . new_assert_cmd ( "keys" )
380425 . args ( [ "address" , name] )
@@ -442,39 +487,41 @@ async fn issue_asset(sandbox: &TestEnv, test: &str, asset: &str, limit: u64, ini
442487 . success ( ) ;
443488}
444489
445- async fn expected_account_ledger_key ( account_addr : & str ) -> ( AccountId , LedgerKey ) {
490+ async fn expected_account_ledger_key ( account_addr : & str ) -> ( AccountId , LedgerKey ) {
446491 let strkey = StrkeyPublicKeyEd25519 :: from_string ( account_addr) . unwrap ( ) . 0 ;
447492
448493 let uint256 = Uint256 ( strkey) ;
449494 let pk = PublicKey :: PublicKeyTypeEd25519 ( uint256) ;
450495 let account_id = AccountId ( pk) ;
451- let ledger_key = LedgerKey :: Account ( LedgerKeyAccount { account_id : account_id. clone ( ) } ) ;
496+ let ledger_key = LedgerKey :: Account ( LedgerKeyAccount {
497+ account_id : account_id. clone ( ) ,
498+ } ) ;
452499 ( account_id, ledger_key)
453500}
454501
455- async fn expected_contract_ledger_key ( contract_id : & str , storage_key : & str ) -> LedgerKey {
502+ async fn expected_contract_ledger_key ( contract_id : & str , storage_key : & str ) -> LedgerKey {
456503 let contract_bytes: [ u8 ; 32 ] = Contract :: from_string ( contract_id) . unwrap ( ) . 0 ;
457504 let contract_id = Hash ( contract_bytes) ;
458- LedgerKey :: ContractData ( LedgerKeyContractData {
505+ LedgerKey :: ContractData ( LedgerKeyContractData {
459506 contract : ScAddress :: Contract ( contract_id) ,
460507 key : ScVal :: Symbol ( storage_key. try_into ( ) . unwrap ( ) ) ,
461- durability : ContractDataDurability :: Persistent }
462- )
508+ durability : ContractDataDurability :: Persistent ,
509+ } )
463510}
464511
465512async fn add_account_data ( sandbox : & TestEnv , account_alias : & str , key : & str , value : & str ) {
466513 sandbox
467- . new_assert_cmd ( "tx" )
468- . args ( [
469- "new" ,
470- "manage-data" ,
471- "--data-name" ,
472- key,
473- "--data-value" ,
474- value,
475- "--source" ,
476- account_alias,
477- ] )
478- . assert ( )
479- . success ( ) ;
480- }
514+ . new_assert_cmd ( "tx" )
515+ . args ( [
516+ "new" ,
517+ "manage-data" ,
518+ "--data-name" ,
519+ key,
520+ "--data-value" ,
521+ value,
522+ "--source" ,
523+ account_alias,
524+ ] )
525+ . assert ( )
526+ . success ( ) ;
527+ }
0 commit comments