Skip to content

Commit

Permalink
fix and amend for 'test_close_bundle'
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiaszimmermann committed Jul 18, 2022
1 parent 4c17458 commit b05e641
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
3 changes: 3 additions & 0 deletions contracts/services/RiskpoolService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ contract RiskpoolService is
external override
onlyOwningRiskpool(bundleId)
{
IBundle.Bundle memory bundle = _bundle.getBundle(bundleId);
require(bundle.state != IBundle.BundleState.Closed, "ERROR:RPS-003:BUNDLE_CLOSED");

(bool success, uint256 netAmount) = _treasury.processCapital(bundleId, amount);
if (success) {
_bundle.fund(bundleId, netAmount);
Expand Down
25 changes: 18 additions & 7 deletions tests/test_bundle_create_use_burn.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ def test_close_bundle(
riskpool = gifTestProduct.getRiskpool().getContract()
initialFunding = 10000

fund_riskpool(instance, owner, riskpool, riskpoolKeeper, testCoin, initialFunding)
bundleOwner = riskpoolKeeper
fund_riskpool(instance, owner, riskpool, bundleOwner, testCoin, initialFunding)

premium = 100
sumInsured = 5000
Expand All @@ -205,8 +206,11 @@ def test_close_bundle(
assert _getBundleDict(riskpool, 0)['balance'] == bundleBalance

# check that bundle may not be closed with non-closed policies
with brownie.reverts('ERROR:BUC-001:NOT_BUNDLE_OWNER'):
riskpool.closeBundle(bundleId, {'from': owner})

with brownie.reverts('ERROR:BUC-015:BUNDLE_WITH_ACTIVE_POLICIES'):
riskpool.closeBundle(bundleId)
riskpool.closeBundle(bundleId, {'from': bundleOwner})

assert _getPolicyDict(instance, policyId)['state'] == 1

Expand All @@ -227,23 +231,30 @@ def test_close_bundle(
assert bundle['balance'] == bundleBalance

# check that is now ok to close the bundle
riskpool.closeBundle(bundleId)
with brownie.reverts('ERROR:BUC-001:NOT_BUNDLE_OWNER'):
riskpool.closeBundle(bundleId, {'from': owner})

riskpool.closeBundle(bundleId, {'from': bundleOwner})

bundle = _getBundleDict(riskpool, 0)
assert bundle['state'] == 2 # BundleState { Active, Locked, Closed }
assert bundle['capital'] == bundleCapital
assert bundle['lockedCapital'] == 0
assert bundle['balance'] == bundleBalance

# check that close is final state
# check that close results in blocking most actions on the bundle
with brownie.reverts('ERROR:BUC-014:CLOSED_IS_FINAL_STATE'):
riskpool.closeBundle(bundleId)
riskpool.closeBundle(bundleId, {'from': bundleOwner})

with brownie.reverts('ERROR:BUC-014:CLOSED_IS_FINAL_STATE'):
riskpool.lockBundle(bundleId)
riskpool.lockBundle(bundleId, {'from': bundleOwner})

with brownie.reverts('ERROR:BUC-014:CLOSED_IS_FINAL_STATE'):
riskpool.unlockBundle(bundleId)
riskpool.unlockBundle(bundleId, {'from': bundleOwner})

with brownie.reverts('ERROR:RPS-003:BUNDLE_CLOSED'):
fundingAmount = 100000
riskpool.fundBundle(bundleId, fundingAmount, {'from': bundleOwner})


# TODO implement test
Expand Down

0 comments on commit b05e641

Please sign in to comment.