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

[P1-L08] Add input validation throughout DVM #1212

Merged
merged 9 commits into from Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions core/contracts/common/implementation/MultiRole.sol
Expand Up @@ -35,6 +35,7 @@ library Shared {
}

function addMember(RoleMembership storage roleMembership, address memberToAdd) internal {
require(memberToAdd != address(0x0), "Cannot set add shared role to 0x0");
chrismaree marked this conversation as resolved.
Show resolved Hide resolved
roleMembership.members[memberToAdd] = true;
}

Expand Down
1 change: 1 addition & 0 deletions core/contracts/oracle/implementation/Store.sol
Expand Up @@ -132,6 +132,7 @@ contract Store is StoreInterface, MultiRole, Withdrawable {
* @param newWeeklyDelayFee fee escalation per week of late fee payment.
*/
function setWeeklyDelayFee(FixedPoint.Unsigned memory newWeeklyDelayFee) public onlyRoleHolder(uint(Roles.Owner)) {
require(newWeeklyDelayFee.isLessThan(1), "weekly delay fee must be <= 100%");
chrismaree marked this conversation as resolved.
Show resolved Hide resolved
weeklyDelayFee = newWeeklyDelayFee;
}

Expand Down
1 change: 1 addition & 0 deletions core/contracts/oracle/implementation/VoteTiming.sol
Expand Up @@ -18,6 +18,7 @@ library VoteTiming {
* @notice Initializes the data object. Sets the phase length based on the input.
*/
function init(Data storage data, uint phaseLength) internal {
require(phaseLength > 0, "Phase length can not be zero");
data.phaseLength = phaseLength;
}

Expand Down
3 changes: 3 additions & 0 deletions core/test/common/MultiRole.js
Expand Up @@ -101,6 +101,9 @@ contract("MultiRole", function(accounts) {
assert.isTrue(await multiRole.holdsRole("1", account3));
await multiRole.revertIfNotHoldingRole("1", { from: account3 });

// Cannot set a shared role role to the 0x0 address.
assert(await didContractThrow(multiRole.addMember("1", zeroAddress, { from: account2 })));

// Anyone who holds the role should be able to remove members.
await multiRole.removeMember("1", account2, { from: account3 });
assert.isFalse(await multiRole.holdsRole("1", account2));
Expand Down
8 changes: 8 additions & 0 deletions core/test/oracle/Store.js
Expand Up @@ -61,6 +61,14 @@ contract("Store", function(accounts) {
let highFee = { rawValue: web3.utils.toWei("1", "ether") };
assert(await didContractThrow(store.setFixedOracleFeePerSecond(highFee, { from: owner })));

// Can set weekly late fees to less than 100%.
await store.setWeeklyDelayFee({ rawValue: web3.utils.toWei("0.99", "ether") }, { from: owner });

// Disallow setting fees higher than 100%.
chrismaree marked this conversation as resolved.
Show resolved Hide resolved
assert(
await didContractThrow(store.setWeeklyDelayFee({ rawValue: web3.utils.toWei("1", "ether") }, { from: owner }))
);

// TODO Check that only permitted role can change the fee
});

Expand Down
6 changes: 6 additions & 0 deletions core/test/oracle/VoteTiming.js
@@ -1,3 +1,5 @@
const { didContractThrow } = require("../../../common/SolidityTestUtils.js");

const VoteTimingTest = artifacts.require("VoteTimingTest");

contract("VoteTiming", function(accounts) {
Expand All @@ -6,6 +8,10 @@ contract("VoteTiming", function(accounts) {
beforeEach(async function() {
voteTiming = await VoteTimingTest.new("100");
});
it("Reject invalid init params", async function() {
// Should not be able to create an instance of VoteTiming with 0 phase length.
assert(await didContractThrow(VoteTimingTest.new("0")));
});

it("Phasing", async function() {
// If time % 200 is between 0 and 99 (inclusive), the phase should be commit.
Expand Down