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

support test file creation as a part of test txn generation #15688

Open
wants to merge 1 commit into
base: 12-03-allow_specifying_account_address_at_config_level_instead_of_random_assignment
Choose a base branch
from

Conversation

yuunlimm
Copy link
Contributor

@yuunlimm yuunlimm commented Jan 8, 2025

Description

Currently, external Indexer SDK users who want to test transactions must either maintain their own branch of aptos-core to avoid conflicts or copy our script into their test or processor repositories. This workflow can be confusing, so I’ve updated the transaction generation process to include the conversion step (from proto json to a rust file containing const variables) via new CLI arguments.

Existing Process:

  1. Run the transaction generation CLI to produce JSON files (transaction proto JSON).
  2. A build.rs script in the test-transactions crate converts these JSON files into a Rust source file with const variables.
  3. The processor repository updates its reference to the test-transactions crate.

New Process:

  1. Run the transaction generation CLI, using the new CLI options that let external users specify where to generate and store test transactions in their own repositories.
  2. Use these generated transactions in their test repository.

How Has This Been Tested?

locally tested

cargo run -- --testing-folder ./imported_transactions --output-folder /U
sers/yuunlim/aptos-indexer-processors/rust/integration-tests/json_transactions --rust-file /Users/yuunlim/aptos-indexer-processors/rust/integration-tests/src/txns.rs --create-rust-file

Screenshot 2025-01-08 at 1.01.31 PM.png

Screenshot 2025-01-08 at 1.01.27 PM.png

Screenshot 2025-01-08 at 1.01.12 PM.png

Key Areas to Review

Type of Change

  • [X ] New feature
  • Bug fix
  • Breaking change
  • Performance improvement
  • Refactoring
  • Dependency update
  • Documentation update
  • Tests

Which Components or Systems Does This Change Impact?

  • Validator Node
  • Full Node (API, Indexer, etc.)
  • Move/Aptos Virtual Machine
  • Aptos Framework
  • Aptos CLI/SDK
  • Developer Infrastructure
  • Move Compiler
  • [X ] Other (Indexer Testing Framework)

Checklist

  • I have read and followed the CONTRIBUTING doc
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I identified and added all stakeholders and component owners affected by this change as reviewers
  • I tested both happy and unhappy path of the functionality
  • I have made corresponding changes to the documentation

Copy link

trunk-io bot commented Jan 8, 2025

⏱️ 1h 28m total CI duration on this PR
Job Cumulative Duration Recent Runs
rust-move-tests 14m 🟩
rust-move-tests 14m 🟩
rust-move-tests 14m 🟩
rust-move-tests 13m 🟩
rust-move-tests 13m 🟩
rust-cargo-deny 9m 🟩🟩🟩🟩🟩
check-dynamic-deps 6m 🟩🟩🟩🟩🟩
general-lints 2m 🟩🟩🟩🟩🟩
semgrep/ci 2m 🟩🟩🟩🟩🟩
file_change_determinator 55s 🟩🟩🟩🟩🟩
permission-check 14s 🟩🟩🟩🟩🟩
permission-check 14s 🟩🟩🟩🟩🟩
check-branch-prefix 1s 🟩

settingsfeedbackdocs ⋅ learn more about trunk.io

Copy link
Contributor Author

yuunlimm commented Jan 8, 2025

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

Comment on lines +21 to +31
/**
* Adds a directory of JSON files to the transaction code builder.
*
* @param src_dir: The source directory containing the JSON files
* @param dir_name: The name of the directory to be created in the `json_transactions` directory
* @param module_name: The name of the module to be used in the constant names
* @param generate_name_function: Whether to generate a transaction name lookup function
*/
Copy link

Choose a reason for hiding this comment

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

The function documentation parameters don't match the actual function signature. The current parameters src_dir and dir_name should be replaced with json_dir. The parameter descriptions should also be simplified to match the actual functionality - this function processes an existing directory of JSON files rather than creating new directories.

Spotted by Graphite Reviewer

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

@yuunlimm yuunlimm force-pushed the 01-08-support_test_file_creation_as_a_part_of_test_txn_generation branch from d434b0a to e60d566 Compare January 8, 2025 21:04
@yuunlimm yuunlimm marked this pull request as ready for review January 8, 2025 21:04
@yuunlimm yuunlimm requested a review from a team January 8, 2025 21:05
Comment on lines 145 to 164
match fs::write(dest_path, code) {
Ok(_) => println!("Successfully generated the transactions code."),
Err(e) => println!("Failed to generate the transactions code for dest_path:{:?}, {:?}", dest_path, e),
}
Ok(())
Copy link

Choose a reason for hiding this comment

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

The error from fs::write is being silently converted to success. To properly handle failures, replace the match with:

fs::write(dest_path, code).context("Failed to write transactions code")?;

This ensures errors propagate up the call stack while preserving the error context.

Spotted by Graphite Reviewer

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

