Skip to content
This repository was archived by the owner on Feb 1, 2024. It is now read-only.

Commit dbe3a13

Browse files
author
Achim Schneider
committed
ink to version 4.0
1 parent 6b797c4 commit dbe3a13

File tree

2 files changed

+72
-10
lines changed

2 files changed

+72
-10
lines changed

crates/contract/Cargo.toml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
[package]
22
name = "contract"
3-
version = "4.0.0-beta"
3+
version = "4.0.0"
44
authors = ["Parity Technologies <[email protected]>"]
55
edition = "2021"
66
publish = false
77

88
[dependencies]
9-
ink = { version = "4.0.0-beta", default-features = false }
9+
ink = { version = "4.0", default-features = false }
1010

1111
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
12-
scale-info = { version = "2", default-features = false, features = ["derive"], optional = true }
12+
scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true }
13+
14+
[dev-dependencies]
15+
ink_e2e = { version = "4.0" }
1316

1417
[lib]
1518
name = "contract"
1619
path = "lib.rs"
17-
crate-type = [
18-
# Used for normal contract Wasm blobs.
19-
"cdylib",
20-
]
20+
crate-type = ["cdylib"]
2121

2222
[features]
2323
default = ["std"]
@@ -26,4 +26,5 @@ std = [
2626
"scale/std",
2727
"scale-info/std",
2828
]
29-
ink-as-dependency = []
29+
ink-as-dependency = []
30+
e2e-tests = []

crates/contract/lib.rs

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub mod flipper {
1616

1717
/// Creates a new flipper smart contract initialized to `false`.
1818
#[ink(constructor)]
19-
pub fn default() -> Self {
19+
pub fn new_default() -> Self {
2020
Self::new(Default::default())
2121
}
2222

@@ -39,7 +39,7 @@ pub mod flipper {
3939

4040
#[ink::test]
4141
fn default_works() {
42-
let flipper = Flipper::default();
42+
let flipper = Flipper::new_default();
4343
assert!(!flipper.get());
4444
}
4545

@@ -51,4 +51,65 @@ pub mod flipper {
5151
assert!(flipper.get());
5252
}
5353
}
54+
55+
#[cfg(all(test, feature = "e2e-tests"))]
56+
mod e2e_tests {
57+
use super::*;
58+
use ink_e2e::build_message;
59+
60+
type E2EResult<T> = std::result::Result<T, Box<dyn std::error::Error>>;
61+
62+
#[ink_e2e::test]
63+
async fn it_works(mut client: ink_e2e::Client<C, E>) -> E2EResult<()> {
64+
// given
65+
let constructor = FlipperRef::new(false);
66+
let contract_acc_id = client
67+
.instantiate("flipper", &ink_e2e::alice(), constructor, 0, None)
68+
.await
69+
.expect("instantiate failed")
70+
.account_id;
71+
72+
let get = build_message::<FlipperRef>(contract_acc_id.clone())
73+
.call(|flipper| flipper.get());
74+
let get_res = client.call_dry_run(&ink_e2e::bob(), &get, 0, None).await;
75+
assert!(matches!(get_res.return_value(), false));
76+
77+
// when
78+
let flip = build_message::<FlipperRef>(contract_acc_id.clone())
79+
.call(|flipper| flipper.flip());
80+
let _flip_res = client
81+
.call(&ink_e2e::bob(), flip, 0, None)
82+
.await
83+
.expect("flip failed");
84+
85+
// then
86+
let get = build_message::<FlipperRef>(contract_acc_id.clone())
87+
.call(|flipper| flipper.get());
88+
let get_res = client.call_dry_run(&ink_e2e::bob(), &get, 0, None).await;
89+
assert!(matches!(get_res.return_value(), true));
90+
91+
Ok(())
92+
}
93+
94+
#[ink_e2e::test]
95+
async fn default_works(mut client: ink_e2e::Client<C, E>) -> E2EResult<()> {
96+
// given
97+
let constructor = FlipperRef::new_default();
98+
99+
// when
100+
let contract_acc_id = client
101+
.instantiate("flipper", &ink_e2e::bob(), constructor, 0, None)
102+
.await
103+
.expect("instantiate failed")
104+
.account_id;
105+
106+
// then
107+
let get = build_message::<FlipperRef>(contract_acc_id.clone())
108+
.call(|flipper| flipper.get());
109+
let get_res = client.call_dry_run(&ink_e2e::bob(), &get, 0, None).await;
110+
assert!(matches!(get_res.return_value(), false));
111+
112+
Ok(())
113+
}
114+
}
54115
}

0 commit comments

Comments
 (0)