Skip to content

Commit 972902c

Browse files
authored
Merge pull request #518 from AugurProject/add-market-unit-tests
added more unit test coverage for market
2 parents 88c3cef + 1839f8b commit 972902c

File tree

5 files changed

+213
-44
lines changed

5 files changed

+213
-44
lines changed

tests/solidity_test_helpers/MockDisputeCrowdsourcer.sol

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,59 +6,89 @@ import 'TEST/MockVariableSupplyToken.sol';
66

77

88
contract MockDisputeCrowdsourcer is IDisputeCrowdsourcer, MockVariableSupplyToken {
9+
bool private contributeWasCalledValue;
10+
uint256 private contributeAmountValue;
11+
address private contributeParticipantValue;
12+
bytes32 private payoutDistributionHashValue;
13+
uint256[] private payoutNumeratorsValue;
14+
uint256 private setSizeValue;
15+
916
function initialize(IMarket market, uint256 _size, bytes32 _payoutDistributionHash, uint256[] _payoutNumerators, bool _invalid) public returns (bool) {
1017
return true;
1118
}
1219

20+
function contributeWasCalled() public returns(bool) { return contributeWasCalledValue; }
21+
22+
function getContributeParticipant() public returns(address) { return contributeParticipantValue; }
23+
24+
function getContributeAmount() public returns(uint256) { return contributeAmountValue; }
25+
1326
function contribute(address _participant, uint256 _amount) public returns (uint256) {
27+
contributeWasCalledValue = true;
28+
contributeParticipantValue = _participant;
29+
contributeAmountValue = _amount;
1430
return 0;
1531
}
16-
32+
1733
function disavow() public returns (bool) {
1834
return true;
1935
}
20-
36+
2137
function getStake() public view returns (uint256) {
2238
return 0;
2339
}
24-
40+
41+
function setPayoutNumeratorsValue(uint256[] _payoutNumerators) public {
42+
payoutNumeratorsValue = _payoutNumerators;
43+
}
44+
45+
function setPayoutDistributionHash(bytes32 _hash) public {
46+
payoutDistributionHashValue = _hash;
47+
}
48+
2549
function getPayoutDistributionHash() public view returns (bytes32) {
26-
return bytes32(0);
50+
return payoutDistributionHashValue;
2751
}
28-
52+
2953
function liquidateLosing() public returns (bool) {
3054
return true;
3155
}
32-
56+
3357
function fork() public returns (bool) {
3458
return true;
3559
}
36-
60+
3761
function redeem(address _redeemer) public returns (bool) {
3862
return true;
3963
}
40-
64+
4165
function isInvalid() public view returns (bool) {
4266
return true;
4367
}
44-
68+
4569
function isDisavowed() public view returns (bool) {
4670
return true;
4771
}
48-
72+
4973
function migrate() public returns (bool) {
5074
return true;
5175
}
52-
76+
5377
function getPayoutNumerator(uint8 _outcome) public view returns (uint256) {
5478
return 0;
5579
}
56-
80+
5781
function getMarket() public view returns (IMarket) {
5882
return IMarket(0);
5983
}
60-
84+
85+
function setSize(uint256 _size) public { setSizeValue = _size; }
86+
6187
function getSize() public view returns (uint256) {
62-
return 0;
88+
return setSizeValue;
89+
}
90+
91+
function callFinishedCrowdsourcingDisputeBond(IMarket _market) public returns(bool) {
92+
return _market.finishedCrowdsourcingDisputeBond();
6393
}
6494
}
Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,37 @@
11
pragma solidity 0.4.18;
22

3-
import 'reporting/IDisputeCrowdsourcer.sol';
43
import 'reporting/IMarket.sol';
54
import 'IController.sol';
6-
5+
import 'reporting/IDisputeCrowdsourcer.sol';
6+
import 'TEST/MockDisputeCrowdsourcer.sol';
77

