move-language / move

Apache License 2.0
2.25k stars 679 forks source link

[Bug] Unable to test code that successful to compiles #962

Closed ghost closed 1 year ago

ghost commented 1 year ago

๐Ÿ› Bug

To reproduce

Code snippet to reproduce

module me::test3 {
    use std::event::emit_event;
    use std::event::EventHandle;
    use std::account::new_event_handle;
    use std::signer::address_of;

    struct TestEvent has drop, store {}

    struct Test0 has key {
        e: EventHandle<TestEvent>,
    }

    fun init_module(s: &signer) {
        move_to(s, Test0 {
            e: new_event_handle(s)
        })
    }

    public entry fun test_emit_event(s: &signer) acquires Test0 {
        emit_event(&mut borrow_global_mut<Test0>(address_of(s)).e, TestEvent {});
    }
    #[test(framework = @0x1)]
    fun a(framework: &signer) {
        test_emit_event(framework);
    }
}
[package]
name = 'tst3'
version = '1.0.0'
[dependencies]
AptosFramework={local="../aptos-core/aptos-move/framework/aptos-framework"}
[addresses]
me = "0xd1b58e44ea11ffd326a280c453b080fd8af294298815a00e65b6e2bffc48d6ac"

Stack trace/error message

// Paste the output here
$ ../aptos move test
INCLUDING DEPENDENCY AptosFramework
INCLUDING DEPENDENCY AptosStdlib
INCLUDING DEPENDENCY MoveStdlib
BUILDING tst3
error[E04020]: missing acquires annotation
   โ”Œโ”€ /media/laptopssd/*mask*/aptos/test3/sources/a.move:19:59
   โ”‚
19 โ”‚     public entry fun test_emit_event(s: &signer) acquires Test0 {
   โ”‚                                                           ^^^^^ The call acquires '(me=0xD1B58E44EA11FFD326A280C453B080FD8AF294298815A00E65B6E2BFFC48D6AC)::test3::Test0', but the 'acquires' list for the current function does not contain this type. It must be present in the calling context's acquires list

Expected Behavior

Should be pass the compile then do the test.

System information

Please complete the following information:

Additional context

Add any other context about the problem here.

is it Chicken or eggs paradox? lol. you want egg, but no chicken, you want chicken, but no egg :eyes:

wrwg commented 1 year ago

This is Aptos specific functionality, so in general, please open issues in aptos-core.

As regards this particular error, unit tests do not call init_module automatically, so you must call it yourself at the beginning of a test.

ghost commented 1 year ago

This is Aptos specific functionality, so in general, please open issues in aptos-core.

As regards this particular error, unit tests do not call init_module automatically, so you must call it yourself at the beginning of a test.

Sorry but it doesnt related Aptos specific functionality fun init_module, Just try to change name to fun init_modules then it still got same error.

wrwg commented 1 year ago

It IS specific for Aptos Move. Also read again what I wrote, I gave you the solution.

On Sat, Mar 4, 2023 at 10:07 AM e99243506bigplay @.***> wrote:

This is Aptos specific functionality, so in general, please open issues in aptos-core.

As regards this particular error, unit tests do not call init_module automatically, so you must call it yourself at the beginning of a test.

Sorry but it doesnt related Aptos specific functionality fun init_module, Just try to change name to fun init_modules then it still got same error.

โ€” Reply to this email directly, view it on GitHub https://github.com/move-language/move/issues/962#issuecomment-1454806920, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC2MSOSJZEVULNSLZBQZEWLW2NZFBANCNFSM6AAAAAAVOQKNGI . You are receiving this because you modified the open/close state.Message ID: @.***>

ghost commented 1 year ago

It IS specific for Aptos Move. Also read again what I wrote, I gave you the solution. โ€ฆ On Sat, Mar 4, 2023 at 10:07 AM e99243506bigplay @.> wrote: This is Aptos specific functionality, so in general, please open issues in aptos-core. As regards this particular error, unit tests do not call init_module automatically, so you must call it yourself at the beginning of a test. Sorry but it doesnt related Aptos specific functionality fun init_module, Just try to change name to fun init_modules then it still got same error. โ€” Reply to this email directly, view it on GitHub <#962 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC2MSOSJZEVULNSLZBQZEWLW2NZFBANCNFSM6AAAAAAVOQKNGI . You are receiving this because you modified the open/close state.Message ID: @.>

Now what? IS It still same be Aptos Move? Please hint me what the solution is?

Code:

module me::test3 {
    struct Test0 has key {}

    public entry fun test() acquires Test0 {
        borrow_global_mut<Test0>(@0x22);
    }

    #[test(framework = @0x1)]
    fun a() {
        test();
    }
}

Move.toml:

[package]
name = 'tst3'
version = '1.0.0'
[dependencies]
AptosFramework={local="../aptos-core/aptos-move/framework/aptos-framework"}
[addresses]
#me = "0xd1b58e44ea11ffd326a280c453b080fd8af294298815a00e65b6e2bffc48d6ac"
me = "0x22"

Output: (on aptos-main branch)

$ ../move-lang/target/x86_64-unknown-linux-gnu/release/move test
INCLUDING DEPENDENCY AptosFramework
INCLUDING DEPENDENCY AptosStdlib
INCLUDING DEPENDENCY MoveStdlib
BUILDING tst3
error[E04020]: missing acquires annotation
   โ”Œโ”€ ./sources/a.move:10:9
   โ”‚
 4 โ”‚     public entry fun test() acquires Test0 {
   โ”‚                                      ----- The call acquires '(me=0x22)::test3::Test0', but the 'acquires' list for the current function does not contain this type. It must be present in the calling context's acquires list
   ยท
10 โ”‚         test();
   โ”‚         ^^^^^^ Invalid call to '(me=0x22)::test3::test'

Even add line move_to(framework, Test0 {}); on beginning of test code, that wont work too.

ghost commented 1 year ago

It IS specific for Aptos Move. Also read again what I wrote, I gave you the solution. โ€ฆ On Sat, Mar 4, 2023 at 10:07 AM e99243506bigplay @.> wrote: This is Aptos specific functionality, so in general, please open issues in aptos-core. As regards this particular error, unit tests do not call init_module automatically, so you must call it yourself at the beginning of a test. Sorry but it doesnt related Aptos specific functionality fun init_module, Just try to change name to fun init_modules then it still got same error. โ€” Reply to this email directly, view it on GitHub <#962 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC2MSOSJZEVULNSLZBQZEWLW2NZFBANCNFSM6AAAAAAVOQKNGI . You are receiving this because you modified the open/close state.Message ID: @.>

Finally, the problem was fun a(framework: &signer) lack of acquires Test0 signature. The move compiler was misleading me. Thanks to Magnum6#6523 to provide the solution.

wrwg commented 1 year ago

Can you please ask such questions on the Aptos discord? GitHub issues should only be opened if you actually found a bug, not for questions how to use Move. This takes away valuable time of the Move developers. You will also get much faster help. Finally, if you really think you found a bug, never open it here but in the aptos-core repo.

ghost commented 1 year ago

Can you please ask such questions on the Aptos discord? GitHub issues should only be opened if you actually found a bug, not for questions how to use Move. This takes away valuable time of the Move developers. You will also get much faster help. Finally, if you really think you found a bug, never open it here but in the aptos-core repo.

Move compiler error message was misleading me to open a Github issue, and I didn't know that solution was so simple at all that like a newbie Move question. Well, as you wish, I will ask any question on Aptos discord at future.