-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Add test-only code publish function #13174
base: main
Are you sure you want to change the base?
Conversation
⏱️ 8s total CI duration on this PR
|
This issue is stale because it has been open 45 days with no activity. Remove the |
Bumping this as the PR eases DevEx |
This issue is stale because it has been open 45 days with no activity. Remove the |
Bumping again as the PR eases DevEx |
This issue is stale because it has been open 45 days with no activity. Remove the |
Bumping per stale label |
This issue is stale because it has been open 45 days with no activity. Remove the |
Bumping per stale label |
This issue is stale because it has been open 45 days with no activity. Remove the |
Bumping per stale label |
Current problem
Currently the
code
module lacks test-only functions, making it difficult for devs to mock out or stub behaviors that depend on autonomous publication during runtime.In particular, when a package is published via
code::publish_package_txn()
, an inner call tocheck_dependencies
verifies that each of its dependencies have acode::PackageRegistry
resource under their accounts:aptos-core/aptos-move/framework/aptos-framework/sources/code.move
Line 273 in 66d9efb
In the general case, the only way to ensure that a
PackageRegistry
exists under an account is to callcode::publish_package_txn()
:aptos-core/aptos-move/framework/aptos-framework/sources/code.move
Lines 155 to 157 in 66d9efb
Hence, to run a test that calls
code::publish_package_txn()
, there first needs to be setup that calls the same function for each of the expected dependencies. Problematically, however, this function relies on an inner call to thenative_request_publish
native function incode.rs
, which errors out withEALREADY_REQUESTED
when one attempts to publish two packages in the same txn:aptos-core/aptos-move/framework/aptos-framework/sources/code.move
Lines 199 to 205 in 66d9efb
aptos-core/aptos-move/framework/src/natives/code.rs
Lines 319 to 323 in 66d9efb
Hence it is impossible to write unit tests for code that publishes a package with even a single dependency (because it is impossible to publish both the dependency and the relevant package during the same unit test, since
native_request_publish
throwsEALREADY_REQUESTED
).For packages that have more than one dependency, it is impossible to publish even the dependencies (e.g. to ensure that a
code::PackageRegistry
exists under each relevant account) for the same reason.Solution
code::publish_package_txn_for_testing()
which circumvents the above hassle by simply ignoring the blocking native function call (which appears to mainly serve metering purposes and occurs after all other extensive validation)This approach will allow developers to write unit tests for code that calls
code::publish_package_txn()