antelope 0.2.0

Antelope Standard Library
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
use crate::{check, Asset, ExtendedSymbol, Name, ParseError};
use std::str::FromStr;

/// The `ExtendedAsset` struct represents an extended asset
///
/// Reference: <https://github.com/AntelopeIO/cdt/blob/main/libraries/eosiolib/core/eosio/asset.hpp>
///
/// # Examples
///
/// ```
/// use antelope::{ExtendedAsset, Name, Symbol, ExtendedSymbol};
///
/// let ext_asset = ExtendedAsset::from_amount(10000, ExtendedSymbol::from_extended(Symbol::from("4,FOO"), Name::from("contract")));
/// assert_eq!(10000, ext_asset.quantity.amount);
/// ```
#[derive(Eq, Copy, Clone, Debug, Default)]
pub struct ExtendedAsset {
    /**
     * The asset
     */
    pub quantity: Asset,
    /**
     * The contract for the asset
     */
    pub contract: Name,
}

impl ExtendedAsset {
    /**
     * Default constructor
     */
    #[inline]
    #[must_use]
    pub fn new() -> Self {
        Self {
            quantity: Asset::new(),
            contract: Name::new(),
        }
    }

    /**
     * Construct a new extended asset given the asset and owner name
     */
    #[inline]
    #[must_use]
    pub fn from_asset(quantity: Asset, contract: Name) -> Self {
        ExtendedAsset { quantity, contract }
    }

    /**
     * Construct a new extended asset given the amount and extended symbol
     */
    #[inline]
    #[must_use]
    pub fn from_amount(amount: i64, extended_symbol: ExtendedSymbol) -> Self {
        ExtendedAsset {
            quantity: Asset::from_amount(amount, extended_symbol.get_symbol()),
            contract: extended_symbol.get_contract(),
        }
    }

    /**
     * Get the extended symbol of the asset
     *
     * @return extended_symbol - The extended symbol of the asset
     */
    #[inline]
    #[must_use]
    pub fn get_extended_symbol(&self) -> ExtendedSymbol {
        ExtendedSymbol::from_extended(self.quantity.symbol, self.contract)
    }

    /**
     * Check if the extended asset is valid. %A valid extended asset has valid quantity and contract
     *
     * @return true - if the extended asset is valid
     * @return false - otherwise
     */
    #[inline]
    #[must_use]
    pub fn is_valid(&self) -> bool {
        self.quantity.is_valid() && self.contract.raw() != 0
    }
}

impl std::fmt::Display for ExtendedAsset {
    /**
     * Converts the extended asset into string
     *
     * @return String in the form of "1.2345 SYM@contract" format
     */
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        write!(f, "{}@{}", self.quantity, self.contract)
    }
}

impl FromStr for ExtendedAsset {
    type Err = ParseError;

    /**
     * Parse ExtendedAsset from string formatted as "1.2345 SYM@contract"
     *
     */
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        let parts: Vec<&str> = s.split('@').collect();
        if parts.len() != 2 {
            return Err(ParseError::BadFormat);
        }

        let quantity = match Asset::from_str(parts[0]) {
            Ok(asset) => asset,
            Err(_) => return Err(ParseError::BadAsset(parts[0].to_string())),
        };
        let contract = match Name::from_str(parts[1]) {
            Ok(name) => name,
            Err(_) => return Err(ParseError::BadName(parts[1].to_string())),
        };

        Ok(ExtendedAsset::from_asset(quantity, contract))
    }
}

impl From<&str> for ExtendedAsset {
    /**
     * Parse ExtendedAsset from string formatted as "1.2345 SYM@contract"
     *
     */
    fn from(s: &str) -> Self {
        Self::from_str(s).unwrap_or_else(|e| panic!("failed to parse extended asset: {}", e))
    }
}

impl AsRef<ExtendedAsset> for ExtendedAsset {
    #[inline]
    #[must_use]
    fn as_ref(&self) -> &ExtendedAsset {
        self
    }
}

impl std::cmp::PartialEq for ExtendedAsset {
    fn eq(&self, other: &ExtendedAsset) -> bool {
        check(self.contract == other.contract, "type mismatch");
        self.quantity == other.quantity
    }
}

impl std::cmp::PartialOrd for ExtendedAsset {
    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
        Some(self.cmp(other))
    }
}

impl std::cmp::Ord for ExtendedAsset {
    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
        check(self.contract == other.contract, "type mismatch");
        self.quantity.cmp(&other.quantity)
    }
}

