Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: update ethers to v6.1 from v5.7 #670

Merged
merged 1 commit into from
Mar 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/forty-zoos-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@farcaster/hub-nodejs': minor
'@farcaster/utils': minor
'@farcaster/hubble': patch
---

upgrade ethers from v5 to v6
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
82 changes: 52 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 @@ -38,42 +37,65 @@ class MockRPCProvider extends BaseProvider {
override async getLogs() {
return [];
}

override async getBlockNumber() {
return 1;
}
}

/** 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 +107,12 @@ beforeAll(async () => {
describe('process events', () => {
beforeEach(async () => {
ethEventsProvider = new EthEventsProvider(hub, mockRPCProvider, mockIdRegistry, mockNameRegistry, 1, 10000);
mockRPCProvider.polling = true;
mockRPCProvider._forEachSubscriber((s) => s.start());
await ethEventsProvider.start();
});

afterEach(async () => {
mockRPCProvider.polling = false;
mockRPCProvider._forEachSubscriber((s) => s.stop());
varunsrin marked this conversation as resolved.
Show resolved Hide resolved
await ethEventsProvider.stop();
});

Expand Down Expand Up @@ -120,10 +142,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 +164,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 +191,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 +208,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