@@ -56,28 +56,28 @@ fun test_create() {
56
56
57
57
// Create a ColorObject and transfer it to its owner.
58
58
{
59
- ts:: next_tx (& mut ts, alice);
60
- let color = new (255 , 0 , 255 , ts:: ctx (& mut ts ));
59
+ ts. next_tx (alice);
60
+ let color = new (255 , 0 , 255 , ts. ctx ());
61
61
transfer::public_transfer (color, alice);
62
62
};
63
63
64
64
// Check that @not_owner does not own the just-created ColorObject.
65
65
{
66
- ts:: next_tx (& mut ts, bob);
67
- assert !(!ts:: has_most_recent_for_sender <ColorObject >(&ts ), 0 );
66
+ ts. next_tx (bob);
67
+ assert !(!ts. has_most_recent_for_sender <ColorObject >(), 0 );
68
68
};
69
69
70
70
// Check that owner indeed owns the just-created ColorObject.
71
71
// Also checks the value fields of the object.
72
72
{
73
- ts:: next_tx (& mut ts, alice);
74
- let object: ColorObject = ts:: take_from_sender (&ts );
75
- let (red, green, blue) = get_color (&object );
73
+ ts. next_tx (alice);
74
+ let object: ColorObject = ts. take_from_sender ();
75
+ let (red, green, blue) = object. get_color ();
76
76
assert !(red == 255 && green == 0 && blue == 255 , 0 );
77
- ts:: return_to_sender (&ts, object);
77
+ ts. return_to_sender (object)
78
78
};
79
79
80
- ts:: end (ts );
80
+ ts. end ();
81
81
}
82
82
83
83
// === Tests covered in Chapter 2 ===
@@ -89,45 +89,41 @@ fun test_copy_into() {
89
89
90
90
// Create two ColorObjects owned by `owner`, and obtain their IDs.
91
91
let (id1, id2) = {
92
- ts:: next_tx (& mut ts, owner);
93
- let ctx = ts:: ctx (& mut ts );
92
+ ts. next_tx (owner);
93
+ let ctx = ts. ctx ();
94
94
95
95
let c = new (255 , 255 , 255 , ctx);
96
96
transfer::public_transfer (c, owner);
97
- let id1 = object::id_from_address (
98
- tx_context::last_created_object_id (ctx),
99
- );
97
+ let id1 = object::id_from_address (ctx.last_created_object_id ());
100
98
101
99
let c = new (0 , 0 , 0 , ctx);
102
100
transfer::public_transfer (c, owner);
103
- let id2 = object::id_from_address (
104
- tx_context::last_created_object_id (ctx),
105
- );
101
+ let id2 = object::id_from_address (ctx.last_created_object_id ());
106
102
107
103
(id1, id2)
108
104
};
109
105
110
106
{
111
- ts:: next_tx (& mut ts, owner);
112
- let mut obj1: ColorObject = ts:: take_from_sender_by_id (&ts, id1);
113
- let obj2: ColorObject = ts:: take_from_sender_by_id (&ts, id2);
114
- let (red, green, blue) = get_color (&obj1 );
107
+ ts. next_tx (owner);
108
+ let mut obj1: ColorObject = ts. take_from_sender_by_id (id1);
109
+ let obj2: ColorObject = ts. take_from_sender_by_id (id2);
110
+ let (red, green, blue) = obj1. get_color ();
115
111
assert !(red == 255 && green == 255 && blue == 255 , 0 );
116
112
117
- copy_into (&obj2, &mut obj1);
118
- ts:: return_to_sender (&ts, obj1);
119
- ts:: return_to_sender (&ts, obj2);
113
+ obj2. copy_into (&mut obj1);
114
+ ts. return_to_sender (obj1);
115
+ ts. return_to_sender (obj2);
120
116
};
121
117
122
118
{
123
- ts:: next_tx (& mut ts, owner);
124
- let obj1: ColorObject = ts:: take_from_sender_by_id (&ts, id1);
125
- let (red, green, blue) = get_color (&obj1 );
119
+ ts. next_tx (owner);
120
+ let obj1: ColorObject = ts. take_from_sender_by_id (id1);
121
+ let (red, green, blue) = obj1. get_color ();
126
122
assert !(red == 0 && green == 0 && blue == 0 , 0 );
127
- ts:: return_to_sender (&ts, obj1);
123
+ ts. return_to_sender (obj1);
128
124
};
129
125
130
- ts:: end (ts );
126
+ ts. end ();
131
127
}
132
128
133
129
#[test]
@@ -137,25 +133,25 @@ fun test_delete() {
137
133
138
134
// Create a ColorObject and transfer it to owner.
139
135
{
140
- ts:: next_tx (& mut ts, owner);
141
- let c = new (255 , 0 , 255 , ts:: ctx (& mut ts ));
136
+ ts. next_tx (owner);
137
+ let c = new (255 , 0 , 255 , ts. ctx ());
142
138
transfer::public_transfer (c, owner);
143
139
};
144
140
145
141
// Delete the ColorObject we just created.
146
142
{
147
- ts:: next_tx (& mut ts, owner);
148
- let object: ColorObject = ts:: take_from_sender (&ts );
143
+ ts. next_tx (owner);
144
+ let object: ColorObject = ts. take_from_sender ();
149
145
delete (object);
150
146
};
151
147
152
148
// Verify that the object was indeed deleted.
153
149
{
154
- ts:: next_tx (& mut ts, owner);
155
- assert !(!ts:: has_most_recent_for_sender <ColorObject >(&ts ), 0 );
150
+ ts. next_tx (owner);
151
+ assert !(!ts. has_most_recent_for_sender <ColorObject >(), 0 );
156
152
};
157
153
158
- ts:: end (ts );
154
+ ts. end ();
159
155
}
160
156
161
157
#[test]
@@ -166,31 +162,31 @@ fun test_transfer() {
166
162
167
163
// Create a ColorObject and transfer it to sender.
168
164
{
169
- ts:: next_tx (& mut ts, sender);
170
- let c = new (255 , 0 , 255 , ts:: ctx (& mut ts ));
165
+ ts. next_tx (sender);
166
+ let c = new (255 , 0 , 255 , ts. ctx ());
171
167
transfer::public_transfer (c, @0xA );
172
168
};
173
169
174
170
// Transfer the object to recipient.
175
171
{
176
- ts:: next_tx (& mut ts, sender);
177
- let object: ColorObject = ts:: take_from_sender (&ts );
172
+ ts. next_tx (sender);
173
+ let object: ColorObject = ts. take_from_sender ();
178
174
transfer::public_transfer (object, recipient);
179
175
};
180
176
181
177
// Check that sender no longer owns the object.
182
178
{
183
- ts:: next_tx (& mut ts, sender);
184
- assert !(!ts:: has_most_recent_for_sender <ColorObject >(&ts ), 0 );
179
+ ts. next_tx (sender);
180
+ assert !(!ts. has_most_recent_for_sender <ColorObject >(), 0 );
185
181
};
186
182
187
183
// Check that recipient now owns the object.
188
184
{
189
- ts:: next_tx (& mut ts, recipient);
190
- assert !(ts:: has_most_recent_for_sender <ColorObject >(&ts ), 0 );
185
+ ts. next_tx (recipient);
186
+ assert !(ts. has_most_recent_for_sender <ColorObject >(), 0 );
191
187
};
192
188
193
- ts:: end (ts );
189
+ ts. end ();
194
190
}
195
191
196
192
// === Tests covered in Chapter 3 ===
@@ -202,25 +198,25 @@ fun test_immutable() {
202
198
let bob = @0xB ;
203
199
204
200
{
205
- ts:: next_tx (& mut ts, alice);
206
- let c = new (255 , 0 , 255 , ts:: ctx (& mut ts ));
201
+ ts. next_tx (alice);
202
+ let c = new (255 , 0 , 255 , ts. ctx ());
207
203
transfer::public_freeze_object (c);
208
204
};
209
205
210
206
// take_owned does not work for immutable objects.
211
207
{
212
- ts:: next_tx (& mut ts, alice);
213
- assert !(!ts:: has_most_recent_for_sender <ColorObject >(&ts ), 0 );
208
+ ts. next_tx (alice);
209
+ assert !(!ts. has_most_recent_for_sender <ColorObject >(), 0 );
214
210
};
215
211
216
212
// Any sender can work.
217
213
{
218
- ts:: next_tx (& mut ts, bob);
219
- let object: ColorObject = ts:: take_immutable (&ts );
220
- let (red, green, blue) = get_color (&object );
214
+ ts. next_tx (bob);
215
+ let object: ColorObject = ts. take_immutable ();
216
+ let (red, green, blue) = object. get_color ();
221
217
assert !(red == 255 && green == 0 && blue == 255 , 0 );
222
218
ts::return_immutable (object);
223
219
};
224
220
225
- ts:: end (ts );
221
+ ts. end ();
226
222
}
0 commit comments