-
Notifications
You must be signed in to change notification settings - Fork 477
Expand file tree
/
Copy pathlib.rs
More file actions
78 lines (67 loc) · 2.22 KB
/
lib.rs
File metadata and controls
78 lines (67 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#![cfg_attr(not(feature = "std"), no_std, no_main)]
#[ink::contract]
pub mod static_buffer {
#[allow(unused_imports)]
use ink::env::BUFFER_SIZE;
#[ink(storage)]
pub struct StaticBuffer {
value: bool,
}
impl StaticBuffer {
/// Creates a dummy smart contract.
#[ink(constructor)]
pub fn new(init_value: bool) -> Self {
Self { value: init_value }
}
/// Sets a default value.
#[ink(constructor)]
pub fn new_default() -> Self {
Self::new(Default::default())
}
/// Returns the caller of the contract.
/// Should panic if the buffer size is less than 32 bytes.
#[ink(message)]
pub fn get_caller(&self) -> AccountId {
self.env().caller()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[ink::test]
#[should_panic(expected = "the output buffer is too small!")]
fn run_out_buffer_memory() {
let flipper = StaticBuffer::new(false);
flipper.get_caller()
}
}
#[cfg(all(test, feature = "e2e-tests"))]
mod e2e_tests {
use super::*;
use ink_e2e::ContractsBackend;
type E2EResult<T> = std::result::Result<T, Box<dyn std::error::Error>>;
#[ink_e2e::test]
async fn e2e_run_out_of_buffer_memory<Client: E2EBackend>(
mut client: Client,
) -> E2EResult<()> {
// given
let constructor = StaticBufferRef::new(false);
let contract = client
.instantiate("static_buffer", &ink_e2e::alice(), constructor, 0, None)
.await
.expect("instantiate failed");
let call = contract.call::<StaticBuffer>();
// when
let get = call.get_caller();
// then panics if `INK_STATIC_BUFFER_SIZE` is less than 32 bytes.
let res = client.call_dry_run(&ink_e2e::bob(), &get, 0, None).await;
println!("{}", super::BUFFER_SIZE);
assert!(
res.is_err(),
"Buffer size was larger than expected: {}",
super::BUFFER_SIZE.to_string()
);
Ok(())
}
}
}