Skip to content

Commit 772d2f2

Browse files
committed
Updated tests
1 parent f3dc1b3 commit 772d2f2

File tree

3 files changed

+34
-19
lines changed

3 files changed

+34
-19
lines changed

contracts/modules/Experimental/TransferManager/SignedTransferManager.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ contract SignedTransferManager is TransferManager {
142142
(targetAddress, nonce, expiry, signature) = abi.decode(_data, (address, uint256, uint256, bytes));
143143

144144
require(!_checkSignatureIsInvalid(signature), "Signature already invalid");
145-
require(targetAddress != address(this), "Signature not for this module");
145+
require(targetAddress == address(this), "Signature not for this module");
146146

147147
bytes32 hash = keccak256(abi.encodePacked(targetAddress, nonce, expiry, _from, _to, _amount));
148148
bytes32 prependedHash = keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));

test/helpers/signData.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ function signData(tmAddress, investorAddress, fromTime, toTime, expiryTime, rest
1818
return ethUtil.ecsign(new Buffer(packedData.slice(2), "hex"), new Buffer(pk, "hex"));
1919
}
2020

21-
function getSignTMSig(tmAddress, fromAddress, toAddress, amount, pk) {
22-
let hash = web3.utils.soliditySha3({t: 'address', v: tmAddress}, {t: 'address', v: fromAddress}, {t: 'address', v: toAddress}, {t: 'uint256', v: new BN(amount)});
23-
let sign = web3.eth.accounts.sign(hash, pk);
24-
return sign.signature;
21+
function getSignTMData(tmAddress, nonce, expiry, fromAddress, toAddress, amount, pk) {
22+
let hash = web3.utils.soliditySha3({t: 'address', v: tmAddress}, {t: 'uint256', v: new BN(nonce)}, {t: 'uint256', v: new BN(expiry)}, {t: 'address', v: fromAddress}, {t: 'address', v: toAddress}, {t: 'uint256', v: new BN(amount)});
23+
let signature = (web3.eth.accounts.sign(hash, pk)).signature;
24+
let data = web3.eth.abi.encodeParameters(['address', 'uint256', 'uint256', 'bytes'], [tmAddress, new BN(nonce).toString(), new BN(expiry).toString(), signature]);
25+
return data;
2526
}
2627

2728
module.exports = {
2829
signData,
29-
getSignTMSig
30+
getSignTMData
3031
};

test/zb_signed_transfer_manager.js

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import latestTime from "./helpers/latestTime";
22
import { duration, promisifyLogWatch, latestBlock } from "./helpers/utils";
33
import takeSnapshot, { increaseTime, revertToSnapshot } from "./helpers/time";
4-
import { getSignTMSig } from "./helpers/signData";
4+
import { getSignTMData } from "./helpers/signData";
55
import { pk } from "./helpers/testprivateKey";
66
import { encodeProxyCall, encodeModuleCall } from "./helpers/encodeCall";
77
import { catchRevert } from "./helpers/exceptions";
@@ -224,26 +224,33 @@ contract("SignedTransferManager", accounts => {
224224

225225
await I_SignedTransferManager.updateSigners([signer.address], [true], {from: token_owner});
226226

227-
const sig = await getSignTMSig(
227+
let nonce = new BN(10);
228+
let expiry = new BN(currentTime.add(new BN(duration.days(100))));
229+
let data = await getSignTMData(
228230
I_SignedTransferManager.address,
231+
nonce,
232+
expiry,
229233
account_investor1,
230234
account_investor2,
231235
oneeth,
232236
signer.privateKey
233237
);
234238

235-
assert.equal(await I_SignedTransferManager.checkSignatureIsInvalid(sig), false);
236-
await I_SignedTransferManager.invalidateSignature(account_investor1, account_investor2, oneeth, sig, {from: signer.address});
237-
assert.equal(await I_SignedTransferManager.checkSignatureIsInvalid(sig), true);
239+
assert.equal(await I_SignedTransferManager.checkSignatureValidity(data), true);
240+
await I_SignedTransferManager.invalidateSignature(account_investor1, account_investor2, oneeth, data, {from: signer.address});
241+
assert.equal(await I_SignedTransferManager.checkSignatureValidity(data), false);
238242
});
239243

240244
it("should allow transfer with valid sig", async () => {
241245
let signer = web3.eth.accounts.create();
242246
await I_SignedTransferManager.updateSigners([signer.address], [true], {from: token_owner});
243247
let oneeth = new BN(web3.utils.toWei("1", "ether"));
244-
245-
const sig = await getSignTMSig(
248+
let nonce = new BN(10);
249+
let expiry = new BN(currentTime.add(new BN(duration.days(100))));
250+
let data = await getSignTMData(
246251
I_SignedTransferManager.address,
252+
nonce,
253+
expiry,
247254
account_investor1,
248255
account_investor2,
249256
oneeth,
@@ -253,28 +260,35 @@ contract("SignedTransferManager", accounts => {
253260
let balance11 = await I_SecurityToken.balanceOf(account_investor1);
254261
let balance21 = await I_SecurityToken.balanceOf(account_investor2);
255262

256-
await I_SecurityToken.transferWithData(account_investor2, oneeth, sig, {from: account_investor1});
263+
assert.equal(await I_SignedTransferManager.checkSignatureValidity(data), true);
264+
265+
await I_SecurityToken.transferWithData(account_investor2, oneeth, data, {from: account_investor1});
266+
267+
assert.equal(await I_SignedTransferManager.checkSignatureValidity(data), false);
268+
await catchRevert(I_SecurityToken.transferWithData(account_investor2, oneeth, data, {from: account_investor1}));
257269

258-
assert.equal(await I_SignedTransferManager.checkSignatureIsInvalid(sig), true);
259270
assert.equal(balance11.sub(oneeth).toString(), (await I_SecurityToken.balanceOf(account_investor1)).toString());
260271
assert.equal(balance21.add(oneeth).toString(), (await I_SecurityToken.balanceOf(account_investor2)).toString());
261272

262-
await catchRevert(I_SecurityToken.transferWithData(account_investor2, oneeth, sig, {from: account_investor1}));
273+
263274
});
264275

265276
it("should not allow transfer if the signer is not on the signer list", async () => {
266277
let signer = web3.eth.accounts.create();
267278
let oneeth = new BN(web3.utils.toWei("1", "ether"));
268-
269-
const sig = await getSignTMSig(
279+
let nonce = new BN(10);
280+
let expiry = new BN(currentTime.add(new BN(duration.days(100))));
281+
let data = await getSignTMData(
270282
I_SignedTransferManager.address,
283+
nonce,
284+
expiry,
271285
account_investor1,
272286
account_investor2,
273287
oneeth,
274288
signer.privateKey
275289
);
276290

277-
await catchRevert(I_SecurityToken.transferWithData(account_investor2, oneeth, sig, {from: account_investor1}));
291+
await catchRevert(I_SecurityToken.transferWithData(account_investor2, oneeth, data, {from: account_investor1}));
278292
});
279293
});
280294
});

0 commit comments

Comments
 (0)