Skip to content

Commit

Permalink
chore: replace tslint with eslint-typescript (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
faustbrian committed Aug 27, 2020
1 parent cdff65f commit 7bccbcc
Show file tree
Hide file tree
Showing 45 changed files with 2,043 additions and 4,238 deletions.
3 changes: 1 addition & 2 deletions .editorconfig
Expand Up @@ -4,6 +4,5 @@ root = true
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
indent_style = tab
trim_trailing_whitespace = true
9 changes: 9 additions & 0 deletions .eslintignore
@@ -0,0 +1,9 @@
/__tests__/**/*.spec.ts
/__tests__/unit/coverage/
/*.js
/build/
/config/
/dist/
/docs/
/node_modules/**
env.json
41 changes: 41 additions & 0 deletions .eslintrc.json
@@ -0,0 +1,41 @@
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.eslint.json",
"extraFileExtensions": [".json"]
},
"plugins": ["@typescript-eslint", "jest", "prettier", "simple-import-sort"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:@typescript-eslint/recommended",
"plugin:jest/recommended",
"plugin:prettier/recommended",
"prettier/@typescript-eslint"
],
"rules": {
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/naming-convention": "off",
"@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/require-await": "off",
"@typescript-eslint/restrict-plus-operands": "off",
"@typescript-eslint/restrict-template-expressions": "off",
"prefer-const": [
"error",
{
"destructuring": "all"
}
],
"prettier/prettier": "error",
"simple-import-sort/sort": "error"
}
}
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -52,7 +52,6 @@ bundle.min.js

# Build
dist
packages/**/dist/

# Microsoft Visual Studio settings
.vs
Expand Down
2 changes: 2 additions & 0 deletions .prettierignore
@@ -1,3 +1,5 @@
.coverage
.pnp.js
.yarn/**
dist
docs
10 changes: 5 additions & 5 deletions .prettierrc.json
@@ -1,7 +1,7 @@
{
"printWidth": 120,
"singleQuote": false,
"tabWidth": 4,
"trailingComma": "all",
"useTabs": false
"printWidth": 120,
"singleQuote": false,
"tabWidth": 4,
"trailingComma": "all",
"useTabs": true
}
20 changes: 10 additions & 10 deletions __tests__/__mocks__/transaction.ts
Expand Up @@ -2,24 +2,24 @@ export const passphrase = "passphrase 1";
export const passphrases = [passphrase, "passphrase 2", "passphrase 3"];
export const publicKey = "03e8021105a6c202097e97e6c6d650942d913099bf6c9f14a6815df1023dde3b87";
export const participants = [
publicKey,
"03dfdaaa7fd28bc9359874b7e33138f4d0afe9937e152c59b83a99fae7eeb94899",
"03de72ef9d3ebf1b374f1214f5b8dde823690ab2aa32b4b8b3226cc568aaed1562",
publicKey,
"03dfdaaa7fd28bc9359874b7e33138f4d0afe9937e152c59b83a99fae7eeb94899",
"03de72ef9d3ebf1b374f1214f5b8dde823690ab2aa32b4b8b3226cc568aaed1562",
];
export const multisigAsset = {
min: 2,
publicKeys: participants,
min: 2,
publicKeys: participants,
};

export const passphrase2 = "passphrase 4";
export const passphrases2 = [passphrase2, "passphrase 5", passphrase];
export const publicKey2 = "038accc28123025d0b1dd306fcc192be42cbb44105e2bc9b61fe4509469aacb8c4";
export const participants2 = [
publicKey2,
"02589e70ae55be9cef04ef8ef1591a96721c8b2fbf082bd3521b4f248f5befb3b7",
publicKey,
publicKey2,
"02589e70ae55be9cef04ef8ef1591a96721c8b2fbf082bd3521b4f248f5befb3b7",
publicKey,
];
export const multisigAsset2 = {
min: 2,
publicKeys: participants2,
min: 2,
publicKeys: participants2,
};
10 changes: 5 additions & 5 deletions __tests__/__support__/index.ts
Expand Up @@ -4,9 +4,9 @@ import { startServer } from "../../src/app/server";
jest.setTimeout(10000);

export const launchServer = async (): Promise<Server> => {
return startServer({
host: "0.0.0.0",
port: 8080,
network: "testnet",
});
return startServer({
host: "0.0.0.0",
port: 8080,
network: "testnet",
});
};
86 changes: 43 additions & 43 deletions __tests__/server/server.test.ts
Expand Up @@ -11,53 +11,53 @@ import { launchServer } from "../__support__";
const sqliteName = "transactions-storage-testnet.sqlite";
let server: Server;
beforeAll(async () => {
fs.removeSync(sqliteName);
fs.removeSync(sqliteName);

server = await launchServer();
Managers.configManager.setFromPreset("testnet");
server = await launchServer();
Managers.configManager.setFromPreset("testnet");
});
afterAll(async () => {
await server.stop();
fs.removeSync(sqliteName);
await server.stop();
fs.removeSync(sqliteName);
});

describe("Server", () => {
describe("Server stop and restart", () => {
it("should save the transactions to the disk when stopping and restore them when restarting", async () => {
const transaction = Transactions.BuilderFactory.multiSignature()
.multiSignatureAsset(mocks.multisigAsset)
.network(23)
.sign(mocks.passphrase)
.multiSign(mocks.passphrase, 0)
.multiSign(mocks.passphrases[1], 1)
.getStruct();
await got.post(`http://localhost:8080/transaction`, {
body: JSON.stringify({
data: transaction,
multisigAsset: mocks.multisigAsset,
}),
});

const response = await got.get(`http://localhost:8080/transactions?publicKey=${mocks.publicKey}`);
const body = JSON.parse(response.body);
expect(body).toBeArrayOfSize(1);
expect(body[0].data).toEqual(JSON.parse(JSON.stringify(transaction)));
expect(body[0].multisigAsset).toEqual(mocks.multisigAsset);
expect(body[0]).toHaveProperty("timestamp");

await server.stop();

expect(fs.existsSync(sqliteName)).toBeTrue(); // transactions should be saved here

server = await launchServer();
const responseAfterRestart = await got.get(
`http://localhost:8080/transactions?publicKey=${mocks.publicKey}`,
);
const bodyAfterRestart = JSON.parse(responseAfterRestart.body);
expect(bodyAfterRestart).toBeArrayOfSize(1);
expect(bodyAfterRestart[0].data).toEqual(JSON.parse(JSON.stringify(transaction)));
expect(bodyAfterRestart[0].multisigAsset).toEqual(mocks.multisigAsset);
expect(bodyAfterRestart[0]).toHaveProperty("timestamp");
});
});
describe("Server stop and restart", () => {
it("should save the transactions to the disk when stopping and restore them when restarting", async () => {
const transaction = Transactions.BuilderFactory.multiSignature()
.multiSignatureAsset(mocks.multisigAsset)
.network(23)
.sign(mocks.passphrase)
.multiSign(mocks.passphrase, 0)
.multiSign(mocks.passphrases[1], 1)
.getStruct();
await got.post(`http://localhost:8080/transaction`, {
body: JSON.stringify({
data: transaction,
multisigAsset: mocks.multisigAsset,
}),
});

const response = await got.get(`http://localhost:8080/transactions?publicKey=${mocks.publicKey}`);
const body = JSON.parse(response.body);
expect(body).toBeArrayOfSize(1);
expect(body[0].data).toEqual(JSON.parse(JSON.stringify(transaction)));
expect(body[0].multisigAsset).toEqual(mocks.multisigAsset);
expect(body[0]).toHaveProperty("timestamp");

await server.stop();

expect(fs.existsSync(sqliteName)).toBeTrue(); // transactions should be saved here

server = await launchServer();
const responseAfterRestart = await got.get(
`http://localhost:8080/transactions?publicKey=${mocks.publicKey}`,
);
const bodyAfterRestart = JSON.parse(responseAfterRestart.body);
expect(bodyAfterRestart).toBeArrayOfSize(1);
expect(bodyAfterRestart[0].data).toEqual(JSON.parse(JSON.stringify(transaction)));
expect(bodyAfterRestart[0].multisigAsset).toEqual(mocks.multisigAsset);
expect(bodyAfterRestart[0]).toHaveProperty("timestamp");
});
});
});

0 comments on commit 7bccbcc

Please sign in to comment.