From 18f5a0716d2314f89f4879ed258e609fa3003679 Mon Sep 17 00:00:00 2001 From: yuunlimm Date: Thu, 23 Jan 2025 10:12:11 -0800 Subject: [PATCH] update --- .../advanced-tutorials/test-transactions.mdx | 31 +++++++++++++++ .../advanced-tutorials/txn-importer.mdx | 39 ++++++++++++++----- 2 files changed, 61 insertions(+), 9 deletions(-) create mode 100644 apps/nextra/pages/en/build/indexer/indexer-sdk/documentation/advanced-tutorials/test-transactions.mdx diff --git a/apps/nextra/pages/en/build/indexer/indexer-sdk/documentation/advanced-tutorials/test-transactions.mdx b/apps/nextra/pages/en/build/indexer/indexer-sdk/documentation/advanced-tutorials/test-transactions.mdx new file mode 100644 index 000000000..a91441a7c --- /dev/null +++ b/apps/nextra/pages/en/build/indexer/indexer-sdk/documentation/advanced-tutorials/test-transactions.mdx @@ -0,0 +1,31 @@ +# Aptos Indexer Testing Framework Overview + +The Aptos Indexer Testing Framework provides two methods to generate testing transactions: **aptos-indexer-transaction-generator** and **Move Scripts**. Both approaches are suited for specific scenarios based on your development and testing requirements, enabling you to test how your system handles various transaction types. + + +## When to Use **aptos-indexer-transaction-generator** +## 1. Fetching Historical Transactions +- Retrieve specific historical transactions from the Aptos blockchain (Testnet or Mainnet) for testing or analysis. +- Ideal for creating mocked transaction inputs for processor tests or regression checks. + +### 2. Simulating Real-World Scenarios +- Validate processor logic or database integrity by replaying transactions from live networks. +- Simulate conditions that mirror real-world environments to ensure robustness. + + +## When to Use **Move Script** +### 1. Deploying Custom Logic +- Write, deploy, and execute custom logic using Move to test your new AIPs (Aptos Improvement Proposals). +- Ideal for creating smart contracts, defining new modules, or implementing specific on-chain functionalities. + +### 2. Prototyping New Features +- Experiment with new decentralized application (dApp) ideas or test custom on-chain workflows. +- Perform operations like: + - Account creation + - Token minting + - Custom transactions +- Define business rules and execute state changes directly on the Aptos blockchain. + +## Summary + +Both **aptos-indexer-transaction-generator** and **Move Scripts** are essential tools in the Aptos Indexer Testing Framework. Use the **aptos-indexer-transaction-generator** for replaying and analyzing real-world transactions, while **Move Scripts** are best for testing custom logic and prototyping features. Choose the method that aligns with your testing goals to ensure a comprehensive validation process. diff --git a/apps/nextra/pages/en/build/indexer/indexer-sdk/documentation/advanced-tutorials/txn-importer.mdx b/apps/nextra/pages/en/build/indexer/indexer-sdk/documentation/advanced-tutorials/txn-importer.mdx index c5311f942..afdc39f42 100644 --- a/apps/nextra/pages/en/build/indexer/indexer-sdk/documentation/advanced-tutorials/txn-importer.mdx +++ b/apps/nextra/pages/en/build/indexer/indexer-sdk/documentation/advanced-tutorials/txn-importer.mdx @@ -4,16 +4,16 @@ title: "Aptos Transaction Import" ## Overview -This will guide how to generate test transactions using the `importer` tool for Aptos networks (Devnet/Testnet/Mainnet). These transactions are then used in automated tests, local development, or regression checks. +This will guide how to generate test transactions using the `aptos-indexer-transactions-generator` tool for Aptos networks (Devnet/Testnet/Mainnet). These transactions are then used in automated tests, local development, or regression checks. ## General Flow of Transaction Importing -First, identify the transaction versions you need to fetch from the Aptos network. This tool interacts with the Aptos gRPC endpoint to retrieve transaction data in JSON format. The transactions are then consolidated into a Rust file, where each transaction is represented as a constant variable. These constants can be seamlessly used as mocked inputs in a testing framework. During testing, the processor fetches the specified transactions, processes them, and writes the results to a database. You can then verify the outcomes by loading the written data and validating it against the expected schema. +First, identify the transaction versions you need to fetch from the Aptos network. This tool interacts with the [Transaction Stream](https://aptos.dev/en/build/indexer/txn-stream) to retrieve transaction data in JSON format. The transactions are then consolidated into a Rust file, where each transaction is represented as a constant variable. These constants can be seamlessly used as mocked inputs in a testing framework. During testing, the processor fetches the specified transactions, processes them, and writes the results to a database. You can then verify the outcomes by loading the written data and validating it against the expected schema. ## Prerequisites 1. Access to a Network (Testnet/Mainnet): - - A valid API key for the gRPC endpoint. ([Refer here](https://developers.aptoslabs.com/docs/api-access)) + - A valid API key for the gRPC endpoint. ([Refer here](https://aptos.dev/en/build/indexer/txn-stream/aptos-hosted-txn-stream)) 2. Clone the [aptos-core](https://github.com/aptos-labs/aptos-core) repository: - Navigate to the `aptos-core/ecosystem/indexer-grpc/indexer-transaction-generator` directory. @@ -52,19 +52,39 @@ mainnet: ### 2. Run the Command to Import Transactions +Navigate to the `indexer-transaction-generator` directory: + +```bash +cd aptos-core/ecosystem/indexer-grpc/indexer-transaction-generator +``` + To import the specified transaction versions, execute the following command: ```bash -cargo run -- --testing-folder ./imported_transactions --output-folder ../indexer-test-transactions/src/ +cargo run -- --testing-folder ./imported_transactions --output-folder /path/to/your/processor-repo/src ``` This command will: -1. Read the configuration from the `imported_transactions.yaml` file. -2. Fetch the specified transaction versions from the selected network (Testnet or Mainnet). -3. Store the resulting JSON files in the specified output folder (`../indexer-test-transactions/src/json_transactions`). +1. Read the configuration from the `imported_transactions.yaml` file located in the folder specified by the --testing-folder flag. +2. Fetch the specified transaction versions from the selected network (Devnet, Testnet or Mainnet). +3. Store the resulting JSON files in the specified output folder (/path/to/your/processor-repo/src/json_transactions). 4. Generate a Rust file (`generated_transactions.rs`) that converts the generated transaction JSON files into constant variables for use in tests. +Note: Replace /path/to/your/processor-repo with the path to your processor repository or preferred storage location. + +**Explanation of Command Flags** +1. `--testing-folder` +What is the --testing-folder flag? +The --testing-folder flag specifies the directory containing the imported_transactions.yaml configuration file. The tool uses this folder to read versions you wish to import. + - Ensure the folder path matches the location of your imported_transactions.yaml file. + - By default, this guide assumes the configuration is stored in ./imported_transactions. Adjust the flag value if you place the file elsewhere. + +2. `--output-folder` +Specifies the destination directory where the generated transaction JSON files and Rust constants will be saved. + - Replace /path/to/your/processor-repo with your processor repository src directory or desired storage location. + - Ensure this folder is part of your version control setup if these files need to be shared. + ## How to Use the Testing Transactions ### Export the Generated File @@ -87,6 +107,7 @@ Include the crate containing the generated transactions as a dependency in the ` Use the exported transaction constants directly in your test cases to simulate real transactions and validate processing logic. -Example usage: - [Example Crate](https://github.com/aptos-labs/aptos-indexer-processor-example/tree/main/test-transactions-example). + +## Next Steps +Once the transaction constants are integrated, you can use them in processor tests to validate functionality. For detailed instructions on writing processor tests, refer to [Writing Processor Tests](TBD). \ No newline at end of file