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

[Bug] Misleading error message in test

Open 0xmaayan opened this issue 2 years ago • 1 comments

🐛 Bug

Getting an error when running aptos move test using this code, unfortunately the error message is not clear and we should provide a better message around missing resources.

To reproduce

Code snippet to reproduce

struct TodoListRegistry has key, store {
  task_count: u64
}

fun init_module() acquires TodoListRegistry, SetTaskEvent {
  let newTask = string::utf8(b"Checkout aptos.dev");
  create_task(newTask);
}

public entry fun create_task(content: String) acquires TodoListRegistry, SetTaskEvent {
  let task_registry = borrow_global_mut<TodoListRegistry>(@myself);
}

#[test]
public entry fun test_set_task_count() acquires TodoListRegistry, SetTaskEvent {
  init_module();
}

Stack trace/error message

┌── test_set_task_count ──────
│ ITE: An unknown error was reported. Location: error[E11001]: test failure
│    ┌─ /my-appt/move/core/sources/main.move:34:25
│    │
│ 33 │   public entry fun create_task(content: String) acquires TodoListRegistry, SetTaskEvent {
│    │                    ----------- In this function in 0xa917d2256d3087fd8f62182264f9016158a07540895c6e18e75957af9dbea22c::main
│ 34 │     let task_registry = borrow_global_mut<TodoListRegistry>(@myself);

Expected Behavior

borrow_global would fail with RESOURCE_NOT_FOUND if the resource doesn't exist at the specified address

System information

Please complete the following information:

Additional context

0xmaayan avatar Jan 02 '23 14:01 0xmaayan

The signature of the constructor function should take a signer. i.e

...
fun init_module(s: &signer) {
...

vivekascoder avatar Jan 03 '23 17:01 vivekascoder

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 Apr 17 '23 01:04 github-actions[bot]

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 Jun 18 '23 02:06 github-actions[bot]