Skip to content
🎉 Welcome! Translations are currently experimental. | 翻訳は現在実験的です。 | 翻译目前处于实验阶段。
Click here to submit feedback! | ここをクリックしてフィードバックを送信してください! | 点击这里提交反馈!
BuildIndexerIndexer SDKDocumentationAdvanced TutorialsGenerating Transactions with Move Scripts

Overview:

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

Prerequisites

  1. Clone the aptos-core repository:
    • Navigate to the aptos-core/ecosystem/indexer-grpc/indexer-transaction-generator directory.

How to Generate Test Transactions using Move Script

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.

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

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 to create accounts.
  3. Update aptos-core/ecosystem/indexer-grpc/indexer-transaction-generator/imported_transactions/testing_accounts.yaml with your accounts.
💡
Note: Do not use real accounts here. Only use test accounts created in the CLI specifically for testing.

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

    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.
    cd ~/aptos-core/ecosystem/indexer-grpc/indexer-transaction-generator
    cargo run -- --testing-folder ./imported_transactions --output-folder ../indexer-test-transactions/src/

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).
  4. Update generated_transactions.rs with the new transaction names specified in step 3.

How to Use Test Transactions

  • Export the Generated File:

    Update the 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.

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

  • Integrate into Test Cases:

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

    Example usage.

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.