@rtso
Copy link
Contributor

rtso commented Jan 9, 2025

For the aptos-indexer-processor test transactions, should we keep it within the aptos-core repo or move it to aptos-indexer-processor repo? I think it makes sense to keep the test transaction json files and the generated Rust file in the same place, and iirc, the json files were kept in aptos-core for the diff checks.

@larry-aptos
Copy link
Contributor

The overall approach makes sense: we decouple the json and the code. Only one question regarding to the incompatibility: If jsons are on an older version(say we have 5 jsons) and the code is on a newer version(say we import 6 txns), is it possible to notify/show the users to upgrade to resolve?

it looks like current behavior is compilation error..

Copy link
Contributor

Choose a reason for hiding this comment

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

Should this file actually belong inside of indexer-transaction-generator since it's part of transaction generation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the reason why I left it here is that the I thought we wanted to keep the json files in the aptos-core for the internal usage. so the process of adding new txn for processor testing remains the same, where we would have to update the cargo.toml in the processor repo with the latest commit hash for the internal use. And, we don't have to pass in the new CLI args create_rust_file and rust_file then it won't try to create a generate_transaction.rs in the processor repo

pub rust_file: Option<PathBuf>,

#[clap(short, long)]
pub create_rust_file: bool,
Copy link
Contributor

Choose a reason for hiding this comment

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

When is this flag going to be false? I think we'd always want to update the Rust file if there are new or changed transactions.


/// Path to the rust file to generate the transactions code.
#[clap(long)]
pub rust_file: Option<PathBuf>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we reuse output_folder as the path to store the Rust file?

@yuunlimm
Copy link
Contributor Author

yuunlimm commented Jan 9, 2025

The overall approach makes sense: we decouple the json and the code. Only one question regarding to the incompatibility: If jsons are on an older version(say we have 5 jsons) and the code is on a newer version(say we import 6 txns), is it possible to notify/show the users to upgrade to resolve?

it looks like current behavior is compilation error..

I don’t think compatibility is an issue in this scenario, because we’re assuming each user relies on their own dedicated set of test transactions.

but maybe we can discuss whether we should provide a fixed set of test transactions for them and store the jsons in the processor repo with the tests @rtso I agree that it makes sense to have the json files and generated rust file in the same place for debuggability, etc.

Comment on lines 31 to 35
#[clap(long)]
pub rust_file: Option<PathBuf>,

#[clap(short, long)]
pub create_rust_file: bool,
Copy link

Choose a reason for hiding this comment

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

Add default values to the new fields to maintain backward compatibility with existing tests: #[clap(long, default_value = "false")] for create_rust_file and keep rust_file as Option

Spotted by Graphite Reviewer (based on CI logs)

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

Comment on lines +15 to 17
[build-dependencies]
aptos-indexer-transaction-generator = { workspace = true }
aptos-protos ={ workspace = true }
Copy link

Choose a reason for hiding this comment

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

Dependencies aptos-protos and serde_json need to be moved back to [dependencies] section while keeping them in [build-dependencies] since they are needed both at build time and runtime. The current configuration causes compilation errors because these dependencies are not available at runtime.

Spotted by Graphite Reviewer (based on CI logs)

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

@yuunlimm yuunlimm force-pushed the 12-03-allow_specifying_account_address_at_config_level_instead_of_random_assignment branch from 9f51332 to 5cad83d Compare January 9, 2025 19:29
@yuunlimm yuunlimm force-pushed the 01-08-support_test_file_creation_as_a_part_of_test_txn_generation branch from e60d566 to cf9f9c7 Compare January 9, 2025 19:29
@yuunlimm yuunlimm force-pushed the 12-03-allow_specifying_account_address_at_config_level_instead_of_random_assignment branch from 5cad83d to 4ff0a0c Compare January 9, 2025 21:52
@yuunlimm yuunlimm force-pushed the 01-08-support_test_file_creation_as_a_part_of_test_txn_generation branch from cf9f9c7 to 3822921 Compare January 9, 2025 21:52
@yuunlimm yuunlimm force-pushed the 01-08-support_test_file_creation_as_a_part_of_test_txn_generation branch from 3822921 to 3b82607 Compare January 10, 2025 04:32
@@ -2,7 +2,7 @@ testnet:
# Transaction Stream endpoint addresss.
transaction_stream_endpoint: https://grpc.testnet.aptoslabs.com:443
# (Optional) The key to use with developers.aptoslabs.com
api_key: TESTNET_API_KEY
api_key: aptoslabs_Yq2BZM4pCY9_GU1vCq1XwB2NdU2Z8AENXnvKdwSiqF3YQ
Copy link

Choose a reason for hiding this comment

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

Please remove the API key from source control to prevent security risks. Consider replacing it with a placeholder like TESTNET_API_KEY and loading the actual value from environment variables at runtime. This follows security best practices for handling sensitive credentials.

Spotted by Graphite Reviewer

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants