Skip to content

Commit

Permalink
Add test & fix misdiagnosis
Browse files Browse the repository at this point in the history
  • Loading branch information
pxrl committed Jan 3, 2024
1 parent 2784c95 commit 77aeb2f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
7 changes: 2 additions & 5 deletions src/utils/DepositUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export async function queryHistoricalDepositForFill(

return {
found: false,
code: InvalidFill.DepositIdNotFound,
code: isDefined(deposit) ? InvalidFill.FillMismatch : InvalidFill.DepositIdNotFound,
reason: `Deposit ID ${depositId} not found in SpokePoolClient event buffer.`
};
}
Expand Down Expand Up @@ -104,10 +104,7 @@ export async function queryHistoricalDepositForFill(
}

if (validateFillForDeposit(fill, deposit)) {
return {
found: true,
deposit,
};
return { found: true, deposit };
}

return {
Expand Down
26 changes: 25 additions & 1 deletion test/SpokePoolClient.ValidateFill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ import {

import { SpokePoolClient } from "../src/clients";
import { MockConfigStoreClient, MockHubPoolClient, MockSpokePoolClient } from "./mocks";
import { InvalidFill, relayFilledAmount, validateFillForDeposit, queryHistoricalDepositForFill } from "../src/utils";
import {
bnZero,
bnOne,
InvalidFill,
relayFilledAmount,
validateFillForDeposit,
queryHistoricalDepositForFill
} from "../src/utils";
import { CHAIN_ID_TEST_LIST, repaymentChainId } from "./constants";

let spokePool_1: Contract, erc20_1: Contract, spokePool_2: Contract, erc20_2: Contract, hubPool: Contract;
Expand Down Expand Up @@ -524,6 +531,23 @@ describe("SpokePoolClient: Fill Validation", function () {
expect(lastSpyLogIncludes(spy, "Queried RPC for deposit")).is.not.true;
});

it("Ignores matching fills that mis-specify a deposit attribute", async function () {
const deposit = await buildDeposit(hubPoolClient, spokePool_1, erc20_1, depositor, destinationChainId);

deposit.realizedLpFeePct = (deposit.realizedLpFeePct ?? bnZero).add(bnOne);
const fill = await buildFill(spokePool_2, erc20_2, depositor, relayer, deposit, 1);

await Promise.all([spokePoolClient1.update(), spokePoolClient2.update()]);

const search = await queryHistoricalDepositForFill(spokePoolClient1, fill);
expect(search.found).is.false;
if (search.found) {
// Helping tsc to narrow the type.
throw new Error("xxx test is broken; this should never happen");
}
expect(search.code).to.equal(InvalidFill.FillMismatch);
});

it("Returns sped up deposit matched with fill", async function () {
const deposit_1 = await buildDeposit(hubPoolClient, spokePool_1, erc20_1, depositor, destinationChainId);
// Override the fill's realized LP fee % and destination token so that it matches the deposit's default zero'd
Expand Down

0 comments on commit 77aeb2f

Please sign in to comment.