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

Commit 0628724

Browse files
committed
Add an additional unit test
1 parent 76b2aee commit 0628724

File tree

2 files changed

+39
-11
lines changed

2 files changed

+39
-11
lines changed

contracts/SetToken.sol

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
pragma solidity 0.4.21;
2+
pragma experimental ABIEncoderV2;
23

34

45
import "zeppelin-solidity/contracts/token/ERC20/StandardToken.sol";
@@ -122,7 +123,7 @@ contract SetToken is StandardToken, DetailedERC20("", "", 18), Set {
122123
// Increment the total token supply
123124
totalSupply = totalSupply.add(quantity);
124125

125-
LogIssuance(msg.sender, quantity);
126+
emit LogIssuance(msg.sender, quantity);
126127

127128
return true;
128129
}
@@ -150,7 +151,7 @@ contract SetToken is StandardToken, DetailedERC20("", "", 18), Set {
150151
assert(ERC20(currentComponent).transfer(msg.sender, transferValue));
151152
}
152153

153-
LogRedemption(msg.sender, quantity);
154+
emit LogRedemption(msg.sender, quantity);
154155

155156
return true;
156157
}
@@ -216,21 +217,31 @@ contract SetToken is StandardToken, DetailedERC20("", "", 18), Set {
216217
unredeemedComponents[currentExcludedToUnredeem][msg.sender].isRedeemed = false;
217218
}
218219

219-
LogPartialRedemption(msg.sender, quantity, excludedComponents);
220+
emit LogPartialRedemption(msg.sender, quantity, excludedComponents);
220221

221222
return true;
222223
}
223224

224-
function redeemExcluded(uint[] quantities, address[] excludedComponents)
225+
/**
226+
* @dev Function to withdraw tokens that have previously been excluded when calling
227+
* the redeemExcluded method
228+
*
229+
* This function should be used to retrieve tokens that have previously excluded
230+
* when calling the redeemExcluded function.
231+
*
232+
* @param componentsToRedeem address[] The list of tokens to redeem
233+
* @param quantities uint[] The quantity of Sets desired to redeem in Wei
234+
*/
235+
function redeemExcluded(address[] componentsToRedeem, uint[] quantities)
225236
public
226237
returns (bool success)
227238
{
228239
require(quantities.length > 0);
229-
require(excludedComponents.length > 0);
230-
require(quantities.length == excludedComponents.length);
240+
require(componentsToRedeem.length > 0);
241+
require(quantities.length == componentsToRedeem.length);
231242

232243
for (uint i = 0; i < quantities.length; i++) {
233-
address currentComponent = excludedComponents[i];
244+
address currentComponent = componentsToRedeem[i];
234245
uint currentQuantity = quantities[i];
235246

236247
// Check there is enough balance
@@ -243,7 +254,7 @@ contract SetToken is StandardToken, DetailedERC20("", "", 18), Set {
243254
assert(ERC20(currentComponent).transfer(msg.sender, currentQuantity));
244255
}
245256

246-
LogRedeemExcluded(msg.sender, excludedComponents);
257+
emit LogRedeemExcluded(msg.sender, componentsToRedeem);
247258

248259
return true;
249260
}

test/setToken-base.spec.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ contract("{Set}", (accounts) => {
5151
let quantitiesToTransfer: BigNumber[] = [];
5252
let setToken: any;
5353

54-
const [testAccount] = accounts;
54+
const [testAccount, testAccount2] = accounts;
5555
const initialTokens: BigNumber = ether(100000000000);
5656
const standardQuantityIssued: BigNumber = ether(10);
5757

@@ -357,6 +357,23 @@ contract("{Set}", (accounts) => {
357357
it(`should throw if the redeem quantity is 0`, async () => {
358358
await expectInvalidOpcodeError(setToken.redeem(new BigNumber(0), TX_DEFAULTS));
359359
});
360+
361+
it(`should allow a separate user who did not issue to redeem the Set`, async () => {
362+
await setToken.transfer(testAccount2, standardQuantityIssued, TX_DEFAULTS);
363+
const redeemReceipt = await setToken.redeem(standardQuantityIssued, { from: testAccount2 });
364+
365+
const { logs } = redeemReceipt;
366+
const formattedLogs = _.map(logs, (log) => extractLogEventAndArgs(log));
367+
const expectedLogs = getExpectedRedeemLogs(
368+
componentAddresses,
369+
quantitiesToTransfer,
370+
setToken.address,
371+
standardQuantityIssued,
372+
testAccount2,
373+
);
374+
375+
expect(JSON.stringify(formattedLogs)).to.equal(JSON.stringify(expectedLogs));
376+
});
360377
});
361378

362379
describe(`50 component set`, () => {
@@ -493,8 +510,8 @@ contract("{Set}", (accounts) => {
493510

494511
it("should work", async () => {
495512
const redeemExcludedReceipt = await setToken.redeemExcluded(
496-
[quantitiesToTransfer[0]],
497513
[componentAddressExcluded],
514+
[quantitiesToTransfer[0]],
498515
TX_DEFAULTS,
499516
);
500517

@@ -518,8 +535,8 @@ contract("{Set}", (accounts) => {
518535
it("should fail if the user doesn't have enough balance", async () => {
519536
const largeQuantity = new BigNumber("1000000000000000000000000000000000000");
520537
await expectRevertError(setToken.redeemExcluded(
521-
[largeQuantity],
522538
[componentAddressExcluded],
539+
[largeQuantity],
523540
TX_DEFAULTS,
524541
));
525542
});

0 commit comments

Comments
 (0)