1616
1717from scripts .setup import (
1818 fund_riskpool ,
19+ fund_customer ,
1920 apply_for_policy ,
2021)
2122
@@ -131,7 +132,7 @@ def test_pause_unpause(
131132 riskpool .burnBundle (bundleId , {'from' :bundleOwner })
132133
133134 # ensure underwriting new policies is not possible for paused riskpool
134- with brownie .reverts ("ERROR:POL-021 :RISKPOOL_NOT_ACTIVE" ):
135+ with brownie .reverts ("ERROR:POL-004 :RISKPOOL_NOT_ACTIVE" ):
135136 policyId2 = apply_for_policy (instance , owner , product , customer , testCoin , 100 , 1000 )
136137
137138 # ensure existing policies may be closed while riskpool is paused
@@ -290,6 +291,7 @@ def test_suspend_resume(
290291
291292 assert bundle2Id == bundleId + 1
292293
294+
293295def test_suspend_archive (
294296 instance : GifInstance ,
295297 testCoin ,
@@ -688,4 +690,192 @@ def test_propose_decline(
688690def _getBundle (instance , riskpool , bundleIdx ):
689691 instanceService = instance .getInstanceService ()
690692 bundleId = riskpool .getBundleId (bundleIdx )
691- return instanceService .getBundle (bundleId )
693+ return instanceService .getBundle (bundleId )
694+
695+ def test_policy_application_with_inactive_riskpool (
696+ instance : GifInstance ,
697+ testCoin ,
698+ gifTestProduct : GifTestProduct ,
699+ instanceOperator : Account ,
700+ productOwner : Account ,
701+ riskpoolKeeper : Account ,
702+ customer : Account ,
703+ capitalOwner : Account
704+ ):
705+ # prepare funded riskpool
706+ riskpool = gifTestProduct .getRiskpool ().getContract ()
707+ riskpoolId = riskpool .getId ()
708+ initialFunding = 10000
709+ fund_riskpool (instance , instanceOperator , capitalOwner , riskpool , riskpoolKeeper , testCoin , initialFunding )
710+
711+ # pause riskpool
712+ componentOwnerService = instance .getComponentOwnerService ()
713+ componentOwnerService .pause (riskpoolId , {'from' : riskpoolKeeper })
714+ assert riskpool .getState () == 4
715+
716+ # attempt to create policy
717+ product = gifTestProduct .getContract ()
718+ premium = 300
719+ sumInsured = 2000
720+
721+ with brownie .reverts ('ERROR:POL-004:RISKPOOL_NOT_ACTIVE' ):
722+ product .applyForPolicy (premium , sumInsured , bytes (0 ), bytes (0 ), {'from' : customer })
723+
724+ assert product .policies () == 0
725+
726+ # unpuase riskpool again
727+ componentOwnerService .unpause (riskpoolId , {'from' : riskpoolKeeper })
728+ assert riskpool .getState () == 3
729+
730+ # verify that policy creation works
731+ tx = product .applyForPolicy (premium , sumInsured , bytes (0 ), bytes (0 ), {'from' : customer })
732+ processId = tx .return_value
733+
734+ assert product .policies () == 1
735+
736+
737+ def test_collect_premium_with_inactive_riskpool (
738+ instance : GifInstance ,
739+ testCoin ,
740+ gifTestProduct : GifTestProduct ,
741+ instanceOperator : Account ,
742+ productOwner : Account ,
743+ riskpoolKeeper : Account ,
744+ customer : Account ,
745+ capitalOwner : Account
746+ ):
747+ # prepare funded riskpool
748+ riskpool = gifTestProduct .getRiskpool ().getContract ()
749+ riskpoolId = riskpool .getId ()
750+ initialFunding = 10000
751+ fund_riskpool (instance , instanceOperator , capitalOwner , riskpool , riskpoolKeeper , testCoin , initialFunding )
752+
753+ # create policy
754+ product = gifTestProduct .getContract ()
755+ premium = 300
756+ sumInsured = 2000
757+ tx = product .applyForPolicy (premium , sumInsured , bytes (0 ), bytes (0 ), {'from' : customer })
758+ processId = tx .return_value
759+
760+ # ComponentState {Created,Proposed,Declined,Active,Paused,Suspended}
761+ assert product .policies () == 1
762+ assert riskpool .getState () == 3
763+
764+ # pause riskpool
765+ componentOwnerService = instance .getComponentOwnerService ()
766+ componentOwnerService .pause (riskpoolId , {'from' : riskpoolKeeper })
767+
768+ assert riskpool .getState () == 4
769+ # fund customer to pay premium now
770+ fund_customer (instance , instanceOperator , customer , testCoin , premium )
771+ assert testCoin .balanceOf (customer ) == premium
772+ assert testCoin .allowance (customer , instance .getTreasury ()) == premium
773+
774+ # attempt to collect premium with paused riskpool
775+ with brownie .reverts ('ERROR:POL-004:RISKPOOL_NOT_ACTIVE' ):
776+ product .collectPremium (processId , premium , {'from' : productOwner })
777+
778+ assert testCoin .balanceOf (customer ) == premium
779+
780+ # unpuase riskpool
781+ componentOwnerService .unpause (riskpoolId , {'from' : riskpoolKeeper })
782+ assert riskpool .getState () == 3
783+
784+ # ensure that collecting premiums works again
785+ tx = product .collectPremium (processId , premium , {'from' : productOwner })
786+ (success , fee , netPremium ) = tx .return_value
787+
788+ assert success
789+ assert testCoin .balanceOf (customer ) == 0
790+
791+
792+
793+
794+ def test_payout_processing_with_inactive_riskpool (
795+ instance : GifInstance ,
796+ testCoin ,
797+ gifTestProduct : GifTestProduct ,
798+ instanceOperator : Account ,
799+ productOwner : Account ,
800+ riskpoolKeeper : Account ,
801+ customer : Account ,
802+ capitalOwner : Account
803+ ):
804+ instanceService = instance .getInstanceService ()
805+
806+ # prepare funded riskpool
807+ riskpool = gifTestProduct .getRiskpool ().getContract ()
808+ riskpoolId = riskpool .getId ()
809+ initialFunding = 10000
810+ fund_riskpool (instance , instanceOperator , capitalOwner , riskpool , riskpoolKeeper , testCoin , initialFunding )
811+
812+ # fund customer to pay premium now
813+ premium = 300
814+ fund_customer (instance , instanceOperator , customer , testCoin , premium )
815+ assert testCoin .balanceOf (customer ) == premium
816+ assert testCoin .allowance (customer , instance .getTreasury ()) == premium
817+
818+ # create policy
819+ product = gifTestProduct .getContract ()
820+ sumInsured = 2000
821+ tx = product .applyForPolicy (premium , sumInsured , bytes (0 ), bytes (0 ), {'from' : customer })
822+ processId = tx .return_value
823+
824+ # ComponentState {Created,Proposed,Declined,Active,Paused,Suspended}
825+ assert instanceService .processIds () == 1
826+ assert instanceService .claims (processId ) == 0
827+ assert product .policies () == 1
828+ assert riskpool .getState () == 3
829+
830+ # pause riskpool
831+ componentOwnerService = instance .getComponentOwnerService ()
832+ componentOwnerService .pause (riskpoolId , {'from' : riskpoolKeeper })
833+
834+ assert riskpool .getState () == 4
835+
836+ claimAmount = 3 * premium
837+ (claimId , payoutId ) = create_claim_no_oracle (product , customer , productOwner , processId , claimAmount )
838+
839+ assert instanceService .claims (processId ) == 1
840+ assert instanceService .payouts (processId ) == 1
841+ assert testCoin .balanceOf (customer ) == 0
842+
843+ # attempt to process payout
844+ with brownie .reverts ('ERROR:POL-004:RISKPOOL_NOT_ACTIVE' ):
845+ product .processPayout (processId , payoutId , {'from' :productOwner })
846+
847+ assert instanceService .claims (processId ) == 1
848+ assert instanceService .payouts (processId ) == 1
849+ assert testCoin .balanceOf (customer ) == 0
850+
851+ # unpause riskpool
852+ componentOwnerService = instance .getComponentOwnerService ()
853+ componentOwnerService .unpause (riskpoolId , {'from' : riskpoolKeeper })
854+
855+ assert riskpool .getState () == 3
856+
857+ # enwure process payout works again
858+ product .processPayout (processId , payoutId , {'from' :productOwner })
859+
860+ assert instanceService .claims (processId ) == 1
861+ assert instanceService .payouts (processId ) == 1
862+ assert testCoin .balanceOf (customer ) == claimAmount
863+
864+ # ensure it's not possible to process same payout a 2nd time
865+ with brownie .reverts ('ERROR:POC-091:POLICY_WITHOUT_OPEN_CLAIMS' ):
866+ product .processPayout (processId , payoutId , {'from' :productOwner })
867+
868+ assert instanceService .claims (processId ) == 1
869+ assert instanceService .payouts (processId ) == 1
870+ assert testCoin .balanceOf (customer ) == claimAmount
871+
872+
873+ def create_claim_no_oracle (product , customer , productOwner , processId , claimAmount ):
874+ tx = product .submitClaimNoOracle (processId , claimAmount , {'from' :customer })
875+ claimId = tx .return_value
876+ product .confirmClaim (processId , claimId , claimAmount , {'from' :productOwner })
877+
878+ tx = product .newPayout (processId , claimId , claimAmount , {'from' :productOwner })
879+ payoutId = tx .return_value
880+
881+ return (claimId , payoutId )
0 commit comments