aptos-labs / aptos-core

Aptos is a layer 1 blockchain built to support the widespread use of blockchain through better technology and user experience.
https://aptosfoundation.org
Other
6.17k stars 3.63k forks source link

[Feature Request]: `aptos move test` Should Prioritize `[dev-addresses]` Over `[addresses]` #14882

Open mshakeg opened 2 weeks ago

mshakeg commented 2 weeks ago

Description

When running tests with aptos move test, the CLI attempts to resolve addresses from the [addresses] section of the Move.toml file, even when [dev-addresses] are defined specifically for testing. This causes address conflicts, especially when placeholder values (like _) are used in the [addresses] section for production or deployment.

The following error occurs when the same named address is used in both sections:

Error: Unable to resolve named address 'staking_contract' in package 'ExamplePackage' when resolving dependencies in dev mode: Attempted to assign a different value '0x9' to an already-assigned named address '0xabc123...'

Current Workaround: The current way to avoid this is to either:

Proposed Solution

It would be more efficient if aptos move test prioritized addresses from [dev-addresses] when running in dev mode. This would allow for smooth local testing without having to temporarily adjust or remove entries from the [addresses] or [dev-addresses] sections.

This change would improve the development experience, especially since the typical workflow involves using specific addresses for local testing first and production addresses later on.

Sample Move.toml:

[package]
name = "ExamplePackage"
version = "1.0.0"
license = "MIT"
authors = ["Dev1", "Dev2"]
upgrade_policy = "immutable"

# Production addresses, using placeholders for now
[addresses]
publisher = "_"
staker_resource_account = "_"

# Dev addresses for local testing
[dev-addresses]
publisher = "0x9"
staker_resource_account = "0x8d..."

[dependencies.Framework]
git = "https://github.com/example/example-core.git"
rev = "mainnet"
subdir = "move/framework"

[dev-dependencies]

Versions:

Related Issues:

https://github.com/aptos-labs/aptos-core/issues/7228

mshakeg commented 2 weeks ago

imo there should also be a way to specify the [addresses] per live network(e.g. mainnet, testnet, devnet or even other custom networks) for example something like:

# ...

[network]
default = "mainnet" # Specify default network (optional)

[network.mainnet]
my_staking = "0x1"
my_staking_resource_account = "0x2"

[network.testnet]
my_staking = "0x4"
my_staking_resource_account = "0x5"

[network.devnet]
my_staking = "0x7"
my_staking_resource_account = "0x8"

[network.customnet]
rpc_url = "https://custom-rpc-url.com" # Custom RPC URL for non-default networks
my_staking = "0xCustom1"
my_staking_resource_account = "0xCustom2"

[dev-addresses]
my_staking = "0xDev1"
my_staking_resource_account = "0xDev2"

# ...