Skip to content

Commit

Permalink
updated transfer manager results (#693)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsam4 authored and adamdossa committed Jun 13, 2019
1 parent 99cf720 commit 0e8c7cd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 24 deletions.
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 @@ -668,13 +668,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 @@ -685,8 +685,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 @@ -525,16 +525,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 @@ -587,12 +577,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

0 comments on commit 0e8c7cd

Please sign in to comment.