|
| 1 | +--- |
| 2 | +title: "Aptos Transaction Import" |
| 3 | +--- |
| 4 | + |
| 5 | +## Overview: |
| 6 | + |
| 7 | +This section outlines the steps for creating a testing transaction with a Move script. |
| 8 | + |
| 9 | +### Steps: |
| 10 | + |
| 11 | +1. **Create Your Move Project** |
| 12 | + |
| 13 | + Create your Move project and write a module to output the scenario that you would like to test in your processor. You can refer to an example [here](https://github.com/aptos-labs/aptos-core/tree/main/ecosystem/indexer-grpc/indexer-transaction-generator/imported_transactions/move_fixtures). |
| 14 | + |
| 15 | +2. **Set Up Accounts** |
| 16 | + |
| 17 | + 1. These accounts will be used to deploy your module. |
| 18 | + 2. Set up as many accounts as you need. Refer to the guide [here](https://aptos.dev/en/build/cli/setup-cli). |
| 19 | + 3. Update `aptos-core/ecosystem/indexer-grpc/indexer-transaction-generator/imported_transactions/testing_accounts.yaml` with your accounts. |
| 20 | + |
| 21 | + > 💡 **Note:** Do not use real accounts here. Only use test accounts created in the CLI specifically for testing. |
| 22 | +
|
| 23 | +3. **Create a Configuration File** |
| 24 | + |
| 25 | + 1. Create a [configuration file in the `move_fixtures` directory](https://github.com/aptos-labs/aptos-core/blob/main/ecosystem/indexer-grpc/indexer-transaction-generator/imported_transactions/move_fixtures/simple_user_script.yaml). |
| 26 | + 2. This configuration file should include unique transaction names and details for each transaction. Example configuration: |
| 27 | + output_name: the name of the transaction json output |
| 28 | + script_path: the path to the Move script |
| 29 | + sender_address: the address of the account that will send the transaction |
| 30 | + |
| 31 | + ```yaml |
| 32 | + transactions: |
| 33 | + - output_name: simple_user_script1 |
| 34 | + script_path: simple_user_script |
| 35 | + sender_address: <account_address> |
| 36 | + - output_name: simple_user_script2 |
| 37 | + script_path: simple_user_script2 |
| 38 | + sender_address: <account_address> |
| 39 | + ``` |
| 40 | +
|
| 41 | +4. **Generate JSON Files and Rust File** |
| 42 | +
|
| 43 | + Once the Move files and configuration are set up, run the same command used to import transactions: |
| 44 | + - testing-folder is where your Move files are stored. |
| 45 | + - output-foler can be set to any folder where you want to store the generated files. |
| 46 | +
|
| 47 | + ```bash |
| 48 | + cargo run -- --testing-folder ./imported_transactions --output-folder ../indexer-test-transactions/src/ |
| 49 | + ``` |
| 50 | + |
| 51 | + This command will: |
| 52 | + |
| 53 | + 1. Read the configuration in the `move_fixtures` folder. |
| 54 | + 2. Execute the specified Move scripts. |
| 55 | + 3. Output the generated JSON files to the designated folder (`~/aptos-core/ecosystem/indexer-grpc/indexer-transaction-generator/json_transactions`). |
| 56 | + 4. Update `generated_transactions.rs` with the new transaction names specified in step 3. |
| 57 | + |
| 58 | +### How to Use the Testing Transactions |
| 59 | + |
| 60 | +- **Export the Generated File**: |
| 61 | + |
| 62 | + Update the [`mod.rs`](https://github.com/aptos-labs/aptos-indexer-processor-example/blob/main/test-transactions-example/src/json_transactions/mod.rs) file to include the generated Rust file containing the transaction constants. |
| 63 | + |
| 64 | +- **Export the `json_transactions` Folder**: |
| 65 | + |
| 66 | + Ensure the `json_transactions` folder is properly exported in the library file. |
| 67 | + |
| 68 | + [Example](https://github.com/aptos-labs/aptos-indexer-processor-example/blob/main/test-transactions-example/src/lib.rs). |
| 69 | + |
| 70 | +- **Add as a Dependency**: |
| 71 | + |
| 72 | + Include the crate containing the generated transactions as a dependency in the `Cargo.toml` file of your test crate. (Internally, transactions are stored in `aptos-core` and used in the [processor repo](https://github.com/aptos-labs/aptos-indexer-processors/blob/0c92d323b0f560b5f8601a831a36520ad9b72d68/rust/Cargo.toml#L34)). |
| 73 | + |
| 74 | +- **Integrate into Test Cases**: |
| 75 | + |
| 76 | + Use the exported transaction constants directly in your test cases to simulate real transactions and validate processing logic. |
| 77 | + |
| 78 | + [Example usage](https://github.com/aptos-labs/aptos-indexer-processor-example/tree/main/test-transactions-example). |
0 commit comments