@@ -2,8 +2,8 @@ use std::sync::Arc;
22use std:: time:: Duration ;
33
44use anyhow:: { Context , Result } ;
5- use miden_client:: ClientError ;
6- use miden_client:: account :: { AccountId , AccountStorageMode } ;
5+ use miden_client:: account :: { AccountId , AccountStorageMode , StorageMap , StorageSlot } ;
6+ use miden_client:: assembly :: { DefaultSourceManager , LibraryPath , Module , ModuleKind } ;
77use miden_client:: asset:: { Asset , FungibleAsset } ;
88use miden_client:: builder:: ClientBuilder ;
99use miden_client:: keystore:: FilesystemKeyStore ;
@@ -22,11 +22,13 @@ use miden_client::transaction::{
2222 PaymentNoteDescription ,
2323 ProvenTransaction ,
2424 TransactionInputs ,
25+ TransactionKernel ,
2526 TransactionProver ,
2627 TransactionProverError ,
2728 TransactionRequestBuilder ,
2829 TransactionStatus ,
2930} ;
31+ use miden_client:: { ClientError , Felt , ScriptBuilder } ;
3032use miden_client_sqlite_store:: ClientBuilderSqliteExt ;
3133
3234use crate :: tests:: config:: ClientConfig ;
@@ -1153,8 +1155,85 @@ pub async fn test_unused_rpc_api(client_config: ClientConfig) -> Result<()> {
11531155 consume_notes ( & mut client, first_basic_account. id ( ) , std:: slice:: from_ref ( & note) ) . await ;
11541156 wait_for_tx ( & mut client, tx_id) . await ?;
11551157
1158+ // Define the account code for the custom library
1159+ let custom_code = "
1160+ use.miden::account
1161+
1162+ export.update_map
1163+ push.1.2.3.4
1164+ # => [VALUE]
1165+ push.0.0.0.0
1166+ # => [KEY, VALUE]
1167+ push.1
1168+ # => [index, KEY, VALUE]
1169+ exec.account::set_map_item
1170+ dropw dropw dropw dropw
1171+ end
1172+ " ;
1173+
1174+ let mut storage_map = StorageMap :: new ( ) ;
1175+ storage_map. insert (
1176+ [ Felt :: new ( 1 ) , Felt :: new ( 2 ) , Felt :: new ( 3 ) , Felt :: new ( 4 ) ] . into ( ) ,
1177+ [ Felt :: new ( 0 ) , Felt :: new ( 0 ) , Felt :: new ( 0 ) , Felt :: new ( 1 ) ] . into ( ) ,
1178+ ) ?;
1179+
1180+ let storage_slots = vec ! [ StorageSlot :: empty_map( ) , StorageSlot :: Map ( storage_map) ] ;
1181+ let ( account_with_map_item, _) = insert_account_with_custom_component (
1182+ & mut client,
1183+ custom_code,
1184+ storage_slots,
1185+ AccountStorageMode :: Public ,
1186+ & keystore,
1187+ )
1188+ . await ?;
1189+
11561190 client. sync_state ( ) . await . unwrap ( ) ;
11571191
1192+ let assembler = TransactionKernel :: assembler ( ) ;
1193+ let source_manager = Arc :: new ( DefaultSourceManager :: default ( ) ) ;
1194+ let module = Module :: parser ( ModuleKind :: Library )
1195+ . parse_str (
1196+ LibraryPath :: new ( "custom_library::set_map_item_library" )
1197+ . context ( "failed to create library path for custom library" ) ?,
1198+ custom_code,
1199+ & source_manager,
1200+ )
1201+ . unwrap ( ) ;
1202+ let custom_lib = assembler. assemble_library ( [ module] ) . unwrap ( ) ;
1203+
1204+ let tx_script = ScriptBuilder :: new ( true )
1205+ . with_statically_linked_library ( & custom_lib) ?
1206+ . compile_tx_script (
1207+ "
1208+ use.custom_library::set_map_item_library
1209+
1210+ begin
1211+ call.set_map_item_library::update_map
1212+ end
1213+ " ,
1214+ ) ?;
1215+
1216+ let tx_request = TransactionRequestBuilder :: new ( ) . custom_script ( tx_script) . build ( ) ?;
1217+ execute_tx_and_sync ( & mut client, account_with_map_item. id ( ) , tx_request. clone ( ) ) . await ?;
1218+
1219+ // Mint a new fungible asset to check account vault changes
1220+ let faucet = insert_new_fungible_faucet ( & mut client, AccountStorageMode :: Private , & keystore)
1221+ . await ?
1222+ . 0 ;
1223+
1224+ let fungible_asset = FungibleAsset :: new ( faucet. id ( ) , MINT_AMOUNT ) ?;
1225+ let tx_request = TransactionRequestBuilder :: new ( ) . build_mint_fungible_asset (
1226+ fungible_asset,
1227+ first_basic_account. id ( ) ,
1228+ NoteType :: Public ,
1229+ client. rng ( ) ,
1230+ ) ?;
1231+ let note_id = tx_request. expected_output_own_notes ( ) . pop ( ) . unwrap ( ) . id ( ) ;
1232+ execute_tx_and_sync ( & mut client, fungible_asset. faucet_id ( ) , tx_request. clone ( ) ) . await ?;
1233+
1234+ let tx_request = TransactionRequestBuilder :: new ( ) . build_consume_notes ( vec ! [ note_id] ) ?;
1235+ execute_tx_and_sync ( & mut client, first_basic_account. id ( ) , tx_request) . await ?;
1236+
11581237 let nullifier = note. nullifier ( ) ;
11591238
11601239 let node_nullifier = client
@@ -1176,6 +1255,21 @@ pub async fn test_unused_rpc_api(client_config: ClientConfig) -> Result<()> {
11761255 . get_note_script_by_root ( note. script ( ) . root ( ) )
11771256 . await
11781257 . unwrap ( ) ;
1258+ let sync_storage_maps = client
1259+ . test_rpc_api ( )
1260+ . sync_storage_maps ( 0 . into ( ) , None , account_with_map_item. id ( ) )
1261+ . await
1262+ . unwrap ( ) ;
1263+ let account_vault_info = client
1264+ . test_rpc_api ( )
1265+ . sync_account_vault ( 0 . into ( ) , None , first_basic_account. id ( ) )
1266+ . await
1267+ . unwrap ( ) ;
1268+ let transactions_info = client
1269+ . test_rpc_api ( )
1270+ . sync_transactions ( 0 . into ( ) , None , vec ! [ first_basic_account. id( ) ] )
1271+ . await
1272+ . unwrap ( ) ;
11791273
11801274 // Remove debug decorators from original note script, as they are not persisted on submission
11811275 // https://github.com/0xMiden/miden-base/issues/1812
@@ -1186,6 +1280,9 @@ pub async fn test_unused_rpc_api(client_config: ClientConfig) -> Result<()> {
11861280 assert_eq ! ( node_nullifier. nullifier, nullifier) ;
11871281 assert_eq ! ( node_nullifier_proof. leaf( ) . entries( ) . first( ) . unwrap( ) . 0 , nullifier. as_word( ) ) ;
11881282 assert_eq ! ( note_script, retrieved_note_script) ;
1283+ assert ! ( !sync_storage_maps. updates. is_empty( ) ) ;
1284+ assert ! ( !account_vault_info. updates. is_empty( ) ) ;
1285+ assert ! ( !transactions_info. transaction_records. is_empty( ) ) ;
11891286
11901287 Ok ( ( ) )
11911288}
0 commit comments