diff --git a/rust/integration-tests/sdk_expected_db_output_files/fungible_asset_processor/first_transaction/coin_supply.json b/rust/integration-tests/sdk_expected_db_output_files/fungible_asset_processor/first_transaction/coin_supply.json new file mode 100644 index 00000000..cd9bd345 --- /dev/null +++ b/rust/integration-tests/sdk_expected_db_output_files/fungible_asset_processor/first_transaction/coin_supply.json @@ -0,0 +1,10 @@ +[ + { + "transaction_version": 1680592683, + "coin_type_hash": "91ceb1308a98389691e05158b07ed5f079ab78461a6bb8d5a4054b1bb5cb8bb6", + "coin_type": "0x1::aptos_coin::AptosCoin", + "supply": "111442820397688086", + "transaction_timestamp": "2024-09-05T11:52:16", + "transaction_epoch": 8371 + } +] \ No newline at end of file diff --git a/rust/integration-tests/sdk_expected_db_output_files/fungible_asset_processor/first_transaction/current_fungible_asset_balances.json b/rust/integration-tests/sdk_expected_db_output_files/fungible_asset_processor/first_transaction/current_fungible_asset_balances.json new file mode 100644 index 00000000..f37c568a --- /dev/null +++ b/rust/integration-tests/sdk_expected_db_output_files/fungible_asset_processor/first_transaction/current_fungible_asset_balances.json @@ -0,0 +1,21 @@ +[ + { + "storage_id": "0xfa4e15c47bc6b38cc404cf08e30e69fd14ff2cc82b136ef3630445a66605653c", + "owner_address": "0x5ae6789dd2fec1a9ec9cccfb3acaf12e93d432f0a3a42c92fe1a9d490b7bbc06", + "asset_type_v2": null, + "asset_type_v1": "0x1::aptos_coin::AptosCoin", + "is_primary": true, + "is_frozen": false, + "amount_v1": "997323833", + "amount_v2": null, + "amount": "997323833", + "last_transaction_version_v1": 1680592683, + "last_transaction_version_v2": null, + "last_transaction_version": 1680592683, + "last_transaction_timestamp_v1": "2024-09-05T11:52:16", + "last_transaction_timestamp_v2": null, + "last_transaction_timestamp": "2024-09-05T11:52:16", + "token_standard": "v1", + "asset_type": "0x1::aptos_coin::AptosCoin" + } +] \ No newline at end of file diff --git a/rust/integration-tests/sdk_expected_db_output_files/fungible_asset_processor/first_transaction/fungible_asset_activities.json b/rust/integration-tests/sdk_expected_db_output_files/fungible_asset_processor/first_transaction/fungible_asset_activities.json new file mode 100644 index 00000000..318d0266 --- /dev/null +++ b/rust/integration-tests/sdk_expected_db_output_files/fungible_asset_processor/first_transaction/fungible_asset_activities.json @@ -0,0 +1,20 @@ +[ + { + "transaction_version": 1680592683, + "event_index": -1, + "owner_address": "0x5ae6789dd2fec1a9ec9cccfb3acaf12e93d432f0a3a42c92fe1a9d490b7bbc06", + "storage_id": "0xfa4e15c47bc6b38cc404cf08e30e69fd14ff2cc82b136ef3630445a66605653c", + "asset_type": "0x1::aptos_coin::AptosCoin", + "is_frozen": null, + "amount": "205700", + "type_": "0x1::aptos_coin::GasFeeEvent", + "is_gas_fee": true, + "gas_fee_payer_address": null, + "is_transaction_success": true, + "entry_function_id_str": "0x5ae6789dd2fec1a9ec9cccfb3acaf12e93d432f0a3a42c92fe1a9d490b7bbc06::managed_mkl_token::initialize_module", + "block_height": 222731447, + "token_standard": "v1", + "transaction_timestamp": "2024-09-05T11:52:16", + "storage_refund_amount": "47280" + } +] \ No newline at end of file diff --git a/rust/integration-tests/sdk_expected_db_output_files/fungible_asset_processor/first_transaction/fungible_asset_balances.json b/rust/integration-tests/sdk_expected_db_output_files/fungible_asset_processor/first_transaction/fungible_asset_balances.json new file mode 100644 index 00000000..0637a088 --- /dev/null +++ b/rust/integration-tests/sdk_expected_db_output_files/fungible_asset_processor/first_transaction/fungible_asset_balances.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/rust/integration-tests/sdk_expected_db_output_files/fungible_asset_processor/first_transaction/fungible_asset_metadata.json b/rust/integration-tests/sdk_expected_db_output_files/fungible_asset_processor/first_transaction/fungible_asset_metadata.json new file mode 100644 index 00000000..07c1dc47 --- /dev/null +++ b/rust/integration-tests/sdk_expected_db_output_files/fungible_asset_processor/first_transaction/fungible_asset_metadata.json @@ -0,0 +1,36 @@ +[ + { + "asset_type": "0x5ae6789dd2fec1a9ec9cccfb3acaf12e93d432f0a3a42c92fe1a9d490b7bbc06::mkl_token::MKL", + "creator_address": "0x5ae6789dd2fec1a9ec9cccfb3acaf12e93d432f0a3a42c92fe1a9d490b7bbc06", + "name": "MKL", + "symbol": "MKL", + "decimals": 6, + "icon_uri": null, + "project_uri": null, + "last_transaction_version": 1680592683, + "last_transaction_timestamp": "2024-09-05T11:52:16", + "supply_aggregator_table_handle_v1": null, + "supply_aggregator_table_key_v1": null, + "token_standard": "v1", + "maximum_v2": null, + "is_token_v2": null, + "supply_v2": null + }, + { + "asset_type": "0x878370592f9129e14b76558689a4b570ad22678111df775befbfcbc9fb3d90ab", + "creator_address": "0x000000000000000000000000000000000000000000000000000000000000000a", + "name": "MKL", + "symbol": "MKL", + "decimals": 6, + "icon_uri": "", + "project_uri": "", + "last_transaction_version": 1680592683, + "last_transaction_timestamp": "2024-09-05T11:52:16", + "supply_aggregator_table_handle_v1": null, + "supply_aggregator_table_key_v1": null, + "token_standard": "v2", + "maximum_v2": "340282366920938463463374607431768211455", + "is_token_v2": null, + "supply_v2": "0" + } +] \ No newline at end of file diff --git a/rust/integration-tests/sdk_expected_db_output_files/fungible_asset_processor/second_transaction/coin_supply.json b/rust/integration-tests/sdk_expected_db_output_files/fungible_asset_processor/second_transaction/coin_supply.json new file mode 100644 index 00000000..02a7bc04 --- /dev/null +++ b/rust/integration-tests/sdk_expected_db_output_files/fungible_asset_processor/second_transaction/coin_supply.json @@ -0,0 +1,10 @@ +[ + { + "transaction_version": 1957950162, + "coin_type_hash": "91ceb1308a98389691e05158b07ed5f079ab78461a6bb8d5a4054b1bb5cb8bb6", + "coin_type": "0x1::aptos_coin::AptosCoin", + "supply": "112743621173497128", + "transaction_timestamp": "2024-11-23T22:32:30", + "transaction_epoch": 9331 + } +] \ No newline at end of file diff --git a/rust/integration-tests/sdk_expected_db_output_files/fungible_asset_processor/second_transaction/current_fungible_asset_balances.json b/rust/integration-tests/sdk_expected_db_output_files/fungible_asset_processor/second_transaction/current_fungible_asset_balances.json new file mode 100644 index 00000000..c17afc6e --- /dev/null +++ b/rust/integration-tests/sdk_expected_db_output_files/fungible_asset_processor/second_transaction/current_fungible_asset_balances.json @@ -0,0 +1,59 @@ +[ + { + "storage_id": "0x1734f2619bb775e59d04469663b9c05614b5ada6afbf2f750095f43cb8d41e40", + "owner_address": "0x345ced5d7c67360d61a1d59d8cd83cb53095a81aa24a337027391b1c7dd1786f", + "asset_type_v2": null, + "asset_type_v1": "0x1::aptos_coin::AptosCoin", + "is_primary": true, + "is_frozen": false, + "amount_v1": "115245132", + "amount_v2": null, + "amount": "115245132", + "last_transaction_version_v1": 1957950162, + "last_transaction_version_v2": null, + "last_transaction_version": 1957950162, + "last_transaction_timestamp_v1": "2024-11-23T22:32:30", + "last_transaction_timestamp_v2": null, + "last_transaction_timestamp": "2024-11-23T22:32:30", + "token_standard": "v1", + "asset_type": "0x1::aptos_coin::AptosCoin" + }, + { + "storage_id": "0xa1ddab83c8209aabffc66264730ba95bcc7d7a7966192c00d800ab734729622c", + "owner_address": "0x7ae7cc51c4fab67181a969f53a5d01a292dad0baf259c92c4e1a13f056768e1c", + "asset_type_v2": "0x878370592f9129e14b76558689a4b570ad22678111df775befbfcbc9fb3d90ab", + "asset_type_v1": "0x5ae6789dd2fec1a9ec9cccfb3acaf12e93d432f0a3a42c92fe1a9d490b7bbc06::mkl_token::MKL", + "is_primary": true, + "is_frozen": false, + "amount_v1": null, + "amount_v2": "431101567356", + "amount": "431101567356", + "last_transaction_version_v1": null, + "last_transaction_version_v2": 1957950162, + "last_transaction_version": 1957950162, + "last_transaction_timestamp_v1": null, + "last_transaction_timestamp_v2": "2024-11-23T22:32:30", + "last_transaction_timestamp": "2024-11-23T22:32:30", + "token_standard": "v1", + "asset_type": "0x5ae6789dd2fec1a9ec9cccfb3acaf12e93d432f0a3a42c92fe1a9d490b7bbc06::mkl_token::MKL" + }, + { + "storage_id": "0xd29b17433643769f27d89851553ec2ab5e4204b66eceecb6eec774668117c3e0", + "owner_address": "0x345ced5d7c67360d61a1d59d8cd83cb53095a81aa24a337027391b1c7dd1786f", + "asset_type_v2": "0x878370592f9129e14b76558689a4b570ad22678111df775befbfcbc9fb3d90ab", + "asset_type_v1": "0x5ae6789dd2fec1a9ec9cccfb3acaf12e93d432f0a3a42c92fe1a9d490b7bbc06::mkl_token::MKL", + "is_primary": true, + "is_frozen": false, + "amount_v1": null, + "amount_v2": "3643926", + "amount": "3643926", + "last_transaction_version_v1": null, + "last_transaction_version_v2": 1957950162, + "last_transaction_version": 1957950162, + "last_transaction_timestamp_v1": null, + "last_transaction_timestamp_v2": "2024-11-23T22:32:30", + "last_transaction_timestamp": "2024-11-23T22:32:30", + "token_standard": "v1", + "asset_type": "0x5ae6789dd2fec1a9ec9cccfb3acaf12e93d432f0a3a42c92fe1a9d490b7bbc06::mkl_token::MKL" + } +] \ No newline at end of file diff --git a/rust/integration-tests/sdk_expected_db_output_files/fungible_asset_processor/second_transaction/fungible_asset_activities.json b/rust/integration-tests/sdk_expected_db_output_files/fungible_asset_processor/second_transaction/fungible_asset_activities.json new file mode 100644 index 00000000..b5df5cc4 --- /dev/null +++ b/rust/integration-tests/sdk_expected_db_output_files/fungible_asset_processor/second_transaction/fungible_asset_activities.json @@ -0,0 +1,56 @@ +[ + { + "transaction_version": 1957950162, + "event_index": -1, + "owner_address": "0x345ced5d7c67360d61a1d59d8cd83cb53095a81aa24a337027391b1c7dd1786f", + "storage_id": "0x1734f2619bb775e59d04469663b9c05614b5ada6afbf2f750095f43cb8d41e40", + "asset_type": "0x1::aptos_coin::AptosCoin", + "is_frozen": null, + "amount": "2100", + "type_": "0x1::aptos_coin::GasFeeEvent", + "is_gas_fee": true, + "gas_fee_payer_address": null, + "is_transaction_success": true, + "entry_function_id_str": "0x5ae6789dd2fec1a9ec9cccfb3acaf12e93d432f0a3a42c92fe1a9d490b7bbc06::managed_liquidity_auction::claim_mkl_reward", + "block_height": 256094969, + "token_standard": "v1", + "transaction_timestamp": "2024-11-23T22:32:30", + "storage_refund_amount": "0" + }, + { + "transaction_version": 1957950162, + "event_index": 0, + "owner_address": "0x7ae7cc51c4fab67181a969f53a5d01a292dad0baf259c92c4e1a13f056768e1c", + "storage_id": "0xa1ddab83c8209aabffc66264730ba95bcc7d7a7966192c00d800ab734729622c", + "asset_type": "0x878370592f9129e14b76558689a4b570ad22678111df775befbfcbc9fb3d90ab", + "is_frozen": null, + "amount": "3643926", + "type_": "0x1::fungible_asset::Withdraw", + "is_gas_fee": false, + "gas_fee_payer_address": null, + "is_transaction_success": true, + "entry_function_id_str": "0x5ae6789dd2fec1a9ec9cccfb3acaf12e93d432f0a3a42c92fe1a9d490b7bbc06::managed_liquidity_auction::claim_mkl_reward", + "block_height": 256094969, + "token_standard": "v2", + "transaction_timestamp": "2024-11-23T22:32:30", + "storage_refund_amount": "0" + }, + { + "transaction_version": 1957950162, + "event_index": 1, + "owner_address": "0x345ced5d7c67360d61a1d59d8cd83cb53095a81aa24a337027391b1c7dd1786f", + "storage_id": "0xd29b17433643769f27d89851553ec2ab5e4204b66eceecb6eec774668117c3e0", + "asset_type": "0x878370592f9129e14b76558689a4b570ad22678111df775befbfcbc9fb3d90ab", + "is_frozen": null, + "amount": "3643926", + "type_": "0x1::fungible_asset::Deposit", + "is_gas_fee": false, + "gas_fee_payer_address": null, + "is_transaction_success": true, + "entry_function_id_str": "0x5ae6789dd2fec1a9ec9cccfb3acaf12e93d432f0a3a42c92fe1a9d490b7bbc06::managed_liquidity_auction::claim_mkl_reward", + "block_height": 256094969, + "token_standard": "v2", + "transaction_timestamp": "2024-11-23T22:32:30", + "storage_refund_amount": "0" + } +] \ No newline at end of file diff --git a/rust/integration-tests/sdk_expected_db_output_files/fungible_asset_processor/second_transaction/fungible_asset_balances.json b/rust/integration-tests/sdk_expected_db_output_files/fungible_asset_processor/second_transaction/fungible_asset_balances.json new file mode 100644 index 00000000..0637a088 --- /dev/null +++ b/rust/integration-tests/sdk_expected_db_output_files/fungible_asset_processor/second_transaction/fungible_asset_balances.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/rust/integration-tests/sdk_expected_db_output_files/fungible_asset_processor/second_transaction/fungible_asset_metadata.json b/rust/integration-tests/sdk_expected_db_output_files/fungible_asset_processor/second_transaction/fungible_asset_metadata.json new file mode 100644 index 00000000..8c339f5f --- /dev/null +++ b/rust/integration-tests/sdk_expected_db_output_files/fungible_asset_processor/second_transaction/fungible_asset_metadata.json @@ -0,0 +1,19 @@ +[ + { + "asset_type": "0x878370592f9129e14b76558689a4b570ad22678111df775befbfcbc9fb3d90ab", + "creator_address": "0x000000000000000000000000000000000000000000000000000000000000000a", + "name": "MKL", + "symbol": "MKL", + "decimals": 6, + "icon_uri": "", + "project_uri": "", + "last_transaction_version": 1957950162, + "last_transaction_timestamp": "2024-11-23T22:32:30", + "supply_aggregator_table_handle_v1": null, + "supply_aggregator_table_key_v1": null, + "token_standard": "v2", + "maximum_v2": "340282366920938463463374607431768211455", + "is_token_v2": null, + "supply_v2": "96895109643615" + } +] \ No newline at end of file diff --git a/rust/integration-tests/src/sdk_tests/fungible_asset_processor_tests.rs b/rust/integration-tests/src/sdk_tests/fungible_asset_processor_tests.rs index 9ee3e1ee..bfa7df30 100644 --- a/rust/integration-tests/src/sdk_tests/fungible_asset_processor_tests.rs +++ b/rust/integration-tests/src/sdk_tests/fungible_asset_processor_tests.rs @@ -48,6 +48,10 @@ mod sdk_fungible_asset_processor_tests { setup_test_environment, validate_json, DEFAULT_OUTPUT_FOLDER, }, }; + use aptos_indexer_testing_framework::{ + database::{PostgresTestDatabase}, + sdk_test_context::{SdkTestContext}, + }; use aptos_indexer_test_transactions::json_transactions::generated_transactions::{ IMPORTED_DEVNET_TXNS_78753811_COIN_TRANSFER_WITH_V2_EVENTS, IMPORTED_MAINNET_TXNS_1680592683_FA_MIGRATION_COIN_INFO, @@ -270,6 +274,85 @@ mod sdk_fungible_asset_processor_tests { // .await; // } + /// Tests processing of two transactions sequentially + /// Validates handling of multiple transactions with shared context + #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + async fn test_fungible_asset_processor_two_transactions() { + let (diff_flag, custom_output_path) = get_test_config(); + let output_path = custom_output_path.unwrap_or_else(|| DEFAULT_OUTPUT_FOLDER.to_string()); + + let mut db = PostgresTestDatabase::new(); + db.setup().await.unwrap(); + + // Process each transaction with a helper function + process_transaction( + &mut db, + &[IMPORTED_MAINNET_TXNS_1680592683_FA_MIGRATION_COIN_INFO], + "first_transaction", + diff_flag, + &output_path, + ) + .await; + + process_transaction( + &mut db, + &[IMPORTED_MAINNET_TXNS_1957950162_FA_MIGRATION_V2_STORE_ONLY], + "second_transaction", + diff_flag, + &output_path, + ) + .await; + } + + async fn process_transaction( + db: &mut PostgresTestDatabase, + txns: &[&[u8]], + transaction_name: &str, + diff_flag: bool, + output_path: &str, + ) { + let mut test_context = SdkTestContext::new(txns); + if test_context.init_mock_grpc().await.is_err() { + panic!("Failed to initialize mock grpc"); + }; + + let db_url = db.get_db_url(); + let (indexer_processor_config, processor_name) = + setup_fa_processor_config(&test_context, &db_url); + + let fungible_asset_processor = FungibleAssetProcessor::new(indexer_processor_config) + .await + .expect("Failed to create FungibleAssetProcessor"); + + match run_processor_test( + &mut test_context, + fungible_asset_processor, + load_data, + db_url, + diff_flag, + output_path.to_string(), + Some(transaction_name.to_string()), + ) + .await + { + Ok(mut db_value) => { + let _ = validate_json( + &mut db_value, + test_context.get_request_start_version(), + processor_name, + output_path.to_string(), + Some(transaction_name.to_string()), + ); + } + Err(e) => { + panic!( + "Test failed on {} due to processor error: {}", + transaction_name, e + ); + } + } + } + // Helper function to abstract out the transaction processing async fn process_fa_txns(txns: &[&[u8]], test_case_name: Option) { let (diff_flag, custom_output_path) = get_test_config();