Skip to content

Commit

Permalink
[EI-519][indexer][testing] Implement scripted transaction generation (#…
Browse files Browse the repository at this point in the history
…14569)

* script transaction

* modify the output path by append the network name

---------

Co-authored-by: yuunlimm <dla0267@gmail.com>
  • Loading branch information
larry-aptos and yuunlimm authored Sep 30, 2024
1 parent 1036592 commit b163f03
Show file tree
Hide file tree
Showing 27 changed files with 924 additions and 107 deletions.
5 changes: 5 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions crates/aptos/src/common/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1501,12 +1501,12 @@ pub struct ChangeSummary {
pub struct FaucetOptions {
/// URL for the faucet endpoint e.g. `https://faucet.devnet.aptoslabs.com`
#[clap(long)]
pub faucet_url: Option<reqwest::Url>,
faucet_url: Option<reqwest::Url>,

/// Auth token to bypass faucet ratelimits. You can also set this as an environment
/// variable with FAUCET_AUTH_TOKEN.
#[clap(long, env)]
pub faucet_auth_token: Option<String>,
faucet_auth_token: Option<String>,
}

impl FaucetOptions {
Expand Down Expand Up @@ -1623,7 +1623,7 @@ pub struct TransactionOptions {
#[clap(flatten)]
pub(crate) gas_options: GasOptions,
#[clap(flatten)]
pub(crate) prompt_options: PromptOptions,
pub prompt_options: PromptOptions,

/// If this option is set, simulate the transaction locally.
#[clap(long)]
Expand Down Expand Up @@ -2037,7 +2037,7 @@ pub struct MultisigAccountWithSequenceNumber {
pub(crate) sequence_number: u64,
}

#[derive(Debug, Parser)]
#[derive(Debug, Default, Parser)]
pub struct TypeArgVec {
/// TypeTag arguments separated by spaces.
///
Expand Down Expand Up @@ -2076,7 +2076,7 @@ impl TryInto<Vec<TypeTag>> for TypeArgVec {
}
}

#[derive(Clone, Debug, Parser)]
#[derive(Clone, Debug, Default, Parser)]
pub struct ArgWithTypeVec {
/// Arguments combined with their type separated by spaces.
///
Expand Down Expand Up @@ -2242,7 +2242,7 @@ impl TryInto<ViewRequest> for EntryFunctionArguments {
}

/// Common options for constructing a script payload
#[derive(Debug, Parser)]
#[derive(Debug, Default, Parser)]
pub struct ScriptFunctionArguments {
#[clap(flatten)]
pub(crate) type_arg_vec: TypeArgVec,
Expand Down
4 changes: 2 additions & 2 deletions crates/aptos/src/governance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -905,10 +905,10 @@ pub struct CompileScriptFunction {
pub compiled_script_path: Option<PathBuf>,

#[clap(flatten)]
pub(crate) framework_package_args: FrameworkPackageArgs,
pub framework_package_args: FrameworkPackageArgs,

#[clap(long, default_value_if("move_2", "true", "7"))]
pub(crate) bytecode_version: Option<u32>,
pub bytecode_version: Option<u32>,

#[clap(long, value_parser = clap::value_parser!(CompilerVersion),
default_value_if("move_2", "true", "2.0"))]
Expand Down
16 changes: 8 additions & 8 deletions crates/aptos/src/move_tool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl MoveTool {
}
}

#[derive(Parser, Default)]
#[derive(Default, Parser)]
pub struct FrameworkPackageArgs {
/// Git revision or branch for the Aptos framework
///
Expand Down Expand Up @@ -379,12 +379,12 @@ pub struct CompilePackage {
/// If set, package metadata should be generated and stored in the package's build directory.
/// This metadata can be used to construct a transaction to publish a package.
#[clap(long)]
pub(crate) save_metadata: bool,
pub save_metadata: bool,

#[clap(flatten)]
pub(crate) included_artifacts_args: IncludedArtifactsArgs,
pub included_artifacts_args: IncludedArtifactsArgs,
#[clap(flatten)]
pub(crate) move_options: MovePackageDir,
pub move_options: MovePackageDir,
}

#[async_trait]
Expand Down Expand Up @@ -726,7 +726,7 @@ pub struct IncludedArtifactsArgs {
/// is the size of bytecode alone; `sparse` is roughly 2 times as much; and `all` 3-4
/// as much.
#[clap(long, default_value_t = IncludedArtifacts::Sparse)]
pub(crate) included_artifacts: IncludedArtifacts,
pub included_artifacts: IncludedArtifacts,
}

/// Publishes the modules in a Move package to the Aptos blockchain
Expand Down Expand Up @@ -2056,11 +2056,11 @@ impl CliCommand<Vec<serde_json::Value>> for ViewFunction {
#[derive(Parser)]
pub struct RunScript {
#[clap(flatten)]
pub(crate) txn_options: TransactionOptions,
pub txn_options: TransactionOptions,
#[clap(flatten)]
pub(crate) compile_proposal_args: CompileScriptFunction,
pub compile_proposal_args: CompileScriptFunction,
#[clap(flatten)]
pub(crate) script_function_args: ScriptFunctionArguments,
pub script_function_args: ScriptFunctionArguments,
}

#[async_trait]
Expand Down
4 changes: 2 additions & 2 deletions crates/aptos/src/node/local_testnet/faucet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ pub struct FaucetArgs {

#[derive(Clone, Debug)]
pub struct FaucetManager {
config: RunConfig,
prerequisite_health_checkers: HashSet<HealthChecker>,
pub config: RunConfig,
pub prerequisite_health_checkers: HashSet<HealthChecker>,
}

impl FaucetManager {
Expand Down
2 changes: 1 addition & 1 deletion crates/aptos/src/node/local_testnet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

mod docker;
mod health_checker;
mod indexer_api;
mod logging;
mod postgres;
Expand All @@ -12,6 +11,7 @@ mod utils;

// This is to allow external crates to use the localnode.
pub mod faucet;
pub mod health_checker;
pub mod node;
pub mod traits;

Expand Down
10 changes: 5 additions & 5 deletions ecosystem/indexer-grpc/indexer-transaction-generator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ rust-version = { workspace = true }
[dependencies]
anyhow = { workspace = true }
# used for localnode.
# aptos = { workspace = true }
# aptos-config = { workspace = true }
aptos = { workspace = true }
aptos-config = { workspace = true }
aptos-faucet-core = { workspace = true }
aptos-indexer-grpc-utils = { workspace = true }
aptos-protos ={ workspace = true }
clap = { workspace = true }
futures = { workspace = true }
# rand = { workspace = true }
# regex = { workspace = true }
rand = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
serde_yaml = { workspace = true }
tokio = { workspace = true }
# toml = { workspace = true }
toml = { workspace = true }
tonic = { workspace = true }
url = { workspace = true }

Expand Down
76 changes: 62 additions & 14 deletions ecosystem/indexer-grpc/indexer-transaction-generator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,66 @@ This tool is to generate transactions for testing purpose.

## Usage

`cargo run -- --config example.yaml --output-folder /your_path_to_store_transactions/`

### Config

```YAML
import_config:
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: YOUR_KEY_HERE
# A map from versions to dump and their output names.
versions_to_import:
123: testnet_v1.json
Under root folder, i.e., `aptos-core`, run

```bash
cargo run -p aptos-indexer-transaction-generator -- \
--testing-folder ecosystem/indexer-grpc/indexer-transaction-generator/example_tests \
--output-folder ecosystem/indexer-grpc/indexer-transaction-generator/example_tests
```

**You can also use absolute path, run(using binary as an example)**

```bash
./aptos-indexer-transaction-generator \
--testing-folder /your/aptos-core/ecosystem/indexer-grpc/indexer-transaction-generator/example_tests \
--output-folder /tmp/ttt
```

### Config overview

* Your testing folder should contain:
* One file called `testing_accounts.yaml`, which contains testing accounts used.
```yaml
accounts:
- private_key: "0x99978d48e7b2d50d0a7a3273db0929447ae59635e71118fa256af654c0ce56c9"
public_key: "0x39b4acc85e026dc056464a5ea00b98f858260eaad2b74dd30b86ae0d4d94ddf5"
account: a531b7fdd7917f73ca216d89a8d9ce0cf7e7cfb9086ca6f6cbf9521532748d16
- ...
```
* One file called `imported_transactions.yaml`, which is used for importing transactions.

```yaml
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: YOUR_KEY_HERE
# A map from versions to dump and their output names.
versions_to_import:
123: testnet_v1.json
mainnet:
...
```
* One folder called `move_fixtures`, which contains move scripts and configs.
* An example script transaction config looks like:
```yaml
transactions:
- output_name: simple_user_script1
script_path: simple_user_script
sender_address: __ACCOUNT_A__
- output_name: simple_user_script2
script_path: simple_user_script2
sender_address: __ACCOUNT_A__
```


You can check the example [here](example_tests).


### Account Management
Each sender_address specified in script transaction config is a place holder string;
the actual account address will be allocated by account manager.

TODO: account manager handles address as script argument.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This folder demonstrates the testing folder structure.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Empty configs to import.
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This folder hosts all the example move scripts.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
transactions:
- output_name: simple_user_script1
script_path: simple_user_script
sender_address: __ACCOUNT_A__
- output_name: simple_user_script2
script_path: simple_user_script2
sender_address: __ACCOUNT_A__

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "test_case"
version = "1.0.0"
authors = []

[addresses]

[dev-addresses]

[dependencies.AptosFramework]
git = "https://github.com/aptos-labs/aptos-core.git"
rev = "mainnet"
subdir = "aptos-move/framework/aptos-framework"

[dev-dependencies]
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
script {
fun main(src: &signer) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
transactions:
- output_name: simple_user_script3
script_path: simple_user_script
sender_address: __ACCOUNT_A__
- output_name: simple_user_script4
script_path: simple_user_script2
sender_address: __ACCOUNT_B__

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "test_case"
version = "1.0.0"
authors = []

[addresses]

[dev-addresses]

[dependencies.AptosFramework]
git = "https://github.com/aptos-labs/aptos-core.git"
rev = "mainnet"
subdir = "aptos-move/framework/aptos-framework"

[dev-dependencies]
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
script {
fun main(src: &signer) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This file serves the accounts to use during account generation.
# These are generated in localnet and safe to share.
accounts:
- private_key: "0x99978d48e7b2d50d0a7a3273db0929447ae59635e71118fa256af654c0ce56c9"
public_key: "0x39b4acc85e026dc056464a5ea00b98f858260eaad2b74dd30b86ae0d4d94ddf5"
account: a531b7fdd7917f73ca216d89a8d9ce0cf7e7cfb9086ca6f6cbf9521532748d16
- private_key: "0xe77498ac20ca67e8f642a6521077c8d5cba54853e7bed1e2c33b67e5a7b6c76e"
public_key: "0xc92c8e7b4467e629ca8cd201a21564de39eea7cbe45b59bfd37f10b56e0a728c"
account: 501b015c58f2a1a62a330a6da80dfee723f528f719d25a4232751986f9a9f43f
- private_key: "0x76a641118ffb5ca5f9de4fe414a7d216d89616e74bec2c445324a2f0ab609ab6"
public_key: "0xef05bede15f422e16c0002e3cee8b4d4341518d99c4695352a1869b0779864fb"
account: 8f0de18409d6fca18c72fac4062fc0f9baa6404296fed93a3ad0250fb671f8b3
- private_key: "0xf24423f014e6f2fdd1914d6961b49a2cfc9eac59b88a57457e4cd9424fc140c8"
public_key: "0xb298975d27dbff3020e5ee7fdbbad8a969d4f2a2d5286e097d1db9760d04dd31"
account: 765d8c8d4d5859f43a56e2756fbf5f3d2483dbaa14f3fb62872df820d6e64eff

Loading

0 comments on commit b163f03

Please sign in to comment.