88
contract MockDisputeCrowdsourcerFactory {
9-
IDisputeCrowdsourcer private disputeCrowdsourcer;
9+
MockDisputeCrowdsourcer private disputeCrowdsourcer;
10+
bytes32 private createdPayoutDistributionHashValue;
11+
uint256[] private createdPayoutNumeratorsValue;
1012

11-
function setDisputeCrowdsourcer(IDisputeCrowdsourcer _disputeCrowdsourcer) public returns (bool) {
13+
function setDisputeCrowdsourcer(MockDisputeCrowdsourcer _disputeCrowdsourcer) public returns (bool) {
1214
disputeCrowdsourcer = _disputeCrowdsourcer;
1315
}
1416

17+
function getDisputeCrowdsourcer() public returns (MockDisputeCrowdsourcer) {
18+
return disputeCrowdsourcer;
19+
}
20+
21+
function getCreatedPayoutDistributionHash() public returns(bytes32) {
22+
return createdPayoutDistributionHashValue;
23+
}
24+
25+
function getCreatedPayoutNumerators() public returns(uint256[]) {
26+
return createdPayoutNumeratorsValue;
27+
}
28+
1529
function createDisputeCrowdsourcer(IController _controller, IMarket _market, uint256 _size, bytes32 _payoutDistributionHash, uint256[] _payoutNumerators, bool _invalid) public returns (IDisputeCrowdsourcer) {
30+
createdPayoutDistributionHashValue = _payoutDistributionHash;
31+
createdPayoutNumeratorsValue = _payoutNumerators;
32+
// set for later testing use
33+
disputeCrowdsourcer.setPayoutDistributionHash(_payoutDistributionHash);
34+
disputeCrowdsourcer.setPayoutNumeratorsValue(_payoutNumerators);
1635
return disputeCrowdsourcer;
1736
}
18-
}
37+
}

