Skip to content

Commit a0ebde8

Browse files
committed
test it
1 parent b2f9668 commit a0ebde8

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

packages/contracts/test/PoolERC20.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,4 +469,54 @@ describe("PoolERC20", () => {
469469
expect(await sdk.poolErc20.balanceOf(usdc, bobSecretKey)).to.equal(70n);
470470
expect(await sdk.poolErc20.balanceOf(btc, bobSecretKey)).to.equal(8n);
471471
});
472+
473+
it("fails to swap if order amounts do not match", async () => {
474+
if (process.env.CI) {
475+
// TODO: install co-noir on github actions and remove this
476+
return;
477+
}
478+
479+
const { note: aliceNote } = await sdk.poolErc20.shield({
480+
account: alice,
481+
token: usdc,
482+
amount: 100n,
483+
secretKey: aliceSecretKey,
484+
});
485+
const { note: bobNote } = await sdk.poolErc20.shield({
486+
account: bob,
487+
token: btc,
488+
amount: 10n,
489+
secretKey: bobSecretKey,
490+
});
491+
492+
await backendSdk.rollup.rollup();
493+
494+
const sellerAmount = await TokenAmount.from({
495+
token: await usdc.getAddress(),
496+
amount: 70n,
497+
});
498+
const buyerAmount = await TokenAmount.from({
499+
token: await btc.getAddress(),
500+
amount: 2n,
501+
});
502+
503+
const swapAlicePromise = sdk.lob.requestSwap({
504+
secretKey: aliceSecretKey,
505+
note: aliceNote,
506+
sellAmount: sellerAmount,
507+
buyAmount: buyerAmount,
508+
});
509+
const swapBobPromise = sdk.lob.requestSwap({
510+
secretKey: bobSecretKey,
511+
note: bobNote,
512+
sellAmount: buyerAmount,
513+
buyAmount: await TokenAmount.from({
514+
token: await usdc.getAddress(),
515+
amount: 71n, // amount differs
516+
}),
517+
});
518+
await expect(
519+
Promise.all([swapAlicePromise, swapBobPromise]),
520+
).to.be.rejectedWith("mpc generated invalid proof");
521+
});
472522
});

0 commit comments

Comments
 (0)