Skip to content

Commit 2cda3d5

Browse files
committed
update readme
1 parent 15eff1c commit 2cda3d5

1 file changed

Lines changed: 101 additions & 0 deletions

File tree

Readme.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Modular low-level building bricks for Move language. Specifically, the executor and tracer abstractions and layered database design borrowed from [revm](https://github.com/bluealloy/revm) that allow you to emulate and inspect an execution.
88
- Static analysis capabilities inherited from [MoveScan](https://dl.acm.org/doi/10.1145/3650212.3680391), the state-of-the-art static analyzer.
99
- Cutting-edge fuzzing reimplemented from scratch learned from [Belobog](https://github.com/abortfuzz/belobog) that supports both property testing and on-chain fuzzing, in the a flavor similar to [foundry](https://getfoundry.sh/forge/advanced-testing/overview) by writing invariants in Move language.
10+
- A `forge test`-like runner (`movy sui test`) that executes your `test_*` functions and automatically fills their object and type-parameter arguments.
1011
- And a lot of more...
1112

1213
Checkout our documentations at [here](https://docs.movy.rs)
@@ -86,6 +87,106 @@ public fun movy_post_increment(
8687
}
8788
```
8889

90+
### Running Tests with `sui test`
91+
92+
`movy sui test` builds and deploys your package, runs `movy_init`, then executes every `#[test]`
93+
function whose name starts with `test_` — much like `forge test`. Unlike the stock Move test
94+
runner, these test functions may take **parameters**, including Sui objects and type parameters,
95+
and `movy` fills them in for you.
96+
97+
```move
98+
// test-data/counter/tests/movy.move
99+
#[test]
100+
fun test_counter_smoke() {
101+
assert!(1 + 1 == 2, 0);
102+
}
103+
104+
// Object and type-parameter arguments are filled by movy:
105+
#[test]
106+
public fun test_increment_typed<T>(ctr: &mut Counter) {
107+
let _ty = std::type_name::get<T>();
108+
let before = counter::value(ctr);
109+
counter::increment(ctr, 3);
110+
assert!(counter::value(ctr) == before + 3, 300);
111+
}
112+
```
113+
114+
Run all tests in a package:
115+
116+
```bash
117+
movy sui test --locals ./test-data/counter
118+
```
119+
120+
#### Discover objects and pending arguments: `--only-init`
121+
122+
`--only-init` runs `movy_init` and then prints the objects it produced together with every test
123+
function and the arguments it still needs — the starting point for filling them in:
124+
125+
```bash
126+
movy sui test --locals ./test-data/counter --only-init
127+
```
128+
129+
```
130+
=== objects after movy_init (3) ===
131+
deployer: 0xb641...
132+
attacker: 0xa773...
133+
0x95e1… 0x2::coin::Coin<0x2::sui::SUI> [owned by 0xa773… (attacker)] v3
134+
0xd726… <pkg>::counter::Counter [shared (v3)] v3
135+
0xdbcf… 0x2::package::UpgradeCap [owned by 0xb641… (deployer)] v2
136+
137+
=== test functions ===
138+
<pkg>::counter_tests::test_counter_smoke() [no args]
139+
<pkg>::counter_tests::test_increment_typed<T0>(&mut <pkg>::counter::Counter) [needs args]
140+
```
141+
142+
#### Fill arguments: `--object-mapping` and `--test-ty`
143+
144+
Bind an object parameter to a specific object, and pin a type parameter to a concrete type (use
145+
the object id printed by `--only-init`):
146+
147+
```bash
148+
movy sui test --locals ./test-data/counter \
149+
--object-mapping 'counter::counter::Counter/0xd726…e5d3' \
150+
--test-ty 'counter::counter_tests::test_increment_typed:0/0x2::sui::SUI'
151+
```
152+
153+
- `--object-mapping <type>/0x<object_id>` — fill an object parameter with the given object.
154+
Repeatable (or comma-separated); entries of the same type are consumed in parameter order.
155+
- `--test-ty <pkg::module::func>:<index>/<type>` — set type parameter `<index>` of a test function.
156+
157+
Types and function selectors accept **local package names** (e.g. `counter::counter::Counter`),
158+
resolved to the currently deployed address. A mapping therefore keeps working across rebuilds even
159+
though the deployed package id changes, and you can paste types straight out of `--only-init` or a
160+
`--trace`. Unmapped object/type arguments fall back to automatic, fuzzer-style filling.
161+
162+
#### Pin deployment addresses: `--deploy-at`
163+
164+
Object ids produced by `movy_init` are stable across source edits, but a freshly deployed package
165+
is assigned a new id whenever its bytecode changes — which also changes every type string
166+
(`<pkgid>::counter::Counter`). Pin the package to a fixed address to keep ids and type strings
167+
stable:
168+
169+
```bash
170+
movy sui test --locals ./test-data/counter --deploy-at counter:0xcafe…
171+
```
172+
173+
`--deploy-at <pkg_name>:0x<address>` is repeatable and matches packages by name.
174+
175+
#### Failures and reproducibility
176+
177+
A test fails (non-zero exit) when the transaction aborts, e.g. a failing `assert!`. In addition,
178+
your `movy_pre_*` / `movy_post_*` invariants are applied while each test runs, so an invariant
179+
violation reported with `crash_because` also fails the test and surfaces the reason:
180+
181+
```
182+
oracle crash detected for <pkg>::counter_tests::test_increment_typed: Counter should be always increasing
183+
```
184+
185+
`--seed` pins the RNG (and thus the gas object and freshly-derived package/object ids), while
186+
`--checkpoint` / `--epoch` / `--epoch-ms` pin the on-chain context and let the run work fully
187+
offline (otherwise they are fetched from `--rpc`). Pass `--trace` to print the execution trace of
188+
each test.
189+
89190
### Call Graph and Type Graph
90191

91192
Generate a type graph for a move package.

0 commit comments

Comments
 (0)