Unit test using std::type_name get

I’m doing some unit testing for my package and there is a case I have to use type_name to check result string.
Anyone got this error before:
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 0000000000000000000000000000000000000000000000000000000000000001::type_name rooted here

@amnn

7 Likes

That definitely looks like something we would want to investigate, thanks for flagging @icebear.near ! Could you share a minimal example of the test that caused this error?

4 Likes

here is my example: counter.move · GitHub
please review it sir @amnn

3 Likes

btw, is there any way to log (like console.log in Typescript) in Sui Move unit tests? @amnn

1 Like

I tested your example, and I was able to get it running locally (The test aborted, but not with an invariant violation). The issue is likely that you need to update your Sui CLI.

We changed the native functions related to type_name::get a couple of weeks ago, this requires a change to the framework, but also a change to the execution engine (which is in the CLI). What has happened is that the version of the framework you are depending on contains the framework change, but the version of the CLI you are depending on does not have the execution engine change.

btw, is there any way to log (like console.log in Typescript) in Sui Move unit tests?

Yes, check out std::debug::print.

6 Likes

thanks a lot ser @amnn

3 Likes