Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generating test transactions with move script #775

Open
wants to merge 1 commit into
base: 01-17-importing_test_transactions
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions apps/nextra/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,13 @@ export default withBundleAnalyzer(
"/en/build/indexer/indexer-sdk/documentation/advanced-tutorials/txn-importer",
permanent: true,
},
{
source:
"/indexer/indexer-sdk/documentation/advanced-tutorials/txn-script",
destination:
"/en/build/indexer/indexer-sdk/documentation/advanced-tutorials/txn-script",
permanent: true,
},
{
source: "/indexer/txn-stream/labs-hosted",
destination: "/en/build/indexer/api/labs-hosted",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ export default {
"txn-importer": {
title: "Importing Transactions",
},
"txn-script": {
title: "Generating Transactions with Move Scripts",
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
---
title: "Aptos Transaction generated using Move Script"
---

import { Callout, Steps } from "nextra/components"

## Overview:

This section outlines how to create test transactions with Move scripts.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it'd help to have details on why you need scripted txn's, and when you would use a scripted txn instead of an imported txn


## Prerequisites

1. Clone the [aptos-core](https://github.com/aptos-labs/aptos-core) repository:
- Navigate to the `aptos-core/ecosystem/indexer-grpc/indexer-transaction-generator` directory.

## How to Generate Test Transactions using Move Script
<Steps>
### Set up `move_fixtures` folder
Before proceeding, ensure you have the move_fixtures folder set up in the appropriate location:
1. Location:
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
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.


<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>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why can't you put move_fixtures in the processor repository? what if they want to add the fixtures to version control?

2. Steps to set up the follder:
- if starting fresh, remove all existing files and projects in the `move_fixtures` folder in the aptos-core repo
- Create your own Move projects/scripts in the move_fixtures folder (detailed in the next step)

### Create Your Move Project

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).

### Set Up Test Accounts

1. These accounts will be used to deploy your module.
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
2. Set up as many accounts as you need. These accounts will be used to send the scripted transactions. Refer to [Aptos CLI](https://aptos.dev/en/build/cli/setup-cli) to create accounts.

3. Update `aptos-core/ecosystem/indexer-grpc/indexer-transaction-generator/imported_transactions/testing_accounts.yaml` with your accounts.

<Callout> **Note:** Do not use real accounts here. Only use test accounts created in the CLI specifically for testing. </Callout>

### Create a Configuration File
Each configuration file defines a sequences of transactions for a test scenario.
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.
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. Example configuration:
output_name: the name of the transaction json output
script_path: the path to the Move script
sender_address: the address of the account that will send the transaction

```yaml
transactions:
- output_name: simple_user_script1
script_path: simple_user_script
sender_address: <account_address>
- output_name: simple_user_script2
script_path: simple_user_script2
sender_address: <account_address>
```

### Generate JSON Files and Rust File

Once the Move files and configuration are set up, run the same command used to import transactions:
- testing-folder is where your Move files are stored.
- output-folder can be set to any folder where you want to store the generated files.

```bash
cd ~/aptos-core/ecosystem/indexer-grpc/indexer-transaction-generator
cargo run -- --testing-folder ./imported_transactions --output-folder ../indexer-test-transactions/src/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cargo run -- --testing-folder ./imported_transactions --output-folder ../indexer-test-transactions/src/
cargo run -- --testing-folder ./imported_transactions --output-folder /path/to/processor/repo/

```

This command will:

1. Read the configuration in the `move_fixtures` folder.
2. Execute the specified Move scripts.
3. Output the generated JSON files to the designated folder (`~/aptos-core/ecosystem/indexer-grpc/indexer-transaction-generator/json_transactions`).
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The output path shown in the documentation (~/aptos-core/ecosystem/indexer-grpc/indexer-transaction-generator/json_transactions) differs from the path specified in the command (../indexer-test-transactions/src/). This discrepancy should be resolved to ensure users can follow the instructions correctly. Consider updating either the command or the documentation to show the correct output path.

Spotted by Graphite Reviewer

Is this helpful? React 👍 or 👎 to let us know.

4. Update `generated_transactions.rs` with the new transaction names specified in step 3.

</Steps>

## How to Use Test Transactions

- **Export the Generated File**:

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.

- **Export the `json_transactions` Folder**:

Ensure the `json_transactions` folder is properly exported in the library file.

[Example](https://github.com/aptos-labs/aptos-indexer-processor-example/blob/main/test-transactions-example/src/lib.rs).

- **Add as a Dependency**:

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)).
Comment on lines +90 to +92
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed as per discussion on previous PR


- **Integrate into Test Cases**:

Use the exported transaction constants directly in your test cases to simulate real transactions and validate processing logic.

[Example usage](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]().
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The empty link [Writing Processor Tests]() will be broken when rendered. Please either add the correct URL path to the parentheses or remove the Markdown link formatting if the destination page doesn't exist yet.

Spotted by Graphite Reviewer

Is this helpful? React 👍 or 👎 to let us know.

Loading