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

Count tm audit change #444

Merged
merged 8 commits into from
Dec 6, 2018
113 changes: 107 additions & 6 deletions test/d_count_transfer_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ contract("CountTransferManager", accounts => {
let I_CountTransferManagerFactory;
let I_GeneralPermissionManager;
let I_CountTransferManager;
let I_CountTransferManager2;
let I_GeneralTransferManager;
let I_GeneralTransferManager2;
let I_ExchangeTransferManager;
let I_ModuleRegistry;
let I_ModuleRegistryProxy;
Expand All @@ -49,12 +51,14 @@ contract("CountTransferManager", accounts => {
let I_SecurityTokenRegistry;
let I_STFactory;
let I_SecurityToken;
let I_SecurityToken2;
let I_PolyToken;
let I_PolymathRegistry;

// SecurityToken Details
const name = "Team";
const symbol = "sap";
const symbol2 = "sapp";
const tokenDetails = "This is equity type of issuance";
const decimals = 18;
const contact = "team@polymath.network";
Expand Down Expand Up @@ -339,12 +343,6 @@ contract("CountTransferManager", accounts => {
await catchRevert(I_SecurityToken.transfer(account_investor3, web3.utils.toWei("2", "ether"), { from: account_investor2 }));
});

it("Should be able to transfer to a new token holder if all tokens are transferred and existing holder is removed", async () => {
console.log('acc2 balancce is ' + (await I_SecurityToken.balanceOf(account_investor2)).toNumber());
await I_SecurityToken.transfer(account_investor3, web3.utils.toWei("4", "ether"), { from: account_investor2 });
assert((await I_SecurityToken.balanceOf(account_investor3)).toNumber(), web3.utils.toWei("4", "ether"));
});

it("Should be able to consolidate balances", async () => {
await I_SecurityToken.transfer(account_investor2, web3.utils.toWei("1", "ether"), { from: account_investor1 });
});
Expand All @@ -354,6 +352,109 @@ contract("CountTransferManager", accounts => {
assert.equal(perm.length, 1);
});

describe("Test cases for adding and removing acc holder at the same time", async () => {
it("deploy a new token & auto attach modules", async () => {

//register ticker and deploy token
await I_PolyToken.approve(I_STRProxied.address, initRegFee, { from: token_owner });
let tx = await I_STRProxied.registerTicker(token_owner, symbol2, contact, { from: token_owner });

await I_PolyToken.approve(I_STRProxied.address, initRegFee, { from: token_owner });
let _blockNo = latestBlock();
let tx2 = await I_STRProxied.generateSecurityToken(name, symbol2, tokenDetails, false, { from: token_owner });

I_SecurityToken2 = SecurityToken.at(tx2.logs[1].args._securityTokenAddress);

let moduleData = (await I_SecurityToken2.getModulesByType(2))[0];
I_GeneralTransferManager2 = GeneralTransferManager.at(moduleData);
});

it("add 3 holders to the token", async () => {

await I_GeneralTransferManager2.modifyWhitelist(
account_investor1,
latestTime(),
latestTime(),
latestTime() + duration.days(10),
true,
{
from: account_issuer,
gas: 500000
}
);

await I_GeneralTransferManager2.modifyWhitelist(
account_investor2,
latestTime(),
latestTime(),
latestTime() + duration.days(10),
true,
{
from: account_issuer,
gas: 500000
}
);

await I_GeneralTransferManager2.modifyWhitelist(
account_investor3,
latestTime(),
latestTime(),
latestTime() + duration.days(10),
true,
{
from: account_issuer,
gas: 500000
}
);

// Jump time
await increaseTime(5000);

// Mint some tokens
await I_SecurityToken2.mint(account_investor1, web3.utils.toWei("1", "ether"), { from: token_owner });
await I_SecurityToken2.mint(account_investor2, web3.utils.toWei("1", "ether"), { from: token_owner });

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing mint statement for account_investor3?

assert.equal((await I_SecurityToken2.balanceOf(account_investor1)).toNumber(), web3.utils.toWei("1", "ether"));
});

// Add count transfer manager and only allow 2 holders
it("Should intialize the auto attached modules", async () => {
let moduleData = (await I_SecurityToken2.getModulesByType(2))[0];
I_GeneralTransferManager2 = GeneralTransferManager.at(moduleData);
});

it("Should successfully attach the CountTransferManager factory with the security token", async () => {
await I_PolyToken.getTokens(web3.utils.toWei("500", "ether"), token_owner);
await catchRevert(
I_SecurityToken2.addModule(P_CountTransferManagerFactory.address, bytesSTO, web3.utils.toWei("500", "ether"), 0, {
from: token_owner
})
);
});

it("Should successfully attach the CountTransferManager with the security token and set max holder to 2", async () => {
const tx = await I_SecurityToken2.addModule(I_CountTransferManagerFactory.address, bytesSTO, 0, 0, { from: token_owner });
assert.equal(tx.logs[2].args._types[0].toNumber(), transferManagerKey, "CountTransferManager doesn't get deployed");
assert.equal(
web3.utils.toAscii(tx.logs[2].args._name).replace(/\u0000/g, ""),
"CountTransferManager",
"CountTransferManager module was not added"
);
I_CountTransferManager2 = CountTransferManager.at(tx.logs[2].args._module);
await I_CountTransferManager2.changeHolderCount(2, {from: token_owner});
console.log('current max holder number is '+ await I_CountTransferManager2.maxHolderCount({from: token_owner}));
});

it("Should allow add a new token holder while transfer all the tokens at one go", async () => {

let amount = (await I_SecurityToken2.balanceOf(account_investor2)).toNumber();
console.log('amount is '+amount);
await I_SecurityToken2.transfer(account_investor3, amount, { from: account_investor2 });
assert((await I_SecurityToken2.balanceOf(account_investor3)).toNumber(), web3.utils.toWei("2", "ether"));

});
});

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