Skip to content
Draft
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
56 changes: 22 additions & 34 deletions test/Dataworker.loadData.deposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
getDefaultBlockRange,
getDisabledBlockRanges,
sinon,
smock,
spyLogIncludes,
setupMockClients,
} from "./utils";

import { Dataworker } from "../src/dataworker/Dataworker"; // Tested
Expand All @@ -35,7 +35,7 @@ let updateAllClients: () => Promise<void>;

// TODO: Rename this file to BundleDataClient
describe("Dataworker: Load bundle data", async function () {
beforeEach(async function () {
before(async function () {
({
erc20_1,
erc20_2,
Expand All @@ -52,6 +52,10 @@ describe("Dataworker: Load bundle data", async function () {
} = await setupDataworker(ethers, 25, 25, 0));
});

beforeEach(function () {
spy.resetHistory();
});

describe("Computing bundle deposits and expired deposits to refund", function () {
let mockOriginSpokePoolClient: MockSpokePoolClient, mockDestinationSpokePoolClient: MockSpokePoolClient;
let mockHubPoolClient: MockHubPoolClient;
Expand All @@ -60,39 +64,23 @@ describe("Dataworker: Load bundle data", async function () {

beforeEach(async function () {
await updateAllClients();
mockHubPoolClient = new MockHubPoolClient(
hubPoolClient.logger,
hubPoolClient.hubPool,
({
mockHubPoolClient,
mockOriginSpokePoolClient,
mockDestinationSpokePoolClient,
mockDestinationSpokePool,
spokePoolClients,
} = await setupMockClients(
hubPoolClient,
configStoreClient,
hubPoolClient.deploymentBlock,
hubPoolClient.chainId
);
// Mock a realized lp fee pct for each deposit so we can check refund amounts and bundle lp fees.
mockHubPoolClient.setDefaultRealizedLpFeePct(lpFeePct);
mockOriginSpokePoolClient = new MockSpokePoolClient(
spokePoolClient_1.logger,
spokePoolClient_1.spokePool,
spokePoolClient_1.chainId,
spokePoolClient_1.deploymentBlock
);
mockDestinationSpokePool = await smock.fake(spokePoolClient_2.spokePool.interface);
mockDestinationSpokePoolClient = new MockSpokePoolClient(
spokePoolClient_2.logger,
mockDestinationSpokePool as Contract,
spokePoolClient_2.chainId,
spokePoolClient_2.deploymentBlock
);
spokePoolClients = {
...spokePoolClients,
[originChainId]: mockOriginSpokePoolClient,
[destinationChainId]: mockDestinationSpokePoolClient,
};
await mockHubPoolClient.update();
await mockOriginSpokePoolClient.update();
await mockDestinationSpokePoolClient.update();
mockHubPoolClient.setTokenMapping(l1Token_1.address, originChainId, erc20_1.address);
mockHubPoolClient.setTokenMapping(l1Token_1.address, destinationChainId, erc20_2.address);
mockHubPoolClient.setTokenMapping(l1Token_1.address, repaymentChainId, l1Token_1.address);
spokePoolClient_1,
spokePoolClient_2,
spokePoolClients,
l1Token_1,
erc20_1,
erc20_2,
lpFeePct
));
const bundleDataClient = new BundleDataClient(
dataworkerInstance.logger,
{
Expand Down
67 changes: 29 additions & 38 deletions test/Dataworker.loadData.fill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { amountToDeposit, destinationChainId, originChainId, repaymentChainId }
import { DataworkerConfig, setupDataworker } from "./fixtures/Dataworker.Fixture";
import {
Contract,
FakeContract,
SignerWithAddress,
V3FillFromDeposit,
assertPromiseError,
Expand All @@ -21,9 +20,9 @@ import {
getDisabledBlockRanges,
randomAddress,
sinon,
smock,
spyLogIncludes,
deployMulticall3,
setupMockClients,
} from "./utils";

import { Dataworker } from "../src/dataworker/Dataworker"; // Tested
Expand Down Expand Up @@ -65,7 +64,7 @@ describe("Dataworker: Load bundle data", async function () {

let updateAllClients: () => Promise<void>;

beforeEach(async function () {
async function deploy() {
({
spokePool_1,
erc20_1,
Expand All @@ -88,6 +87,12 @@ describe("Dataworker: Load bundle data", async function () {
for (const deployer of [depositor, relayer]) {
await deployMulticall3(deployer);
}
}

before(deploy);

beforeEach(function () {
spy.resetHistory();
});

it("Default conditions", async function () {
Expand Down Expand Up @@ -115,19 +120,27 @@ describe("Dataworker: Load bundle data", async function () {
describe("Compute fills to refund", function () {
let mockOriginSpokePoolClient: MockSpokePoolClient, mockDestinationSpokePoolClient: MockSpokePoolClient;
let mockHubPoolClient: MockHubPoolClient;
let mockDestinationSpokePool: FakeContract;
let mockConfigStore: MockConfigStoreClient;
const lpFeePct = toBNWei("0.01");

beforeEach(async function () {
await updateAllClients();
mockHubPoolClient = new MockHubPoolClient(
hubPoolClient.logger,
hubPoolClient.hubPool,
configStoreClient,
hubPoolClient.deploymentBlock,
hubPoolClient.chainId
);
// Reset config store state that may have been modified by preceding tests,
// since configStoreClient is shared across tests (created once in before()).
(configStoreClient as unknown as MockConfigStoreClient).cumulativeDisabledChainUpdates = [];
(configStoreClient as unknown as MockConfigStoreClient).liteChainIndicesUpdates = [];
({ mockHubPoolClient, mockOriginSpokePoolClient, mockDestinationSpokePoolClient, spokePoolClients } =
await setupMockClients(
hubPoolClient,
configStoreClient,
spokePoolClient_1,
spokePoolClient_2,
spokePoolClients,
l1Token_1,
erc20_1,
erc20_2,
lpFeePct
));
mockConfigStore = new MockConfigStoreClient(
configStoreClient.logger,
configStoreClient.configStore,
Expand All @@ -137,33 +150,6 @@ describe("Dataworker: Load bundle data", async function () {
undefined,
true
);
// Mock a realized lp fee pct for each deposit so we can check refund amounts and bundle lp fees.
mockHubPoolClient.setDefaultRealizedLpFeePct(lpFeePct);
mockOriginSpokePoolClient = new MockSpokePoolClient(
spokePoolClient_1.logger,
spokePoolClient_1.spokePool,
spokePoolClient_1.chainId,
spokePoolClient_1.deploymentBlock
);

mockDestinationSpokePool = await smock.fake(spokePoolClient_2.spokePool.interface);
mockDestinationSpokePoolClient = new MockSpokePoolClient(
spokePoolClient_2.logger,
mockDestinationSpokePool as Contract,
spokePoolClient_2.chainId,
spokePoolClient_2.deploymentBlock
);
spokePoolClients = {
...spokePoolClients,
[originChainId]: mockOriginSpokePoolClient,
[destinationChainId]: mockDestinationSpokePoolClient,
};
await mockHubPoolClient.update();
await mockOriginSpokePoolClient.update();
await mockDestinationSpokePoolClient.update();
mockHubPoolClient.setTokenMapping(l1Token_1.address, originChainId, erc20_1.address);
mockHubPoolClient.setTokenMapping(l1Token_1.address, destinationChainId, erc20_2.address);
mockHubPoolClient.setTokenMapping(l1Token_1.address, repaymentChainId, l1Token_1.address);
const bundleDataClient = new MockBundleDataClient(
dataworkerInstance.logger,
{
Expand Down Expand Up @@ -1005,6 +991,11 @@ describe("Dataworker: Load bundle data", async function () {
});

describe("Tests against contract deployments", function () {
beforeEach(async function () {
await deploy();
await updateAllClients();
});

it("Validates fill against old deposit if deposit is not in-memory", async function () {
// For this test, we need to actually send a deposit on the spoke pool
// because queryHistoricalDepositForFill eth_call's the contract.
Expand Down
56 changes: 22 additions & 34 deletions test/Dataworker.loadData.prefill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
fillV3Relay,
getDefaultBlockRange,
randomAddress,
smock,
setupMockClients,
} from "./utils";
import { Dataworker } from "../src/dataworker/Dataworker"; // Tested
import {
Expand Down Expand Up @@ -46,7 +46,7 @@ describe("Dataworker: Load bundle data: Pre-fill and Pre-Slow-Fill request logic

let updateAllClients: () => Promise<void>;

beforeEach(async function () {
before(async function () {
({
erc20_1,
erc20_2,
Expand All @@ -65,6 +65,10 @@ describe("Dataworker: Load bundle data: Pre-fill and Pre-Slow-Fill request logic
await updateAllClients();
});

beforeEach(function () {
spy.resetHistory();
});

describe("Tests with real events", function () {
describe("Pre-fills", function () {
it("Fetches and refunds fill if fill status is Filled", async function () {
Expand Down Expand Up @@ -106,39 +110,23 @@ describe("Dataworker: Load bundle data: Pre-fill and Pre-Slow-Fill request logic
const lpFeePct = toBNWei("0.01");

beforeEach(async function () {
mockHubPoolClient = new MockHubPoolClient(
hubPoolClient.logger,
hubPoolClient.hubPool,
({
mockHubPoolClient,
mockOriginSpokePoolClient,
mockDestinationSpokePoolClient,
mockDestinationSpokePool,
spokePoolClients,
} = await setupMockClients(
hubPoolClient,
configStoreClient,
hubPoolClient.deploymentBlock,
hubPoolClient.chainId
);
// Mock a realized lp fee pct for each deposit so we can check refund amounts and bundle lp fees.
mockHubPoolClient.setDefaultRealizedLpFeePct(lpFeePct);
mockOriginSpokePoolClient = new MockSpokePoolClient(
spokePoolClient_1.logger,
spokePoolClient_1.spokePool,
spokePoolClient_1.chainId,
spokePoolClient_1.deploymentBlock
);
mockDestinationSpokePool = await smock.fake(spokePoolClient_2.spokePool.interface);
mockDestinationSpokePoolClient = new MockSpokePoolClient(
spokePoolClient_2.logger,
mockDestinationSpokePool as Contract,
spokePoolClient_2.chainId,
spokePoolClient_2.deploymentBlock
);
spokePoolClients = {
...spokePoolClients,
[originChainId]: mockOriginSpokePoolClient,
[destinationChainId]: mockDestinationSpokePoolClient,
};
await mockHubPoolClient.update();
await mockOriginSpokePoolClient.update();
await mockDestinationSpokePoolClient.update();
mockHubPoolClient.setTokenMapping(l1Token_1.address, originChainId, erc20_1.address);
mockHubPoolClient.setTokenMapping(l1Token_1.address, destinationChainId, erc20_2.address);
mockHubPoolClient.setTokenMapping(l1Token_1.address, repaymentChainId, l1Token_1.address);
spokePoolClient_1,
spokePoolClient_2,
spokePoolClients,
l1Token_1,
erc20_1,
erc20_2,
lpFeePct
));
const bundleDataClient = new MockBundleDataClient(
dataworkerInstance.logger,
{
Expand Down
60 changes: 26 additions & 34 deletions test/Dataworker.loadData.unexecutableSlowFill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
getDisabledBlockRanges,
mineRandomBlocks,
requestSlowFill,
smock,
setupMockClients,
} from "./utils";

import { Dataworker } from "../src/dataworker/Dataworker"; // Tested
Expand Down Expand Up @@ -116,7 +116,7 @@ describe("Dataworker: Load bundle data: Computing unexecutable slow fills", asyn
} as interfaces.SlowFillRequestWithBlock);
}

beforeEach(async function () {
async function deploy() {
({
spokePool_1,
erc20_1,
Expand All @@ -135,13 +135,29 @@ describe("Dataworker: Load bundle data: Computing unexecutable slow fills", asyn
updateAllClients,
} = await setupDataworker(ethers, 25, 25, 0));
await updateAllClients();
mockHubPoolClient = new MockHubPoolClient(
hubPoolClient.logger,
hubPoolClient.hubPool,
}

before(deploy);

beforeEach(async function () {
spy.resetHistory();
({
mockHubPoolClient,
mockOriginSpokePoolClient,
mockDestinationSpokePoolClient,
mockDestinationSpokePool,
spokePoolClients,
} = await setupMockClients(
hubPoolClient,
configStoreClient,
hubPoolClient.deploymentBlock,
hubPoolClient.chainId
);
spokePoolClient_1,
spokePoolClient_2,
spokePoolClients,
l1Token_1,
erc20_1,
erc20_2,
lpFeePct
));
mockConfigStore = new MockConfigStoreClient(
configStoreClient.logger,
configStoreClient.configStore,
Expand All @@ -151,32 +167,6 @@ describe("Dataworker: Load bundle data: Computing unexecutable slow fills", asyn
undefined,
true
);
// Mock a realized lp fee pct for each deposit so we can check refund amounts and bundle lp fees.
mockHubPoolClient.setDefaultRealizedLpFeePct(lpFeePct);
mockOriginSpokePoolClient = new MockSpokePoolClient(
spokePoolClient_1.logger,
spokePoolClient_1.spokePool,
spokePoolClient_1.chainId,
spokePoolClient_1.deploymentBlock
);
mockDestinationSpokePool = await smock.fake(spokePoolClient_2.spokePool.interface);
mockDestinationSpokePoolClient = new MockSpokePoolClient(
spokePoolClient_2.logger,
mockDestinationSpokePool as Contract,
spokePoolClient_2.chainId,
spokePoolClient_2.deploymentBlock
);
spokePoolClients = {
...spokePoolClients,
[originChainId]: mockOriginSpokePoolClient,
[destinationChainId]: mockDestinationSpokePoolClient,
};
await mockHubPoolClient.update();
await mockOriginSpokePoolClient.update();
await mockDestinationSpokePoolClient.update();
mockHubPoolClient.setTokenMapping(l1Token_1.address, originChainId, erc20_1.address);
mockHubPoolClient.setTokenMapping(l1Token_1.address, destinationChainId, erc20_2.address);
mockHubPoolClient.setTokenMapping(l1Token_1.address, repaymentChainId, l1Token_1.address);
const bundleDataClient = new BundleDataClient(
dataworkerInstance.logger,
{
Expand Down Expand Up @@ -464,6 +454,8 @@ describe("Dataworker: Load bundle data: Computing unexecutable slow fills", asyn
});

describe("Tests against contract deployments", function () {
beforeEach(deploy);

it("Filters for fast fills replacing slow fills from older bundles", async function () {
// Generate a deposit that cannot be slow filled, to test that its ignored as a slow fill excess.
// Generate a second deposit that can be slow filled but will be slow filled in an older bundle
Expand Down
Loading
Loading