@@ -53,7 +53,7 @@ pub struct FirstLast {
5353
5454pub struct CustomTypesContract ;
5555
56- const NAME : Symbol = symbol! (" NAME" );
56+ const NAME : Symbol = Symbol :: from_str (" NAME" );
5757
5858#[contractimpl]
5959impl CustomTypesContract {
@@ -123,9 +123,9 @@ retrieved later.
123123``` rust
124124pub struct CustomTypesContract ;
125125
126- const NAME : Symbol = symbol! (" NAME" );
126+ const NAME : Symbol = Symbol :: from_str (" NAME" );
127127
128- #[contractimpl]
128+ #[contractimpl(export_if = " export " ) ]
129129impl CustomTypesContract {
130130 pub fn store (env : Env , name : Name ) {
131131 env . contract_data (). set (NAME , name );
@@ -148,22 +148,25 @@ Open the `custom_types/src/test.rs` file to follow along.
148148#[test]
149149fn test () {
150150 let env = Env :: default ();
151- let contract_id = BytesN :: from_array (& env , & [0 ; 32 ]);
151+ let contract_id = FixedBinary :: from_array (& env , [0 ; 32 ]);
152152 env . register_contract (& contract_id , CustomTypesContract );
153- let client = CustomTypesContractClient :: new (& env , & contract_id );
154153
155- assert_eq! (client . retrieve ( ), Name :: None );
154+ assert_eq! (retrieve :: invoke ( & env , & contract_id ), Name :: None );
156155
157- client . store (& Name :: FirstLast (FirstLast {
158- first : symbol! (" first" ),
159- last : symbol! (" last" ),
160- }));
156+ store :: invoke (
157+ & env ,
158+ & contract_id ,
159+ & Name :: FirstLast (FirstLast {
160+ first : Symbol :: from_str (" first" ),
161+ last : Symbol :: from_str (" last" ),
162+ }),
163+ );
161164
162165 assert_eq! (
163- client . retrieve ( ),
166+ retrieve :: invoke ( & env , & contract_id ),
164167 Name :: FirstLast (FirstLast {
165- first : symbol! (" first" ),
166- last : symbol! (" last" ),
168+ first : Symbol :: from_str (" first" ),
169+ last : Symbol :: from_str (" last" ),
167170 }),
168171 );
169172}
@@ -180,46 +183,44 @@ Contracts must be registered with the environment with a contract ID, which is a
18018332-byte value.
181184
182185``` rust
183- let contract_id = BytesN :: from_array (& env , [0 ; 32 ]);
184- env . register_contract (& contract_id , CustomTypesContract );
186+ let contract_id = FixedBinary :: from_array (& env , [0 ; 32 ]);
187+ env . register_contract (& contract_id , HelloContract );
185188```
186189
187190All public functions within an ` impl ` block that is annotated with the
188- ` #[contractimpl] ` attribute have a corresponding function generated in a
189- generated client type. The client type will be named the same as the contract
190- type with ` Client ` appended. For example, in our contract the contract type is
191- ` CustomTypesContract ` , and the client is named ` CustomTypesContractClient ` .
192-
193- ``` rust
194- let client = CustomTypesContractClient :: new (& env , & contract_id );
195- ```
191+ ` #[contractimpl] ` attribute have an ` invoke ` function generated, that can be
192+ used to invoke the contract function within the environment.
196193
197194The test invokes the ` retrieve ` function on the registered contract, and asserts
198195that it returns ` Name::None ` .
199196
200197``` rust
201- assert_eq! (client . retrieve ( ), Name :: None );
198+ assert_eq! (retrieve :: invoke ( & env , & contract_id ), Name :: None );
202199```
203200
204201The test then invokes the ` store ` function on the registered contract, to change
205202the name that is stored.
206203
207204``` rust
208- client . store (& Name :: FirstLast (FirstLast {
209- first : symbol! (" first" ),
210- last : symbol! (" last" ),
211- }));
205+ store :: invoke (
206+ & env ,
207+ & contract_id ,
208+ & Name :: FirstLast (FirstLast {
209+ first : Symbol :: from_str (" first" ),
210+ last : Symbol :: from_str (" last" ),
211+ }),
212+ );
212213```
213214
214215The test invokes the ` retrieve ` function again, to assert that it returns the
215216name that was previously stored.
216217
217218``` rust
218219assert_eq! (
219- client . retrieve ( ),
220+ retrieve :: invoke ( & env , & contract_id ),
220221 Name :: FirstLast (FirstLast {
221- first : symbol! (" first" ),
222- last : symbol! (" last" ),
222+ first : Symbol :: from_str (" first" ),
223+ last : Symbol :: from_str (" last" ),
223224 }),
224225);
225226```
0 commit comments