Skip to content

Commit

Permalink
add require and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil Elsasser committed Sep 27, 2018
1 parent e803713 commit 645bb2e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
5 changes: 3 additions & 2 deletions contracts/MarketCollateralPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ contract MarketCollateralPool is Ownable {
/// @param marketContractAddress address of the MARKET Contract being traded.
function settleAndClose(address marketContractAddress) external {
MarketContract marketContract = MarketContract(marketContractAddress);
require(marketContract.isSettled());
require(marketContract.isSettled(), "Contract is not settled");
UserNetPosition storage userNetPos = contractAddressToUserPosition[marketContractAddress][msg.sender];
if (userNetPos.netPosition != 0) {
// this user has a position that we need to settle based upon the settlement price of the contract
Expand Down Expand Up @@ -373,7 +373,8 @@ contract MarketCollateralPool is Ownable {


modifier onlyMarketContract(){
require(MARKET_CONTRACT_REGISTRY.isAddressWhiteListed(msg.sender));
require(MARKET_CONTRACT_REGISTRY.isAddressWhiteListed(msg.sender),
"Can only be called by a white listed MarketContract");
_;
}

Expand Down
24 changes: 21 additions & 3 deletions test/MarketCollateralPool.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ contract('MarketCollateralPool', function(accounts) {
accounts[3]
);
await marketToken.setLockQtyToAllowTrading(10);
error = null;

error = null;
try {
await collateralPool.depositTokensForTrading(fourBalance, { from: accounts[3] });
} catch (err) {
Expand Down Expand Up @@ -557,12 +557,30 @@ contract('MarketCollateralPool', function(accounts) {
it('should fail if settleAndClose() is called before settlement', async () => {

let error = null;
let settleAndCloseError = null;
try {
await collateralPool.settleAndClose.call(marketContract.address, { from: accounts[0] });
} catch (err) {
error = err;
settleAndCloseError = err;
}
assert.ok(settleAndCloseError instanceof Error, 'settleAndClose() did not fail before settlement');
});

it('should only allow updatePositions to be called by a market contract', async () => {

assert.ok(error instanceof Error, 'settleAndClose() did not fail before settlement');
let error = null;
let updatePositionsError = null;
try {
await collateralPool.updatePositions(
accounts[0],
accounts[1],
1,
entryOrderPrice
);
} catch (err) {
updatePositionsError = err;
}
assert.ok(updatePositionsError instanceof Error, "didn't fail to call updatePositions from non MarketContract address");
});

});

0 comments on commit 645bb2e

Please sign in to comment.