@@ -117,7 +117,10 @@ access(all) contract interface FungibleToken: ViewResolver {
117
117
post {
118
118
// `result` refers to the return value
119
119
result.balance == amount:
120
- " Withdrawal amount must be the same as the balance of the withdrawn Vault"
120
+ " FungibleToken.Provider.withdraw: Cannot withdraw tokens!"
121
+ .concat (" The balance of the withdrawn tokens (" ).concat (result.balance.toString ())
122
+ .concat (" ) is not equal to the amount requested to be withdrawn (" )
123
+ .concat (amount.toString ()).concat (" )" )
121
124
}
122
125
}
123
126
}
@@ -178,7 +181,9 @@ access(all) contract interface FungibleToken: ViewResolver {
178
181
emit Burned (type : self .getType ().identifier, amount : self .balance, fromUUID : self .uuid)
179
182
}
180
183
post {
181
- self .balance == 0 .0 : " The balance must be set to zero during the burnCallback method so that it cannot be spammed"
184
+ self .balance == 0 .0 :
185
+ " FungibleToken.Vault.burnCallback: Cannot burn this Vault with Burner.burn()."
186
+ .concat (" The balance must be set to zero during the burnCallback method so that it cannot be spammed" )
182
187
}
183
188
self .balance = 0 .0
184
189
}
@@ -211,15 +216,29 @@ access(all) contract interface FungibleToken: ViewResolver {
211
216
access (Withdraw) fun withdraw (amount : UFix64 ): @{Vault} {
212
217
pre {
213
218
self .balance > = amount:
214
- " Amount withdrawn must be less than or equal than the balance of the Vault"
219
+ " FungibleToken.Vault.withdraw: Cannot withdraw tokens! "
220
+ .concat (" The amount requested to be withdrawn (" ).concat (amount.toString ())
221
+ .concat (" ) is greater than the balance of the Vault (" )
222
+ .concat (self .balance.toString ()).concat (" )." )
215
223
}
216
224
post {
217
- result.getType () == self .getType (): " Must return the same vault type as self"
225
+ result.getType () == self .getType ():
226
+ " FungibleToken.Vault.withdraw: Cannot withdraw tokens!"
227
+ .concat (" The withdraw method tried to return an incompatible Vault type <" )
228
+ .concat (result.getType ().identifier).concat (" >. " )
229
+ .concat (" It must return a Vault with the same type as self (" )
230
+ .concat (self .getType ().identifier).concat (" >." )
231
+
218
232
// use the special function `before` to get the value of the `balance` field
219
233
// at the beginning of the function execution
220
234
//
221
235
self .balance == before (self .balance) - amount:
222
- " New Vault balance must be the difference of the previous balance and the withdrawn Vault balance"
236
+ " FungibleToken.Vault.withdraw: Cannot withdraw tokens!"
237
+ .concat (" The sender's balance after the withdrawal (" )
238
+ .concat (self .balance.toString ())
239
+ .concat (" ) must be the difference of the previous balance (" ).concat (before (self .balance.toString ()))
240
+ .concat (" ) and the amount withdrawn (" ).concat (amount.toString ())
241
+
223
242
emit Withdrawn (
224
243
type : result.getType ().identifier,
225
244
amount : amount,
@@ -238,7 +257,13 @@ access(all) contract interface FungibleToken: ViewResolver {
238
257
// as the vault that is accepting the deposit
239
258
pre {
240
259
from .isInstance (self .getType ()):
241
- " Cannot deposit an incompatible token type"
260
+ " FungibleToken.Vault.deposit: Cannot deposit tokens!"
261
+ .concat (" The type of the deposited tokens <" )
262
+ .concat (from.getType ().identifier)
263
+ .concat (" > has to be the same type as the Vault being deposited into <" )
264
+ .concat (self .getType ().identifier)
265
+ .concat (" >. Check that you are withdrawing and depositing to the correct paths in the sender and receiver accounts" )
266
+ .concat (" and that those paths hold the same Vault types." )
242
267
}
243
268
post {
244
269
emit Deposited (
@@ -250,7 +275,11 @@ access(all) contract interface FungibleToken: ViewResolver {
250
275
balanceAfter : self .balance
251
276
)
252
277
self .balance == before (self .balance) + before (from.balance):
253
- " New Vault balance must be the sum of the previous balance and the deposited Vault"
278
+ " FungibleToken.Vault.deposit: Cannot deposit tokens!"
279
+ .concat (" The receiver's balance after the deposit (" )
280
+ .concat (self .balance.toString ())
281
+ .concat (" ) must be the sum of the previous balance (" ).concat (before (self .balance.toString ()))
282
+ .concat (" ) and the amount deposited (" ).concat (before (from.balance).toString ())
254
283
}
255
284
}
256
285
@@ -259,8 +288,18 @@ access(all) contract interface FungibleToken: ViewResolver {
259
288
/// @return A Vault of the same type that has a balance of zero
260
289
access (all) fun createEmptyVault (): @{Vault} {
261
290
post {
262
- result.balance == 0 .0 : " The newly created Vault must have zero balance"
263
- result.getType () == self .getType (): " The newly created Vault must have the same type as the creating vault"
291
+ result.balance == 0 .0 :
292
+ " FungibleToken.Vault.createEmptyVault: Empty Vault creation failed!"
293
+ .concat (" The newly created Vault must have zero balance but it has a balance of " )
294
+ .concat (result.balance.toString ())
295
+
296
+ result.getType () == self .getType ():
297
+ " FungibleToken.Vault.createEmptyVault: Empty Vault creation failed!"
298
+ .concat (" The type of the new Vault <" )
299
+ .concat (result.getType ().identifier)
300
+ .concat (" > has to be the same type as the Vault that created it <" )
301
+ .concat (self .getType ().identifier)
302
+ .concat (" >." )
264
303
}
265
304
}
266
305
}
@@ -270,8 +309,18 @@ access(all) contract interface FungibleToken: ViewResolver {
270
309
/// @return A Vault of the requested type that has a balance of zero
271
310
access (all) fun createEmptyVault (vaultType : Type ): @{FungibleToken.Vault} {
272
311
post {
273
- result.getType () == vaultType: " The returned vault does not match the desired type"
274
- result.balance == 0 .0 : " The newly created Vault must have zero balance"
312
+ result.balance == 0 .0 :
313
+ " FungibleToken.createEmptyVault: Empty Vault creation failed!"
314
+ .concat (" The newly created Vault must have zero balance but it has a balance of " )
315
+ .concat (result.balance.toString ())
316
+
317
+ result.getType () == vaultType:
318
+ " FungibleToken.Vault.createEmptyVault: Empty Vault creation failed!"
319
+ .concat (" The type of the new Vault <" )
320
+ .concat (result.getType ().identifier)
321
+ .concat (" > has to be the same as the type that was requested <" )
322
+ .concat (vaultType.identifier)
323
+ .concat (" >." )
275
324
}
276
325
}
277
326
}
0 commit comments