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

Made TM results consistent #693

Merged
merged 2 commits into from
Jun 13, 2019
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
5 changes: 1 addition & 4 deletions contracts/libraries/TokenLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -432,11 +432,9 @@ library TokenLib {
bool isValid = false;
bool isForceValid = false;
// Use the local variables to avoid the stack too deep error
transfersFrozen = false; // bool unarchived = false;
bytes32 appCode;
for (uint256 i = 0; i < modules.length; i++) {
if (!modulesToData[modules[i]].isArchived) {
transfersFrozen = true;
(ITransferManager.Result valid, bytes32 reason) = ITransferManager(modules[i]).verifyTransfer(from, to, value, data);
if (valid == ITransferManager.Result.INVALID) {
isInvalid = true;
Expand All @@ -448,9 +446,8 @@ library TokenLib {
}
}
}
// If no unarchived modules, return true by default
// Use the local variables to avoid the stack too deep error
isValid = transfersFrozen ? (isForceValid ? true : (isInvalid ? false : isValid)) : true;
isValid = isForceValid ? true : (isInvalid ? false : isValid);
return (isValid, isValid ? bytes32(StatusCodes.code(StatusCodes.Status.TransferSuccess)): appCode);
}
return (false, bytes32(StatusCodes.code(StatusCodes.Status.TransfersHalted)));
Expand Down
7 changes: 3 additions & 4 deletions contracts/tokens/SecurityToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -671,13 +671,13 @@ contract SecurityToken is ERC20, ReentrancyGuard, SecurityTokenStorage, IERC1594
bool isInvalid;
bool isValid;
bool isForceValid;
bool unarchived;
address module;
uint256 tmLength = modules[TRANSFER_KEY].length;
for (uint256 i = 0; i < tmLength; i++) {
module = modules[TRANSFER_KEY][i];
if (!modulesToData[module].isArchived) {
unarchived = true;
// refer to https://github.com/PolymathNetwork/polymath-core/wiki/Transfer-manager-results
// for understanding what these results mean
ITransferManager.Result valid = ITransferManager(module).executeTransfer(_from, _to, _value, _data);
if (valid == ITransferManager.Result.INVALID) {
isInvalid = true;
Expand All @@ -688,8 +688,7 @@ contract SecurityToken is ERC20, ReentrancyGuard, SecurityTokenStorage, IERC1594
}
}
}
// If no unarchived modules, return true by default
return unarchived ? (isForceValid ? true : (isInvalid ? false : isValid)) : true;
return isForceValid ? true : (isInvalid ? false : isValid);
}
return false;
}
Expand Down
18 changes: 2 additions & 16 deletions test/o_security_token.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,16 +519,6 @@ contract("SecurityToken", async (accounts) => {
let tx = await I_SecurityToken.removeModule(I_GeneralTransferManager.address, { from: token_owner });
assert.equal(tx.logs[0].args._types[0], transferManagerKey);
assert.equal(tx.logs[0].args._module, I_GeneralTransferManager.address);
await I_SecurityToken.issue(account_investor1, new BN(web3.utils.toWei("500")), "0x0", { from: token_owner });
let _canTransfer = await I_SecurityToken.canTransfer.call(account_investor2, new BN(web3.utils.toWei("200")), "0x0", {from: account_investor1});

assert.isTrue(_canTransfer[0]);
assert.equal(_canTransfer[1], 0x51);
assert.equal(_canTransfer[2], empty_hash);

await I_SecurityToken.transfer(account_investor2, new BN(web3.utils.toWei("200")), { from: account_investor1 });

assert.equal((await I_SecurityToken.balanceOf(account_investor2)).div(new BN(10).pow(new BN(18))).toNumber(), 200);
await revertToSnapshot(key);
});

Expand Down Expand Up @@ -581,12 +571,8 @@ contract("SecurityToken", async (accounts) => {
assert.equal(moduleData[3], true);
});

it("Should successfully issue tokens while GTM archived", async () => {
let key = await takeSnapshot();
await I_SecurityToken.issue(one_address, new BN(100).mul(new BN(10).pow(new BN(18))), "0x0", { from: token_owner, gas: 500000 });
let balance = await I_SecurityToken.balanceOf(one_address);
assert.equal(balance.div(new BN(10).pow(new BN(18))).toNumber(), 100);
await revertToSnapshot(key);
it("Should fail to issue (or transfer) tokens while all TM are archived archived", async () => {
await catchRevert(I_SecurityToken.issue(one_address, new BN(100).mul(new BN(10).pow(new BN(18))), "0x0", { from: token_owner }));
});

it("Should successfully unarchive the general transfer manager module from the securityToken", async () => {
Expand Down