Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/adding require failure messages #265

Merged
merged 13 commits into from Sep 11, 2019

Running prettier.

  • Loading branch information
Freydal committed Sep 9, 2019
commit 68ceabf40721dcbf31fcb7cf3d719a25d8c01cf8
@@ -184,7 +184,7 @@ describe("ValidatorRegistry", async () => {
it("should require a balance greater or equal to the minimumBalance", async () => {
const from = accounts[1];
const idleBalance = await kosuToken.balanceOf.callAsync(from);
await testHelpers.clearTreasury(from)
await testHelpers.clearTreasury(from);
await kosuToken.transfer.awaitTransactionSuccessAsync(accounts[0], idleBalance, { from });

await kosuToken.balanceOf
@@ -260,12 +260,9 @@ describe("ValidatorRegistry", async () => {

await kosuToken.approve.awaitTransactionSuccessAsync(treasury.address, minimumBalance);

await validatorRegistry.registerListing.callAsync(
tendermintPublicKey,
minimumBalance,
TestValues.zero,
paradigmMarket,
).should.eventually.be.rejected.and.have.property("message")
await validatorRegistry.registerListing
.callAsync(tendermintPublicKey, minimumBalance, TestValues.zero, paradigmMarket)
.should.eventually.be.rejected.and.have.property("message")
.that.includes("listing with public key exists");
});

@@ -337,12 +334,9 @@ describe("ValidatorRegistry", async () => {

it("should fail with less tokens than minimum", async () => {
const minimum = await validatorRegistry.minimumBalance.callAsync();
await validatorRegistry.registerListing.callAsync(
tendermintPublicKey,
minimum.minus(new BigNumber("1")),
TestValues.zero,
paradigmMarket,
).should.eventually.be.rejected.and.have.property("message")
await validatorRegistry.registerListing
.callAsync(tendermintPublicKey, minimum.minus(new BigNumber("1")), TestValues.zero, paradigmMarket)
.should.eventually.be.rejected.and.have.property("message")
.that.includes("must register with at least minimum balance");
await validatorRegistry.registerListing.awaitTransactionSuccessAsync(
tendermintPublicKey,
@@ -354,12 +348,9 @@ describe("ValidatorRegistry", async () => {

it("should fail when you try to generate too many tokens", async () => {
const max = await validatorRegistry.maxRewardRate.callAsync();
await validatorRegistry.registerListing.callAsync(
tendermintPublicKey,
minimumBalance,
max.plus(new BigNumber("1")),
paradigmMarket,
).should.eventually.be.rejected.and.have.property("message")
await validatorRegistry.registerListing
.callAsync(tendermintPublicKey, minimumBalance, max.plus(new BigNumber("1")), paradigmMarket)
.should.eventually.be.rejected.and.have.property("message")
.that.includes("reward rate exceeds max");
await validatorRegistry.registerListing.awaitTransactionSuccessAsync(
tendermintPublicKey,
@@ -419,9 +410,10 @@ describe("ValidatorRegistry", async () => {

describe("confirmListing", () => {
it("should not confirm a null listing", async () => {
await validatorRegistry.confirmListing.callAsync(tendermintPublicKey).should.eventually
.be.rejected.and.have.property("message")
.that.includes("not listing owner");
await validatorRegistry.confirmListing
.callAsync(tendermintPublicKey)
.should.eventually.be.rejected.and.have.property("message")
.that.includes("not listing owner");
});

it("should require sufficient blocks to pass before confirmation", async () => {
@@ -433,9 +425,10 @@ describe("ValidatorRegistry", async () => {
paradigmMarket,
);
const appBlock = decodeKosuEvents(result.logs)[0].applicationBlockNumber;
await validatorRegistry.confirmListing.callAsync(tendermintPublicKey).should.eventually
.be.rejected.and.have.property("message")
.that.includes("application period active");
await validatorRegistry.confirmListing
.callAsync(tendermintPublicKey)
.should.eventually.be.rejected.and.have.property("message")
.that.includes("application period active");

await testHelpers.skipApplicationPeriod(appBlock);

@@ -469,8 +462,9 @@ describe("ValidatorRegistry", async () => {
tendermintPublicKey,
paradigmMarket,
).should.eventually.be.fulfilled;
await validatorRegistry.confirmListing.callAsync(tendermintPublicKey).should
.eventually.be.rejected.and.have.property("message")
await validatorRegistry.confirmListing
.callAsync(tendermintPublicKey)
.should.eventually.be.rejected.and.have.property("message")
.that.includes("listing not pending");

await testHelpers.skipChallengePeriod(result.blockNumber);
@@ -482,9 +476,11 @@ describe("ValidatorRegistry", async () => {
});

it("should only let the listing owner confirm the listing", async () => {
await validatorRegistry.confirmListing.callAsync(tendermintPublicKey, {
from: accounts[1],
}).should.eventually.be.rejected.and.have.property("message")
await validatorRegistry.confirmListing
.callAsync(tendermintPublicKey, {
from: accounts[1],
})
.should.eventually.be.rejected.and.have.property("message")
.that.includes("not listing owner");
await validatorRegistry.confirmListing.awaitTransactionSuccessAsync(tendermintPublicKey).should
.eventually.be.fulfilled;
@@ -536,9 +532,10 @@ describe("ValidatorRegistry", async () => {
{ from: accounts[1] },
).should.eventually.be.fulfilled;

await validatorRegistry.initExit.callAsync(tendermintPublicKey).should.eventually.be
.rejected.and.have.property("message")
.that.includes("listing not accepted");
await validatorRegistry.initExit
.callAsync(tendermintPublicKey)
.should.eventually.be.rejected.and.have.property("message")
.that.includes("listing not accepted");

await testHelpers.finishChallenge(tendermintPublicKey, result.blockNumber);
await testHelpers.exitListing(tendermintPublicKey);
@@ -549,10 +546,12 @@ describe("ValidatorRegistry", async () => {
.be.fulfilled;

// should only let the owner initExit
await validatorRegistry.initExit.callAsync(tendermintPublicKey, {
from: accounts[1],
}).should.eventually.be.rejected.and.have.property("message")
.that.includes("not listing owner");
await validatorRegistry.initExit
.callAsync(tendermintPublicKey, {
from: accounts[1],
})
.should.eventually.be.rejected.and.have.property("message")
.that.includes("not listing owner");

const iniitalMaxRewardRate = await validatorRegistry.maxRewardRate.callAsync();

@@ -587,17 +586,20 @@ describe("ValidatorRegistry", async () => {
.eventually.be.fulfilled;

// should not allow a listing to exit until after the exit period
await validatorRegistry.finalizeExit.callAsync(tendermintPublicKey).should.eventually.be
.rejected.and.have.property("message")
.that.includes("exiting cool off period active");
await validatorRegistry.finalizeExit
.callAsync(tendermintPublicKey)
.should.eventually.be.rejected.and.have.property("message")
.that.includes("exiting cool off period active");

await testHelpers.skipExitPeriod(result.blockNumber);

// should only let the owner finalizeExit
await validatorRegistry.finalizeExit.callAsync(tendermintPublicKey, {
from: accounts[1],
}).should.eventually.be.rejected.and.have.property("message")
.that.includes("not listing owner");
await validatorRegistry.finalizeExit
.callAsync(tendermintPublicKey, {
from: accounts[1],
})
.should.eventually.be.rejected.and.have.property("message")
.that.includes("not listing owner");

const oldReward = await validatorRegistry.maxRewardRate.callAsync();

@@ -810,9 +812,10 @@ describe("ValidatorRegistry", async () => {
});

// should require challenge to be ended
await validatorRegistry.resolveChallenge.callAsync(tendermintPublicKey).should.eventually
.be.rejected.and.have.property("message")
.that.includes("challenge has not ended");
await validatorRegistry.resolveChallenge
.callAsync(tendermintPublicKey)
.should.eventually.be.rejected.and.have.property("message")
.that.includes("challenge has not ended");

await testHelpers.skipChallengePeriod(blockNumber);
const initialListingHolderSystemBalance = await treasury.systemBalance.callAsync(accounts[0]);
@@ -824,9 +827,10 @@ describe("ValidatorRegistry", async () => {
.should.eventually.be.fulfilled;

// should fail if called a second time
await validatorRegistry.resolveChallenge.callAsync(tendermintPublicKey).should.eventually
.be.rejected.and.have.property("message")
.that.includes("listing is not challenged");
await validatorRegistry.resolveChallenge
.callAsync(tendermintPublicKey)
.should.eventually.be.rejected.and.have.property("message")
.that.includes("listing is not challenged");

const decodedLogs = decodeKosuEvents(result.logs);
decodedLogs[1].eventType.should.eq("ValidatorRemoved");
@@ -1364,10 +1368,12 @@ describe("ValidatorRegistry", async () => {
from: accounts[5],
});

await validatorRegistry.claimWinnings.callAsync(new BigNumber(challengeId), {
from: accounts[5],
}).should.eventually.be.rejected.and.have.property("message")
.that.includes("challenge hasn't ended");
await validatorRegistry.claimWinnings
.callAsync(new BigNumber(challengeId), {
from: accounts[5],
})
.should.eventually.be.rejected.and.have.property("message")
.that.includes("challenge hasn't ended");

await testHelpers.skipChallengePeriod(blockNumber);
await validatorRegistry.claimWinnings.awaitTransactionSuccessAsync(new BigNumber(challengeId), {
@@ -1786,27 +1792,28 @@ describe("ValidatorRegistry", async () => {

it("should not modify a negative reward", async () => {
await testHelpers.prepareConfirmedListing("0xffaabb", { reward: TestValues.oneWei.times("-1") });
await validatorRegistry.reduceReward.callAsync("0xffaabb", TestValues.zero).should
.eventually.be.rejected.and.have.property("message")
.that.includes("listing is not generating tokens");
await validatorRegistry.reduceReward
.callAsync("0xffaabb", TestValues.zero)
.should.eventually.be.rejected.and.have.property("message")
.that.includes("listing is not generating tokens");
await testHelpers.exitListing("0xffaabb");
});

it("should not modify a zero reward", async () => {
await testHelpers.prepareConfirmedListing("0xffaabb");
await validatorRegistry.reduceReward.callAsync("0xffaabb", TestValues.oneWei).should
.eventually.be.rejected.and.have.property("message")
.that.includes("listing is not generating tokens");
await validatorRegistry.reduceReward
.callAsync("0xffaabb", TestValues.oneWei)
.should.eventually.be.rejected.and.have.property("message")
.that.includes("listing is not generating tokens");
await testHelpers.exitListing("0xffaabb");
});

it("should not increase a reward", async () => {
await testHelpers.prepareConfirmedListing("0xffaabb", { reward: TestValues.oneWei });
await validatorRegistry.reduceReward.callAsync(
"0xffaabb",
TestValues.oneWei.plus(TestValues.oneWei),
).should.eventually.be.rejected.and.have.property("message")
.that.includes("not reducing reward rate");
await validatorRegistry.reduceReward
.callAsync("0xffaabb", TestValues.oneWei.plus(TestValues.oneWei))
.should.eventually.be.rejected.and.have.property("message")
.that.includes("not reducing reward rate");
await testHelpers.exitListing("0xffaabb");
});
});
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.