Skip to content

Commit 9d90f22

Browse files
committed
generating test transactions with move script
1 parent 7a7095e commit 9d90f22

File tree

4 files changed

+116
-1
lines changed

4 files changed

+116
-1
lines changed

apps/nextra/next.config.mjs

+7
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,13 @@ export default withBundleAnalyzer(
466466
"/en/build/indexer/indexer-sdk/documentation/advanced-tutorials/txn-importer",
467467
permanent: true,
468468
},
469+
{
470+
source:
471+
"/indexer/indexer-sdk/documentation/advanced-tutorials/txn-script",
472+
destination:
473+
"/en/build/indexer/indexer-sdk/documentation/advanced-tutorials/txn-script",
474+
permanent: true,
475+
},
469476
{
470477
source: "/indexer/txn-stream/labs-hosted",
471478
destination: "/en/build/indexer/api/labs-hosted",

apps/nextra/pages/en/build/indexer/indexer-sdk/advanced-tutorials/_meta.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@ export default {
55
"txn-importer": {
66
title: "Importing Transactions",
77
},
8+
"txn-script": {
9+
title: "Generating Transactions with Move Scripts",
10+
},
811
};

apps/nextra/pages/en/build/indexer/indexer-sdk/advanced-tutorials/txn-importer.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: "Aptos Transaction Import"
2+
title: "Importing Transactions"
33
---
44

55
## Overview
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
---
2+
title: "Generating Transactions with Move Scripts"
3+
---
4+
5+
import { Callout, Steps } from "nextra/components"
6+
7+
## Overview:
8+
9+
This section outlines how to create test transactions with Move scripts.
10+
11+
## Prerequisites
12+
13+
1. Clone the [aptos-core](https://github.com/aptos-labs/aptos-core) repository:
14+
- Navigate to the `aptos-core/ecosystem/indexer-grpc/indexer-transaction-generator` directory.
15+
16+
## How to Generate Test Transactions using Move Script
17+
<Steps>
18+
### Set up `move_fixtures` folder
19+
Before proceeding, ensure you have the `move_fixtures` folder set up in the appropriate location:
20+
1. Location:
21+
The `move_fixtures` folder should be created in the `aptos-core/ecosystem/indexer-grpc/indexer-transaction-generator/imported_transactions` directory. This is the folder where Move scripts and their configurations for test transactions will be stored.
22+
23+
<Callout> **Note:** Do not create the `move_fixtures` folder in your processor repository. All Move-related files should reside in the `aptos-core` repository under the specified directory. </Callout>
24+
2. Steps to set up the folder:
25+
- if starting fresh, remove all existing files and projects in the `move_fixtures` folder in the aptos-core repo
26+
- Create your own Move projects/scripts in the move_fixtures folder (detailed in the next step)
27+
28+
### Create Your Move Project and Write your Move Script
29+
30+
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).
31+
32+
### Set Up Test Accounts
33+
34+
1. These accounts will be used to deploy your module.
35+
2. Set up as many accounts as you need. These accounts will be used to send the scripted transactions. Refer to the guide [here](https://aptos.dev/en/build/cli/setup-cli) to create accounts.
36+
3. Update [`aptos-core/ecosystem/indexer-grpc/indexer-transaction-generator/imported_transactions/testing_accounts.yaml`](https://github.com/aptos-labs/aptos-core/blob/main/ecosystem/indexer-grpc/indexer-transaction-generator/imported_transactions/testing_accounts.yaml) with your accounts.
37+
38+
<Callout> **Note:** Do not use real accounts here. Only use **test accounts** created in the CLI specifically for testing. Always select **devnet** when setting up a test account, as it will be required later in the script to configure the account profile and fund it using the faucet. </Callout>
39+
40+
### Create a Configuration File
41+
Each configuration file defines a sequences of transactions for a test scenario.
42+
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). Name the configuration file according to the test scenario it corresponds to.
43+
2. This configuration file should contain unique transaction names and details for each transaction. The transactions should be listed in the order they are to be executed.
44+
The configuration file should be structured like this:
45+
- output_name: This field specifies the name of the output file where the results of the transaction will be saved.
46+
- script_path: This field holds the path to the Move script file that will be executed as part of the transaction.
47+
- sender_address: : This field contains the address of the account that will send the transaction.
48+
49+
```yaml
50+
transactions:
51+
- output_name: simple_user_script1
52+
script_path: simple_user_script
53+
sender_address: <account_address>
54+
- output_name: simple_user_script2
55+
script_path: simple_user_script2
56+
sender_address: <account_address>
57+
```
58+
59+
### Generate JSON Files and Rust File
60+
61+
Once the Move files and configuration are set up, run the same command used to import transactions but with extra flag `mode`:
62+
- testing-folder is where your Move files are stored.
63+
- output-folder can be set to any folder where you want to store the generated files.
64+
- The `--mode=script` flag specifies that the transaction generator should operate in script mode, meaning it will execute Move scripts and generate corresponding transaction data. By default, the mode is set to import, which fetches transactions from the network.
65+
66+
```bash
67+
cd ~/aptos-core/ecosystem/indexer-grpc/indexer-transaction-generator
68+
cargo run -- --testing-folder ./imported_transactions --output-folder ../indexer-test-transactions/src/ --script
69+
```
70+
71+
This command will:
72+
73+
1. Read the configuration in the `move_fixtures` folder.
74+
2. Execute the specified Move scripts.
75+
3. Output the generated JSON files to the designated folder (`~/aptos-core/ecosystem/indexer-grpc/indexer-transaction-generator/json_transactions`).
76+
4. Overwrite `generated_transactions.rs` with the new transaction data based on the generated JSON files. This file contains the transaction constants that can be used in tests.
77+
78+
### Verification
79+
80+
Verify that the json_transactions folder in the target directory contains the generated JSON files with the specified names from the configuration file, and ensure that generated_transactions.rs has been updated accordingly.
81+
82+
</Steps>
83+
84+
## How to Use Test Transactions
85+
86+
### Export the Generated File
87+
88+
Update the `mod.rs` file to include the generated Rust file containing the transaction constants. If `mod.rs` doesn’t exist, create one in the target folder:
89+
90+
[Reference mod.rs](https://github.com/aptos-labs/aptos-indexer-processor-example/blob/main/test-transactions-example/src/json_transactions/mod.rs).
91+
92+
### Export the `json_transactions` Folder
93+
94+
Since the `generated_transactions.rs` relies on the `json_transactions` Ensure the `json_transactions` folder is properly exported in the library file for your tests have direct access to the transaction data.
95+
96+
[Reference lib.rs](https://github.com/aptos-labs/aptos-indexer-processor-example/blob/main/test-transactions-example/src/lib.rs).
97+
98+
### Integrate into Test Cases
99+
100+
Use the exported transaction constants directly in your test cases to simulate real transactions and validate processing logic.
101+
102+
[Example Crate](https://github.com/aptos-labs/aptos-indexer-processor-example/tree/main/test-transactions-example).
103+
104+
## Next Steps
105+
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.

0 commit comments

Comments
 (0)