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

Commit f02833e

Browse files
committed
Added some more unit tests
1 parent 1efed3c commit f02833e

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

contracts/SetToken.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ contract SetToken is StandardToken, DetailedERC20("", "", 18), Set {
183183
// Excluded tokens should be less than the number of components
184184
// Otherwise, use the normal redeem function
185185
require(excludedComponents.length < components.length);
186+
require(excludedComponents.length > 0);
186187

187188
for (uint i = 0; i < components.length; i++) {
188189
bool isExcluded = false;

test/setToken-base.spec.ts

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ contract("{Set}", (accounts) => {
173173
});
174174

175175
describe("of Sets with fractional units", () => {
176+
beforeEach(async () => {
177+
componentA = await StandardTokenMock.new(testAccount, initialTokens, "Component A", "A");
178+
});
179+
176180
it("should be able to issue and redeem a Set defined with a fractional unit", async () => {
177181
const halfGWeiUnits = gWei(1).div(2); // Represents half a gWei
178182

@@ -192,13 +196,13 @@ contract("{Set}", (accounts) => {
192196

193197
await setToken.issue(quantityInWei, TX_DEFAULTS);
194198

195-
assertTokenBalance(componentA, initialTokens.sub(quantityA), testAccount);
196-
assertTokenBalance(setToken, quantityInWei, testAccount);
199+
assertTokenBalance(componentA, initialTokens.sub(quantityA), testAccount, "Component A after issue");
200+
assertTokenBalance(setToken, quantityInWei, testAccount, "Set Token after issue");
197201

198202
await setToken.redeem(quantityInWei, TX_DEFAULTS);
199203

200-
assertTokenBalance(componentA, initialTokens, testAccount);
201-
assertTokenBalance(setToken, new BigNumber(0), testAccount);
204+
assertTokenBalance(componentA, initialTokens, testAccount, "A after redeem");
205+
assertTokenBalance(setToken, new BigNumber(0), testAccount, "Set after redeem");
202206
});
203207

204208
it("should disallow issuing a Set when the amount is too low", async () => {
@@ -256,7 +260,7 @@ contract("{Set}", (accounts) => {
256260
let quantityB: BigNumber;
257261
let quantityC: BigNumber;
258262

259-
// Create a Set two components with set tokens issued
263+
// Create a Set with three components with set tokens issued
260264
beforeEach(async () => {
261265
componentA = await StandardTokenMock.new(testAccount, initialTokens, "Component A", "A");
262266
componentB = await StandardTokenMock.new(testAccount, initialTokens, "Component B", "B");
@@ -305,6 +309,20 @@ contract("{Set}", (accounts) => {
305309
TX_DEFAULTS,
306310
));
307311
});
312+
313+
it("should fail if there are no exclusions", async () => {
314+
await expectRevertError(setToken.partialRedeem(quantityIssued, [], TX_DEFAULTS));
315+
});
316+
317+
it("should fail if an excluded token is invalid", async () => {
318+
const INVALID_ADDRESS = "0x0000000000000000000000000000000000000001";
319+
320+
await expectInvalidOpcodeError(setToken.partialRedeem(
321+
quantityIssued,
322+
[componentA.address, INVALID_ADDRESS],
323+
TX_DEFAULTS,
324+
));
325+
});
308326
});
309327

310328
describe("Redeem Excluded", async () => {
@@ -346,5 +364,14 @@ contract("{Set}", (accounts) => {
346364
const [excludedBalanceAofOwner] = await setToken.unredeemedComponents(componentA.address, testAccount);
347365
expect(excludedBalanceAofOwner).to.be.bignumber.equal(0);
348366
});
367+
368+
it("should fail if the user doesn't have enough balance", async () => {
369+
const largeQuantity = new BigNumber("1000000000000000000000000000000000000");
370+
expectRevertError(setToken.redeemExcluded(
371+
largeQuantity,
372+
componentA.address,
373+
TX_DEFAULTS,
374+
));
375+
});
349376
});
350377
});

0 commit comments

Comments
 (0)