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

[WIP] improve(utils): Avoid recomputing relayData hashes #657

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 10 additions & 8 deletions test/SpokePoolClient.ValidateFill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ describe("SpokePoolClient: Fill Validation", function () {
await spokePoolClient1.update();

expect(spokePoolClient1.getDepositForFill(fill))
.excludingEvery(["realizedLpFeePct", "quoteBlockNumber"])
.excludingEvery(["realizedLpFeePct", "quoteBlockNumber", "_hash"])
.to.deep.equal(deposit);
});

Expand Down Expand Up @@ -631,7 +631,7 @@ describe("SpokePoolClient: Fill Validation", function () {
expect(fill_2.relayExecutionInfo.fillType === FillType.FastFill).to.be.true;

expect(spokePoolClient1.getDepositForFill(fill_1))
.excludingEvery(["quoteBlockNumber", "realizedLpFeePct"])
.excludingEvery(["quoteBlockNumber", "realizedLpFeePct", "_hash"])
.to.deep.equal(deposit_1);
expect(spokePoolClient1.getDepositForFill(fill_2)).to.equal(undefined);

Expand All @@ -652,22 +652,24 @@ describe("SpokePoolClient: Fill Validation", function () {

expect(validateFillForDeposit(validFill, deposit_2)).to.be.true;

const _hash = undefined;

// Invalid input amount.
expect(validateFillForDeposit({ ...validFill, inputAmount: toBNWei(1337) }, deposit_2)).to.be.false;
expect(validateFillForDeposit({ ...validFill, inputAmount: toBNWei(1337), _hash }, deposit_2)).to.be.false;

// Changed the output token.
expect(validateFillForDeposit(validFill, { ...deposit_2, outputToken: owner.address })).to.be.false;
expect(validateFillForDeposit(validFill, { ...deposit_2, outputToken: owner.address, _hash })).to.be.false;

// Changed the output amount.
expect(validateFillForDeposit({ ...validFill, outputAmount: toBNWei(1337) }, deposit_2)).to.be.false;
expect(validateFillForDeposit({ ...validFill, outputAmount: toBNWei(1337), _hash }, deposit_2)).to.be.false;

// Invalid depositId.
expect(validateFillForDeposit({ ...validFill, depositId: 1337 }, deposit_2)).to.be.false;
expect(validateFillForDeposit({ ...validFill, depositId: 1337, _hash }, deposit_2)).to.be.false;

// Changed the depositor.
expect(validateFillForDeposit({ ...validFill, depositor: relayer.address }, deposit_2)).to.be.false;
expect(validateFillForDeposit({ ...validFill, depositor: relayer.address, _hash }, deposit_2)).to.be.false;

// Changed the recipient.
expect(validateFillForDeposit({ ...validFill, recipient: relayer.address }, deposit_2)).to.be.false;
expect(validateFillForDeposit({ ...validFill, recipient: relayer.address, _hash }, deposit_2)).to.be.false;
Comment on lines +655 to +673
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests exposed a sharp edge - producing a new relayData event based on an existing one, with some modified fields, risks inadvertently copying the old _hash. It needs to be manually unset. It's a pretty big foot gun...

});
});
8 changes: 4 additions & 4 deletions test/SpokePoolClient.v3Events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { MockHubPoolClient, MockSpokePoolClient, MockConfigStoreClient } from "../src/clients/mocks";
import { DepositWithBlock, FillWithBlock, SlowFillRequest, SlowFillRequestWithBlock } from "../src/interfaces";
import { EMPTY_MESSAGE, ZERO_ADDRESS } from "../src/constants";
import { getCurrentTime, isDefined, randomAddress } from "../src/utils";
import { getCurrentTime, getRelayDataHash, isDefined, randomAddress } from "../src/utils";

Check failure on line 9 in test/SpokePoolClient.v3Events.ts

View workflow job for this annotation

GitHub Actions / Lint

'getRelayDataHash' is defined but never used
import {
createSpyLogger,
fillFromDeposit,
Expand Down Expand Up @@ -209,9 +209,9 @@
// The SpokePoolClient appends destinationChainId, so check for it specifically.
expect(slowFillRequest?.destinationChainId).to.not.be.undefined;
expect(slowFillRequest?.destinationChainId).to.equal(destinationChainId);
Object.entries(relayData).forEach(
([k, v]) => expect(isDefined(v)).to.equal(true) && expect(slowFillRequest?.[k]).to.equal(v)
);
Object.entries(relayData)
.filter(([k]) => k !== "_hash")
.forEach(([k, v]) => expect(isDefined(v)).to.equal(true) && expect(slowFillRequest?.[k]).to.equal(v));
});
});

Expand Down
Loading