Skip to content

Commit

Permalink
fix: resolve validate flow ts
Browse files Browse the repository at this point in the history
  • Loading branch information
james-a-morris committed Sep 5, 2023
1 parent 8223f66 commit a2348a8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
30 changes: 26 additions & 4 deletions test/UBAClient.validateFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
ethers,
hubPoolFixture,
} from "./utils";
import { CHAIN_ID_TEST_LIST, expect, randomAddress, toBNWei } from "./constants";
import { BigNumber, CHAIN_ID_TEST_LIST, expect, randomAddress, toBNWei } from "./constants";
import { SpokePoolClientsByChain, UbaFlow, UbaInflow, UbaOutflow } from "../src/interfaces";
import { MockConfigStoreClient, MockHubPoolClient, MockSpokePoolClient, MockUBAClient } from "./mocks";
import { UBA_MIN_CONFIG_STORE_VERSION } from "../src/common";
Expand Down Expand Up @@ -37,7 +37,23 @@ const realizedLpFeePct = toBNWei("0.13");

// Make these test flows partial types so we can leave some of the params undefined until we get to the individual
// tests.
let partialInflow: Omit<UbaInflow, "blockNumber">, partialOutflow: Omit<UbaOutflow, "blockNumber" | "matchedDeposit">;
let partialInflow: Omit<UbaInflow, "blockNumber">;
let partialOutflow: Omit<UbaOutflow, "blockNumber" | "matchedDeposit"> & {
fillAmount: BigNumber;
totalFilledAmount: BigNumber;
depositor: string;
destinationToken: string;
recipient: string;
relayerFeePct: BigNumber;
updatableRelayData: {
recipient: string;
isSlowRelay: boolean;
message: string;
payoutAdjustmentPct: BigNumber;
relayerFeePct: BigNumber;
};
message: string;
};

describe("UBAClient: Flow validation", function () {
beforeEach(async function () {
Expand Down Expand Up @@ -243,7 +259,10 @@ describe("UBAClient: Flow validation", function () {

const expectedLpFee = inflow.amount.mul(baselineFee).div(toBNWei(1));
expect(result?.lpFee).to.equal(expectedLpFee);
deepEqualsWithBigNumber(result?.flow, inflow);
deepEqualsWithBigNumber(
result?.flow as unknown as Record<string, unknown>,
inflow as unknown as Record<string, unknown>
);
});
});
describe("Outflow", function () {
Expand Down Expand Up @@ -285,7 +304,10 @@ describe("UBAClient: Flow validation", function () {
// LP fee is just the realizedLpFee applied to the amount
const expectedLpFee = outflow.amount.mul(outflow.realizedLpFeePct).div(toBNWei(1));
expect(result?.lpFee).to.equal(expectedLpFee);
deepEqualsWithBigNumber(result?.flow, outflow);
deepEqualsWithBigNumber(
result?.flow as unknown as Record<string, unknown>,
outflow as unknown as Record<string, unknown>
);

// Now, we change the outflow's realizedLpFeePct such that it doesn't match with the deposit, it
// should return undefined.
Expand Down
1 change: 1 addition & 0 deletions test/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { HardhatEthersHelpers } from "@nomiclabs/hardhat-ethers/types";
import type { ethers } from "ethers";
import winston from "winston";
import * as utils from "@across-protocol/contracts-v2/dist/test-utils";
import { sinon } from "../utils";

export type EthersTestLibrary = typeof ethers & HardhatEthersHelpers;
export type SpyLoggerResult = {
Expand Down
7 changes: 5 additions & 2 deletions test/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@ const assert = chai.assert;
export { assert, chai };

export function deepEqualsWithBigNumber(
x: Iterable<unknown> | Record<string | number, unknown>,
y: Iterable<unknown> | Record<string | number, unknown>,
x?: Iterable<unknown> | Record<string | number, unknown>,
y?: Iterable<unknown> | Record<string | number, unknown>,
omitKeys: string[] = []
): boolean {
if (x === undefined || y === undefined) {
return false;
}
const sortedKeysX = Object.fromEntries(
Object.keys(x)
.sort()
Expand Down

0 comments on commit a2348a8

Please sign in to comment.