@@ -508,7 +508,7 @@ test.serial("verify users allowance after `approve` with fee.", async t => {
508508 ) . forEach ( result => t . is ( result , BigInt ( 0 ) ) ) ;
509509} ) ;
510510
511- test . serial ( "verify transaction after `approve` with fee." , async t => {
511+ test . serial ( "verify transactions after `approve` with fee." , async t => {
512512 ( await Promise . all ( allActors . map ( actor => actor . transaction ( BigInt ( 3 ) ) ) ) ) . forEach ( result =>
513513 t . like ( result , {
514514 Ok : {
@@ -679,7 +679,7 @@ test.serial("verify users allowance after `approve` with zero fee.", async t =>
679679 ) . forEach ( result => t . is ( result , BigInt ( 0 ) ) ) ;
680680} ) ;
681681
682- test . serial ( "verify transaction after `approve` with zero fee." , async t => {
682+ test . serial ( "verify transactions after `approve` with zero fee." , async t => {
683683 ( await Promise . all ( allActors . map ( actor => actor . transaction ( BigInt ( 6 ) ) ) ) ) . forEach ( result =>
684684 t . like ( result , {
685685 Ok : {
@@ -932,7 +932,7 @@ test.serial("verify users allowance after `transferFrom` with fee.", async t =>
932932 ) . forEach ( result => t . is ( result , BigInt ( 0 ) ) ) ;
933933} ) ;
934934
935- test . serial ( "verify transaction after `transferFrom` with fee." , async t => {
935+ test . serial ( "verify transactions after `transferFrom` with fee." , async t => {
936936 ( await Promise . all ( allActors . map ( actor => actor . transaction ( BigInt ( 10 ) ) ) ) ) . forEach ( result =>
937937 t . like ( result , {
938938 Ok : {
@@ -1082,7 +1082,7 @@ test.serial("verify users allowance after `transferFrom` with zero fee.", async
10821082 ) . forEach ( result => t . is ( result , BigInt ( 0 ) ) ) ;
10831083} ) ;
10841084
1085- test . serial ( "verify transaction after `transferFrom` with zero fee." , async t => {
1085+ test . serial ( "verify transactions after `transferFrom` with zero fee." , async t => {
10861086 ( await Promise . all ( allActors . map ( actor => actor . transaction ( BigInt ( 11 ) ) ) ) ) . forEach ( result =>
10871087 t . like ( result , {
10881088 Ok : {
@@ -1221,7 +1221,7 @@ test.serial("verify users balance after `transfer` with fee.", async t => {
12211221 ) ;
12221222} ) ;
12231223
1224- test . serial ( "verify transaction after `transfer` with fee." , async t => {
1224+ test . serial ( "verify transactions after `transfer` with fee." , async t => {
12251225 ( await Promise . all ( allActors . map ( actor => actor . transaction ( BigInt ( 15 ) ) ) ) ) . forEach ( result =>
12261226 t . like ( result , {
12271227 Ok : {
@@ -1326,7 +1326,7 @@ test.serial("verify users balance after `transfer` with zero fee.", async t => {
13261326 ) ;
13271327} ) ;
13281328
1329- test . serial ( "verify transaction after `transfer` with zero fee." , async t => {
1329+ test . serial ( "verify transactions after `transfer` with zero fee." , async t => {
13301330 ( await Promise . all ( allActors . map ( actor => actor . transaction ( BigInt ( 19 ) ) ) ) ) . forEach ( result =>
13311331 t . like ( result , {
13321332 Ok : {
@@ -1385,3 +1385,121 @@ test.serial("verify transaction after `transfer` with zero fee.", async t => {
13851385 ) ;
13861386} ) ;
13871387
1388+ test . serial ( "error on `withdraw` with amount exceed u64 range." , async t => {
1389+ t . deepEqual ( await aliceWicpActor . withdraw ( BigInt ( "0xffffffffffffffffffff" ) , aliceAccountId . toHex ( ) ) , {
1390+ Err : { Other : "failed to cast usize from nat" }
1391+ } ) ;
1392+ } ) ;
1393+
1394+ test . serial ( "error on `withdraw` with invalid e8s amount." , async t => {
1395+ t . deepEqual ( await johnWicpActor . withdraw ( BigInt ( 0 ) , johnAccountId . toHex ( ) ) , {
1396+ Err : { InvalidE8sAmount : null }
1397+ } ) ;
1398+ } ) ;
1399+
1400+ test . serial ( "error on `withdraw` with invalid account id." , async t => {
1401+ t . deepEqual ( await aliceWicpActor . withdraw ( BigInt ( 10_000 ) , `${ aliceAccountId . toHex ( ) } asdfasfjdklfjsf"` ) , {
1402+ Err : { InvalidAccountId : null }
1403+ } ) ;
1404+ } ) ;
1405+
1406+ test . serial ( "error on `withdraw` when owner have insufficient balance WICP." , async t => {
1407+ t . deepEqual ( await aliceWicpActor . withdraw ( BigInt ( 200_000_001 ) , aliceAccountId . toHex ( ) ) , {
1408+ Err : { InsufficientBalance : null }
1409+ } ) ;
1410+ t . deepEqual ( await bobWicpActor . withdraw ( BigInt ( 100_000_001 ) , bobAccountId . toHex ( ) ) , {
1411+ Err : { InsufficientBalance : null }
1412+ } ) ;
1413+ t . deepEqual ( await johnWicpActor . withdraw ( BigInt ( 1 ) , johnAccountId . toHex ( ) ) , {
1414+ Err : { InsufficientBalance : null }
1415+ } ) ;
1416+ t . deepEqual ( await custodianWicpActor . withdraw ( BigInt ( 69_700_000_001 ) , custodianAccountId . toHex ( ) ) , {
1417+ Err : { InsufficientBalance : null }
1418+ } ) ;
1419+ } ) ;
1420+
1421+ test . serial ( "withdraw WICP." , async t => {
1422+ t . deepEqual ( await aliceWicpActor . withdraw ( BigInt ( 200_000_000 ) , aliceAccountId . toHex ( ) ) , {
1423+ Ok : BigInt ( 23 )
1424+ } ) ;
1425+ t . deepEqual ( await bobWicpActor . withdraw ( BigInt ( 100_000_000 ) , bobAccountId . toHex ( ) ) , {
1426+ Ok : BigInt ( 24 )
1427+ } ) ;
1428+ t . deepEqual ( await custodianWicpActor . withdraw ( BigInt ( 69_700_000_000 ) , custodianAccountId . toHex ( ) ) , {
1429+ Ok : BigInt ( 25 )
1430+ } ) ;
1431+ } ) ;
1432+
1433+ test . serial ( "verify stats after `withdraw`." , async t => {
1434+ const result = await custodianWicpActor . stats ( ) ;
1435+ t . truthy ( result . cycles ) ;
1436+ t . is ( result . icps , BigInt ( 0 ) ) ;
1437+ t . is ( result . total_supply , BigInt ( 0 ) ) ;
1438+ t . is ( result . total_transactions , BigInt ( 25 ) ) ;
1439+ t . is ( result . total_unique_holders , BigInt ( 0 ) ) ;
1440+ t . truthy ( await custodianWicpActor . cycles ( ) ) ;
1441+ t . is ( await custodianWicpActor . icps ( ) , BigInt ( 0 ) ) ;
1442+ t . is ( await custodianWicpActor . totalSupply ( ) , BigInt ( 0 ) ) ;
1443+ t . is ( await custodianWicpActor . totalTransactions ( ) , BigInt ( 25 ) ) ;
1444+ t . is ( await custodianWicpActor . totalUniqueHolders ( ) , BigInt ( 0 ) ) ;
1445+ } ) ;
1446+
1447+ test . serial ( "verify users balance after `withdraw`." , async t => {
1448+ ( await Promise . all ( allActors . map ( actor => actor . balanceOf ( aliceIdentity . getPrincipal ( ) ) ) ) ) . forEach ( result =>
1449+ t . is ( result , BigInt ( 0 ) )
1450+ ) ;
1451+ ( await Promise . all ( allActors . map ( actor => actor . balanceOf ( bobIdentity . getPrincipal ( ) ) ) ) ) . forEach ( result =>
1452+ t . is ( result , BigInt ( 0 ) )
1453+ ) ;
1454+ ( await Promise . all ( allActors . map ( actor => actor . balanceOf ( johnIdentity . getPrincipal ( ) ) ) ) ) . forEach ( result =>
1455+ t . is ( result , BigInt ( 0 ) )
1456+ ) ;
1457+ ( await Promise . all ( allActors . map ( actor => actor . balanceOf ( custodianIdentity . getPrincipal ( ) ) ) ) ) . forEach ( result =>
1458+ t . is ( result , BigInt ( 0 ) )
1459+ ) ;
1460+ } ) ;
1461+
1462+ test . serial ( "verify transactions after `withdraw`." , async t => {
1463+ ( await Promise . all ( allActors . map ( actor => actor . transaction ( BigInt ( 23 ) ) ) ) ) . forEach ( result =>
1464+ t . like ( result , {
1465+ Ok : {
1466+ operation : "withdraw" ,
1467+ details : [
1468+ [ "from" , { Principal : aliceIdentity . getPrincipal ( ) } ] ,
1469+ [ "to" , { TextContent : aliceAccountId . toHex ( ) } ] ,
1470+ [ "amount" , { NatContent : BigInt ( 200_000_000 ) } ] ,
1471+ [ "block_height" , { Nat64Content : BigInt ( 8 ) } ]
1472+ ] ,
1473+ caller : aliceIdentity . getPrincipal ( )
1474+ }
1475+ } )
1476+ ) ;
1477+ ( await Promise . all ( allActors . map ( actor => actor . transaction ( BigInt ( 24 ) ) ) ) ) . forEach ( result =>
1478+ t . like ( result , {
1479+ Ok : {
1480+ operation : "withdraw" ,
1481+ details : [
1482+ [ "from" , { Principal : bobIdentity . getPrincipal ( ) } ] ,
1483+ [ "to" , { TextContent : bobAccountId . toHex ( ) } ] ,
1484+ [ "amount" , { NatContent : BigInt ( 100_000_000 ) } ] ,
1485+ [ "block_height" , { Nat64Content : BigInt ( 9 ) } ]
1486+ ] ,
1487+ caller : bobIdentity . getPrincipal ( )
1488+ }
1489+ } )
1490+ ) ;
1491+ ( await Promise . all ( allActors . map ( actor => actor . transaction ( BigInt ( 25 ) ) ) ) ) . forEach ( result =>
1492+ t . like ( result , {
1493+ Ok : {
1494+ operation : "withdraw" ,
1495+ details : [
1496+ [ "from" , { Principal : custodianIdentity . getPrincipal ( ) } ] ,
1497+ [ "to" , { TextContent : custodianAccountId . toHex ( ) } ] ,
1498+ [ "amount" , { NatContent : BigInt ( 69_700_000_000 ) } ] ,
1499+ [ "block_height" , { Nat64Content : BigInt ( 10 ) } ]
1500+ ] ,
1501+ caller : custodianIdentity . getPrincipal ( )
1502+ }
1503+ } )
1504+ ) ;
1505+ } ) ;
0 commit comments