Skip to content

Commit

Permalink
Address review findings
Browse files Browse the repository at this point in the history
(push missing `git add`)
  • Loading branch information
jakmeier committed Mar 18, 2022
1 parent da8230b commit af3132a
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions runtime/near-test-contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,18 @@ pub fn trivial_contract() -> &'static [u8] {
}

/// Contract with exact size in bytes.
pub fn sized_contract(size: usize) -> &'static [u8] {
static CONTRACT: OnceCell<Vec<u8>> = OnceCell::new();
CONTRACT
.get_or_init(|| {
let payload = "x".repeat(size);
let base_size =
wat::parse_str(format!("(module (data \"{payload}\") (func (export \"main\")))"))
.unwrap()
.len();
let adjusted_size = size as i64 - (base_size as i64 - size as i64);
let payload = "x".repeat(adjusted_size as usize);
let code = format!("(module (data \"{payload}\") (func (export \"main\")))");
let contract = wat::parse_str(code).unwrap();
assert_eq!(contract.len(), size);
contract
})
.as_slice()
pub fn sized_contract(size: usize) -> Vec<u8> {
let payload = "x".repeat(size);
let base_size =
wat::parse_str(format!("(module (data \"{payload}\") (func (export \"main\")))"))
.unwrap()
.len();
let adjusted_size = size as i64 - (base_size as i64 - size as i64);
let payload = "x".repeat(adjusted_size as usize);
let code = format!("(module (data \"{payload}\") (func (export \"main\")))");
let contract = wat::parse_str(code).unwrap();
assert_eq!(contract.len(), size);
contract
}

/// Standard test contract which can call various host functions.
Expand Down

0 comments on commit af3132a

Please sign in to comment.