impl std::ops::SubAssign for ExtendedAsset {
    /**
     * Subtraction assignment operator
     *
     * @param other - Another extended asset to subtract this extended asset with
     * @post The amount of this extended asset is subtracted by the amount of extended asset `other`
     */
    fn sub_assign(&mut self, other: ExtendedAsset) {
        check(self.contract == other.contract, "type mismatch");
        self.quantity -= other.quantity;
    }
}

impl std::ops::AddAssign for ExtendedAsset {
    /**
     * Addition assignment operator
     *
     * @param other - Another extended asset to add this extended asset with
     * @post The amount of this extended asset is subtracted by the amount of extended asset `other`
     */
    fn add_assign(&mut self, other: ExtendedAsset) {
        check(self.contract == other.contract, "type mismatch");
        self.quantity += other.quantity;
    }
}

impl std::ops::MulAssign<i64> for ExtendedAsset {
    /**
     * Multiplication assignment operator, with a number
     *
     * @details Multiplication assignment operator. Multiply the amount of this asset with a number and then assign the value to itself.
     * @param a - The multiplier for the asset's amount
     * @return asset - Reference to this asset
     * @post The amount of this asset is multiplied by a
     */
    fn mul_assign(&mut self, a: i64) {
        self.quantity *= a;
    }
}

impl std::ops::DivAssign<i64> for ExtendedAsset {
    /**
     * Division assignment operator, with a number proceeding
     *
     * @brief Division assignment operator, with a number proceeding
     * @param self - The asset to be divided
     * @param a - The divisor for the asset's amount
     * @return asset - Reference to the asset, which has been divided
     */
    fn div_assign(&mut self, a: i64) {
        self.quantity /= a;
    }
}

impl std::ops::Neg for ExtendedAsset {
    type Output = ExtendedAsset;
    /**
     * Negate the amount of the asset
     *
     * @return a new asset with the negated amount
     */
    fn neg(self) -> ExtendedAsset {
        ExtendedAsset {
            quantity: -self.quantity,
            contract: self.contract,
        }
    }
}

impl std::ops::Add for ExtendedAsset {
    type Output = Self;

    /**
     * Addition operator
     *
     * @param other - The second asset to be added to the first asset
     * @return asset - New asset as the result of addition
     */
    fn add(self, other: Self) -> Self {
        check(self.contract == other.contract, "type mismatch");
        let mut result = self;
        result += other;
        result
    }
}

impl std::ops::Sub for ExtendedAsset {
    type Output = Self;

    /**
     * Addition operator
     *
     * @param other - The second asset to be added to the first asset
     * @return asset - New asset as the result of addition
     */
    fn sub(self, other: Self) -> Self {
        check(self.contract == other.contract, "type mismatch");
        let mut result = self;
        result -= other;
        result
    }
}

impl std::ops::Mul<i64> for ExtendedAsset {
    type Output = ExtendedAsset;

    /**
     * Multiplication operator, with a number proceeding
     *
     * @brief Multiplication operator, with a number proceeding
     * @param a - The asset to be multiplied
     * @param b - The multiplier for the asset's amount
     * @return asset - New asset as the result of multiplication
     */
    fn mul(self, b: i64) -> ExtendedAsset {
        let mut result = self;
        result *= b;
        result
    }
}

impl std::ops::Mul<ExtendedAsset> for i64 {
    type Output = ExtendedAsset;

    /**
     * Multiplication operator, with a number preceeding
     *
     * @param a - The multiplier for the asset's amount
     * @param b - The asset to be multiplied
     * @return asset - New asset as the result of multiplication
     */
    fn mul(self, a: ExtendedAsset) -> ExtendedAsset {
        a * self
    }
}

impl std::ops::Div<i64> for ExtendedAsset {
    type Output = ExtendedAsset;

    /**
     * Division operator, with a number proceeding
     *
     * @param a - The asset to be divided
     * @param b - The divisor for the asset's amount
     * @return asset - New asset as the result of division
     */
    fn div(self, b: i64) -> ExtendedAsset {
        let mut result = self;
        result /= b;
        result
    }
}

impl std::ops::Div<ExtendedAsset> for ExtendedAsset {
    type Output = i64;

