Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit 7243c40

Browse files
committed
importing test transactions
1 parent e69ef98 commit 7243c40

File tree

5 files changed

+119
-0
lines changed

5 files changed

+119
-0
lines changed

apps/nextra/next.config.mjs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,19 @@ export default withBundleAnalyzer(
447447
"/en/build/indexer/indexer-sdk/documentation/run-processor",
448448
permanent: true,
449449
},
450+
{
451+
source: "/indexer/indexer-sdk/documentation/advanced-tutorials",
452+
destination:
453+
"/en/build/indexer/indexer-sdk/documentation/advanced-tutorials",
454+
permanent: true,
455+
},
456+
{
457+
source:
458+
"/indexer/indexer-sdk/documentation/advanced-tutorials/txn-importer",
459+
destination:
460+
"/en/build/indexer/indexer-sdk/documentation/advanced-tutorials/txn-importer",
461+
permanent: true,
462+
},
450463
{
451464
source: "/indexer/txn-stream/labs-hosted",
452465
destination: "/en/build/indexer/api/labs-hosted",

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,7 @@ export default {
1818
"version-tracking": {
1919
title: "Version Tracking",
2020
},
21+
"advanced-tutorials": {
22+
title: "Advanced Tutorials",
23+
},
2124
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: "Advanced Tutorials"
3+
---
4+
5+
# Documentation
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default {
2+
// setup: { title: "Initial Setup" },
3+
"txn-importer": {
4+
title: "Importing Transactions",
5+
},
6+
};
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
---
2+
title: "Aptos Transaction Import"
3+
---
4+
5+
## Overview
6+
7+
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.
8+
9+
## General Flow of Transaction Importing
10+
11+
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.
12+
13+
## Prerequisites
14+
15+
1. Access to a Network (Testnet/Mainnet):
16+
- A valid API key for the gRPC endpoint. ([Refer here](https://developers.aptoslabs.com/docs/api-access))
17+
2. Clone the [aptos-core](https://github.com/aptos-labs/aptos-core) repository:
18+
- Navigate to the `aptos-core/ecosystem/indexer-grpc/indexer-transaction-generator` directory.
19+
20+
## Steps
21+
22+
### 1. Specify Versions to Import
23+
24+
Locate and open the file:
25+
26+
```bash
27+
ecosystem/indexer-grpc/indexer-transaction-generator/imported_transactions/imported_transactions.yaml
28+
```
29+
30+
In this file, specify the versions to import from Devnet|Testnet|Mainnet by configuring the appropriate endpoint, API key, and mapping version numbers to descriptive output names. An example configuration is shown below:
31+
32+
```yaml
33+
testnet:
34+
transaction_stream_endpoint: https://grpc.testnet.aptoslabs.com:443
35+
api_key: TESTNET_API_KEY # <--- Replace this with your API key to generate files locally
36+
versions_to_import:
37+
1: 1_genesis
38+
2: 2_new_block_event
39+
3: 3_empty_txn
40+
278556781: 278556781_v1_coin_register_fa_metadata
41+
1255836496: 1255836496_v2_fa_metadata_
42+
5979639459: 5979639459_coin_register
43+
5992795934: 5992795934_fa_activities
44+
5523474016: 5523474016_validator_txn
45+
46+
mainnet:
47+
transaction_stream_endpoint: https://grpc.mainnet.aptoslabs.com:443
48+
api_key: MAINNET_API_KEY
49+
versions_to_import:
50+
308783012: 308783012_fa_transfer
51+
```
52+
53+
### 2. Run the Command to Import Transactions
54+
55+
To import the specified transaction versions, execute the following command:
56+
57+
```bash
58+
cargo run -- --testing-folder ./imported_transactions --output-folder ../indexer-test-transactions/src/
59+
```
60+
61+
This command will:
62+
63+
1. Read the configuration from the `imported_transactions.yaml` file.
64+
2. Fetch the specified transaction versions from the selected network (Testnet or Mainnet).
65+
3. Store the resulting JSON files in the specified output folder (`../indexer-test-transactions/src/json_transactions`).
66+
4. Generate a Rust file (`generated_transactions.rs`) that converts the generated transaction JSON files into constant variables for use in tests.
67+
68+
## How to Use the Testing Transactions
69+
70+
### Export the Generated File
71+
72+
Update the `mod.rs` file to include the generated Rust file containing the transaction constants.
73+
74+
[Reference mod.rs](https://github.com/aptos-labs/aptos-indexer-processor-example/blob/main/test-transactions-example/src/json_transactions/mod.rs).
75+
76+
### Export the `json_transactions` Folder
77+
78+
Ensure the `json_transactions` folder is properly exported in the library file.
79+
80+
[Reference lib.rs](https://github.com/aptos-labs/aptos-indexer-processor-example/blob/main/test-transactions-example/src/lib.rs).
81+
82+
### Add as a Dependency
83+
84+
Include the crate containing the generated transactions as a dependency in the `Cargo.toml` file of your test crate. (Internally, we store transactions in `aptos-core` and use them in the [processor repo](https://github.com/aptos-labs/aptos-indexer-processors/blob/0c92d323b0f560b5f8601a831a36520ad9b72d68/rust/Cargo.toml#L34)).
85+
86+
### Integrate into Test Cases
87+
88+
Use the exported transaction constants directly in your test cases to simulate real transactions and validate processing logic.
89+
90+
Example usage:
91+
92+
[Example Crate](https://github.com/aptos-labs/aptos-indexer-processor-example/tree/main/test-transactions-example).

0 commit comments

Comments
 (0)