Skip to content

Commit

Permalink
address Pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mpetrunic committed May 2, 2019
1 parent f7f6c8f commit eefabc3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 20 deletions.
5 changes: 2 additions & 3 deletions src/eth1/impl/ethers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {DB} from "../../db";

export interface EthersEth1Options extends Eth1Options {
provider: ethers.providers.BaseProvider;
db: DB;
contract?: Contract;
}

Expand All @@ -36,12 +35,12 @@ export class EthersEth1Notifier extends EventEmitter implements Eth1Notifier {
private opts: EthersEth1Options;


public constructor(opts: EthersEth1Options) {
public constructor(opts: EthersEth1Options, {db}) {
super();
this.opts = opts;
this.provider = opts.provider;
this.contract = this.opts.contract;
this.db = opts.db;
this.db = db;
this.depositCount = 0;
this._latestBlockHash = null;
this.genesisBlockHash = null;
Expand Down
10 changes: 6 additions & 4 deletions src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ class BeaconNode {

this.db = new LevelDB(this.conf.db);
this.network = new P2PNetwork(this.conf.network);
this.eth1 = new EthersEth1Notifier({
...this.conf.eth1,
db: this.db
});
this.eth1 = new EthersEth1Notifier(
this.conf.eth1,
{
db: this.db
}
);
this.sync = new Sync(this.conf.sync, {
network: this.network,
});
Expand Down
6 changes: 2 additions & 4 deletions test/e2e/eth1/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import {Eth1Wallet, EthersEth1Notifier} from "../../../src/eth1";
import {depositContract} from "../../../src/eth1/dev/defaults";
import {PrivateEth1Network} from "../../../src/eth1/dev";
import logger from "../../../src/logger/winston";
import {LevelDB, PouchDb} from "../../../src/db";
import level from "level";
import {PouchDb} from "../../../src/db";

describe("Eth1Notifier - using deployed contract", () => {

Expand Down Expand Up @@ -36,8 +35,7 @@ describe("Eth1Notifier - using deployed contract", () => {
address: depositContractAddress,
},
provider,
db
});
}, {db});
await eth1Notifier.start();
});

Expand Down
14 changes: 5 additions & 9 deletions test/unit/eth1/ethers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ describe("Eth1Notifier", () => {
db.deleteGenesisDeposits = sandbox.stub();
eth1 = new EthersEth1Notifier({
depositContract: defaults.depositContract,
provider,
db
});
provider
}, {db});
});

after(async () => {
Expand All @@ -52,10 +51,9 @@ describe("Eth1Notifier", () => {
const notifier = new EthersEth1Notifier({
depositContract: defaults.depositContract,
provider,
db,
// @ts-ignore
contract
});
}, {db});
contract.on.returns(null);
await notifier.start();
expect(contract.on.withArgs('Deposit', sinon.match.any).calledOnce).to.be.true;
Expand All @@ -70,10 +68,9 @@ describe("Eth1Notifier", () => {
const notifier = new EthersEth1Notifier({
depositContract: defaults.depositContract,
provider,
db,
// @ts-ignore
contract
});
}, {db});
contract.removeAllListeners.returns(null);
await notifier.stop();
expect(contract.removeAllListeners.withArgs('Deposit').calledOnce).to.be.true;
Expand Down Expand Up @@ -144,9 +141,8 @@ describe("Eth1Notifier", () => {
const notifier = new EthersEth1Notifier({
depositContract: defaults.depositContract,
provider,
db,
contract
});
}, {db});
const testDepositRoot = Buffer.alloc(32);
spy.resolves('0x' + testDepositRoot.toString('hex'));

Expand Down

0 comments on commit eefabc3

Please sign in to comment.