aptos-core
aptos-core copied to clipboard
Create Testing Aptos guide with a focus on Move
🐛 Bug
When update aptos-move/framework/aptos-framework to rev main, my test case failed:
│ 146 │ public fun get_current_block_height(): u64 acquires BlockResource {
│ │ ------------------------ In this function in 0x1::block
│ 147 │ borrow_global<BlockResource>(@aptos_framework).height
│ │ ^^^^^^^^^^^^^
│
│
│ VMError (if there is one): VMError {
│ major_status: MISSING_DATA,
│ sub_status: None,
│ message: None,
│ exec_state: None,
│ location: Module(
│ ModuleId {
│ address: 0000000000000000000000000000000000000000000000000000000000000001,
│ name: Identifier(
│ "block",
│ ),
│ },
│ ),
│ indices: [],
│ offsets: [
│ (
│ FunctionDefinitionIndex(3),
│ 1,
│ ),
│ ],
│ }
└──────────────────
the prev version, test is all pass
you probably need to initialize this first.
@movekevin / @wrwg / @rajkaramchedu / @clay-aptos we should probably have a guide for testing Aptos Move
call this function: https://github.com/aptos-labs/aptos-core/blob/a3d463386e827612de8c3597cd944c5932aafc58/aptos-move/framework/aptos-framework/sources/genesis.move#L443 in your test code.
It's private, how to call it?
That one is not private. You can also use this one which directly adds the BlockResource you need that contains the block height. https://github.com/aptos-labs/aptos-core/blob/c58e5aebda595c4ffa572efd4292cd1095ae26ea/aptos-move/framework/aptos-framework/sources/block.move#L206. It's public test-only
you probably need to initialize this first.
@movekevin / @wrwg / @rajkaramchedu / @clay-aptos we should probably have a guide for testing Aptos Move
call this function:
https://github.com/aptos-labs/aptos-core/blob/a3d463386e827612de8c3597cd944c5932aafc58/aptos-move/framework/aptos-framework/sources/genesis.move#L443
in your test code.
Ack on a testing guide. Will start tracking and working on it. @davidiw , if you have particular sources I should work with, please let me know. Thanks!
@clay-aptos f you want to take a look, I think a good starting point would be the #[test_only] functions in various core modules such as block.move, stake.move, staking_config.move, etc.
We can chat later as well about some common unit test needs and how to initialize testing states.
@clay-aptos f you want to take a look, I think a good starting point would be the #[test_only] functions in various core modules such as block.move, stake.move, staking_config.move, etc.
We can chat later as well about some common unit test needs and how to initialize testing states.
Thanks, Kevin! This is a great pointer. I am making this to a doc issue and reopening.
wait for your document
@wrwg , @movekevin says I should pick your brain. May I set up some time with you this week? Thanks!
This issue is stale because it has been open 45 days with no activity. Remove the stale
label or comment - otherwise this will be closed in 15 days.
@movekevin I recall you saying you had some ideas here.
This issue is stale because it has been open 45 days with no activity. Remove the stale
label or comment - otherwise this will be closed in 15 days.
I think immediate help for this (and other similar documentation issues) is port the original Move tutorial to Aptos. It covers testing quite extensively. In fact I would say, together with the book and the tutorial, documentation is relative complete. Move isn't that complicated, by intention.
@clay-aptos do we already have an issue for porting the tutorial? I'm sure we find someone in the Move team to work on this, some of them actually run this tutorial back at Meta and know it (including me).
@wrwg , I am happy to use the existing: https://github.com/aptos-labs/aptos-core/issues/6375#issuecomment-1441208359
I just reopened it and expanded its scope to include the NFT Tutorial. Is the plan for me to simply copy the adapted version we have in a private repo right now, @wrwg ? If so, I can work on that this week? If not, please help me understand the plan. Thanks!
I am closing this out given we are tracking the work above in issue: https://github.com/aptos-labs/aptos-core/issues/6921