Skip to content

Commit

Permalink
refactor: remove lodash dependencies & general housekeeping
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Faust committed Sep 16, 2019
1 parent 08ca0fa commit 3c12f5a
Show file tree
Hide file tree
Showing 86 changed files with 774 additions and 2,153 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
import "jest-extended";

import { Application } from "@packages/core-kernel/src/application";
import { Container, interfaces, Identifiers } from "@packages/core-kernel/src/ioc";
import { Container, Identifiers } from "@packages/core-kernel/src/ioc";
import { ServiceProvider } from "@packages/core-kernel/src/services/actions";
import { Actions } from "@packages/core-kernel/src/services/actions/actions";

let app: Application;
let container: interfaces.Container;

beforeEach(() => {
container = new Container();
container.snapshot();

app = new Application(container);
});

afterEach(() => container.restore());
beforeEach(() => (app = new Application(new Container())));

describe("ActionsServiceProvider", () => {
it(".register", async () => {
Expand Down
16 changes: 6 additions & 10 deletions __tests__/unit/core-kernel/services/cache/service-provider.test.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
import "jest-extended";

import { Application } from "@packages/core-kernel/src/application";
import { Container, interfaces, Identifiers } from "@packages/core-kernel/src/ioc";
import { Container, Identifiers } from "@packages/core-kernel/src/ioc";
import { ServiceProvider } from "@packages/core-kernel/src/services/cache";
import { MemoryCacheStore } from "@packages/core-kernel/src/services/cache/drivers/memory";

let app: Application;
let container: interfaces.Container;

beforeEach(() => {
container = new Container();
container.snapshot();

app = new Application(container);
});

afterEach(() => container.restore());
beforeEach(() => (app = new Application(new Container())));

describe("CacheServiceProvider", () => {
it(".register", async () => {
expect(app.isBound(Identifiers.CacheManager)).toBeFalse();
expect(app.isBound(Identifiers.CacheService)).toBeFalse();

await app.resolve<ServiceProvider>(ServiceProvider).register();

expect(app.isBound(Identifiers.CacheManager)).toBeTrue();
expect(app.isBound(Identifiers.CacheService)).toBeTrue();
expect(app.get(Identifiers.CacheService)).toBeInstanceOf(MemoryCacheStore);
});
});
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
import "jest-extended";

import { Application } from "@packages/core-kernel/src/application";
import { Container, interfaces, Identifiers } from "@packages/core-kernel/src/ioc";
import { Container, Identifiers } from "@packages/core-kernel/src/ioc";
import { ServiceProvider } from "@packages/core-kernel/src/services/events";
import { MemoryEventDispatcher } from "@packages/core-kernel/src/services/events/drivers/memory";

let app: Application;
let container: interfaces.Container;

beforeEach(() => {
container = new Container();
container.snapshot();

app = new Application(container);
});

afterEach(() => container.restore());
beforeEach(() => (app = new Application(new Container())));

describe("EventDispatcherServiceProvider", () => {
it(".register", async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
import "jest-extended";

import { Application } from "@packages/core-kernel/src/application";
import { Container, interfaces, Identifiers } from "@packages/core-kernel/src/ioc";
import { Container, Identifiers } from "@packages/core-kernel/src/ioc";
import { ServiceProvider } from "@packages/core-kernel/src/services/filesystem";
import { LocalFilesystem } from "@packages/core-kernel/src/services/filesystem/drivers/local";

let app: Application;
let container: interfaces.Container;

beforeEach(() => {
container = new Container();
container.snapshot();

app = new Application(container);
});

afterEach(() => container.restore());
beforeEach(() => (app = new Application(new Container())));

describe("FilesystemServiceProvider", () => {
it(".register", async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
import "jest-extended";

import { Application } from "@packages/core-kernel/src/application";
import { Container, interfaces, Identifiers } from "@packages/core-kernel/src/ioc";
import { Container, Identifiers } from "@packages/core-kernel/src/ioc";
import { ServiceProvider } from "@packages/core-kernel/src/services/mixins";
import { MixinService } from "@packages/core-kernel/src/services/mixins/mixins";

let app: Application;
let container: interfaces.Container;

beforeEach(() => {
container = new Container();
container.snapshot();

app = new Application(container);
});

afterEach(() => container.restore());
beforeEach(() => (app = new Application(new Container())));

describe("MixinServiceProvider", () => {
it(".register", async () => {
Expand All @@ -23,5 +16,6 @@ describe("MixinServiceProvider", () => {
await app.resolve<ServiceProvider>(ServiceProvider).register();

expect(app.isBound(Identifiers.MixinService)).toBeTrue();
expect(app.get(Identifiers.MixinService)).toBeInstanceOf(MixinService);
});
});
12 changes: 2 additions & 10 deletions __tests__/unit/core-kernel/services/queue/service-provider.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
import "jest-extended";

import { Application } from "@packages/core-kernel/src/application";
import { Container, interfaces, Identifiers } from "@packages/core-kernel/src/ioc";
import { Container, Identifiers } from "@packages/core-kernel/src/ioc";
import { ServiceProvider } from "@packages/core-kernel/src/services/queue";
import { MemoryQueue } from "@packages/core-kernel/src/services/queue/drivers/memory";

let app: Application;
let container: interfaces.Container;

beforeEach(() => {
container = new Container();
container.snapshot();

app = new Application(container);
});

afterEach(() => container.restore());
beforeEach(() => (app = new Application(new Container())));

describe("QueueServiceProvider", () => {
it(".register", async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
import "jest-extended";

import { Application } from "@packages/core-kernel/src/application";
import { Container, interfaces, Identifiers } from "@packages/core-kernel/src/ioc";
import { Container, Identifiers } from "@packages/core-kernel/src/ioc";
import { ServiceProvider } from "@packages/core-kernel/src/services/schedule";
import { Schedule } from "@packages/core-kernel/src/services/schedule/schedule";

let app: Application;
let container: interfaces.Container;

beforeEach(() => {
container = new Container();
container.snapshot();

app = new Application(container);
});

afterEach(() => container.restore());
beforeEach(() => (app = new Application(new Container())));

describe("LogServiceProvider", () => {
it(".register", async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
import "jest-extended";

import { Application } from "@packages/core-kernel/src/application";
import { Container, interfaces, Identifiers } from "@packages/core-kernel/src/ioc";
import { Container, Identifiers } from "@packages/core-kernel/src/ioc";
import { ServiceProvider } from "@packages/core-kernel/src/services/validation";
import { JoiValidator } from "@packages/core-kernel/src/services/validation/drivers/joi";

let app: Application;
let container: interfaces.Container;

beforeEach(() => {
container = new Container();
container.snapshot();

app = new Application(container);
});

afterEach(() => container.restore());
beforeEach(() => (app = new Application(new Container())));

describe("ValidationServiceProvider", () => {
it(".register", async () => {
Expand Down
31 changes: 0 additions & 31 deletions __tests__/unit/core-kernel/utils/capped-set.test.ts

This file was deleted.

52 changes: 39 additions & 13 deletions __tests__/unit/core-kernel/utils/delegate-calculator.test.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,68 @@
import "jest-extended";

import { Wallets } from "@arkecosystem/core-state";
import { app } from "@arkecosystem/core-kernel";
import { Identifiers } from "@packages/core-kernel/src/ioc";
import { AttributeService } from "@packages/core-kernel/src/services/attributes";
import { Wallet } from "@packages/core-state/src/wallets";
import { Managers, Utils } from "@arkecosystem/crypto";
import { calculateApproval, calculateForgedTotal } from "@packages/core-kernel/src/utils/delegate-calculator";

let delegate: Wallets.Wallet;
let attributes;
beforeAll(() => {
// @fixme: we modify the real app instance instead of using a container and snapshot.
// There are some context issues that result in "core-state" resolving a different container
// then we initially specify in the test so those bindings would not be available.

beforeEach(() => {
attributes = {
producedBlocks: 0,
};
app.bind<AttributeService>(Identifiers.AttributeService)
.to(AttributeService)
.inSingletonScope();

delegate = new Wallets.Wallet("D61xc3yoBQDitwjqUspMPx1ooET6r1XLt7");
delegate.setAttribute("delegate", attributes);
app.get<AttributeService>(Identifiers.AttributeService).set("wallet");

app.get<AttributeService>(Identifiers.AttributeService)
.get("wallet")
.bind("delegate");

app.get<AttributeService>(Identifiers.AttributeService)
.get("wallet")
.bind("delegate.voteBalance");

Managers.configManager.set("genesisBlock.totalAmount", 1000000 * 1e8);
});

describe("Delegate Calculator", () => {
describe("calculateApproval", () => {
it("should calculate correctly with a height", () => {
attributes.voteBalance = Utils.BigNumber.make(10000 * 1e8);
const delegate = new Wallet("D61xc3yoBQDitwjqUspMPx1ooET6r1XLt7");

delegate.setAttribute("delegate", {
producedBlocks: 0,
voteBalance: Utils.BigNumber.make(10000 * 1e8),
});

expect(calculateApproval(delegate, 1)).toBe(1);
});

it("should calculate correctly with 2 decimals", () => {
attributes.voteBalance = Utils.BigNumber.make(16500 * 1e8);
const delegate = new Wallet("D61xc3yoBQDitwjqUspMPx1ooET6r1XLt7");

delegate.setAttribute("delegate", {
producedBlocks: 0,
voteBalance: Utils.BigNumber.make(16500 * 1e8),
});

expect(calculateApproval(delegate, 1)).toBe(1.65);
});
});

describe("calculateForgedTotal", () => {
it("should calculate correctly", () => {
attributes.forgedFees = Utils.BigNumber.make(10);
attributes.forgedRewards = Utils.BigNumber.make(100);
const delegate = new Wallet("D61xc3yoBQDitwjqUspMPx1ooET6r1XLt7");

delegate.setAttribute("delegate", {
producedBlocks: 0,
forgedFees: Utils.BigNumber.make(10),
forgedRewards: Utils.BigNumber.make(100),
});

expect(calculateForgedTotal(delegate)).toBe("110");
});
Expand Down
20 changes: 0 additions & 20 deletions __tests__/unit/core-kernel/utils/has-some-property.test.ts

This file was deleted.

Loading

0 comments on commit 3c12f5a

Please sign in to comment.