@@ -338,16 +338,6 @@ contract("CappedSTO", accounts => {
338
338
) ;
339
339
} ) ;
340
340
341
- it ( "Should buy the tokens -- Failed due to wrong granularity" , async ( ) => {
342
- await catchRevert (
343
- web3 . eth . sendTransaction ( {
344
- from : account_investor1 ,
345
- to : I_CappedSTO_Array_ETH [ 0 ] . address ,
346
- value : web3 . utils . toWei ( "0.1111" , "ether" )
347
- } )
348
- ) ;
349
- } ) ;
350
-
351
341
it ( "Should Buy the tokens" , async ( ) => {
352
342
blockNo = latestBlock ( ) ;
353
343
fromTime = latestTime ( ) ;
@@ -427,17 +417,8 @@ contract("CappedSTO", accounts => {
427
417
assert . isFalse ( await I_CappedSTO_Array_ETH [ 0 ] . paused . call ( ) ) ;
428
418
} ) ;
429
419
430
- it ( "Should buy the tokens -- Failed due to wrong granularity" , async ( ) => {
431
- await catchRevert (
432
- web3 . eth . sendTransaction ( {
433
- from : account_investor1 ,
434
- to : I_CappedSTO_Array_ETH [ 0 ] . address ,
435
- value : web3 . utils . toWei ( "0.1111" , "ether" )
436
- } )
437
- ) ;
438
- } ) ;
439
-
440
- it ( "Should restrict to buy tokens after hiting the cap in second tx first tx pass" , async ( ) => {
420
+ it ( "Should buy the granular unit tokens and refund pending amount" , async ( ) => {
421
+ await I_SecurityToken_ETH . changeGranularity ( 10 ** 21 , { from : token_owner } ) ;
441
422
let tx = await I_GeneralTransferManager . modifyWhitelist (
442
423
account_investor2 ,
443
424
fromTime ,
@@ -448,15 +429,26 @@ contract("CappedSTO", accounts => {
448
429
from : account_issuer
449
430
}
450
431
) ;
451
-
452
432
assert . equal ( tx . logs [ 0 ] . args . _investor , account_investor2 , "Failed in adding the investor in whitelist" ) ;
433
+ const initBalance = BigNumber ( await web3 . eth . getBalance ( account_investor2 ) ) ;
434
+ tx = await I_CappedSTO_Array_ETH [ 0 ] . buyTokens ( account_investor2 , { from : account_investor2 , value : web3 . utils . toWei ( "1.5" , "ether" ) , gasPrice : 1 } ) ;
435
+ const finalBalance = BigNumber ( await web3 . eth . getBalance ( account_investor2 ) ) ;
436
+ assert . equal ( finalBalance . add ( BigNumber ( tx . receipt . gasUsed ) ) . add ( web3 . utils . toWei ( "1" , "ether" ) ) . toNumber ( ) , initBalance . toNumber ( ) ) ;
437
+ await I_SecurityToken_ETH . changeGranularity ( 1 , { from : token_owner } ) ;
438
+ assert . equal ( ( await I_CappedSTO_Array_ETH [ 0 ] . getRaised . call ( ETH ) ) . dividedBy ( new BigNumber ( 10 ) . pow ( 18 ) ) . toNumber ( ) , 2 ) ;
439
+
440
+ assert . equal ( ( await I_SecurityToken_ETH . balanceOf ( account_investor2 ) ) . dividedBy ( new BigNumber ( 10 ) . pow ( 18 ) ) . toNumber ( ) , 1000 ) ;
441
+ } ) ;
442
+
443
+ it ( "Should restrict to buy tokens after hiting the cap in second tx first tx pass" , async ( ) => {
444
+
453
445
454
446
// Fallback transaction
455
447
await web3 . eth . sendTransaction ( {
456
448
from : account_investor2 ,
457
449
to : I_CappedSTO_Array_ETH [ 0 ] . address ,
458
450
gas : 2100000 ,
459
- value : web3 . utils . toWei ( "9 " , "ether" )
451
+ value : web3 . utils . toWei ( "8 " , "ether" )
460
452
} ) ;
461
453
462
454
assert . equal ( ( await I_CappedSTO_Array_ETH [ 0 ] . getRaised . call ( ETH ) ) . dividedBy ( new BigNumber ( 10 ) . pow ( 18 ) ) . toNumber ( ) , 10 ) ;
@@ -793,8 +785,8 @@ contract("CappedSTO", accounts => {
793
785
await I_CappedSTO_Array_POLY [ 0 ] . unpause ( { from : account_issuer } ) ;
794
786
} ) ;
795
787
796
-
797
- it ( "Should restrict to buy tokens after hiting the cap in second tx first tx pass" , async ( ) => {
788
+ it ( "Should buy the granular unit tokens and charge only required POLY" , async ( ) => {
789
+ await I_SecurityToken_POLY . changeGranularity ( 10 ** 22 , { from : token_owner } ) ;
798
790
let tx = await I_GeneralTransferManager . modifyWhitelist (
799
791
account_investor2 ,
800
792
P_fromTime ,
@@ -806,15 +798,25 @@ contract("CappedSTO", accounts => {
806
798
gas : 500000
807
799
}
808
800
) ;
809
-
801
+ console . log ( ( await I_SecurityToken_POLY . balanceOf ( account_investor2 ) ) . dividedBy ( new BigNumber ( 10 ) . pow ( 18 ) ) . toNumber ( ) ) ;
810
802
assert . equal ( tx . logs [ 0 ] . args . _investor , account_investor2 , "Failed in adding the investor in whitelist" ) ;
811
-
812
803
await I_PolyToken . getTokens ( 10000 * Math . pow ( 10 , 18 ) , account_investor2 ) ;
813
-
814
804
await I_PolyToken . approve ( I_CappedSTO_Array_POLY [ 0 ] . address , 9000 * Math . pow ( 10 , 18 ) , { from : account_investor2 } ) ;
805
+ const initRaised = ( await I_CappedSTO_Array_POLY [ 0 ] . getRaised . call ( POLY ) ) . dividedBy ( new BigNumber ( 10 ) . pow ( 18 ) ) . toNumber ( ) ;
806
+ tx = await I_CappedSTO_Array_POLY [ 0 ] . buyTokensWithPoly ( 3000 * Math . pow ( 10 , 18 ) , { from : account_investor2 } ) ;
807
+ await I_SecurityToken_POLY . changeGranularity ( 1 , { from : token_owner } ) ;
808
+ assert . equal ( ( await I_CappedSTO_Array_POLY [ 0 ] . getRaised . call ( POLY ) ) . dividedBy ( new BigNumber ( 10 ) . pow ( 18 ) ) . toNumber ( ) , initRaised + 2000 ) ; //2000 this call, 1000 earlier
809
+ assert . equal ( ( await I_PolyToken . balanceOf ( account_investor2 ) ) . dividedBy ( new BigNumber ( 10 ) . pow ( 18 ) ) . toNumber ( ) , 8000 ) ;
810
+ assert . equal (
811
+ ( await I_SecurityToken_POLY . balanceOf ( account_investor2 ) ) . dividedBy ( new BigNumber ( 10 ) . pow ( 18 ) ) . toNumber ( ) ,
812
+ 10000
813
+ ) ;
814
+ } ) ;
815
815
816
+
817
+ it ( "Should restrict to buy tokens after hiting the cap in second tx first tx pass" , async ( ) => {
816
818
// buyTokensWithPoly transaction
817
- await I_CappedSTO_Array_POLY [ 0 ] . buyTokensWithPoly ( 9000 * Math . pow ( 10 , 18 ) , { from : account_investor2 } ) ;
819
+ await I_CappedSTO_Array_POLY [ 0 ] . buyTokensWithPoly ( 7000 * Math . pow ( 10 , 18 ) , { from : account_investor2 } ) ;
818
820
819
821
assert . equal ( ( await I_CappedSTO_Array_POLY [ 0 ] . getRaised . call ( POLY ) ) . dividedBy ( new BigNumber ( 10 ) . pow ( 18 ) ) . toNumber ( ) , 10000 ) ;
820
822
0 commit comments