Skip to content

Commit 03700ea

Browse files
tchataignerraulk
andauthored
Integration test framework: Initial PR (#471)
Co-authored-by: raulk <[email protected]>x Co-authored-by: Raúl Kripalani <[email protected]>
1 parent 7bf6731 commit 03700ea

File tree

28 files changed

+758
-3
lines changed

28 files changed

+758
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ target
22
Cargo.lock
33
*.wat
44
*.wasm
5+
!testing/integration/tests/assets/*
56
.idea/

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ members = [
44
"sdk",
55
"shared",
66
"testing/conformance",
7+
"testing/integration",
78
"ipld/*",
89
]
910

fvm/CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
Changes to the reference FVM implementation.
44

55
## Unreleased
6+
7+
- Added `testing` feature to change module visibility
8+
- Changed visibility of `account_actor`, `init_actor` and `system_actor` to public to use them in the integration test
9+
framework.
610

711
## 0.7.1 [2022-04-18]
812

@@ -33,4 +37,4 @@ BREAKING: Updates the FVM to the latest syscall struct alignment
3337
- `StateTree::consume` -> `StateTree::into_store`
3438
- BREAKING: remove unused (by the FVM) `verify_post_discount` from the FVM PriceList.
3539

36-
[FIP0032]: https://github.com/filecoin-project/FIPs/blob/master/FIPS/fip-0032.md
40+
[FIP0032]: https://github.com/filecoin-project/FIPs/blob/master/FIPS/fip-0032.md

fvm/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,5 @@ features = ["cranelift", "pooling-allocator", "parallel-compilation"]
4949
default = ["opencl"]
5050
opencl = ["filecoin-proofs-api/opencl"]
5151
cuda = ["filecoin-proofs-api/cuda"]
52+
testing = []
53+

fvm/src/lib.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,23 @@ pub mod state_tree;
2323

2424
mod blockstore;
2525

26+
#[cfg(not(feature = "testing"))]
2627
mod account_actor;
28+
#[cfg(not(feature = "testing"))]
2729
mod init_actor;
30+
#[cfg(not(feature = "testing"))]
31+
mod system_actor;
32+
33+
#[cfg(feature = "testing")]
34+
pub mod account_actor;
35+
#[cfg(feature = "testing")]
36+
pub mod init_actor;
37+
#[cfg(feature = "testing")]
38+
pub mod system_actor;
39+
2840
mod market_actor;
2941
mod power_actor;
3042
mod reward_actor;
31-
mod system_actor;
3243

3344
pub mod trace;
3445

sdk/CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
## [Unreleased]
44

5+
- Added _cfg = "testing"_ on `testing` module.
6+
- Added a `testing` module to access `assert_*` macros to be able to do assertions in actors code.
7+
58
## 0.6.0 [2022-04-14]
69

710
BREAKING: Upgrades to fvm_shared 0.6.0, and the new syscall struct alignment.
811
https://github.com/filecoin-project/fvm-specs/issues/63
912

1013
## 0.5.0 [2022-04-11]
1114

12-
Upgrades the SDK to fvm_shared 0.5.0. This release includes a significant breaking change to exit codes.
15+
Upgrades the SDK to fvm_shared 0.5.0. This release includes a significant breaking change to exit codes.

sdk/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ fvm_ipld_encoding = { version = "0.1", path = "../ipld/encoding" }
2323
[features]
2424
default = ["debug"]
2525
debug = ["lazy_static"]
26+
testing = []

sdk/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ pub mod sself;
1212
pub mod sys;
1313
pub mod vm;
1414

15+
#[cfg(feature = "testing")]
16+
pub mod testing;
17+
1518
/// The maximum supported CID size. (SPEC_AUDIT)
1619
pub const MAX_CID_LEN: usize = 100;
1720

sdk/src/testing.rs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Wrapper around the assert macro to have a hand on which exit code we want to give to our failed
2+
// assertion
3+
#[macro_export]
4+
macro_rules! assert {
5+
($cond:expr, $(,)?) => {{
6+
let res = std::panic::catch_unwind(|| {
7+
core::assert!($cond);
8+
});
9+
if res.is_err() {
10+
let panic_msg = match res.err() {
11+
Some(err) => match err.downcast::<String>() {
12+
Ok(panic_msg_box) => Some(panic_msg_box.as_str()),
13+
Err(err) => None,
14+
},
15+
None => unreachable!(),
16+
};
17+
18+
$crate::vm::abort(
19+
fvm_shared::error::ExitCode::USR_ASSERTION_FAILED.value(),
20+
panic_msg,
21+
);
22+
}
23+
}};
24+
}
25+
26+
// Utility macro to generate macro code for assert_eq and assert_ne
27+
macro_rules! assert2 {
28+
($assert_macro:ident) => {
29+
with_dollar_sign! {
30+
($d:tt) => {
31+
#[macro_export]
32+
macro_rules! $assert_macro {
33+
($d left:expr, $d right:expr $d(,$d arg:tt)*) => {
34+
let res = std::panic::catch_unwind(|| {
35+
core::$assert_macro!($d left, $d right);
36+
});
37+
if res.is_err() {
38+
let panic_msg = match res.err() {
39+
Some(err) => match err.downcast::<String>() {
40+
Ok(panic_msg_box) => Some(panic_msg_box.as_str()),
41+
Err(err) => None,
42+
},
43+
None => unreachable!(),
44+
};
45+
46+
$crate::vm::abort(
47+
fvm_shared::error::ExitCode::USR_ASSERTION_FAILED.value(),
48+
panic_msg,
49+
);
50+
}
51+
};
52+
}
53+
}
54+
}
55+
};
56+
}
57+
58+
// Utility macro to allow for nested repetition
59+
macro_rules! with_dollar_sign {
60+
($($body:tt)*) => {
61+
macro_rules! __with_dollar_sign { $($body)* }
62+
__with_dollar_sign!($);
63+
}
64+
}
65+
66+
// Wrapper around the assert_eq macro to have a hand on which exit code we want to give to our failed
67+
// assertion
68+
assert2!(assert_eq);
69+
70+
// Wrapper around the assert_ne macro to have a hand on which exit code we want to give to our failed
71+
// assertion
72+
assert2!(assert_ne);

shared/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
- Added `testing` feature to have `Default` derive on `Message`. Extended this feature to `Address` and `Payload`.
6+
37
## 0.6.0 [2022-04-14]
48

59
BREAKING: Switch syscall struct alignment: https://github.com/filecoin-project/fvm-specs/issues/63
610

711
Actors built against this new version of fvm_shared will be incompatible with prior FVM versions,
812
and vice-versa.
913

14+
- Added `Display` trait to `Type` for error printing.
15+
- Added _cfg = "testing"_ on `Default` trait for `Message` structure.
16+
1017
## 0.5.1 [2022-04-11]
1118

1219
Add the `USR_ASSERTION_FAILED` exit code.

0 commit comments

Comments
 (0)