@@ -642,4 +642,90 @@ contract('JoinAndQuit', accounts => {
642
642
}
643
643
} ) ;
644
644
645
+ it ( "refund" , async function ( ) {
646
+ var testSetup = await setup ( accounts ) ;
647
+ await testSetup . standardTokenMock . approve ( testSetup . joinAndQuit . address , testSetup . minFeeToJoin , { from :accounts [ 3 ] } ) ;
648
+ var donatorBalance = await testSetup . standardTokenMock . balanceOf ( accounts [ 3 ] ) ;
649
+ var tx = await testSetup . joinAndQuit . proposeToJoin (
650
+ "description-hash" ,
651
+ testSetup . minFeeToJoin ,
652
+ { from :accounts [ 3 ] } ) ;
653
+
654
+ //Vote with reputation to trigger execution
655
+ var proposalId = await helpers . getValueFromLogs ( tx , '_proposalId' , 1 ) ;
656
+ await testSetup . joinAndQuitParams . votingMachine . absoluteVote . vote ( proposalId , 1 , 0 , helpers . NULL_ADDRESS , { from :accounts [ 2 ] } ) ;
657
+ assert . equal ( await testSetup . standardTokenMock . balanceOf ( testSetup . org . avatar . address ) , testSetup . minFeeToJoin ) ;
658
+ assert . equal ( ( await testSetup . joinAndQuit . fundings ( accounts [ 3 ] ) ) . funding , testSetup . minFeeToJoin ) ;
659
+ try {
660
+ await testSetup . joinAndQuit . refund ( { from :accounts [ 3 ] } ) ;
661
+ assert ( false , 'cannot refund before deadline' ) ;
662
+ } catch ( ex ) {
663
+ helpers . assertVMException ( ex ) ;
664
+ }
665
+ await helpers . increaseTime ( testSetup . fundingGoalDeadline ) ;
666
+ tx = await testSetup . joinAndQuit . refund ( { from :accounts [ 3 ] } ) ;
667
+ assert . equal ( tx . logs . length , 1 ) ;
668
+ assert . equal ( tx . logs [ 0 ] . event , "Refund" ) ;
669
+ assert . equal ( tx . logs [ 0 ] . args . _avatar , testSetup . org . avatar . address ) ;
670
+ assert . equal ( tx . logs [ 0 ] . args . _beneficiary , accounts [ 3 ] ) ;
671
+ assert . equal ( tx . logs [ 0 ] . args . _refund , testSetup . minFeeToJoin ) ;
672
+ assert . equal ( ( await testSetup . standardTokenMock . balanceOf ( accounts [ 3 ] ) ) . toString ( ) , donatorBalance . toString ( ) ) ;
673
+ } ) ;
674
+
675
+ it ( "refund - cannot if funding goal reached." , async function ( ) {
676
+ var testSetup = await setup ( accounts ) ;
677
+ await testSetup . standardTokenMock . approve ( testSetup . joinAndQuit . address , testSetup . fundingGoal + 1 , { from :accounts [ 3 ] } ) ;
678
+ var tx = await testSetup . joinAndQuit . proposeToJoin (
679
+ "description-hash" ,
680
+ testSetup . fundingGoal + 1 ,
681
+ { from :accounts [ 3 ] } ) ;
682
+
683
+ //Vote with reputation to trigger execution
684
+ var proposalId = await helpers . getValueFromLogs ( tx , '_proposalId' , 1 ) ;
685
+ await testSetup . joinAndQuitParams . votingMachine . absoluteVote . vote ( proposalId , 1 , 0 , helpers . NULL_ADDRESS , { from :accounts [ 2 ] } ) ;
686
+
687
+ await helpers . increaseTime ( testSetup . fundingGoalDeadline ) ;
688
+ try {
689
+ await testSetup . joinAndQuit . refund ( { from :accounts [ 3 ] } ) ;
690
+ assert ( false , 'cannot if funding goal reached' ) ;
691
+ } catch ( ex ) {
692
+ helpers . assertVMException ( ex ) ;
693
+ }
694
+ } ) ;
695
+
696
+ it ( "refund with eth" , async function ( ) {
697
+ var testSetup = await setup ( accounts , true ) ;
698
+ var tx = await testSetup . joinAndQuit . proposeToJoin (
699
+ "description-hash" ,
700
+ testSetup . minFeeToJoin ,
701
+ { from :accounts [ 3 ] , value :testSetup . minFeeToJoin } ) ;
702
+
703
+ //Vote with reputation to trigger execution
704
+ var proposalId = await helpers . getValueFromLogs ( tx , '_proposalId' , 1 ) ;
705
+ await testSetup . joinAndQuitParams . votingMachine . absoluteVote . vote ( proposalId , 1 , 0 , helpers . NULL_ADDRESS , { from :accounts [ 2 ] } ) ;
706
+ assert . equal ( ( await testSetup . joinAndQuit . fundings ( accounts [ 3 ] ) ) . funding , testSetup . minFeeToJoin ) ;
707
+ try {
708
+ await testSetup . joinAndQuit . refund ( { from :accounts [ 3 ] } ) ;
709
+ assert ( false , 'cannot refund before deadline' ) ;
710
+ } catch ( ex ) {
711
+ helpers . assertVMException ( ex ) ;
712
+ }
713
+ await helpers . increaseTime ( testSetup . fundingGoalDeadline ) ;
714
+ var balanceBefore = await avatarBalance ( testSetup ) ;
715
+ tx = await testSetup . joinAndQuit . refund ( { from :accounts [ 3 ] } ) ;
716
+ assert . equal ( tx . logs . length , 1 ) ;
717
+ assert . equal ( tx . logs [ 0 ] . event , "Refund" ) ;
718
+ assert . equal ( tx . logs [ 0 ] . args . _avatar , testSetup . org . avatar . address ) ;
719
+ assert . equal ( tx . logs [ 0 ] . args . _beneficiary , accounts [ 3 ] ) ;
720
+ assert . equal ( tx . logs [ 0 ] . args . _refund , testSetup . minFeeToJoin ) ;
721
+ assert . equal ( await avatarBalance ( testSetup ) , balanceBefore - testSetup . minFeeToJoin ) ;
722
+ try {
723
+ await testSetup . joinAndQuit . refund ( { from :accounts [ 3 ] } ) ;
724
+ assert ( false , 'cannot refund twice' ) ;
725
+ } catch ( ex ) {
726
+ helpers . assertVMException ( ex ) ;
727
+ }
728
+ } ) ;
729
+
730
+
645
731
} ) ;
0 commit comments