Skip to content

Commit

Permalink
make test better
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholaspai committed Nov 29, 2024
1 parent 0282f30 commit 10c401b
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions test/Dataworker.executePoolRebalances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,11 +478,10 @@ describe("Dataworker: Execute pool rebalances", async function () {
});
it("submits update: liquid reserves post-sync are enough to execute leaf", async function () {
// Liquid reserves cover one leaf but not two.
const netSendAmount = toBNWei("10");
const liquidReserves = toBNWei("11");
const postUpdateLiquidReserves = toBNWei("20");

// Current reserves are insufficient to cover the two leaves:
mockHubPoolClient.setLpTokenInfo(l1Token_1.address, 0, liquidReserves);
mockHubPoolClient.setLpTokenInfo(l1Token_1.address, 0, bnZero);

// Post-update, liquid reserves will be enough to cover the two leaves:
fakeHubPool.multicall.returns([
Expand All @@ -492,22 +491,26 @@ describe("Dataworker: Execute pool rebalances", async function () {
true, // enabled
0, // last lp fee update
bnZero, // utilized reserves
netSendAmount.mul(2),
postUpdateLiquidReserves,
bnZero, // unaccumulated fees
]),
]);

const updated = await dataworkerInstance._updateExchangeRatesBeforeExecutingNonHubChainLeaves(
{},
balanceAllocator,
// Each leaf's net send amount is individually less than the post-updateliquid reserves,
// but the sum of the three is greater than the post-update liquid reserves.
// This should force the dataworker to submit an update.
[
{ netSendAmounts: [netSendAmount], l1Tokens: [l1Token_1.address], chainId: 1 },
{ netSendAmounts: [netSendAmount], l1Tokens: [l1Token_1.address], chainId: 10 },
{ netSendAmounts: [toBNWei("4")], l1Tokens: [l1Token_1.address], chainId: 1 },
{ netSendAmounts: [toBNWei("9")], l1Tokens: [l1Token_1.address], chainId: 10 },
{ netSendAmounts: [toBNWei("7")], l1Tokens: [l1Token_1.address], chainId: 137 },
],
true
);
expect(updated.size).to.equal(1);
expect(spy.getCall(-1).lastArg.virtualHubPoolBalance).to.equal(netSendAmount.mul(2));
expect(spy.getCall(-1).lastArg.virtualHubPoolBalance).to.equal(postUpdateLiquidReserves);
expect(updated.has(l1Token_1.address)).to.be.true;
expect(multiCallerClient.transactionCount()).to.equal(1);
});
Expand Down

0 comments on commit 10c401b

Please sign in to comment.