Skip to content

Commit ee03a7e

Browse files
committed
generating test transactions with move script
1 parent d1e31ef commit ee03a7e

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed

apps/nextra/next.config.mjs

+7
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,13 @@ export default withBundleAnalyzer(
460460
"/en/build/indexer/indexer-sdk/documentation/advanced-tutorials/txn-importer",
461461
permanent: true,
462462
},
463+
{
464+
source:
465+
"/indexer/indexer-sdk/documentation/advanced-tutorials/txn-script",
466+
destination:
467+
"/en/build/indexer/indexer-sdk/documentation/advanced-tutorials/txn-script",
468+
permanent: true,
469+
},
463470
{
464471
source: "/indexer/txn-stream/labs-hosted",
465472
destination: "/en/build/indexer/api/labs-hosted",

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

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