Skip to content

Commit

Permalink
add test to ensure refund consolidation
Browse files Browse the repository at this point in the history
  • Loading branch information
luketchang committed Sep 13, 2023
1 parent 78b9196 commit 099bc9c
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion packages/core/test/OpRequestBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ describe("OpRequestBuilder", () => {
expect(opRequest.request).to.eql(expected);
});

it("combines requests of same asset when no conf payments", async () => {
it("combines joinsplit requests of same asset when no conf payments", async () => {
const sk = generateRandomSpendingKey();
const signer = new NocturneSigner(sk);
const refundAddr = signer.generateRandomStealthAddress();
Expand Down Expand Up @@ -334,4 +334,46 @@ describe("OpRequestBuilder", () => {

expect(opRequest.request).to.eql(expected);
});

it("combines refunds for same asset", async () => {
const sk = generateRandomSpendingKey();
const signer = new NocturneSigner(sk);
const refundAddr = signer.generateRandomStealthAddress();

const actions = range(2).map((i) => ({
contractAddress: DUMMY_CONTRACT_ADDR,
encodedFunction: getDummyHex(i),
}));
const expected: OperationRequest = {
joinSplitRequests: [
{
asset: shitcoin,
unwrapValue: 100n,
},
],
refunds: [
{ encodedAsset: AssetTrait.encode(ponzi), minRefundValue: 400n },
],
refundAddr: refundAddr,
actions,
chainId: 1n,
tellerContract: DUMMY_CONFIG.tellerAddress(),
deadline: 2n,
};

const provider = ethers.getDefaultProvider();
const builder = newOpRequestBuilder(provider, 1n, DUMMY_CONFIG);
const opRequest = await builder
.__action(DUMMY_CONTRACT_ADDR, getDummyHex(0))
.__action(DUMMY_CONTRACT_ADDR, getDummyHex(1))
.__unwrap(shitcoin, 100n)
.__refund({ asset: ponzi, minRefundValue: 100n })
.__refund({ asset: ponzi, minRefundValue: 100n })
.__refund({ asset: ponzi, minRefundValue: 200n })
.refundAddr(refundAddr)
.deadline(2n)
.build();

expect(opRequest.request).to.eql(expected);
});
});

0 comments on commit 099bc9c

Please sign in to comment.