sui: [Bug] take_last_created_owned does not return the latest created object
Steps to Reproduce Issue
When calling test_scenario::take_last_created_owned
in a test sequence, the returned object is not always the latest created.
Will provide code to reproduce in first comment.
Expected Result
I expect that test_scenario::take_last_created_owned
to return the last created object of type T created.
Actual Result
test_scenario::take_last_created_owned
is not always returning the last created object, this is deterministic, but the number of objects to cause this differs, I belive based on some kind of checksum but I don’t know. Funcs such as test_scenario::get_account_owned_inventory
are not public to help me debug this.
System Information
- OS: Windows 10
- Compiler: VS2022 / Sui Move 0.6.1
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 16 (10 by maintainers)
That’s known issue and we have a fix in one of the build.rs, the move compiler require more stack when running in windows…
I will create a PR to fix it in sui move
PR #3620 should fix this issue. I have also added the repro code as a test case. Thanks for reporting! @jamescarter-le
Took a look at this. I believe there is indeed an issue with the native implementation of
test_scenario
module. In the implementation, we grab all the objects owned by the address, pop an object from the back, and return the object. However, the object inventory is implemented using aBTreeMap
which does not preserve the insertion order of entries: https://github.com/MystenLabs/sui/blob/main/crates/sui-framework/src/natives/test_scenario.rs#L55Instead the entries will be sorted by the keys (
ObjectId
). Therefore when wepop_back
, we don’t get the most recent created/inserted object. The easiest fix I can think of is to use a different map that does preserve the insertion order. If no such map exists, we can include the insertion order in the value of the entry and sort using values. I will try out the approaches and put up a PR later.@emmazzz Can you help take a look?
I will try to look into it later today, but if you’d like to try digging in yourself then I’d follow the first approach you describe. The instructions on how to build and test Sui locally can be found here
The test_scenario package consists of both Move code and native functions implemented in Rust. There is no Move debugger at the moment, but technically you could indeed step through the Rust code - we don’t have official instructions on how to set it up in this context, though.