-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #412 from near/austin/code_size_tests
feat: add compiled code size tests
- Loading branch information
Showing
3 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/// Compiles contract to wasm with release configuration and returns the code size. | ||
fn check_example_size(example: &str) -> usize { | ||
let status = std::process::Command::new("cargo") | ||
.env("RUSTFLAGS", "-C link-arg=-s") | ||
.args(&["build", "--release", "--target", "wasm32-unknown-unknown", "--manifest-path"]) | ||
.arg(format!("../examples/{}/Cargo.toml", example)) | ||
.status() | ||
.unwrap(); | ||
if !status.success() { | ||
panic!("building wasm example returned non-zero code {}", status); | ||
} | ||
|
||
let wasm = std::fs::read(format!( | ||
"../examples/{}/target/wasm32-unknown-unknown/release/{}.wasm", | ||
example, | ||
example.replace("-", "_") | ||
)) | ||
.unwrap(); | ||
|
||
wasm.len() | ||
} | ||
|
||
#[test] | ||
fn lock_fungible_code_size_check() { | ||
let size = check_example_size("lockable-fungible-token"); | ||
|
||
// Current contract size at the time of writing this test is 164_433, giving about ~10% buffer. | ||
assert!(size < 180_000); | ||
} | ||
|
||
#[test] | ||
fn status_message_code_size_check() { | ||
let size = check_example_size("status-message"); | ||
|
||
// Currently 140823. | ||
assert!(size < 155_000); | ||
} |