Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add reclaimERC20 to ISTO #165

Merged
merged 1 commit into from
Jul 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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