@@ -16,7 +16,7 @@ pub mod flipper {
16
16
17
17
/// Creates a new flipper smart contract initialized to `false`.
18
18
#[ ink( constructor) ]
19
- pub fn default ( ) -> Self {
19
+ pub fn new_default ( ) -> Self {
20
20
Self :: new ( Default :: default ( ) )
21
21
}
22
22
@@ -39,7 +39,7 @@ pub mod flipper {
39
39
40
40
#[ ink:: test]
41
41
fn default_works ( ) {
42
- let flipper = Flipper :: default ( ) ;
42
+ let flipper = Flipper :: new_default ( ) ;
43
43
assert ! ( !flipper. get( ) ) ;
44
44
}
45
45
@@ -51,4 +51,65 @@ pub mod flipper {
51
51
assert ! ( flipper. get( ) ) ;
52
52
}
53
53
}
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
+ }
54
115
}
0 commit comments