aptos-core icon indicating copy to clipboard operation
aptos-core copied to clipboard

Create Testing Aptos guide with a focus on Move

Open seaprotocol opened this issue 2 years ago • 8 comments

🐛 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

seaprotocol avatar Oct 21 '22 15:10 seaprotocol

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.

davidiw avatar Oct 22 '22 21:10 davidiw

It's private, how to call it?

seaprotocol avatar Oct 23 '22 13:10 seaprotocol

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

movekevin avatar Oct 23 '22 16:10 movekevin

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 avatar Oct 24 '22 14:10 clay-aptos

@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.

movekevin avatar Oct 24 '22 16:10 movekevin

@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.

clay-aptos avatar Oct 24 '22 16:10 clay-aptos

wait for your document

seaprotocol avatar Oct 25 '22 03:10 seaprotocol

@wrwg , @movekevin says I should pick your brain. May I set up some time with you this week? Thanks!

clay-aptos avatar Nov 01 '22 20:11 clay-aptos

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.

github-actions[bot] avatar Jan 02 '23 01:01 github-actions[bot]

@movekevin I recall you saying you had some ideas here.

clay-aptos avatar Jan 05 '23 01:01 clay-aptos

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.

github-actions[bot] avatar Feb 25 '23 02:02 github-actions[bot]

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 avatar Feb 26 '23 02:02 wrwg

@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!

clay-aptos avatar Feb 27 '23 18:02 clay-aptos

I am closing this out given we are tracking the work above in issue: https://github.com/aptos-labs/aptos-core/issues/6921

clay-aptos avatar Mar 09 '23 16:03 clay-aptos