From f0e1c0957590c79461c4db71bb4b069a20bfb1fa Mon Sep 17 00:00:00 2001 From: Paul <108695806+pxrl@users.noreply.github.com> Date: Wed, 3 Jan 2024 19:02:23 +0100 Subject: [PATCH] improve(EventManager): Auto-enqueue generated events (#481) This frees the caller from having to track generated events. --- src/clients/mocks/MockConfigStoreClient.ts | 35 +++++++------------ src/clients/mocks/MockEvents.ts | 19 +++++++++- src/clients/mocks/MockHubPoolClient.ts | 35 ++++++++++--------- src/clients/mocks/MockSpokePoolClient.ts | 18 +++++----- ...HubPoolClient.DepositToDestinationToken.ts | 13 +------ test/HubPoolClient.RootBundleEvents.ts | 8 ++--- test/SpokePool.Utilities.ts | 9 ++--- test/SpokePoolClient.RefundRequests.ts | 2 -- test/UBAClientUtilities.ts | 25 +++++-------- test/utils/HubPoolUtils.ts | 6 ++-- 10 files changed, 72 insertions(+), 98 deletions(-) diff --git a/src/clients/mocks/MockConfigStoreClient.ts b/src/clients/mocks/MockConfigStoreClient.ts index fb61e4cf9..938ac1bfb 100644 --- a/src/clients/mocks/MockConfigStoreClient.ts +++ b/src/clients/mocks/MockConfigStoreClient.ts @@ -8,12 +8,11 @@ import { DEFAULT_CONFIG_STORE_VERSION, GLOBAL_CONFIG_STORE_KEYS, } from "../AcrossConfigStoreClient"; -import { EventManager, getEventManager } from "./MockEvents"; +import { EventManager, EventOverrides, getEventManager } from "./MockEvents"; export class MockConfigStoreClient extends AcrossConfigStoreClient { public configStoreVersion = DEFAULT_CONFIG_STORE_VERSION; private eventManager: EventManager | null; - private events: Event[] = []; private ubaActivationBlockOverride: number | undefined; private availableChainIdsOverride: number[] | undefined; @@ -37,11 +36,9 @@ export class MockConfigStoreClient extends AcrossConfigStoreClient { this.chainId = chainId; this.eventManager = mockUpdate ? getEventManager(chainId, this.eventSignatures) : null; if (isDefined(this.eventManager) && this.eventManager) { - this.updateGlobalConfig( - GLOBAL_CONFIG_STORE_KEYS.CHAIN_ID_INDICES, - JSON.stringify(availableChainIdsOverride), - this.eventManager.blockNumber - ); + this.updateGlobalConfig(GLOBAL_CONFIG_STORE_KEYS.CHAIN_ID_INDICES, JSON.stringify(availableChainIdsOverride), { + blockNumber: this.eventManager.blockNumber, + }); } } @@ -72,10 +69,6 @@ export class MockConfigStoreClient extends AcrossConfigStoreClient { this.configStoreVersion = version; } - addEvent(event: Event): void { - this.events.push(event); - } - async _update(): Promise { // Backwards compatibility for pre-existing MockConfigStoreClient users. if (this.eventManager === null) { @@ -89,7 +82,7 @@ export class MockConfigStoreClient extends AcrossConfigStoreClient { // All requested event types must be populated in the array (even if empty). const globalConfigUpdateTimes: number[] = []; const _events: Event[][] = eventNames.map(() => []); - for (const event of this.events.flat()) { + for (const event of this.eventManager.getEvents().flat()) { const idx = eventNames.indexOf(event.event as string); if (idx !== -1) { _events[idx].push(event); @@ -100,7 +93,6 @@ export class MockConfigStoreClient extends AcrossConfigStoreClient { globalConfigUpdateTimes.push(block.timestamp); } } - this.events = []; // Transform 2d-events array into a record. const events = Object.fromEntries(eventNames.map((eventName, idx) => [eventName, _events[idx]])); @@ -117,33 +109,30 @@ export class MockConfigStoreClient extends AcrossConfigStoreClient { }; } - updateGlobalConfig(key: string, value: string, blockNumber?: number): Event { - return this.generateConfig("UpdatedGlobalConfig", utf8ToHex(key), value, blockNumber); + updateGlobalConfig(key: string, value: string, overrides: EventOverrides = {}): Event { + return this.generateConfig("UpdatedGlobalConfig", utf8ToHex(key), value, overrides); } - updateTokenConfig(key: string, value: string, blockNumber?: number): Event { + updateTokenConfig(key: string, value: string, overrides: EventOverrides = {}): Event { // Verify that the key is a valid address if (ethers.utils.isAddress(key) === false) { throw new Error(`Invalid address: ${key}`); } - return this.generateConfig("UpdatedTokenConfig", key, value, blockNumber); + return this.generateConfig("UpdatedTokenConfig", key, value, overrides); } - private generateConfig(event: string, key: string, value: string, blockNumber?: number): Event { + private generateConfig(event: string, key: string, value: string, overrides: EventOverrides = {}): Event { assert(this.eventManager !== null); const topics = [key, value]; const args = { key, value }; - const configEvent = this.eventManager.generateEvent({ + return this.eventManager.generateEvent({ event, address: this.configStore.address, topics: topics.map((topic) => topic.toString()), args, - blockNumber, + blockNumber: overrides.blockNumber, }); - - this.addEvent(configEvent); - return configEvent; } } diff --git a/src/clients/mocks/MockEvents.ts b/src/clients/mocks/MockEvents.ts index 1ba4419f8..7582ed94e 100644 --- a/src/clients/mocks/MockEvents.ts +++ b/src/clients/mocks/MockEvents.ts @@ -4,6 +4,9 @@ import { random } from "lodash"; import { isDefined, randomAddress, toBN } from "../../utils"; const { id, keccak256, toUtf8Bytes } = ethersUtils; +export type EventOverrides = { + blockNumber?: number; +}; type Block = providers.Block; type TransactionResponse = providers.TransactionResponse; @@ -37,6 +40,7 @@ const removeListener = (): void => { export class EventManager { private logIndexes: Record = {}; + public events: Event[] = []; public readonly minBlockRange = 10; public readonly eventSignatures: Record = {}; @@ -51,6 +55,16 @@ export class EventManager { }); } + addEvent(event: Event): void { + this.events.push(event); + } + + getEvents(): Event[] { + const events = this.events; + this.events = []; + return events; + } + generateEvent(inputs: EthersEventTemplate): Event { const { address, event, topics: _topics, data, args } = inputs; const eventSignature = `${event}(${this.eventSignatures[event]})`; @@ -94,7 +108,7 @@ export class EventManager { }); }; - return { + const generatedEvent = { blockNumber, transactionIndex, logIndex, @@ -113,6 +127,9 @@ export class EventManager { getTransactionReceipt, removeListener, } as Event; + + this.addEvent(generatedEvent); + return generatedEvent; } } diff --git a/src/clients/mocks/MockHubPoolClient.ts b/src/clients/mocks/MockHubPoolClient.ts index a2974d965..d82e7cb02 100644 --- a/src/clients/mocks/MockHubPoolClient.ts +++ b/src/clients/mocks/MockHubPoolClient.ts @@ -4,7 +4,7 @@ import { randomAddress, assign } from "../../utils"; import { L1Token, PendingRootBundle } from "../../interfaces"; import { AcrossConfigStoreClient as ConfigStoreClient } from "../AcrossConfigStoreClient"; import { HubPoolClient, HubPoolUpdate } from "../HubPoolClient"; -import { EventManager, getEventManager } from "./MockEvents"; +import { EventManager, EventOverrides, getEventManager } from "./MockEvents"; const emptyRootBundle: PendingRootBundle = { poolRebalanceRoot: "", @@ -20,7 +20,6 @@ const emptyRootBundle: PendingRootBundle = { export class MockHubPoolClient extends HubPoolClient { public rootBundleProposal = emptyRootBundle; - private events: Event[] = []; private l1TokensMock: L1Token[] = []; // L1Tokens and their associated info. private tokenInfoToReturn: L1Token = { address: "", decimals: 0, symbol: "" }; @@ -58,10 +57,6 @@ export class MockHubPoolClient extends HubPoolClient { this.latestBlockSearched = blockNumber; } - addEvent(event: Event): void { - this.events.push(event); - } - addL1Token(l1Token: L1Token) { this.l1TokensMock.push(l1Token); } @@ -107,13 +102,15 @@ export class MockHubPoolClient extends HubPoolClient { // Ensure an array for every requested event exists, in the requested order. // All requested event types must be populated in the array (even if empty). const _events: Event[][] = eventNames.map(() => []); - this.events.flat().forEach((event) => { - const idx = eventNames.indexOf(event.event as string); - if (idx !== -1) { - _events[idx].push(event); - } - }); - this.events = []; + this.eventManager + .getEvents() + .flat() + .forEach((event) => { + const idx = eventNames.indexOf(event.event as string); + if (idx !== -1) { + _events[idx].push(event); + } + }); // Transform 2d-events array into a record. const events = Object.fromEntries(eventNames.map((eventName, idx) => [eventName, _events[idx]])); @@ -139,7 +136,7 @@ export class MockHubPoolClient extends HubPoolClient { destinationChainId: number, l1Token: string, destinationToken: string, - blockNumber?: number + overrides: EventOverrides = {} ): Event { const event = "SetPoolRebalanceRoute"; @@ -155,7 +152,7 @@ export class MockHubPoolClient extends HubPoolClient { address: this.hubPool.address, topics: topics.map((topic) => topic.toString()), args, - blockNumber, + blockNumber: overrides.blockNumber, }); } @@ -166,7 +163,8 @@ export class MockHubPoolClient extends HubPoolClient { poolRebalanceRoot?: string, relayerRefundRoot?: string, slowRelayRoot?: string, - proposer?: string + proposer?: string, + overrides: EventOverrides = {} ): Event { const event = "ProposeRootBundle"; @@ -191,6 +189,7 @@ export class MockHubPoolClient extends HubPoolClient { address: this.hubPool.address, topics: topics.map((topic) => topic.toString()), args, + blockNumber: overrides.blockNumber, }); } @@ -202,7 +201,8 @@ export class MockHubPoolClient extends HubPoolClient { bundleLpFees: BigNumber[], netSendAmounts: BigNumber[], runningBalances: BigNumber[], - caller?: string + caller?: string, + overrides: EventOverrides = {} ): Event { const event = "RootBundleExecuted"; @@ -225,6 +225,7 @@ export class MockHubPoolClient extends HubPoolClient { address: this.hubPool.address, topics: topics.map((topic) => topic.toString()), args, + blockNumber: overrides.blockNumber, }); } } diff --git a/src/clients/mocks/MockSpokePoolClient.ts b/src/clients/mocks/MockSpokePoolClient.ts index 388d4b467..ca39fcde0 100644 --- a/src/clients/mocks/MockSpokePoolClient.ts +++ b/src/clients/mocks/MockSpokePoolClient.ts @@ -6,7 +6,7 @@ import { ZERO_ADDRESS } from "../../constants"; import { DepositWithBlock, FillWithBlock, FundsDepositedEvent, RefundRequestWithBlock } from "../../interfaces"; import { bnZero, toBNWei, forEachAsync, randomAddress } from "../../utils"; import { SpokePoolClient, SpokePoolUpdate } from "../SpokePoolClient"; -import { EventManager, getEventManager } from "./MockEvents"; +import { EventManager, EventOverrides, getEventManager } from "./MockEvents"; type Block = providers.Block; @@ -14,7 +14,6 @@ type Block = providers.Block; // user to bypass on-chain queries and inject ethers Event objects directly. export class MockSpokePoolClient extends SpokePoolClient { public eventManager: EventManager; - private events: Event[] = []; private realizedLpFeePct: BigNumber | undefined = bnZero; private realizedLpFeePctOverride = false; private destinationTokenForChainOverride: Record = {}; @@ -67,10 +66,6 @@ export class MockSpokePoolClient extends SpokePoolClient { this.latestBlockSearched = blockNumber; } - addEvent(event: Event): void { - this.events.push(event); - } - setDepositIds(_depositIds: number[]): void { this.depositIdAtBlock = []; if (_depositIds.length === 0) { @@ -103,14 +98,13 @@ export class MockSpokePoolClient extends SpokePoolClient { // Ensure an array for every requested event exists, in the requested order. // All requested event types must be populated in the array (even if empty). const events: Event[][] = eventsToQuery.map(() => []); - await forEachAsync(this.events.flat(), async (event) => { + await forEachAsync(this.eventManager.getEvents().flat(), async (event) => { const idx = eventsToQuery.indexOf(event.event as string); if (idx !== -1) { events[idx].push(event); blocks[event.blockNumber] = await event.getBlock(); } }); - this.events = []; this.blocks = blocks; // Update latestDepositIdQueried. @@ -258,7 +252,12 @@ export class MockSpokePoolClient extends SpokePoolClient { }); } - generateDepositRoute(originToken: string, destinationChainId: number, enabled: boolean): Event { + generateDepositRoute( + originToken: string, + destinationChainId: number, + enabled: boolean, + overrides: EventOverrides = {} + ): Event { const event = "EnabledDepositRoute"; const topics = [originToken, destinationChainId]; @@ -269,6 +268,7 @@ export class MockSpokePoolClient extends SpokePoolClient { address: this.spokePool.address, topics: topics.map((topic) => topic.toString()), args, + blockNumber: overrides.blockNumber, }); } } diff --git a/test/HubPoolClient.DepositToDestinationToken.ts b/test/HubPoolClient.DepositToDestinationToken.ts index ba2f9f3e3..2273ac913 100644 --- a/test/HubPoolClient.DepositToDestinationToken.ts +++ b/test/HubPoolClient.DepositToDestinationToken.ts @@ -51,7 +51,6 @@ describe("HubPoolClient: Deposit to Destination Token", function () { /Could not find SpokePool mapping/ ); const e1 = hubPoolClient.setPoolRebalanceRoute(destinationChainId, randomL1Token, randomDestinationToken); - hubPoolClient.addEvent(e1); await hubPoolClient.update(); // If input hub pool block is before all events, should throw. @@ -64,7 +63,6 @@ describe("HubPoolClient: Deposit to Destination Token", function () { // Now try changing the destination token. Client should correctly handle this. const e2 = hubPoolClient.setPoolRebalanceRoute(destinationChainId, randomL1Token, randomDestinationToken2); - hubPoolClient.addEvent(e2); await hubPoolClient.update(); expect(hubPoolClient.getL2TokenForL1TokenAtBlock(randomL1Token, destinationChainId, e2.blockNumber)).to.equal( @@ -79,7 +77,6 @@ describe("HubPoolClient: Deposit to Destination Token", function () { /Could not find HubPool mapping/ ); const e1 = hubPoolClient.setPoolRebalanceRoute(destinationChainId, randomL1Token, randomDestinationToken); - hubPoolClient.addEvent(e1); await hubPoolClient.update(); // If input hub pool block is before all events, should throw. @@ -92,7 +89,6 @@ describe("HubPoolClient: Deposit to Destination Token", function () { // Now try changing the L1 token while keeping destination chain and L2 token the same. const e2 = hubPoolClient.setPoolRebalanceRoute(destinationChainId, randomOriginToken, randomDestinationToken); - hubPoolClient.addEvent(e2); await hubPoolClient.update(); expect( @@ -117,7 +113,6 @@ describe("HubPoolClient: Deposit to Destination Token", function () { }; const e0 = hubPoolClient.setPoolRebalanceRoute(originChainId, randomL1Token, randomOriginToken); - hubPoolClient.addEvent(e0); await hubPoolClient.update(); expect(hubPoolClient.getL1TokenForDeposit({ ...depositData, quoteBlockNumber: e0.blockNumber })).to.equal( randomL1Token @@ -138,7 +133,6 @@ describe("HubPoolClient: Deposit to Destination Token", function () { ).to.throw(/Could not find HubPool mapping/); const e1 = hubPoolClient.setPoolRebalanceRoute(originChainId, randomOriginToken, randomOriginToken); - hubPoolClient.addEvent(e1); await hubPoolClient.update(); expect(hubPoolClient.getL1TokenForDeposit({ ...depositData, quoteBlockNumber: e1.blockNumber })).to.equal( randomOriginToken @@ -152,8 +146,6 @@ describe("HubPoolClient: Deposit to Destination Token", function () { const e0 = hubPoolClient.setPoolRebalanceRoute(originChainId, randomL1Token, randomOriginToken); const e1 = hubPoolClient.setPoolRebalanceRoute(destinationChainId, randomL1Token, randomDestinationToken); - hubPoolClient.addEvent(e0); - hubPoolClient.addEvent(e1); await hubPoolClient.update(); expect( hubPoolClient.getL2TokenForDeposit({ ...depositData, destinationChainId, quoteBlockNumber: e1.blockNumber }) @@ -180,7 +172,6 @@ describe("HubPoolClient: Deposit to Destination Token", function () { ).to.throw(/Could not find HubPool mapping/); const e2 = hubPoolClient.setPoolRebalanceRoute(destinationChainId, randomL1Token, randomL1Token); - hubPoolClient.addEvent(e2); await hubPoolClient.update(); expect( hubPoolClient.getL2TokenForDeposit({ ...depositData, destinationChainId, quoteBlockNumber: e2.blockNumber }) @@ -206,9 +197,8 @@ describe("HubPoolClient: Deposit to Destination Token", function () { Number(chainId), hubPoolToken, spokePoolToken, - events[0]?.blockNumber // Force all updates to be parsed in the same block. + { blockNumber: events[0]?.blockNumber } // Force all updates to be parsed in the same block. ); - hubPoolClient.addEvent(event); events.push(event); }); @@ -247,7 +237,6 @@ describe("HubPoolClient: Deposit to Destination Token", function () { // Update the token mapping and read it into the HubPoolClient. const update = hubPoolClient.setPoolRebalanceRoute(destinationChainId, randomL1Token, randomDestinationToken2); - hubPoolClient.addEvent(update); await hubPoolClient.update(); // Mapping should still be valid until the latest update. diff --git a/test/HubPoolClient.RootBundleEvents.ts b/test/HubPoolClient.RootBundleEvents.ts index 479456cc9..5a9ad9519 100644 --- a/test/HubPoolClient.RootBundleEvents.ts +++ b/test/HubPoolClient.RootBundleEvents.ts @@ -461,12 +461,11 @@ describe("HubPoolClient: RootBundle Events", function () { await configStoreClient.update(); const bundleEvaluationBlockNumbers = chainIds.map(() => toBN(random(100, 1000, false))); - const proposalEvent = hubPoolClient.proposeRootBundle( + hubPoolClient.proposeRootBundle( Math.floor(Date.now() / 1000) - 1, // challengePeriodEndTimestamp chainIds.length, // poolRebalanceLeafCount bundleEvaluationBlockNumbers ); - hubPoolClient.addEvent(proposalEvent); await hubPoolClient.update(); // Propose a root bundle and execute the associated leaves. @@ -490,7 +489,6 @@ describe("HubPoolClient: RootBundle Events", function () { l1Tokens.map(() => toBN(0)), // netSendAmounts runningBalances ); - hubPoolClient.addEvent(leafEvent); return leafEvent; }); await hubPoolClient.update(); @@ -536,12 +534,11 @@ describe("HubPoolClient: RootBundle Events", function () { await configStoreClient.update(); const bundleEvaluationBlockNumbers = chainIds.map(() => toBN(random(100, 1000, false))); - const proposalEvent = hubPoolClient.proposeRootBundle( + hubPoolClient.proposeRootBundle( Math.floor(Date.now() / 1000) - 1, // challengePeriodEndTimestamp chainIds.length, // poolRebalanceLeafCount bundleEvaluationBlockNumbers ); - hubPoolClient.addEvent(proposalEvent); await hubPoolClient.update(); // Propose a root bundle and execute the associated leaves. @@ -549,7 +546,6 @@ describe("HubPoolClient: RootBundle Events", function () { const leafEvents = chainIds.map((chainId, idx) => { const groupIndex = toBN(chainId === hubPoolClient.chainId ? 0 : 1); const leafEvent = hubPoolClient.executeRootBundle(groupIndex, idx, toBN(chainId), [], [], [], []); - hubPoolClient.addEvent(leafEvent); return leafEvent; }); await hubPoolClient.update(); diff --git a/test/SpokePool.Utilities.ts b/test/SpokePool.Utilities.ts index 63742eb5b..9633559bf 100644 --- a/test/SpokePool.Utilities.ts +++ b/test/SpokePool.Utilities.ts @@ -43,7 +43,6 @@ const generateValidRefundRequest = async ( destinationChainId: destination.chainId, destinationToken: ZERO_ADDRESS, } as DepositWithBlock); - origin.addEvent(event); await origin.update(); // Pull the DepositWithBlock event out of the origin SpokePoolClient to use as a Fill template. @@ -54,7 +53,6 @@ const generateValidRefundRequest = async ( const fillTemplate = fillFromDeposit(deposit, randomAddress()); fillTemplate.repaymentChainId = (repayment ?? destination).chainId; event = destination.generateFill(fillTemplate as FillWithBlock); - destination.addEvent(event); await destination.update(); // Pull the FillWithBlock event out of the destination SpokePoolClient. @@ -67,7 +65,6 @@ const generateValidRefundRequest = async ( if (repayment !== destination) { const refundRequestTemplate = refundRequestFromFill(fill, fill.destinationToken); event = repayment.generateRefundRequest(refundRequestTemplate as RefundRequestWithBlock); - repayment.addEvent(event); await repayment.update(); // Pull the DepositWithBlock event out of the origin SpokePoolClient to use as a Fill template. @@ -136,10 +133,8 @@ describe("SpokePoolClient: Event Filtering", function () { // @todo: destinationToken [ZERO_ADDRESS].forEach((originToken) => { - let event = spokePoolClient.generateDepositRoute(originToken, destinationChainId, true); - spokePoolClient.addEvent(event); - event = hubPoolClient.setPoolRebalanceRoute(destinationChainId, originToken, originToken); - hubPoolClient.addEvent(event); + spokePoolClient.generateDepositRoute(originToken, destinationChainId, true); + hubPoolClient.setPoolRebalanceRoute(destinationChainId, originToken, originToken); }); } } diff --git a/test/SpokePoolClient.RefundRequests.ts b/test/SpokePoolClient.RefundRequests.ts index a9664335a..4bf34b5ad 100644 --- a/test/SpokePoolClient.RefundRequests.ts +++ b/test/SpokePoolClient.RefundRequests.ts @@ -41,7 +41,6 @@ describe("SpokePoolClient: Refund Requests", function () { for (let _idx = 0; _idx < 5; ++_idx) { const refundRequest = { relayer, originChainId } as RefundRequestWithBlock; const testEvent = spokePoolClient.generateRefundRequest(refundRequest); - spokePoolClient.addEvent(testEvent); refundRequestEvents.push(spreadEventWithBlockNumber(testEvent) as RefundRequestWithBlock); } await spokePoolClient.update(); @@ -67,7 +66,6 @@ describe("SpokePoolClient: Refund Requests", function () { const blockNumber = latestBlockSearched + 1 + txn; const refundRequest = { relayer, originChainId, blockNumber } as RefundRequestWithBlock; const testEvent = spokePoolClient.generateRefundRequest(refundRequest); - spokePoolClient.addEvent(testEvent); refundRequestEvents.push({ ...spreadEventWithBlockNumber(testEvent), repaymentChainId, diff --git a/test/UBAClientUtilities.ts b/test/UBAClientUtilities.ts index 6b47942bb..592f91654 100644 --- a/test/UBAClientUtilities.ts +++ b/test/UBAClientUtilities.ts @@ -365,8 +365,7 @@ describe("UBAClientUtilities", function () { }); // Generate mock events, very simple tests to start it("Returns UBA deposits", async function () { - const event = spokePoolClient.generateDeposit(deposit); - spokePoolClient.addEvent(event); + spokePoolClient.generateDeposit(deposit); await spokePoolClient.update(); const flows = await clients.getUBAFlows(tokenSymbol, chainId, spokePoolClients, hubPoolClient); @@ -377,8 +376,7 @@ describe("UBAClientUtilities", function () { // We expect the getUBAFlows() call to throw because realizedLpFeePct will be set for these deposits spokePoolClient.setDefaultRealizedLpFeePct(toBNWei("0.1")); - const event = spokePoolClient.generateDeposit(deposit); - spokePoolClient.addEvent(event); + spokePoolClient.generateDeposit(deposit); await spokePoolClient.update(); void assertPromiseError( @@ -387,19 +385,16 @@ describe("UBAClientUtilities", function () { ); }); it("Returns fills matched with deposits", async function () { - const depositEvent = spokePoolClient.generateDeposit(deposit); - spokePoolClient.addEvent(depositEvent); + spokePoolClient.generateDeposit(deposit); await spokePoolClient.update(); - const event = destinationSpokePoolClient.generateFill(fill); - destinationSpokePoolClient.addEvent(event); + destinationSpokePoolClient.generateFill(fill); // Add an invalid fill: - const invalidFillEvent = destinationSpokePoolClient.generateFill({ + destinationSpokePoolClient.generateFill({ ...fill, depositId: deposit.depositId + 1, }); - destinationSpokePoolClient.addEvent(invalidFillEvent); await destinationSpokePoolClient.update(); // Look up flows on destination chain @@ -409,8 +404,7 @@ describe("UBAClientUtilities", function () { expect(interfaces.isUbaOutflow(flows[0])).to.be.true; }); it("Returns refunds matched with fills matched with deposits", async function () { - const depositEvent = spokePoolClient.generateDeposit(deposit); - spokePoolClient.addEvent(depositEvent); + spokePoolClient.generateDeposit(deposit); await spokePoolClient.update(); // Generate fill with repaymentChain != destinationChain @@ -418,23 +412,20 @@ describe("UBAClientUtilities", function () { ...fill, repaymentChainId, }); - destinationSpokePoolClient.addEvent(fillEvent); await destinationSpokePoolClient.update(); - const event = repaymentSpokePoolClient.generateRefundRequest({ + repaymentSpokePoolClient.generateRefundRequest({ ...refund, fillBlock: toBN(fillEvent.blockNumber), }); - repaymentSpokePoolClient.addEvent(event); await repaymentSpokePoolClient.update(); // Add an invalid refund: - const invalidRefundEvent = repaymentSpokePoolClient.generateRefundRequest({ + repaymentSpokePoolClient.generateRefundRequest({ ...refund, fillBlock: toBN(fillEvent.blockNumber), previousIdenticalRequests: toBN(2), }); - repaymentSpokePoolClient.addEvent(invalidRefundEvent); await repaymentSpokePoolClient.update(); // Look up flows on destination chain diff --git a/test/utils/HubPoolUtils.ts b/test/utils/HubPoolUtils.ts index 4363e1d91..6922fe32b 100644 --- a/test/utils/HubPoolUtils.ts +++ b/test/utils/HubPoolUtils.ts @@ -37,13 +37,12 @@ export async function publishValidatedBundles( return toBN(nextBlockRangesForChain[chainId].end); }); - const rootBundleProposal = hubPoolClient.proposeRootBundle( + hubPoolClient.proposeRootBundle( Date.now(), // challengePeriodEndTimestamp chainIds.length, // poolRebalanceLeafCount bundleEvaluationBlockNumbers, createRandomBytes32() // Random pool rebalance root we can check. ); - hubPoolClient.addEvent(rootBundleProposal); await hubPoolClient.update(); chainIds.forEach((chainId) => { expectedBlockRanges[chainId].push({ @@ -51,7 +50,7 @@ export async function publishValidatedBundles( }); }); chainIds.forEach((chainId, leafIndex) => { - const leafEvent = hubPoolClient.executeRootBundle( + hubPoolClient.executeRootBundle( toBN(0), leafIndex, toBN(chainId), @@ -60,7 +59,6 @@ export async function publishValidatedBundles( runningBalances, // netSendAmounts runningBalances.concat(incentiveBalances) // runningBalances ); - hubPoolClient.addEvent(leafEvent); }); await hubPoolClient.update();