tests/solidity_test_helpers/MockInitialReporter.sol

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ contract MockInitialReporter is IInitialReporter {
99
address private designatedReporter;
1010
bytes32 private payoutDistributionHash;
1111
uint256 private reportTimestamp;
12+
bool private reportWasCalledValue;
1213

1314
function setReportTimestamp(uint256 _reportTimestamp) public returns (bool) {
1415
reportTimestamp = _reportTimestamp;
@@ -30,30 +31,33 @@ contract MockInitialReporter is IInitialReporter {
3031
return _feeWindow.mintFeeTokens(_amount);
3132
}
3233

34+
function reportWasCalled() public returns(bool) { return reportWasCalledValue; }
35+
3336
function report(address _reporter, bytes32 _payoutDistributionHash, uint256[] _payoutNumerators, bool _invalid) public returns (bool) {
37+
reportWasCalledValue = true;
3438
return true;
3539
}
3640

3741
function resetReportTimestamp() public returns (bool) {
3842
return true;
3943
}
40-
44+
4145
function designatedReporterShowed() public view returns (bool) {
4246
return true;
4347
}
44-
48+
4549
function designatedReporterWasCorrect() public view returns (bool) {
4650
return true;
4751
}
48-
52+
4953
function getDesignatedReporter() public view returns (address) {
5054
return designatedReporter;
5155
}
52-
56+
5357
function getReportTimestamp() public view returns (uint256) {
5458
return reportTimestamp;
5559
}
56-
60+
5761
function depositGasBond() public payable returns (bool) {
5862
return true;
5963
}
@@ -102,4 +106,7 @@ contract MockInitialReporter is IInitialReporter {
102106
return 0;
103107
}
104108

109+
function callFinishedCrowdsourcingDisputeBond(IMarket _market) public returns(bool) {
110+
return _market.finishedCrowdsourcingDisputeBond();
111+
}
105112
}

tests/solidity_test_helpers/MockUniverse.sol

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,23 @@ contract MockUniverse is Initializable, IUniverse {
5555
Controller private controller;
5656
bool private setIsContainerForReportingParticipantValue;
5757
bool private setIsForkingValue;
58+
bool private getOrCacheValidityBondWallCalledValue;
59+
bool private getOrCacheTargetReporterGasCostsWasCalledValue;
60+
uint256 private setDisputeThresholdForForkValue;
61+
bool private getOrCreateNextFeeWindowWasCalledValue;
62+
IUniverse private setWinningChildUniverseValue;
63+
bool private addMarketToWasCalledValue;
64+
bool private removeMarketFromWasCalledValue;
5865
/*
5966
* setters to feed the getters and impl of IUniverse
6067
*/
68+
function reset() public {
69+
setforkValue = false;
70+
getOrCreateNextFeeWindowWasCalledValue = false;
71+
addMarketToWasCalledValue = false;
72+
removeMarketFromWasCalledValue = false;
73+
}
74+
6175
function getForkCalled() public returns(bool) {
6276
return setforkValue;
6377
}
@@ -126,15 +140,15 @@ contract MockUniverse is Initializable, IUniverse {
126140
setTargetRepMarketCapInAttoethValue = _setTargetRepMarketCapInAttoethValue;
127141
}
128142

129-
function setValidityBond(uint256 _setValidityBondValue) public {
143+
function setOrCacheValidityBond(uint256 _setValidityBondValue) public {
130144
setValidityBondValue = _setValidityBondValue;
131145
}
132146

133-
function setDesignatedReportStake(uint256 _setDesignatedReportStakeValue) public {
147+
function setOrCacheDesignatedReportStake(uint256 _setDesignatedReportStakeValue) public {
134148
setDesignatedReportStakeValue = _setDesignatedReportStakeValue;
135149
}
136150

137-
function setDesignatedReportNoShowBond(uint256 _setDesignatedReportNoShowBondValue) public {
151+
function setOrCacheDesignatedReportNoShowBond(uint256 _setDesignatedReportNoShowBondValue) public {
138152
setDesignatedReportNoShowBondValue = _setDesignatedReportNoShowBondValue;
139153
}
140154

@@ -158,7 +172,7 @@ contract MockUniverse is Initializable, IUniverse {
158172
setCalculateFloatingValueValue = _setCalculateFloatingValueValue;
159173
}
160174

161-
function setTargetReporterGasCosts(uint256 _setTargetReporterGasCostsValue) public {
175+
function setOrCacheTargetReporterGasCosts(uint256 _setTargetReporterGasCostsValue) public {
162176
setTargetReporterGasCostsValue = _setTargetReporterGasCostsValue;
163177
}
164178

@@ -205,6 +219,7 @@ contract MockUniverse is Initializable, IUniverse {
205219
function setIsContainerForReportingParticipant(bool _value) public {
206220
setIsContainerForReportingParticipantValue = _value;
207221
}
222+
208223
/*
209224
* Impl of IUniverse and ITyped
210225
*/
@@ -267,7 +282,10 @@ contract MockUniverse is Initializable, IUniverse {
267282
return setCurrentFeeWindowValue;
268283
}
269284

285+
function getOrCreateNextFeeWindowWasCalled() public returns(bool) { return getOrCreateNextFeeWindowWasCalledValue;}
286+
270287
function getOrCreateNextFeeWindow() public returns (IFeeWindow) {
288+
getOrCreateNextFeeWindowWasCalledValue = true;
271289
return setNextFeeWindowValue;
272290
}
273291

@@ -287,7 +305,10 @@ contract MockUniverse is Initializable, IUniverse {
287305
return setTargetRepMarketCapInAttoethValue;
288306
}
289307

308+
function getOrCacheValidityBondWallCalled() public returns(bool) { return getOrCacheValidityBondWallCalledValue; }
309+
290310
function getOrCacheValidityBond() public returns (uint256) {
311+
getOrCacheValidityBondWallCalledValue = true;
291312
return setValidityBondValue;
292313
}
293314

@@ -339,7 +360,10 @@ contract MockUniverse is Initializable, IUniverse {
339360
return _newValue;
340361
}
341362

363+
function getOrCacheTargetReporterGasCostsWasCalled() public returns(bool) { return getOrCacheTargetReporterGasCostsWasCalledValue; }
364+
342365
function getOrCacheTargetReporterGasCosts() public returns (uint256) {
366+
getOrCacheTargetReporterGasCostsWasCalledValue = true;
343367
return setTargetReporterGasCostsValue;
344368
}
345369

@@ -399,21 +423,31 @@ contract MockUniverse is Initializable, IUniverse {
399423
function createChildUniverse(uint256[] _parentPayoutNumerators, bool _parentInvalid) public returns (IUniverse) {
400424
return IUniverse(0);
401425
}
402-
426+
403427
function isContainerForReportingParticipant(IReportingParticipant _reportingParticipant) public view returns (bool) {
404428
return setIsContainerForReportingParticipantValue;
405429
}
406430

431+
function addMarketToWasCalled() public returns(bool) { return addMarketToWasCalledValue; }
432+
407433
function addMarketTo() public returns (bool) {
434+
addMarketToWasCalledValue = true;
408435
return true;
409436
}
410437

438+
function removeMarketFromWasCalled() public returns(bool) { return removeMarketFromWasCalledValue; }
439+
411440
function removeMarketFrom() public returns (bool) {
441+
removeMarketFromWasCalledValue = true;
412442
return true;
413443
}
414444

445+
function setWinningChildUniverse(IUniverse _winning) public {
446+
setWinningChildUniverseValue = _winning;
447+
}
448+
415449
function getWinningChildUniverse() public view returns (IUniverse) {
416-
return IUniverse(0);
450+
return setWinningChildUniverseValue;
417451
}
418452

419453
function getCurrentFeeWindow() public view returns (IFeeWindow) {
@@ -438,8 +472,10 @@ contract MockUniverse is Initializable, IUniverse {
438472
return true;
439473
}
440474

475+
function setDisputeThresholdForFork(uint256 _value) public { setDisputeThresholdForForkValue = _value; }
476+
441477
function getDisputeThresholdForFork() public view returns (uint256) {
442-
return 0;
478+
return setDisputeThresholdForForkValue;
443479
}
444480

445481
function getInitialReportMinValue() public view returns (uint256) {

0 commit comments

Comments
 (0)