    /**
     * Division operator, with another asset
     *
     * @param a - The asset which amount acts as the dividend
     * @param b - The asset which amount acts as the divisor
     * @return int64_t - the resulted amount after the division
     * @pre Both asset must have the same symbol
     */
    fn div(self, other: ExtendedAsset) -> Self::Output {
        check(self.contract == other.contract, "type mismatch");
        self.quantity / other.quantity
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::{Symbol, SymbolCode};

    #[test]
    fn test_new_extended_asset() {
        let asset = ExtendedAsset::new();
        assert_eq!(asset.quantity, Asset::new());
        assert_eq!(asset.contract, Name::new());
    }

    #[test]
    fn test_from_asset() {
        let quantity = Asset::from_amount(1234567, Symbol::from("4,SYM"));
        let contract = Name::from("contract");
        let asset = ExtendedAsset::from_asset(quantity, contract);
        assert_eq!(asset.quantity, quantity);
        assert_eq!(asset.contract, contract);
    }

    #[test]
    fn test_from_amount() {
        let extended_symbol = ExtendedSymbol::from_extended(Symbol::from("4,SYM"), Name::from("contract"));
        let asset = ExtendedAsset::from_amount(1234567, extended_symbol);
        assert_eq!(asset.quantity, Asset::from_amount(1234567, extended_symbol.get_symbol()));
        assert_eq!(asset.contract, extended_symbol.get_contract());
        assert_eq!(asset.quantity.amount, 1234567);
    }

    #[test]
    fn test_get_extended_symbol() {
        let extended_symbol = ExtendedSymbol::from_extended(Symbol::from("4,SYM"), Name::from("contract"));
        let asset = ExtendedAsset::from_amount(1234567, extended_symbol);
        assert_eq!(asset.get_extended_symbol(), extended_symbol);
    }

    #[test]
    fn test_ord() {
        let a = ExtendedAsset::from_amount(100, ExtendedSymbol::from_extended(Symbol::from("4,SYM"), Name::from("contract")));
        let b = ExtendedAsset::from_amount(200, ExtendedSymbol::from_extended(Symbol::from("4,SYM"), Name::from("contract")));
        let c = ExtendedAsset::from_amount(200, ExtendedSymbol::from_extended(Symbol::from("4,SYM"), Name::from("contract")));

        assert!(a < b);
        assert!(b > a);
        assert!(b == c);
        assert!(b != a);
    }

    #[test]
    #[should_panic(expected = "comparison of assets with different symbols is not allowed")]
    fn test_ord_panic1() {
        let a = ExtendedAsset::from_amount(100, ExtendedSymbol::from_extended(Symbol::from("4,SYM"), Name::from("contract")));
        let b = ExtendedAsset::from_amount(100, ExtendedSymbol::from_extended(Symbol::from("5,SYM"), Name::from("contract")));

        assert!(a != b);
    }
    #[test]
    #[should_panic(expected = "comparison of assets with different symbols is not allowed")]
    fn test_ord_panic2() {
        let a = ExtendedAsset::from_amount(100, ExtendedSymbol::from_extended(Symbol::from("4,SYM"), Name::from("contract")));
        let b = ExtendedAsset::from_amount(200, ExtendedSymbol::from_extended(Symbol::from("5,SYM"), Name::from("contract")));

        assert!(a < b);
    }
    #[test]
    #[should_panic(expected = "comparison of assets with different symbols is not allowed")]
    fn test_ord_panic3() {
        let a = ExtendedAsset::from_amount(100, ExtendedSymbol::from_extended(Symbol::from("4,SYM"), Name::from("contract")));
        let b = ExtendedAsset::from_amount(100, ExtendedSymbol::from_extended(Symbol::from("5,SYM"), Name::from("contract")));

        assert!(a <= b);
    }
    #[test]
    #[should_panic(expected = "type mismatch")]
    fn test_ord_panic4() {
        let a = ExtendedAsset::from_amount(100, ExtendedSymbol::from_extended(Symbol::from("4,SYM"), Name::from("contract1")));
        let b = ExtendedAsset::from_amount(100, ExtendedSymbol::from_extended(Symbol::from("4,SYM"), Name::from("contract2")));

        assert!(a != b);
    }
    #[test]
    #[should_panic(expected = "type mismatch")]
    fn test_ord_panic5() {
        let a = ExtendedAsset::from_amount(100, ExtendedSymbol::from_extended(Symbol::from("4,SYM"), Name::from("contract1")));
        let b = ExtendedAsset::from_amount(200, ExtendedSymbol::from_extended(Symbol::from("4,SYM"), Name::from("contract2")));

        assert!(a < b);
    }
    #[test]
    #[should_panic(expected = "type mismatch")]
    fn test_ord_panic6() {
        let a = ExtendedAsset::from_amount(100, ExtendedSymbol::from_extended(Symbol::from("4,SYM"), Name::from("contract1")));
        let b = ExtendedAsset::from_amount(200, ExtendedSymbol::from_extended(Symbol::from("4,SYM"), Name::from("contract2")));

        assert!(a <= b);
    }

    #[test]
    fn test_partial_ord() {
        let a = ExtendedAsset::from_amount(100, ExtendedSymbol::from_extended(Symbol::from("4,SYM"), Name::from("contract")));
        let b = ExtendedAsset::from_amount(200, ExtendedSymbol::from_extended(Symbol::from("4,SYM"), Name::from("contract")));
        let c = ExtendedAsset::from_amount(200, ExtendedSymbol::from_extended(Symbol::from("4,SYM"), Name::from("contract")));

        assert!(a <= b);
        assert!(b >= a);
        assert!(b > a);
        assert!(b >= c);
        assert!(a < b);
        assert!(c <= b);
    }

    #[test]
    fn test_is_valid() {
        assert!(ExtendedAsset::from_amount(100, ExtendedSymbol::from("4,SYM@contract")).is_valid());
        assert!(ExtendedAsset::from_asset(Asset::from_amount(1234567, Symbol::from("4,SYM")), Name::from("contract")).is_valid());
        assert!(!ExtendedAsset::from_asset(Asset::from_amount(1234567, Symbol::from("4,SYM")), Name::new()).is_valid());
        assert!(!ExtendedAsset::from_asset(Asset::new(), Name::from("contract")).is_valid());
        assert!(!ExtendedAsset::from_asset(Asset::default(), Name::default()).is_valid());
    }

    #[test]
    fn test_to_string() {
        assert_eq!(
            ExtendedAsset::from_amount(10000, ExtendedSymbol::from("4,SYM@contract")).to_string(),
            "1.0000 SYM@contract"
        );
        assert_eq!(
            ExtendedAsset::from_amount(0, ExtendedSymbol::from("4,SYM@contract")).to_string(),
            "0.0000 SYM@contract"
        );
        assert_eq!(
            ExtendedAsset::from_amount(1, ExtendedSymbol::from("0,SYM@contract")).to_string(),
            "1 SYM@contract"
        );
        assert_eq!(
            ExtendedAsset::from_asset(Asset::new(), Name::from("contract")).to_string(),
            "0 @contract"
        );
        assert_eq!(ExtendedAsset::from_asset(Asset::default(), Name::default()).to_string(), "0 @");
    }

    #[test]
    fn test_sub_assign() {
        let mut asset1 = ExtendedAsset::from_amount(10000, ExtendedSymbol::from("4,SYM@contract"));
        let asset2 = ExtendedAsset::from_amount(20000, ExtendedSymbol::from("4,SYM@contract"));
        asset1 -= asset2;

        assert_eq!(asset1.quantity.amount, -10000);
    }

    #[test]
    fn test_add_assign() {
        let mut asset1 = ExtendedAsset::from_amount(10000, ExtendedSymbol::from("4,SYM@contract"));
        let asset2 = ExtendedAsset::from_amount(20000, ExtendedSymbol::from("4,SYM@contract"));
        asset1 += asset2;

        assert_eq!(asset1.quantity.amount, 30000);
        assert_eq!(asset1.to_string(), "3.0000 SYM@contract");
    }

    #[test]
    fn test_mul_assign() {
        let mut asset1 = ExtendedAsset::from_amount(10000, ExtendedSymbol::from("4,SYM@contract"));
        asset1 /= 2;

        assert_eq!(asset1.quantity.amount, 5000);
        assert_eq!(asset1.to_string(), "0.5000 SYM@contract");
    }

    #[test]
    fn test_div_assign() {
        let mut asset1 = ExtendedAsset::from_amount(10000, ExtendedSymbol::from("4,SYM@contract"));
        asset1 *= 2;

        assert_eq!(asset1.quantity.amount, 20000);
        assert_eq!(asset1.to_string(), "2.0000 SYM@contract");
    }

    #[test]
    fn test_neg() {
        let mut asset1 = ExtendedAsset::from_amount(10000, ExtendedSymbol::from("4,SYM@contract"));
        asset1 = -asset1;

        assert_eq!(asset1.quantity.amount, -10000);
        assert_eq!(asset1.to_string(), "-1.0000 SYM@contract");
    }

    #[test]
    fn test_add_operator() {
        let asset1 = ExtendedAsset::from_amount(10000, ExtendedSymbol::from("4,SYM@contract"));
        let asset2 = ExtendedAsset::from_amount(20000, ExtendedSymbol::from("4,SYM@contract"));

        let result = asset1 + asset2;
        assert_eq!(result.quantity.amount, 30000);
        assert_eq!(result.to_string(), "3.0000 SYM@contract");
    }

    #[test]
    fn test_sub_operator() {
        let asset1 = ExtendedAsset::from_amount(10000, ExtendedSymbol::from("4,SYM@contract"));
        let asset2 = ExtendedAsset::from_amount(20000, ExtendedSymbol::from("4,SYM@contract"));

        let result = asset1 - asset2;
        assert_eq!(result.quantity.amount, -10000);
        assert_eq!(result.to_string(), "-1.0000 SYM@contract");
    }

    #[test]
    fn test_div_operator() {
        let asset1 = ExtendedAsset::from_amount(10000, ExtendedSymbol::from("4,SYM@contract"));
        let asset2 = ExtendedAsset::from_amount(20000, ExtendedSymbol::from("4,SYM@contract"));

        let result = asset2 / asset1;
        assert_eq!(result, 2);
    }

    #[test]
    fn test_mul_operator() {
        let asset1 = ExtendedAsset::from_amount(10000, ExtendedSymbol::from("4,SYM@contract"));

        let result = asset1 * 2;
        assert_eq!(result.quantity.amount, 20000);
        assert_eq!(result.to_string(), "2.0000 SYM@contract");
    }

    #[test]
    fn test_div_operator2() {
        let asset1 = ExtendedAsset::from_amount(10000, ExtendedSymbol::from("4,SYM@contract"));

        let result = asset1 / 2;
        assert_eq!(result.quantity.amount, 5000);
        assert_eq!(result.to_string(), "0.5000 SYM@contract");
    }

    #[test]
    #[should_panic(expected = "type mismatch")]
    fn test_add_panic() {
        let a = ExtendedAsset::from_amount(100, ExtendedSymbol::from_extended(Symbol::from("4,SYM"), Name::from("contract1")));
        let b = ExtendedAsset::from_amount(200, ExtendedSymbol::from_extended(Symbol::from("4,SYM"), Name::from("contract2")));

        let _ = a + b;
    }

    #[test]
    #[should_panic(expected = "type mismatch")]
    fn test_sub_panic() {
        let a = ExtendedAsset::from_amount(100, ExtendedSymbol::from_extended(Symbol::from("4,SYM"), Name::from("contract1")));
        let b = ExtendedAsset::from_amount(200, ExtendedSymbol::from_extended(Symbol::from("4,SYM"), Name::from("contract2")));

        let _ = a - b;
    }

    #[test]
    #[should_panic(expected = "type mismatch")]
    fn test_div_panic() {
        let a = ExtendedAsset::from_amount(100, ExtendedSymbol::from_extended(Symbol::from("4,SYM"), Name::from("contract1")));
        let b = ExtendedAsset::from_amount(200, ExtendedSymbol::from_extended(Symbol::from("4,SYM"), Name::from("contract2")));

        let _ = a / b;
    }

    #[test]
    fn test_from_str() {
        let expected = ExtendedAsset {
            quantity: Asset::from_amount(1_0000, Symbol::from("4,SYM")),
            contract: Name::from("contract"),
        };
        let actual = ExtendedAsset::from("1.0000 SYM@contract");
        assert_eq!(actual, expected);
    }

    #[test]
    fn test_from_str2() {
        let expected = ExtendedAsset {
            quantity: Asset::from_amount(1_0000, Symbol::from("4,SYM")),
            contract: Name::default(),
        };
        let actual = ExtendedAsset::from("1.0000 SYM@");
        assert_eq!(actual, expected);
    }

    #[test]
    fn test_from_str_1() {
        // Valid input
        assert_eq!(
            "1.2345 SYM@contract".parse::<ExtendedAsset>(),
            Ok(ExtendedAsset::from_asset(
                Asset::from_amount(12345, Symbol::from_precision(SymbolCode::from("SYM"), 4)),
                Name::from("contract")
            ))
        );

        // Invalid format (missing '@')
        assert_eq!("1.2345 SYM-contract".parse::<ExtendedAsset>(), Err(ParseError::BadFormat));

        // Invalid asset format
        assert_eq!(
            "1.2345SYM@contract".parse::<ExtendedAsset>(),
            Err(ParseError::BadAsset(String::from("1.2345SYM")))
        );

        assert_eq!(
            "1.2345 SYM@contr9ct".parse::<ExtendedAsset>(),
            Err(ParseError::BadName(String::from("contr9ct")))
        );
    }
}