Skip to content

Commit

Permalink
feat: Refactor storage events to use OnChainEvent (#1210)
Browse files Browse the repository at this point in the history
* feat: Refactor storage events to use OnChainEvent

* Add tests for getOnChainEvents

* Add changeset

* Guarantee ordering to fix tests
  • Loading branch information
sanjayprabhu authored Aug 2, 2023
1 parent 996be82 commit 67e9466
Show file tree
Hide file tree
Showing 42 changed files with 939 additions and 1,999 deletions.
8 changes: 8 additions & 0 deletions .changeset/tidy-panthers-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@farcaster/hub-nodejs": patch
"@farcaster/hub-web": patch
"@farcaster/core": patch
"@farcaster/hubble": patch
---

feat: refactor storage rent events to on chain events
8 changes: 3 additions & 5 deletions apps/hubble/src/console/genCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
FarcasterNetwork,
Message,
Metadata,
getFarcasterTime,
} from "@farcaster/hub-nodejs";
import { ConsoleCommandInterface } from "./console.js";

Expand Down Expand Up @@ -79,12 +78,11 @@ export class GenCommand implements ConsoleCommandInterface {
return `Failed to submit custody event for fid ${fid}: ${idResult.error}`;
}

const rentRegistryEvent = Factories.RentRegistryEvent.build({
const rentRegistryEvent = Factories.StorageRentOnChainEvent.build({
fid,
expiry: getFarcasterTime()._unsafeUnwrap() + 365 * 24 * 60 * 60,
units: 2,
storageRentEventBody: Factories.StorageRentEventBody.build({ units: 2 }),
});
const rentResult = await this.adminRpcClient.submitRentRegistryEvent(rentRegistryEvent, metadata);
const rentResult = await this.adminRpcClient.submitOnChainEvent(rentRegistryEvent, metadata);

if (rentResult.isOk()) {
numSuccess++;
Expand Down
40 changes: 9 additions & 31 deletions apps/hubble/src/eth/l2EventsProvider.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FarcasterNetwork, StorageRegistryEventType } from "@farcaster/hub-nodejs";
import { FarcasterNetwork, OnChainEventType, StorageRegistryEventType } from "@farcaster/hub-nodejs";
import { StorageRegistry } from "./abis.js";
import { jestRocksDB } from "../storage/db/jestUtils.js";
import Engine from "../storage/engine/index.js";
Expand All @@ -7,17 +7,14 @@ import { deployStorageRegistry, publicClient, testClient, walletClientWithAccoun
import { accounts } from "../test/constants.js";
import { sleep } from "../utils/crypto.js";
import { L2EventsProvider, OptimismConstants } from "./l2EventsProvider.js";
import {
getNextRentRegistryEventFromIterator,
getNextStorageAdminRegistryEventFromIterator,
getRentRegistryEventsIterator,
getStorageAdminRegistryEventsIterator,
} from "../storage/db/storageRegistryEvent.js";
import { Transport, toBytes } from "viem";
import { Transport } from "viem";
import OnChainEventStore from "../storage/stores/onChainEventStore.js";
import StoreEventHandler from "../storage/stores/storeEventHandler.js";

const db = jestRocksDB("protobufs.l2EventsProvider.test");
const engine = new Engine(db, FarcasterNetwork.TESTNET);
const hub = new MockHub(db, engine);
const onChainEventStore = new OnChainEventStore(db, new StoreEventHandler(db));

let l2EventsProvider: L2EventsProvider;
let storageRegistryAddress: `0x${string}`;
Expand Down Expand Up @@ -174,28 +171,9 @@ describe("process events", () => {
await testClient.mine({ blocks: 7 });
await waitForBlock(Number(maxUnitsTrx.blockNumber) + L2EventsProvider.numConfirmations);

const postCreditRegistryEventIterator = await getRentRegistryEventsIterator(db, 1);
const postCreditRegistryEvent = await getNextRentRegistryEventFromIterator(postCreditRegistryEventIterator);
expect(postCreditRegistryEvent).toBeDefined();
expect(postCreditRegistryEvent?.fid).toEqual(1);
expect(postCreditRegistryEvent?.type).toEqual(StorageRegistryEventType.RENT);

const storageAdminRegistryEventIterator = await getStorageAdminRegistryEventsIterator(db);
const storageAdminEvents = [];
for (let i = 0; i < 4; i++) {
storageAdminEvents.push(await getNextStorageAdminRegistryEventFromIterator(storageAdminRegistryEventIterator));
}

expect(storageAdminEvents[0]?.type).toEqual(StorageRegistryEventType.SET_PRICE);
expect(storageAdminEvents[0]?.value).toEqual(toBytes(BigInt(1)));

expect(storageAdminEvents[1]?.type).toEqual(StorageRegistryEventType.SET_DEPRECATION_TIMESTAMP);
expect(storageAdminEvents[1]?.value).toEqual(toBytes(BigInt(100000000000000)));

expect(storageAdminEvents[2]?.type).toEqual(StorageRegistryEventType.SET_GRACE_PERIOD);
expect(storageAdminEvents[2]?.value).toEqual(toBytes(BigInt(1)));

expect(storageAdminEvents[3]?.type).toEqual(StorageRegistryEventType.SET_MAX_UNITS);
expect(storageAdminEvents[3]?.value).toEqual(toBytes(BigInt(1)));
const events = await onChainEventStore.getOnChainEvents(OnChainEventType.EVENT_TYPE_STORAGE_RENT, 1);
expect(events.length).toEqual(1);
expect(events[0]?.fid).toEqual(1);
expect(events[0]?.storageRentEventBody?.units).toEqual(1);
}, 30000);
});
Loading

0 comments on commit 67e9466

Please sign in to comment.