1- use sha2:: { Digest , Sha256 } ;
2- use soroban_cli:: {
3- config:: { address:: UnresolvedMuxedAccount , locator} ,
4- tx:: builder:: TxExt ,
5- xdr:: {
6- self , AccountId , AlphaNum4 , Asset , AssetCode4 , ChangeTrustAsset , ChangeTrustOp ,
7- ClaimPredicate , ClaimableBalanceId , Claimant , ClaimantV0 , ConfigSettingId ,
8- ContractDataDurability , CreateClaimableBalanceOp , CreateClaimableBalanceResult , Hash ,
9- LedgerEntryData , LedgerKey , LedgerKeyAccount , LedgerKeyClaimableBalance ,
10- LedgerKeyConfigSetting , LedgerKeyContractCode , LedgerKeyContractData , LedgerKeyData ,
11- LedgerKeyLiquidityPool , LedgerKeyTrustLine , Limits , LiquidityPoolConstantProductParameters ,
12- LiquidityPoolParameters , Operation , OperationBody , OperationResult , OperationResultTr ,
13- PoolId , PublicKey , ScAddress , ScVal , String64 , StringM , TransactionEnvelope ,
14- TransactionResult , TransactionResultResult , TrustLineAsset , Uint256 , VecM , WriteXdr ,
15- } ,
16- } ;
17-
18- use soroban_rpc:: FullLedgerEntries ;
19- use soroban_rpc:: GetTransactionResponse ;
20- use soroban_spec_tools:: utils:: padded_hex_from_str;
21- use soroban_test:: AssertExt ;
221use soroban_test:: TestEnv ;
23- use stellar_strkey:: { ed25519:: PublicKey as StrkeyPublicKeyEd25519 , Contract } ;
24-
25- use crate :: integration:: util:: { deploy_contract, test_address, DeployOptions , HELLO_WORLD } ;
262
27- // account data tests
28- // todo: test with --offer,
293#[ tokio:: test]
304async fn ledger_latest ( ) {
315 let sandbox = & TestEnv :: new ( ) ;
32- let account_alias = "new_account" ;
33- let new_account_addr = new_account ( sandbox, account_alias) ;
34- let output = sandbox
6+ sandbox
357 . new_assert_cmd ( "ledger" )
368 . arg ( "latest" )
379 . arg ( "--network" )
@@ -41,116 +13,4 @@ async fn ledger_latest() {
4113 . stdout ( predicates:: str:: contains ( "Sequence:" ) )
4214 . stdout ( predicates:: str:: contains ( "Protocol Version:" ) )
4315 . stdout ( predicates:: str:: contains ( "ID:" ) ) ;
44-
45- // let (_, expected_key) = expected_account_ledger_key(&new_account_addr).await;
46- // let parsed: FullLedgerEntries = serde_json::from_str(&output).expect("Failed to parse JSON");
47-
48- // assert!(!parsed.entries.is_empty());
49- // assert_eq!(parsed.entries[0].key, expected_key);
50- // assert!(matches!(
51- // parsed.entries[0].val,
52- // LedgerEntryData::Account { .. }
53- // ));
54- }
55-
56- // Helper Fns
57- fn new_account ( sandbox : & TestEnv , name : & str ) -> String {
58- sandbox. generate_account ( name, None ) . assert ( ) . success ( ) ;
59- sandbox. fund_account ( name) . success ( ) ;
60-
61- sandbox
62- . new_assert_cmd ( "keys" )
63- . args ( [ "address" , name] )
64- . assert ( )
65- . success ( )
66- . stdout_as_str ( )
67- }
68-
69- async fn issue_asset (
70- sandbox : & TestEnv ,
71- test_addr : & str ,
72- issuer_alias : & str ,
73- asset : & str ,
74- limit : u64 ,
75- initial_balance : u64 ,
76- ) {
77- let client = sandbox. network . rpc_client ( ) . unwrap ( ) ;
78- let test_before = client. get_account ( test_addr) . await . unwrap ( ) ;
79- sandbox
80- . new_assert_cmd ( "tx" )
81- . args ( [
82- "new" ,
83- "change-trust" ,
84- "--line" ,
85- asset,
86- "--limit" ,
87- limit. to_string ( ) . as_str ( ) ,
88- ] )
89- . assert ( )
90- . success ( )
91- . stdout_as_str ( ) ;
92-
93- let after = client. get_account ( test_addr) . await . unwrap ( ) ;
94- assert_eq ! ( test_before. num_sub_entries + 1 , after. num_sub_entries) ;
95-
96- // Send asset to the test
97- sandbox
98- . new_assert_cmd ( "tx" )
99- . args ( [
100- "new" ,
101- "payment" ,
102- "--destination" ,
103- test_addr,
104- "--asset" ,
105- asset,
106- "--amount" ,
107- initial_balance. to_string ( ) . as_str ( ) ,
108- "--source" ,
109- issuer_alias,
110- ] )
111- . assert ( )
112- . success ( ) ;
113- }
114-
115- async fn expected_account_ledger_key ( account_addr : & str ) -> ( AccountId , LedgerKey ) {
116- let account_id = get_account_id ( account_addr) ;
117- let ledger_key = LedgerKey :: Account ( LedgerKeyAccount {
118- account_id : account_id. clone ( ) ,
119- } ) ;
120- ( account_id, ledger_key)
121- }
122-
123- fn get_account_id ( account_addr : & str ) -> AccountId {
124- let strkey = StrkeyPublicKeyEd25519 :: from_string ( account_addr) . unwrap ( ) . 0 ;
125-
126- let uint256 = Uint256 ( strkey) ;
127- let pk = PublicKey :: PublicKeyTypeEd25519 ( uint256) ;
128- AccountId ( pk)
129- }
130-
131- async fn expected_contract_ledger_key ( contract_id : & str , storage_key : & str ) -> LedgerKey {
132- let contract_bytes: [ u8 ; 32 ] = Contract :: from_string ( contract_id) . unwrap ( ) . 0 ;
133- let contract_id = Hash ( contract_bytes) ;
134- LedgerKey :: ContractData ( LedgerKeyContractData {
135- contract : ScAddress :: Contract ( contract_id) ,
136- key : ScVal :: Symbol ( storage_key. try_into ( ) . unwrap ( ) ) ,
137- durability : ContractDataDurability :: Persistent ,
138- } )
139- }
140-
141- async fn add_account_data ( sandbox : & TestEnv , account_alias : & str , key : & str , value : & str ) {
142- sandbox
143- . new_assert_cmd ( "tx" )
144- . args ( [
145- "new" ,
146- "manage-data" ,
147- "--data-name" ,
148- key,
149- "--data-value" ,
150- value,
151- "--source" ,
152- account_alias,
153- ] )
154- . assert ( )
155- . success ( ) ;
15616}
0 commit comments