Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Bug] VM Load problems with one unit test poisons the whole module unit tests #10346

Open
brmataptos opened this issue Oct 2, 2023 · 1 comment
Assignees
Labels
bug Something isn't working stale-exempt Prevents issues from being automatically marked and closed as stale

Comments

@brmataptos
Copy link
Contributor

🐛 Bug

Adding a unit test to a module can make existing tests fail.

To reproduce

Add the following code to the end of aptos-core/aptos-move/framework/aptos-stdlib/sources/debug.move:

    #[test_only]
    struct InnerStruct has key, store, copy {
        amount: u64
    }

    #[test_only]
    struct OuterStruct has key {
        any_field: vector<InnerStruct>
    }

    #[test(account=@0x1234)]
    fun test_print_inner_struct(account: &signer) acquires OuterStruct {
        let account_address = std::signer::address_of(account);
        move_to(account, OuterStruct {any_field: vector::empty()});
        let anystruct = borrow_global_mut<OuterStruct>(account_address);
        vector::for_each_mut<InnerStruct>(&mut anystruct.any_field, |field| {
            aptos_std::debug::print(field); // INTERNAL TEST ERROR: INTERNAL VM INVARIANT VIOLATION
            // let field: &mut InnerStruct = field;
            // field.amount = field.amount + upgrade_amount;
        });
    }

and run "cargo test -p aptos-framework -- --skip prover".

This triggers a bug in the VM and causes not just this test to fail:

[ FAIL    ] 0x1::debug::test_print_inner_struct

but also a bunch of other tests that previously passed:

[ FAIL    ] 0x1::debug::test
[ FAIL    ] 0x1::debug::test_print_generic_struct
[ FAIL    ] 0x1::debug::test_print_inner_struct
[ FAIL    ] 0x1::debug::test_print_nested_struct
[ FAIL    ] 0x1::debug::test_print_primitive_types
[ FAIL    ] 0x1::debug::test_print_quoted_string
[ FAIL    ] 0x1::debug::test_print_string
[ FAIL    ] 0x1::debug::test_print_struct
[ FAIL    ] 0x1::debug::test_print_vector_of_vectors
[ FAIL    ] 0x1::debug::test_print_vectors

Btw, just adding the [test_only] struct declarations above does not cause failure.

Each failing test also yields output similar to the following (with --nocapture):

┌── test_print_generic_struct ──────
│ error[E11001]: test failure
│     ┌─ /Users/brm/code/aptos-core/aptos-move/framework/aptos-stdlib/sources/debug.move:295:13
│     │
│ 290 │     fun test_print_inner_struct(account: &signer) acquires OuterStruct {
│     │         ----------------------- In this function in 0x1::debug
│     ·
│ 295 │             aptos_std::debug::print(field); // INTERNAL TEST ERROR: INTERNAL VM INVARIANT VIOLATION
│     │             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ INTERNAL TEST ERROR: INTERNAL VM INVARIANT VIOLATION.
│ Test was not expected to error, but it gave a UNEXPECTED_VERIFIER_ERROR (code 2017) error originating in the module 0000000000000000000000000000000000
000000000000000000000000000001::debug rooted here
│ 

Note that this output is for the test test_print_generic_struct but the failure (and all of them) mentions problems with the new code test_print_inner_struct, so the problem is probably that all the tests load the same code and are rejected due to invalid bytecode in a different method in the module.

Expected Behavior

Newly added test fails, but not existing tests. Or we get a more informative error message.

@brmataptos brmataptos added the bug Something isn't working label Oct 2, 2023
@brmataptos brmataptos moved this from 🆕 New to For Grabs in Move Language and Runtime Oct 2, 2023
@sausagee sausagee added the stale-exempt Prevents issues from being automatically marked and closed as stale label Nov 13, 2023
@brmataptos
Copy link
Contributor Author

@rahxephon89 @wrwg Should we bump the priority up for this? We should at least be aware of it when we run tests.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working stale-exempt Prevents issues from being automatically marked and closed as stale
Projects
Status: For Grabs
Development

No branches or pull requests

3 participants