Skip to content
This repository was archived by the owner on Jan 18, 2023. It is now read-only.

Commit dcbb507

Browse files
committed
Add an additional test for multiple components partial redeemed
1 parent 0628724 commit dcbb507

File tree

1 file changed

+70
-7
lines changed

1 file changed

+70
-7
lines changed

test/setToken-base.spec.ts

Lines changed: 70 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,24 @@ contract("{Set}", (accounts) => {
349349
assertTokenBalance(setToken, new BigNumber(0), testAccount);
350350
});
351351

352+
it(`should work with sequential redeems`, async () => {
353+
const halfAmount = standardQuantityIssued.div(new BigNumber(2));
354+
await setToken.redeem(halfAmount, TX_DEFAULTS);
355+
356+
const [component1, component2] = components;
357+
const [quantity1, quantity2] = quantitiesToTransfer;
358+
359+
assertTokenBalance(component1, initialTokens.sub(quantity1.div(2)), testAccount);
360+
assertTokenBalance(component2, initialTokens.sub(quantity2.div(2)), testAccount);
361+
assertTokenBalance(setToken, standardQuantityIssued.div(2), testAccount);
362+
363+
await setToken.redeem(halfAmount, TX_DEFAULTS);
364+
365+
assertTokenBalance(component1, initialTokens, testAccount);
366+
assertTokenBalance(component2, initialTokens, testAccount);
367+
assertTokenBalance(setToken, new BigNumber(0), testAccount);
368+
});
369+
352370
it(`should throw if the user does not have sufficient balance`, async () => {
353371
const largeAmount = initialTokens.mul(initialTokens);
354372
await expectRevertError(setToken.redeem(largeAmount, TX_DEFAULTS));
@@ -496,29 +514,29 @@ contract("{Set}", (accounts) => {
496514
});
497515

498516
describe("Redeem Excluded", async () => {
499-
let componentExcluded: any;
500-
let componentAddressExcluded: Address;
517+
describe(`of Standard Set with a single component partial redeemed`, () => {
518+
let componentExcluded: any;
519+
let componentAddressExcluded: Address[];
501520

502-
describe(`of Standard Set`, () => {
503521
beforeEach(async () => {
504522
await deployStandardSetAndIssue(3, standardQuantityIssued);
505523
componentExcluded = components[0];
506-
componentAddressExcluded = componentAddresses[0];
524+
componentAddressExcluded = [componentAddresses[0]];
507525

508-
await setToken.partialRedeem(standardQuantityIssued, [componentAddressExcluded], TX_DEFAULTS);
526+
await setToken.partialRedeem(standardQuantityIssued, componentAddressExcluded, TX_DEFAULTS);
509527
});
510528

511529
it("should work", async () => {
512530
const redeemExcludedReceipt = await setToken.redeemExcluded(
513-
[componentAddressExcluded],
531+
componentAddressExcluded,
514532
[quantitiesToTransfer[0]],
515533
TX_DEFAULTS,
516534
);
517535

518536
const { logs } = redeemExcludedReceipt;
519537
const formattedLogs = _.map(logs, (log) => extractLogEventAndArgs(log));
520538
const expectedLogs = getExpectedRedeemExcludedLogs(
521-
[componentAddressExcluded],
539+
componentAddressExcluded,
522540
[quantitiesToTransfer[0]],
523541
setToken.address,
524542
testAccount,
@@ -541,5 +559,50 @@ contract("{Set}", (accounts) => {
541559
));
542560
});
543561
});
562+
563+
describe(`of Standard Set with a multiple components partial redeemed`, () => {
564+
let componentsExcluded: any[];
565+
let componentAddressesExcluded: Address[];
566+
567+
beforeEach(async () => {
568+
await deployStandardSetAndIssue(3, standardQuantityIssued);
569+
componentsExcluded = [components[0], components[1]];
570+
componentAddressesExcluded = [componentAddresses[0], componentAddresses[1]];
571+
572+
await setToken.partialRedeem(standardQuantityIssued, componentAddressesExcluded, TX_DEFAULTS);
573+
});
574+
575+
it("should work when redeem excluding multiple tokens", async () => {
576+
const redeemExcludedReceipt = await setToken.redeemExcluded(
577+
componentAddressesExcluded,
578+
[quantitiesToTransfer[0], quantitiesToTransfer[1]],
579+
TX_DEFAULTS,
580+
);
581+
582+
const { logs } = redeemExcludedReceipt;
583+
const formattedLogs = _.map(logs, (log) => extractLogEventAndArgs(log));
584+
const expectedLogs = getExpectedRedeemExcludedLogs(
585+
componentAddressesExcluded,
586+
[quantitiesToTransfer[0], quantitiesToTransfer[1]],
587+
setToken.address,
588+
testAccount,
589+
);
590+
591+
expect(JSON.stringify(formattedLogs)).to.equal(JSON.stringify(expectedLogs));
592+
const [excludedBalance1ofOwner] = await setToken.unredeemedComponents(
593+
componentAddressesExcluded[0],
594+
testAccount,
595+
);
596+
expect(excludedBalance1ofOwner).to.be.bignumber.equal(0);
597+
assertTokenBalance(componentsExcluded[0], initialTokens, testAccount);
598+
599+
const [excludedBalance2ofOwner] = await setToken.unredeemedComponents(
600+
componentAddressesExcluded[1],
601+
testAccount,
602+
);
603+
expect(excludedBalance2ofOwner).to.be.bignumber.equal(0);
604+
assertTokenBalance(componentsExcluded[1], initialTokens, testAccount);
605+
});
606+
});
544607
});
545608
});

0 commit comments

Comments
 (0)