Skip to content

Commit

Permalink
Merge 0df5133 into 7af7346
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephane Gosselin committed Jul 5, 2018
2 parents 7af7346 + 0df5133 commit c41833b
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
11 changes: 11 additions & 0 deletions contracts/modules/STO/ISTO.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,15 @@ contract ISTO is IModule, Pausable {
endTime = _newEndDate;
}

/**
* @notice Reclaim ERC20Basic compatible tokens
* @param _tokenContract The address of the token contract
*/
function reclaimERC20(address _tokenContract) external onlyOwner {
require(_tokenContract != address(0));
ERC20Basic token = ERC20Basic(_tokenContract);
uint256 balance = token.balanceOf(address(this));
require(token.transfer(msg.sender, balance));
}

}
33 changes: 33 additions & 0 deletions test/capped_sto.js
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,39 @@ contract('CappedSTO', accounts => {

});

describe("Reclaim poly sent to STO by mistake", async() => {

it("Should fail to reclaim POLY because token contract address is 0 address", async() => {
let value = web3.utils.toWei('100','ether');
await I_PolyToken.getTokens(value, account_investor1);
await I_PolyToken.transfer(I_CappedSTO_Array_ETH[0].address, value, { from: account_investor1 });

let errorThrown = false;
try {
await I_CappedSTO_Array_ETH[0].reclaimERC20('0x0000000000000000000000000000000000000000', { from: token_owner });
} catch(error) {
console.log(` tx revert -> token contract address is 0 address`.grey);
ensureException(error);
errorThrown = true;
}
assert.ok(errorThrown, message);
});

it("Should successfully reclaim POLY", async() => {
let initInvestorBalance = await I_PolyToken.balanceOf(account_investor1);
let initOwnerBalance = await I_PolyToken.balanceOf(token_owner);
let initContractBalance = await I_PolyToken.balanceOf(I_CappedSTO_Array_ETH[0].address);
let value = web3.utils.toWei('100','ether');

await I_PolyToken.getTokens(value, account_investor1);
await I_PolyToken.transfer(I_CappedSTO_Array_ETH[0].address, value, { from: account_investor1 });
await I_CappedSTO_Array_ETH[0].reclaimERC20(I_PolyToken.address, { from: token_owner });
assert.equal((await I_PolyToken.balanceOf(account_investor3)).toNumber(), initInvestorBalance.toNumber(), "tokens are not transfered out from investor account");
assert.equal((await I_PolyToken.balanceOf(token_owner)).toNumber(), initOwnerBalance.add(value).add(initContractBalance).toNumber(), "tokens are not added to the owner account");
assert.equal((await I_PolyToken.balanceOf(I_CappedSTO_Array_ETH[0].address)).toNumber(), 0, "tokens are not trandfered out from STO contract");
});
});

describe("Attach second ETH STO module", async() => {

it("Should successfully attach the second STO module to the security token", async () => {
Expand Down
33 changes: 33 additions & 0 deletions test/presale_sto.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,39 @@ contract('PreSaleSTO', accounts => {

});

describe("Reclaim poly sent to STO by mistake", async() => {

it("Should fail to reclaim POLY because token contract address is 0 address", async() => {
let value = web3.utils.toWei('100','ether');
await I_PolyToken.getTokens(value, account_investor1);
await I_PolyToken.transfer(I_PreSaleSTO.address, value, { from: account_investor1 });

let errorThrown = false;
try {
await I_PreSaleSTO.reclaimERC20('0x0000000000000000000000000000000000000000', { from: token_owner });
} catch(error) {
console.log(` tx revert -> token contract address is 0 address`.grey);
ensureException(error);
errorThrown = true;
}
assert.ok(errorThrown, message);
});

it("Should successfully reclaim POLY", async() => {
let initInvestorBalance = await I_PolyToken.balanceOf(account_investor1);
let initOwnerBalance = await I_PolyToken.balanceOf(token_owner);
let initContractBalance = await I_PolyToken.balanceOf(I_PreSaleSTO.address);
let value = web3.utils.toWei('100','ether');

await I_PolyToken.getTokens(value, account_investor1);
await I_PolyToken.transfer(I_PreSaleSTO.address, value, { from: account_investor1 });
await I_PreSaleSTO.reclaimERC20(I_PolyToken.address, { from: token_owner });
assert.equal((await I_PolyToken.balanceOf(account_investor3)).toNumber(), initInvestorBalance.toNumber(), "tokens are not transfered out from investor account");
assert.equal((await I_PolyToken.balanceOf(token_owner)).toNumber(), initOwnerBalance.add(value).add(initContractBalance).toNumber(), "tokens are not added to the owner account");
assert.equal((await I_PolyToken.balanceOf(I_PreSaleSTO.address)).toNumber(), 0, "tokens are not trandfered out from STO contract");
});
});

describe("Test cases for the PresaleSTOFactory", async() => {
it("should get the exact details of the factory", async() => {
assert.equal(await I_PreSaleSTOFactory.setupCost.call(),0);
Expand Down

0 comments on commit c41833b

Please sign in to comment.