Skip to content

Commit

Permalink
[move-cli][test] trigger the cyclic check on the VM side
Browse files Browse the repository at this point in the history
The goal of this test case is to check that the VM properly rejects a module
with cyclic dependencies even in the multi-module publishing setting.

Here is the procedure:

1. publish two modules with dependencies `B --depends_on--> A`.

   (See the code in package `p1`)

2. compile a set of modules with dependencies `A --may_use--> C --depends_on--> B'`

   (See the code in package `p2`)

   NOTE that module `B'` is an update to module `B` with dependency to module
   `A` removed.  We need this tweak here, otherwise, the compiler will flag the
   cyclic dependency and we can never reach the publishing step to test the VM.

3. publish the modules compiled in step 2, but only module `A` and `C` with the
   `--override-ordering` flag. Without this flag, all modules will be published.

   This will trigger the check on the VM side and the VM aborts correctly with
   `INVALID_FRIEND_DECL_WITH_MODULES_IN_DEPENDENCIES

Closes: move-language#39
  • Loading branch information
meng-xu-cs authored and bors-libra committed Feb 2, 2022
1 parent 927c229 commit 7dc417f
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## Test Case Explanation

The goal of this test case is to check that the VM properly rejects a module
with cyclic dependencies even in the multi-module publishing setting.

Here is the procedure:

1. publish two modules with dependencies `B --depends_on--> A`.

(See the code in package `p1`)


2. compile a set of modules with dependencies `A --may_use--> C --depends_on--> B'`

(See the code in package `p2`)

NOTE that module `B'` is an update to module `B` with dependency to module
`A` removed. We need this tweak here, otherwise, the compiler will flag the
cyclic dependency and we can never reach the publishing step to test the VM.


3. publish the modules compiled in step 2, but only module `A` and `C` with the
`--override-ordering` flag. Without this flag, all modules will be published.

This will trigger the check on the VM side and the VM aborts correctly with
`INVALID_FRIEND_DECL_WITH_MODULES_IN_DEPENDENCIES`.
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
Command `sandbox publish --override-ordering A --override-ordering B -v`:
error[E02004]: invalid 'module' declaration
┌─ ./sources/CyclicFriendsPart2.move:8:24
7 │ friend 0x3::A;
│ -------------- '0x3::A' is a friend of '0x3::C'
8 │ public fun foo() { 0x3::B::foo() }
│ ^^^^^^^^^^^ '0x3::B' uses '0x3::C'. This 'use' relationship creates a dependency cycle.
┌─ ./sources/CyclicFriendsPart1.move:6:24
6 │ public fun foo() { 0x3::A::foo() }
│ ----------- '0x3::A' uses '0x3::B'

Command `-p p1 sandbox publish --override-ordering A --override-ordering B -v`:
Found 2 modules
Publishing a new module 00000000000000000000000000000003::A (wrote 82 bytes)
Publishing a new module 00000000000000000000000000000003::B (wrote 93 bytes)
Wrote 175 bytes of module ID's and code
Command `-p p2 sandbox publish --override-ordering A --override-ordering C -v`:
Found 3 modules
Invalid multi-module publishing: VMError with status INVALID_FRIEND_DECL_WITH_MODULES_IN_DEPENDENCIES at location Module ModuleId { address: 00000000000000000000000000000003, name: Identifier("C") } and message At least one module, 00000000000000000000000000000003::A, appears in both the dependency set and the friend set
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
sandbox publish --override-ordering A --override-ordering B -v
-p p1 sandbox publish --override-ordering A --override-ordering B -v
-p p2 sandbox publish --override-ordering A --override-ordering C -v
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[package]
name = "cyclic_multi_module_publish"
version = "0.0.0"
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
module 0x3::D {
module 0x3::A {
public fun foo() {}
}

module 0x3::B {
public fun foo() {}
public fun bar() {}
}

module 0x3::C {
Expand Down

0 comments on commit 7dc417f

Please sign in to comment.