mirror of
https://github.com/pezkuwichain/wasm-instrument.git
synced 2026-06-09 20:11:06 +00:00
Remove everything not needed by substrate
Also rename to wasm-instrument
This commit is contained in:
+6
-6
@@ -1,10 +1,10 @@
|
||||
use parity_wasm::elements;
|
||||
use pwasm_utils as utils;
|
||||
use std::{
|
||||
fs,
|
||||
io::{self, Read, Write},
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
use wasm_instrument as instrument;
|
||||
|
||||
fn slurp<P: AsRef<Path>>(path: P) -> io::Result<Vec<u8>> {
|
||||
let mut f = fs::File::open(path)?;
|
||||
@@ -41,7 +41,7 @@ fn run_diff_test<F: FnOnce(&[u8]) -> Vec<u8>>(test_dir: &str, name: &str, test:
|
||||
validate_wasm(&fixture_wasm).expect("Fixture is invalid");
|
||||
|
||||
let expected_wat = slurp(&expected_path).unwrap_or_default();
|
||||
let expected_wat = String::from_utf8_lossy(&expected_wat);
|
||||
let expected_wat = std::str::from_utf8(&expected_wat).expect("Failed to decode expected wat");
|
||||
|
||||
let actual_wasm = test(fixture_wasm.as_ref());
|
||||
validate_wasm(&actual_wasm).expect("Result module is invalid");
|
||||
@@ -52,7 +52,7 @@ fn run_diff_test<F: FnOnce(&[u8]) -> Vec<u8>>(test_dir: &str, name: &str, test:
|
||||
println!("difference!");
|
||||
println!("--- {}", expected_path.display());
|
||||
println!("+++ {} test {}", test_dir, name);
|
||||
for diff in diff::lines(&expected_wat, &actual_wat) {
|
||||
for diff in diff::lines(expected_wat, &actual_wat) {
|
||||
match diff {
|
||||
diff::Result::Left(l) => println!("-{}", l),
|
||||
diff::Result::Both(l, _) => println!(" {}", l),
|
||||
@@ -78,7 +78,7 @@ mod stack_height {
|
||||
run_diff_test("stack-height", concat!(stringify!($name), ".wat"), |input| {
|
||||
let module =
|
||||
elements::deserialize_buffer(input).expect("Failed to deserialize");
|
||||
let instrumented = utils::stack_height::inject_limiter(module, 1024)
|
||||
let instrumented = instrument::inject_stack_limiter(module, 1024)
|
||||
.expect("Failed to instrument with stack counter");
|
||||
elements::serialize(instrumented).expect("Failed to serialize")
|
||||
});
|
||||
@@ -102,11 +102,11 @@ mod gas {
|
||||
#[test]
|
||||
fn $name() {
|
||||
run_diff_test("gas", concat!(stringify!($name), ".wat"), |input| {
|
||||
let rules = utils::rules::Set::default();
|
||||
let rules = instrument::gas_metering::ConstantCostRules::default();
|
||||
|
||||
let module =
|
||||
elements::deserialize_buffer(input).expect("Failed to deserialize");
|
||||
let instrumented = utils::inject_gas_counter(module, &rules, "env")
|
||||
let instrumented = instrument::gas_metering::inject(module, &rules, "env")
|
||||
.expect("Failed to instrument with gas metering");
|
||||
elements::serialize(instrumented).expect("Failed to serialize")
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user