Skip to content

Commit

Permalink
refactor: update ethers to v6.1 from v5.7
Browse files Browse the repository at this point in the history
  • Loading branch information
varunsrin committed Mar 18, 2023
1 parent 8f2c6ef commit fca54ac
Show file tree
Hide file tree
Showing 21 changed files with 238 additions and 614 deletions.
2 changes: 1 addition & 1 deletion apps/hubble/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"@multiformats/multiaddr": "^11.0.0",
"async-lock": "^1.4.0",
"commander": "~10.0.0",
"ethers": "~5.7.2",
"ethers": "6.1.0",
"libp2p": "0.42.2",
"neverthrow": "~6.0.0",
"node-cron": "~3.0.2",
Expand Down
78 changes: 48 additions & 30 deletions apps/hubble/src/eth/ethEventsProvider.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Event } from '@ethersproject/contracts';
import { BaseProvider, Block, TransactionReceipt, TransactionResponse } from '@ethersproject/providers';
import * as protobufs from '@farcaster/protobufs';
import { Factories, bytesToHexString, hexStringToBytes } from '@farcaster/utils';
import { BigNumber, Contract, utils } from 'ethers';
import { AbstractProvider, Block, Contract, Log, Provider, TransactionReceipt, TransactionResponse } from 'ethers';
import { OrphanFilter } from 'ethers/types/providers';
import { IdRegistry, NameRegistry } from '~/eth/abis';
import { EthEventsProvider } from '~/eth/ethEventsProvider';
import { bytesToBytes32 } from '~/eth/utils';
Expand All @@ -29,7 +28,7 @@ const generateEthAddressHex = () => {
};

/** A Mock RPC provider */
class MockRPCProvider extends BaseProvider {
class MockRPCProvider extends AbstractProvider {
constructor() {
// The Goerli networkID is 5
super(5);
Expand All @@ -41,39 +40,58 @@ class MockRPCProvider extends BaseProvider {
}

/** A Mock Event. Note the disabled no-empty-function rule at the top, it is needed to allow no-op functions in the mock. */
class MockEvent implements Event {
event?: string;
eventSignature?: string;
args?: utils.Result;
decodeError?: Error;
decode?: (data: string, topics?: string[] | undefined) => any;
// eslint-disable-next-line @typescript-eslint/no-empty-function
removeListener: () => void = () => {};
getBlock: () => Promise<Block> = () => Promise.resolve({} as Block);
getTransaction: () => Promise<TransactionResponse> = () => Promise.resolve({} as TransactionResponse);
getTransactionReceipt: () => Promise<TransactionReceipt> = () => Promise.resolve({} as TransactionReceipt);
class MockEvent implements Log {
address: string;
blockNumber: number;
blockHash: string;
transactionIndex: number;
removed: boolean;
address: string;
data: string;
index: number;
provider: Provider;
removed: boolean;
topics: string[];
transactionHash: string;
logIndex: number;
transactionIndex: number;

constructor(blockNumber: number, blockHash: string, transactionHash: string, logIndex: number) {
// Allow no-op functions in the mock
// eslint-disable-next-line @typescript-eslint/no-empty-function
removeListener: () => void = () => {};
getBlock: () => Promise<Block> = () => Promise.resolve({} as Block);
getTransaction: () => Promise<TransactionResponse> = () => Promise.resolve({} as TransactionResponse);
getTransactionReceipt: () => Promise<TransactionReceipt> = () => Promise.resolve({} as TransactionReceipt);

constructor(
blockNumber: number,
blockHash: string,
transactionHash: string,
index: number,
provider: AbstractProvider
) {
this.blockNumber = blockNumber;
this.blockHash = blockHash;
this.transactionHash = transactionHash;
this.logIndex = logIndex;
this.index = index;
this.provider = provider;

this.transactionIndex = 0;
this.removed = false;
this.address = '';
this.data = '';
this.topics = [];
}

get eventName(): string {
throw new Error('Method not implemented.');
}
get eventSignature(): string {
throw new Error('Method not implemented.');
}

toJSON() {
throw new Error('Method not implemented.');
}
removedEvent(): OrphanFilter {
throw new Error('Method not implemented.');
}
}

beforeAll(async () => {
Expand All @@ -85,12 +103,12 @@ beforeAll(async () => {
describe('process events', () => {
beforeEach(async () => {
ethEventsProvider = new EthEventsProvider(hub, mockRPCProvider, mockIdRegistry, mockNameRegistry, 1, 10000);
mockRPCProvider.polling = true;
// mockRPCProvider.polling = true;
await ethEventsProvider.start();
});

afterEach(async () => {
mockRPCProvider.polling = false;
// mockRPCProvider.polling = false;
await ethEventsProvider.stop();
});

Expand Down Expand Up @@ -120,10 +138,10 @@ describe('process events', () => {
const rRegister = mockIdRegistry.emit(
'Register',
address1,
BigNumber.from(fid),
BigInt(fid),
'',
'',
new MockEvent(blockNumber++, '0xb00001', '0x400001', 0)
new MockEvent(blockNumber++, '0xb00001', '0x400001', 0, mockRPCProvider)
);
expect(rRegister).toBeTruthy();

Expand All @@ -142,8 +160,8 @@ describe('process events', () => {
'Transfer',
address1,
address2,
BigNumber.from(fid),
new MockEvent(blockNumber++, '0xb00002', '0x400002', 0)
BigInt(fid),
new MockEvent(blockNumber++, '0xb00002', '0x400002', 0, mockRPCProvider)
);
// The event is not immediately available, since it has to wait for confirmations. We should still get the Register event
const existingIdRegistryEvent = await getIdRegistryEvent(db, fid);
Expand All @@ -169,7 +187,7 @@ describe('process events', () => {
'0x000001',
'0x000002',
bytesToBytes32(fname)._unsafeUnwrap(),
new MockEvent(blockNumber++, '0xb00001', '0x400001', 0)
new MockEvent(blockNumber++, '0xb00001', '0x400001', 0, mockRPCProvider)
);
expect(rTransfer).toBeTruthy();

Expand All @@ -186,8 +204,8 @@ describe('process events', () => {
mockNameRegistry.emit(
'Renew',
bytesToBytes32(fname)._unsafeUnwrap(),
BigNumber.from(Date.now() + 1000),
new MockEvent(blockNumber++, '0xb00002', '0x400002', 0)
BigInt(Date.now() + 1000),
new MockEvent(blockNumber++, '0xb00002', '0x400002', 0, mockRPCProvider)
);
// The event is not immediately available, since it has to wait for confirmations. We should still get the Transfer event
expect(await getNameRegistryEvent(db, fname)).toMatchObject({
Expand Down
Loading

0 comments on commit fca54ac

Please sign in to comment.