diff --git a/conf/config.json b/conf/config.json index 748030f7..bb688885 100644 --- a/conf/config.json +++ b/conf/config.json @@ -13,7 +13,7 @@ "voteQuorum": 50, "pVoteQuorum": 50, "exitTimeDelay": 600, - "exitTimeExpiry": 600 + "exitPeriodLen": 600 }, "name": "The TestChain Registry", "token": { diff --git a/contracts/Parameterizer.sol b/contracts/Parameterizer.sol index 3fb4b5c9..7cc7ecc8 100644 --- a/contracts/Parameterizer.sol +++ b/contracts/Parameterizer.sol @@ -114,11 +114,11 @@ contract Parameterizer { // type of majority out of 100 necessary for proposal success in parameterizer set("pVoteQuorum", _parameters[11]); - // minimum length of time between initExit & finalizeExit + // minimum length of time user has to wait to exit the registry set("exitTimeDelay", _parameters[12]); - // maximum length of time between initExit & finalizeExit - set("exitTimeExpiry", _parameters[13]); + // maximum length of time user can wait to exit the registry + set("exitPeriodLen", _parameters[13]); } // ----------------------- diff --git a/contracts/Registry.sol b/contracts/Registry.sol index 69798d19..cc4fe36a 100644 --- a/contracts/Registry.sol +++ b/contracts/Registry.sol @@ -136,26 +136,6 @@ contract Registry { emit _Withdrawal(_listingHash, _amount, listing.unstakedDeposit, msg.sender); } - /** - @dev Allows the owner of a listingHash to remove the listingHash from the whitelist - Returns all tokens to the owner of the listingHash - @param _listingHash A listingHash msg.sender is the owner of. - */ - // function exit(bytes32 _listingHash) external { - // Listing storage listing = listings[_listingHash]; - - // require(msg.sender == listing.owner); - // require(isWhitelisted(_listingHash)); - - // // Cannot exit during ongoing challenge - // require(listing.challengeID == 0 || challenges[listing.challengeID].resolved); - - // // Remove listingHash & return tokens - // resetListing(_listingHash); - // emit _ListingWithdrawn(_listingHash); - // } - - /** @dev Initialize an exit timer for a listing to leave the whitelist @param _listingHash A listing hash msg.sender is the owner of @@ -168,14 +148,14 @@ contract Registry { // Cannot exit during ongoing challenge require(listing.challengeID == 0 || challenges[listing.challengeID].resolved); - // Ensure that you either never called initExit() or your expiry time is up + // Ensure that you either never called initExit() or exitPeriodLen passed require(listing.exitTime == 0 || now > - listing.exitTime.add(parameterizer.get("exitTimeExpiry"))); + listing.exitTime.add(parameterizer.get("exitPeriodLen"))); // Set when the listing may be removed from the whitelist listing.exitTime = now.add(parameterizer.get("exitTimeDelay")); emit _ExitInitialized(_listingHash, listing.exitTime, - listing.exitTime.add(parameterizer.get("exitTimeExpiry")), msg.sender); + listing.exitTime.add(parameterizer.get("exitPeriodLen")), msg.sender); } /** @@ -195,10 +175,10 @@ contract Registry { require(listing.exitTime > 0); // Get the time when the exit is no longer valid - uint timeExpired = listing.exitTime.add(parameterizer.get("exitTimeExpiry")); + uint timeExpired = listing.exitTime.add(parameterizer.get("exitPeriodLen")); - // Time to exit has to be after exit delay but before the exit expiry time - require((listing.exitTime < now) && (now < timeExpired)); + // Time to exit has to be after exit delay but before the exitPeriodLen is over + require(listing.exitTime < now && now < timeExpired); resetListing(_listingHash); emit _ListingWithdrawn(_listingHash, msg.sender); diff --git a/test/ParameterizerFactory/newParameterizerBYOToken.js b/test/ParameterizerFactory/newParameterizerBYOToken.js index 516ac97e..c6326eb3 100644 --- a/test/ParameterizerFactory/newParameterizerBYOToken.js +++ b/test/ParameterizerFactory/newParameterizerBYOToken.js @@ -47,7 +47,7 @@ contract('ParameterizerFactory', (accounts) => { paramConfig.voteQuorum, paramConfig.pVoteQuorum, paramConfig.exitTimeDelay, - paramConfig.exitTimeExpiry, + paramConfig.exitPeriodLen, ]; const parameterizerReceipt = await parameterizerFactory .newParameterizerBYOToken(token.address, parameters, { from: accounts[0] }); diff --git a/test/ParameterizerFactory/newParameterizerWithToken.js b/test/ParameterizerFactory/newParameterizerWithToken.js index 14925935..e22851c8 100644 --- a/test/ParameterizerFactory/newParameterizerWithToken.js +++ b/test/ParameterizerFactory/newParameterizerWithToken.js @@ -39,7 +39,7 @@ contract('ParameterizerFactory', (accounts) => { paramConfig.voteQuorum, paramConfig.pVoteQuorum, paramConfig.exitTimeDelay, - paramConfig.exitTimeExpiry, + paramConfig.exitPeriodLen, ]; const parameterizerReceipt = await parameterizerFactory.newParameterizerWithToken( tokenParams.supply, diff --git a/test/RegistryFactory/newRegistryBYOToken.js b/test/RegistryFactory/newRegistryBYOToken.js index e880bc28..09a31379 100644 --- a/test/RegistryFactory/newRegistryBYOToken.js +++ b/test/RegistryFactory/newRegistryBYOToken.js @@ -47,7 +47,7 @@ contract('RegistryFactory', (accounts) => { paramConfig.voteQuorum, paramConfig.pVoteQuorum, paramConfig.exitTimeDelay, - paramConfig.exitTimeExpiry, + paramConfig.exitPeriodLen, ]; // new registry using factory/proxy diff --git a/test/RegistryFactory/newRegistryWithToken.js b/test/RegistryFactory/newRegistryWithToken.js index 63dc8854..6b681400 100644 --- a/test/RegistryFactory/newRegistryWithToken.js +++ b/test/RegistryFactory/newRegistryWithToken.js @@ -40,7 +40,7 @@ contract('RegistryFactory', (accounts) => { paramConfig.voteQuorum, paramConfig.pVoteQuorum, paramConfig.exitTimeDelay, - paramConfig.exitTimeExpiry, + paramConfig.exitPeriodLen, ]; // new registry using factory/proxy diff --git a/test/registry/finalizeExit.js b/test/registry/finalizeExit.js index ac303435..c8f4eefc 100644 --- a/test/registry/finalizeExit.js +++ b/test/registry/finalizeExit.js @@ -24,43 +24,38 @@ contract('Registry', (accounts) => { }); it('should allow a listing to exit when no challenge exists', async () => { + // Adding an application to the whitelist const listing = utils.getListingHash('google.com'); - const initialApplicantTokenHoldings = await token.balanceOf.call(applicant); - await utils.addToWhitelist(listing, paramConfig.minDeposit, applicant, registry); - const isWhitelisted = await registry.isWhitelisted.call(listing); assert.strictEqual(isWhitelisted, true, 'the listing was not added to the registry'); - + // Exiting the whitelist await registry.initExit(listing, { from: applicant }); - await utils.increaseTime(paramConfig.exitTimeDelay + 1); await registry.finalizeExit(listing, { from: applicant }); - const isWhitelistedAfterExit = await registry.isWhitelisted.call(listing); assert.strictEqual(isWhitelistedAfterExit, false, 'the listing was not removed on exit'); - const finalApplicantTokenHoldings = await token.balanceOf.call(applicant); assert.strictEqual( initialApplicantTokenHoldings.toString(10), finalApplicantTokenHoldings.toString(10), 'the applicant\'s tokens were not returned to them after exiting the registry', ); - + // Make sure resetListing(), called in finalizeExit() correctly removed the listing const listingStruct = await registry.listings.call(listing); assert.strictEqual(listingStruct[5].toString(), '0', 'exit time did not reset'); }); it('should not allow a listing to finalize exit when exit was not initialized', async () => { + // Adding an application to the whitelist const listing = utils.getListingHash('youtube.com'); - const initialApplicantTokenHoldings = await token.balanceOf.call(applicant); - await utils.addToWhitelist(listing, paramConfig.minDeposit, applicant, registry); - const isWhitelisted = await registry.isWhitelisted.call(listing); assert.strictEqual(isWhitelisted, true, 'the listing was not added to the registry'); + + // Trying to finalize an exit without ever calling initExit() try { await registry.finalizeExit(listing, { from: applicant }); assert(false, 'exit succeeded when it should have failed due to exit not being initialized'); @@ -78,26 +73,26 @@ contract('Registry', (accounts) => { initialApplicantTokenHoldings.sub(paramConfig.minDeposit).toString(), 'the applicant\'s tokens were returned in spite of failing to exit', ); - + // Make sure the listing did not successfully initialize exit const listingStruct = await registry.listings.call(listing); - assert.strictEqual(listingStruct[5].toString(), '0', 'exit time was initialized'); + assert.strictEqual(listingStruct[5].toString(), '0', 'exit time was initialized even though initExit() was never called'); }); - it('should not allow a listing to finalize exit when time is not up', async () => { + it('should not allow a listing to finalize exit during the waiting period', async () => { + // Adding an application to the whitelist const listing = utils.getListingHash('hangouts.com'); - const initialApplicantTokenHoldings = await token.balanceOf.call(applicant); - await utils.addToWhitelist(listing, paramConfig.minDeposit, applicant, registry); - const isWhitelisted = await registry.isWhitelisted.call(listing); assert.strictEqual(isWhitelisted, true, 'the listing was not added to the registry'); + await registry.initExit(listing, { from: applicant }); // blockTimestamp is used to calculate when the applicant's exit time is up const blockTimestamp = new BigNumber(await utils.getBlockTimestamp()); + // Trying to finalize exit during waiting period try { await registry.finalizeExit(listing, { from: applicant }); - assert(false, 'exit succeeded when it should have failed due to time not being up'); + assert(false, 'exit succeeded when it should have failed becuase the user called finalizeExit before the delay period was over'); } catch (err) { const errMsg = err.toString(); assert(utils.isEVMException(err), errMsg); @@ -111,17 +106,16 @@ contract('Registry', (accounts) => { initialApplicantTokenHoldings.sub(paramConfig.minDeposit).toString(), 'the applicant\'s tokens were returned in spite of failing to exit', ); + // Make sure exitTimeDelay was correctly set const listingStruct = await registry.listings.call(listing); assert.strictEqual(listingStruct[5].toString(), blockTimestamp.add(paramConfig.exitTimeDelay).toString(), 'exit time was not initialized'); }); it('should not allow a listing to finalize an exit when a challenge does exist', async () => { + // Adding an application to the whitelist const listing = utils.getListingHash('520.com'); - const initialApplicantTokenHoldings = await token.balanceOf.call(applicant); - await utils.addToWhitelist(listing, paramConfig.minDeposit, applicant, registry); - const isWhitelisted = await registry.isWhitelisted.call(listing); assert.strictEqual(isWhitelisted, true, 'the listing was not added to the registry'); @@ -129,10 +123,12 @@ contract('Registry', (accounts) => { // blockTimestamp is used to calculate when the applicant's exit time is up const blockTimestamp = new BigNumber(await utils.getBlockTimestamp()); await utils.increaseTime(paramConfig.exitTimeDelay + 1); + // Challenge the listing await registry.challenge(listing, '', { from: challenger }); - // Make an assertion to prove that challenge does exit + // Assert that challenge does exit const initialListingStruct = await registry.listings.call(listing); assert.notStrictEqual(initialListingStruct[4].toString(), '0', 'Challenge was never created'); + // Trying to finalize an exit while there is an ongoing challenge try { await registry.finalizeExit(listing, { from: applicant }); assert(false, 'exit succeeded when it should have failed'); @@ -157,27 +153,25 @@ contract('Registry', (accounts) => { assert.strictEqual(listingStruct[5].toString(), blockTimestamp.add(paramConfig.exitTimeDelay).toString(), 'exit time was not initialized'); }); - it('should not allow a listing to finalize an exit when exitTimeExpiry has elapsed', async () => { + it('should not allow a listing to finalize an exit when exitPeriodLen has elapsed', async () => { + // Adding an application to the whitelist const listing = utils.getListingHash('620-200.com'); - const initialApplicantTokenHoldings = await token.balanceOf.call(applicant); await utils.addToWhitelist(listing, paramConfig.minDeposit, applicant, registry); - const isWhitelisted = await registry.isWhitelisted.call(listing); assert.strictEqual(isWhitelisted, true, 'the listing was not added to the registry'); + // Initialize exit and advance time passed exitPeriodLen await registry.initExit(listing, { from: applicant }); - // blockTimestamp is used to calculate when the applicant's exit time is up const blockTimestamp = new BigNumber(await utils.getBlockTimestamp()); - await utils.increaseTime(paramConfig.exitTimeDelay + 1); - await utils.increaseTime(paramConfig.exitTimeExpiry + 1); + await utils.increaseTime(paramConfig.exitPeriodLen + 1); const listingStruct = await registry.listings.call(listing); try { await registry.finalizeExit(listing, { from: applicant }); - assert(false, 'exit succeeded when it should have failed since exitTimeExpiry elapsed'); + assert(false, 'exit succeeded when it should have failed since exitPeriodLen elapsed'); } catch (err) { const errMsg = err.toString(); assert(utils.isEVMException(err), errMsg); @@ -186,7 +180,7 @@ contract('Registry', (accounts) => { assert.strictEqual( isWhitelistedAfterExit, true, - 'the listing was able to exit since exitTimeExpiry elapsed', + 'the listing was able to exit since exitPeriodLen elapsed', ); const finalApplicantTokenHoldings = await token.balanceOf.call(applicant); assert.strictEqual( @@ -199,28 +193,27 @@ contract('Registry', (accounts) => { }); it('should allow a listing to finalize after re-initializing a previous exit', async () => { + // Add an application to the whitelsit const listing = utils.getListingHash('720-300.com'); - const initialApplicantTokenHoldings = await token.balanceOf.call(applicant); - await utils.addToWhitelist(listing, paramConfig.minDeposit, applicant, registry); - const isWhitelisted = await registry.isWhitelisted.call(listing); assert.strictEqual(isWhitelisted, true, 'the listing was not added to the registry'); - // Initialize exit and fast forward past expiry date + // Initialize exit and fast forward past exitPeriodLen await registry.initExit(listing, { from: applicant }); await utils.increaseTime(paramConfig.exitTimeDelay + 1); - await utils.increaseTime(paramConfig.exitTimeExpiry + 1); + await utils.increaseTime(paramConfig.exitPeriodLen + 1); + // finalizeExit should fail since exitPeriodLen has passed try { await registry.finalizeExit(listing, { from: applicant }); - assert(false, 'exit succeeded when it should have failed since exitTimeExpiry elapsed'); + assert(false, 'exit succeeded when it should have failed since exitPeriodLen elapsed'); } catch (err) { const errMsg = err.toString(); assert(utils.isEVMException(err), errMsg); } - // Re-initialize the exit and finalize the exit before the expiry time + // Re-initialize the exit and finalize exit await registry.initExit(listing, { from: applicant }); await utils.increaseTime(paramConfig.exitTimeDelay + 1); await registry.finalizeExit(listing, { from: applicant }); @@ -229,7 +222,7 @@ contract('Registry', (accounts) => { assert.strictEqual( isWhitelistedAfterExit, false, - 'the listing was not able to exit even though exitTimeExpiry did not elapse', + 'the listing was not able to exit even though exitPeriodLen did not elapse', ); const finalApplicantTokenHoldings = await token.balanceOf.call(applicant); assert.strictEqual( diff --git a/test/registry/initExit.js b/test/registry/initExit.js index 3810e9dd..91d9b8c6 100644 --- a/test/registry/initExit.js +++ b/test/registry/initExit.js @@ -23,15 +23,14 @@ contract('Registry', (accounts) => { await utils.approveProxies(accounts, token, false, false, registry); }); - it('exit time state should be correctly set', async () => { + it('exitTimeDelay should be correctly set', async () => { + // Adding an application to the whitelist const listing = utils.getListingHash('hangoutz.com'); - const initialApplicantTokenHoldings = await token.balanceOf.call(applicant); - await utils.addToWhitelist(listing, paramConfig.minDeposit, applicant, registry); - const isWhitelisted = await registry.isWhitelisted.call(listing); assert.strictEqual(isWhitelisted, true, 'the listing was not added to the registry'); + await registry.initExit(listing, { from: applicant }); // blockTimestamp is used to calculate when the applicant's exit time is up const blockTimestamp = new BigNumber(await utils.getBlockTimestamp()); @@ -40,26 +39,26 @@ contract('Registry', (accounts) => { assert.strictEqual( finalApplicantTokenHoldings.toString(), initialApplicantTokenHoldings.sub(paramConfig.minDeposit).toString(), - 'the applicant\'s tokens were returned in spite of exit', + 'the applicant\'s tokens were returned in spite of failing to exit', ); + // Make sure exitTimeDelay was correctly set const listingStruct = await registry.listings.call(listing); assert.strictEqual(listingStruct[5].toString(), blockTimestamp.add(paramConfig.exitTimeDelay).toString(), 'exit time was not initialized'); }); it('should not allow a listing to initialize an exit when a challenge exists', async () => { + // Adding an application to the whitelist const listing = utils.getListingHash('420.com'); - const initialApplicantTokenHoldings = await token.balanceOf.call(applicant); - await utils.addToWhitelist(listing, paramConfig.minDeposit, applicant, registry); - const isWhitelisted = await registry.isWhitelisted.call(listing); assert.strictEqual(isWhitelisted, true, 'the listing was not added to the registry'); + // Challenge a listing and then fail to initialize exit because of the challenge await registry.challenge(listing, '', { from: challenger }); try { await registry.initExit(listing, { from: applicant }); - assert(false, 'exit succeeded when it should have failed'); + assert(false, 'exit succeeded when it should have failed due to an existing challenge'); } catch (err) { const errMsg = err.toString(); assert(utils.isEVMException(err), errMsg); @@ -71,44 +70,38 @@ contract('Registry', (accounts) => { true, 'the listing was able to exit while a challenge was active', ); - const finalApplicantTokenHoldings = await token.balanceOf.call(applicant); assert.strictEqual( finalApplicantTokenHoldings.toString(), initialApplicantTokenHoldings.sub(paramConfig.minDeposit).toString(), 'the applicant\'s tokens were returned in spite of failing to exit', ); - + // Make sure the listing did not successfully initialize exit const listingStruct = await registry.listings.call(listing); - assert.strictEqual(listingStruct[5].toString(), '0', 'exit time was initialized'); + assert.strictEqual(listingStruct[5].toString(), '0', 'exitTimeDelay was initialized'); }); it('should not initialize an exit by someone who doesn\'t own the listing', async () => { + // Adding an application to the whitelist const listing = utils.getListingHash('chilling.com'); - await utils.addToWhitelist(listing, paramConfig.minDeposit, applicant, registry); try { + // Another user (challenger) is trying initialize the applicant's exit await registry.initExit(listing, { from: challenger }); - assert(false, 'exit initialized when it should have failed'); + assert(false, 'exit initialized when the listing owner did not call initExit()'); } catch (err) { const errMsg = err.toString(); assert(utils.isEVMException(err), errMsg); } - const isWhitelistedAfterExit = await registry.isWhitelisted.call(listing); - assert.strictEqual( - isWhitelistedAfterExit, - true, - 'the listing was initialized by someone other than its owner', - ); + // Make sure the listing did not successfully initialize exit const listingStruct = await registry.listings.call(listing); assert.strictEqual(listingStruct[5].toString(), '0', 'exit time should not have been initialized'); }); it('should revert if listing is in application stage', async () => { const listing = utils.getListingHash('nogoodnames.com'); - await utils.as(applicant, registry.apply, listing, paramConfig.minDeposit, ''); const initialListingStruct = await registry.listings.call(listing); @@ -124,8 +117,9 @@ contract('Registry', (accounts) => { } assert(false, 'exit succeeded for non-whitelisted listing'); + // Make sure the listing did not successfully initialize exit const listingStruct = await registry.listings.call(listing); - assert.strictEqual(listingStruct[5].toString(), '0', 'exit time should not have been initialized'); + assert.strictEqual(listingStruct[5].toString(), '0', 'exit time should not have been initialized since listing is in application stage'); }); }); }); diff --git a/test/utils.js b/test/utils.js index ae52dd1f..859fda65 100644 --- a/test/utils.js +++ b/test/utils.js @@ -44,7 +44,7 @@ const utils = { paramConfig.voteQuorum, paramConfig.pVoteQuorum, paramConfig.exitTimeDelay, - paramConfig.exitTimeExpiry, + paramConfig.exitPeriodLen, ], 'The TestChain Registry', );