Skip to content

Commit

Permalink
Refactor eslint and prettier linter implementation (UMAprotocol#1202)
Browse files Browse the repository at this point in the history
* updated linter implementation

Signed-off-by: Christopher Maree <christopher.maree@gmail.com>

* Another test

Signed-off-by: Christopher Maree <christopher.maree@gmail.com>

* test

Signed-off-by: Christopher Maree <christopher.maree@gmail.com>

* updated .gitignore

Signed-off-by: Christopher Maree <christopher.maree@gmail.com>

* test

Signed-off-by: Christopher Maree <christopher.maree@gmail.com>

* update

Signed-off-by: Christopher Maree <christopher.maree@gmail.com>

* removed file

Signed-off-by: Christopher Maree <christopher.maree@gmail.com>

* test auto lint

Signed-off-by: Christopher Maree <christopher.maree@gmail.com>

* update comment

Signed-off-by: Christopher Maree <christopher.maree@gmail.com>

* final test

Signed-off-by: Christopher Maree <christopher.maree@gmail.com>

* test pretty-quick

Signed-off-by: Christopher Maree <christopher.maree@gmail.com>

* lint test

Signed-off-by: Christopher Maree <christopher.maree@gmail.com>

* fixed contract test

Signed-off-by: Christopher Maree <christopher.maree@gmail.com>

* lint test

Signed-off-by: Christopher Maree <christopher.maree@gmail.com>

* test

Signed-off-by: Christopher Maree <christopher.maree@gmail.com>

* fixed star box

Signed-off-by: Christopher Maree <christopher.maree@gmail.com>

* reverted file changes

Signed-off-by: Christopher Maree <christopher.maree@gmail.com>

* updated package.json

Signed-off-by: Christopher Maree <christopher.maree@gmail.com>

* updated package.json

Signed-off-by: Christopher Maree <christopher.maree@gmail.com>

* Revert Voting.sol

* reverted package version for circleCI

Signed-off-by: Christopher Maree <christopher.maree@gmail.com>

* locked version

Signed-off-by: Christopher Maree <christopher.maree@gmail.com>

* Updated price feed

Signed-off-by: Christopher Maree <christopher.maree@gmail.com>

* updated liquidator bot

Signed-off-by: Christopher Maree <christopher.maree@gmail.com>

* test commit

Signed-off-by: Christopher Maree <christopher.maree@gmail.com>

* test no verify

Signed-off-by: Christopher Maree <christopher.maree@gmail.com>

* test lint-fix

Signed-off-by: Christopher Maree <christopher.maree@gmail.com>

* test

Signed-off-by: Christopher Maree <christopher.maree@gmail.com>

* test

Signed-off-by: Christopher Maree <christopher.maree@gmail.com>
  • Loading branch information
chrismaree authored Apr 14, 2020
1 parent 50a88a3 commit 97a1602
Show file tree
Hide file tree
Showing 16 changed files with 170 additions and 136 deletions.
8 changes: 8 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules
coverage
docs
modules
public
ui
sponsor-dapp-v2
voter-dapp
20 changes: 9 additions & 11 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@ module.exports = {
env: {
browser: true
},
extends: "eslint:recommended",
extends: ["plugin:prettier/recommended"],
plugins: ["prettier"],
parserOptions: {
ecmaVersion: 2018,
sourceType: "module"
ecmaFeatures: {
jsx: true,
modules: true
}
},
parser: "babel-eslint",
rules: {
"prettier/prettier": ["error"],
indent: ["error", 2, { SwitchCase: 1 }],
"linebreak-style": ["error", "unix"],
quotes: ["error", "double", { avoidEscape: true }],
semi: ["error", "always"],
"spaced-comment": ["error", "always", { exceptions: ["-", "+"] }],
"no-undef": [0],
"no-unused-vars": [0],
"no-case-declarations": [0],
"no-constant-condition": [0],
"no-redeclare": [0],
"no-console": [0],
"no-irregular-whitespace": [0]
"spaced-comment": ["error", "always", { exceptions: ["-", "+"] }]
}
};
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public
ui
.DS_Store
antora.yml
.eslintcache

# GAE deployment files and directories for GAE deployments.
app.yaml
Expand Down
7 changes: 7 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules
coverage
docs
modules
public
ui
*/build/
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{
"files": "*.sol",
"options": {
"tabWidth": 4,
"tabWidth": 4
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion ci/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ PROTOCOL_DIR=$(pwd)

# Lint JS
echo "Linting Solidity and js"
npm run lint_check
npm run lint
4 changes: 2 additions & 2 deletions disputer/disputer.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class Disputer {
} catch (error) {
Logger.error({
at: "Disputer",
message: `Failed to dispute liquidation`,
message: "Failed to dispute liquidation",
error: error
});
continue;
Expand Down Expand Up @@ -170,7 +170,7 @@ class Disputer {
} catch (error) {
Logger.error({
at: "Disputer",
message: `Failed to withdraw dispute rewards`,
message: "Failed to withdraw dispute rewards",
error: error
});
continue;
Expand Down
5 changes: 3 additions & 2 deletions financial-templates-lib/ExpiringMultiPartyClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class ExpiringMultiPartyClient {
continue;
}

// Construct Liquidation data to save.
// Construct Liquidation data to save
const liquidationData = {
sponsor: liquidation.sponsor,
id: id.toString(),
Expand Down Expand Up @@ -201,7 +201,8 @@ class ExpiringMultiPartyClient {
// Filter out empty positions.
positions[i].rawCollateral.toString() === "0"
? acc
: acc.concat([
: /* eslint-disable indent */
acc.concat([
{
sponsor: address,
requestPassTimestamp: positions[i].requestPassTimestamp,
Expand Down
6 changes: 3 additions & 3 deletions financial-templates-lib/logger/Logger.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// The logger has a number of different levels based on the severity of the incident:
//-> Debugs: self explanatory. Normal status-based logging. These can trigger
// -> Debugs: self explanatory. Normal status-based logging. These can trigger
// every iteration. Unlimited volume. Prints to console.
//-> Info: when something happens that is notable, but not necessarily actionable.
// -> Info: when something happens that is notable, but not necessarily actionable.
// These should not trigger every iteration. Any on-chain event that executed correctly.
// Print to console & trigger a slack message.
//-> Error: anything that requires human intervention. If the bot is low on funds or a
// -> Error: anything that requires human intervention. If the bot is low on funds or a
// transaction fails(some txn failures are sporadic and normal, but it may be difficult
// to distinguish).These can trigger every iteration, but only if it's because the bot
// encounters a persistent issue that requires human intervention to solve.
Expand Down
4 changes: 2 additions & 2 deletions financial-templates-lib/logger/SlackTransport.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const slackFormatter = info => {
type: "section",
text: {
type: "mrkdwn",
text: `*incorrectly formatted winston message!*`
text: "*incorrectly formatted winston message!*"
}
}
]
Expand All @@ -35,7 +35,7 @@ const slackFormatter = info => {
};

// All messages from winston come in as a Json object. The loop below expands this object
//and adds mrkdwn sections for each key value pair with a bullet point. If the section is
// and adds mrkdwn sections for each key value pair with a bullet point. If the section is
// an object then it was passed containing multiple sub points. This is also expanded as a
// sub indented section. If the key is `tx` then it is encoded as a etherscan URL.
for (const key in info) {
Expand Down
46 changes: 20 additions & 26 deletions financial-templates-lib/test/ExpiringMultiPartyClient.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { toWei } = web3.utils;

const { ExpiringMultiPartyClient } = require("../ExpiringMultiPartyClient");
const { delay } = require('../delay');
const { delay } = require("../delay");

const ExpiringMultiParty = artifacts.require("ExpiringMultiParty");
const Finder = artifacts.require("Finder");
Expand All @@ -11,8 +11,8 @@ const TokenFactory = artifacts.require("TokenFactory");
const Token = artifacts.require("ExpandedERC20");

contract("ExpiringMultiPartyClient.js", function(accounts) {
const sponsor1 = accounts[0]
const sponsor2 = accounts[1]
const sponsor1 = accounts[0];
const sponsor2 = accounts[1];

const zeroAddress = "0x0000000000000000000000000000000000000000";

Expand Down Expand Up @@ -80,7 +80,7 @@ contract("ExpiringMultiPartyClient.js", function(accounts) {
await emp.create({ rawValue: toWei("10") }, { rawValue: toWei("50") }, { from: sponsor1 });
await updateAndVerify(
client,
[sponsor1], //expected sponsor
[sponsor1], // expected sponsor
[
{
sponsor: sponsor1,
Expand All @@ -90,7 +90,7 @@ contract("ExpiringMultiPartyClient.js", function(accounts) {
requestPassTimestamp: "0",
withdrawalRequestAmount: "0"
}
] //expected position
] // expected position
);

// Calling create again from the same sponsor should add additional collateral & debt.
Expand Down Expand Up @@ -142,12 +142,7 @@ contract("ExpiringMultiPartyClient.js", function(accounts) {
{ rawValue: toWei("100") },
{ from: sponsor1 }
);
await emp.createLiquidation(
sponsor2,
{ rawValue: toWei("99999") },
{ rawValue: toWei("100") },
{ from: sponsor1 }
);
await emp.createLiquidation(sponsor2, { rawValue: toWei("99999") }, { rawValue: toWei("100") }, { from: sponsor1 });

await updateAndVerify(
client,
Expand Down Expand Up @@ -224,11 +219,11 @@ contract("ExpiringMultiPartyClient.js", function(accounts) {
);
});

it("Returns undisputed liquidations", async function () {
it("Returns undisputed liquidations", async function() {
const liquidator = sponsor2;

await emp.create({ rawValue: toWei("150") }, { rawValue: toWei("100") }, { from: sponsor1 });
await syntheticToken.transfer(liquidator, toWei("100"), { from: sponsor1 })
await syntheticToken.transfer(liquidator, toWei("100"), { from: sponsor1 });

// Create a new liquidation for account[0]'s position.
const { liquidationId } = await emp.createLiquidation.call(
Expand Down Expand Up @@ -261,7 +256,7 @@ contract("ExpiringMultiPartyClient.js", function(accounts) {
assert.deepStrictEqual([], client.getUndisputedLiquidations().sort());
});

it("Returns expired liquidations", async function () {
it("Returns expired liquidations", async function() {
const liquidator = sponsor2;

await emp.create({ rawValue: toWei("150") }, { rawValue: toWei("100") }, { from: sponsor1 });
Expand Down Expand Up @@ -324,13 +319,13 @@ contract("ExpiringMultiPartyClient.js", function(accounts) {
);

// Withdraw from the expired liquidation and check that the liquidation is deleted.
await emp.withdrawLiquidation("0", sponsor1, { from: liquidator })
await emp.withdrawLiquidation("0", sponsor1, { from: liquidator });
await client._update();
assert.deepStrictEqual([], client.getExpiredLiquidations().sort());
});

it("Returns disputed liquidations", async function () {
const liquidator = sponsor2;
it("Returns disputed liquidations", async function() {
const liquidator = sponsor2;

await emp.create({ rawValue: toWei("150") }, { rawValue: toWei("100") }, { from: sponsor1 });
await syntheticToken.transfer(liquidator, toWei("100"), { from: sponsor1 });
Expand Down Expand Up @@ -373,7 +368,7 @@ contract("ExpiringMultiPartyClient.js", function(accounts) {
liquidator: liquidator,
disputer: sponsor1
}
],
],
client.getDisputedLiquidations().sort()
);
assert.deepStrictEqual([], client.getUndisputedLiquidations().sort());
Expand All @@ -382,26 +377,25 @@ contract("ExpiringMultiPartyClient.js", function(accounts) {
// withdraw from the unsuccessfully disputed liquidation and check that the liquidation is deleted.
const disputePrice = toWei("1.6");
await mockOracle.pushPrice(web3.utils.utf8ToHex("UMATEST"), liquidationTime, disputePrice);
await emp.withdrawLiquidation("0", sponsor1, { from: liquidator })
await emp.withdrawLiquidation("0", sponsor1, { from: liquidator });
await client._update();
assert.deepStrictEqual([], client.getDisputedLiquidations().sort());
})
});

it("Does not update unless forced to", async function () {
it("Does not update unless forced to", async function() {
await client.update();
const lastUpdateTime = client.lastUpdateTimestamp;

// Move time forward so that if an update were to happen, then
// Move time forward so that if an update were to happen, then
// the `lastUpdateTimestamp` get reset.
await delay(Number(1_000));

// Call regular update function which should return because we are within the update threshold.
await client.update();
assert.equal(client.lastUpdateTimestamp, lastUpdateTime)
assert.equal(client.lastUpdateTimestamp, lastUpdateTime);

// Force an update and check that the last timestamp has reset.
await client.forceUpdate();
assert(client.lastUpdateTimestamp > lastUpdateTime)

})
assert(client.lastUpdateTimestamp > lastUpdateTime);
});
});
53 changes: 25 additions & 28 deletions financial-templates-lib/test/GasEstimator.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,54 @@
const { delay } = require('../delay');
const { delay } = require("../delay");

const { GasEstimator } = require("../GasEstimator");

contract("GasEstimator.js", function() {

let gasEstimator;


describe("Construction with default config", () => {
beforeEach(() => {
gasEstimator = new GasEstimator();
})
gasEstimator = new GasEstimator();
});

it("Default parameters are set correctly", () => {
assert(gasEstimator.updateThreshold > 0);
assert(gasEstimator.defaultFastPriceGwei > 0);
assert(gasEstimator.updateThreshold > 0);
assert(gasEstimator.defaultFastPriceGwei > 0);
});
it("Returns gas prices in wei before initial update", () => {
assert.equal(gasEstimator.defaultFastPriceGwei, gasEstimator.getCurrentFastPrice()/1e9);
assert.equal(gasEstimator.defaultFastPriceGwei, gasEstimator.getCurrentFastPrice() / 1e9);
});
it("Returns gas prices in wei after update", async () => {
await gasEstimator.update();
const latestFastGasPrice = gasEstimator.getCurrentFastPrice() / 1e9;
if (latestFastGasPrice === gasEstimator.defaultFastPriceGwei) {
console.log(`API Request to ethgasstation.info failed, using default gas price in Gwei: ${latestFastGasPrice}`);
}
assert(latestFastGasPrice > 0);
await gasEstimator.update();
const latestFastGasPrice = gasEstimator.getCurrentFastPrice() / 1e9;
if (latestFastGasPrice === gasEstimator.defaultFastPriceGwei) {
console.log(`API Request to ethgasstation.info failed, using default gas price in Gwei: ${latestFastGasPrice}`);
}
assert(latestFastGasPrice > 0);
});
it("Does not update if called before update threshold", async () => {
await gasEstimator.update();
const lastUpdateTimestamp = gasEstimator.lastUpdateTimestamp;
await delay(Number(1_000));
await gasEstimator.update();
assert.equal(lastUpdateTimestamp, gasEstimator.lastUpdateTimestamp);
await gasEstimator.update();
const lastUpdateTimestamp = gasEstimator.lastUpdateTimestamp;
await delay(Number(1_000));
await gasEstimator.update();
assert.equal(lastUpdateTimestamp, gasEstimator.lastUpdateTimestamp);
});
});

describe("Construction with custom config", () => {
beforeEach(() => {
gasEstimator = new GasEstimator(updateThreshold=1.5, defaultFastPriceGwei=10);
gasEstimator = new GasEstimator((updateThreshold = 1.5), (defaultFastPriceGwei = 10));
});

it("Default parameters are set correctly", () => {
assert.equal(gasEstimator.updateThreshold, 1.5);
assert.equal(gasEstimator.defaultFastPriceGwei, 10);
assert.equal(gasEstimator.updateThreshold, 1.5);
assert.equal(gasEstimator.defaultFastPriceGwei, 10);
});
it("Updates if called after update threshold", async () => {
await gasEstimator.update();
const lastUpdateTimestamp = gasEstimator.lastUpdateTimestamp;
await delay(Number(2_000));
await gasEstimator.update();
assert.isTrue(lastUpdateTimestamp < gasEstimator.lastUpdateTimestamp);
await gasEstimator.update();
const lastUpdateTimestamp = gasEstimator.lastUpdateTimestamp;
await delay(Number(1_500));
await gasEstimator.update();
assert(lastUpdateTimestamp < gasEstimator.lastUpdateTimestamp);
});
});

});
Loading

0 comments on commit 97a1602

Please sign in to comment.