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

Voting module test refactor #348

Merged
merged 17 commits into from
Oct 18, 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
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ scTopics
coverageEnv
/flat
/tempPoly
.eslintrc.js
.eslintrc.js
package-lock.json
bridge.log
.node-xml*
.solcover.js.bk
allFiredEvents
2 changes: 1 addition & 1 deletion .solcover.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ module.exports = {
copyPackages: ['openzeppelin-solidity'],
testCommand: 'node ../node_modules/.bin/truffle test `find test/*.js ! -name a_poly_oracle.js -and ! -name s_v130_to_v140_upgrade.js` --network coverage',
deepSkip: true,
skipFiles: ['external', 'flat', 'helpers', 'mocks', 'oracles'],
skipFiles: ['external', 'flat', 'helpers', 'mocks', 'oracles', 'libraries/KindMath.sol', 'storage'],
forceParse: ['mocks', 'oracles']
};
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.
[__1.5.0__](https://www.npmjs.com/package/polymath-core?activeTab=readme) __15-08-18__

## Added
* Migrated from `npm` to `yarn`.
* Added `SingleTradeVolumeRestrictionManager` module
* Added flag in `PercentageTransferManager` to allow ignoring of issuance transfers
* Added `transferWithData`, `transferFromWithData`, `mintWithData`, `burnWithData` to allow passing of a `bytes _data` for off-chain validation
Expand All @@ -25,11 +26,12 @@ All notable changes to this project will be documented in this file.
* Add `getReputationOfFactory()` & `getModuleListOfType()` functions to get the array type data from the ModuleRegistry contract.
* Add `_setupCost` in `LogGenerateModuleFromFactory` event.
* Add new function `getAllModulesByName()`, To get the list of modules having the same name. #198.
* Add new function `modifyTickerDetails()`, To modify the details of undeployed ticker. #230
* Add new function `modifyTickerDetails()`, To modify the details of undeployed ticker. #230

## Fixed
* Generalize the STO varaible names and added them in `ISTO.sol` to use the common standard in all STOs.
* Generalize the event when any new token get registered with the polymath ecosystem. `LogNewSecurityToken` should emit _ticker, _name, _securityTokenAddress, _owner, _addedAt, _registrant respectively. #230
* Generalize the event when any new token get registered with the polymath ecosystem. `LogNewSecurityToken` should emit _ticker, _name, _securityTokenAddress, _owner, _addedAt, _registrant respectively. #230
* Change the function name of `withdraPoly` to `withdrawERC20` and make the function generalize to extract tokens from the ST contract. parmeters are contract address and the value need to extract from the securityToken.

## Removed
* Remove `swarmHash` from the `registerTicker(), addCustomTicker(), generateSecurityToken(), addCustomSecurityToken()` functions of TickerRegistry.sol and SecurityTokenRegistry.sol. #230
Expand Down
3 changes: 2 additions & 1 deletion CLI/commands/ST20Generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const MODULES_TYPES = {
PERMISSION: 1,
TRANSFER: 2,
STO: 3,
DIVIDENDS: 4
DIVIDENDS: 4,
BURN: 5
}

const cappedSTOFee = 20000;
Expand Down
3 changes: 2 additions & 1 deletion CLI/commands/dividends_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const MODULES_TYPES = {
PERMISSION: 1,
TRANSFER: 2,
STO: 3,
DIVIDENDS: 4
DIVIDENDS: 4,
BURN: 5
}

// App flow
Expand Down
12 changes: 11 additions & 1 deletion CLI/commands/helpers/contract_abis.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ let stoInterfaceABI;
let cappedSTOABI;
let usdTieredSTOABI;
let generalTransferManagerABI;
let generalPermissionManagerABI;
let polyTokenABI;
let cappedSTOFactoryABI;
let usdTieredSTOFactoryABI;
let erc20DividendCheckpointABI;
let etherDividendCheckpointABI;
let moduleInterfaceABI;
let ownableABI;
let moduleFactoryABI;

Expand All @@ -25,16 +27,18 @@ try {
cappedSTOABI = JSON.parse(require('fs').readFileSync('./build/contracts/CappedSTO.json').toString()).abi;
usdTieredSTOABI = JSON.parse(require('fs').readFileSync('./build/contracts/USDTieredSTO.json').toString()).abi;
generalTransferManagerABI = JSON.parse(require('fs').readFileSync('./build/contracts/GeneralTransferManager.json').toString()).abi;
generalPermissionManagerABI = JSON.parse(require('fs').readFileSync('./build/contracts/GeneralPermissionManager.json').toString()).abi;
polyTokenABI = JSON.parse(require('fs').readFileSync('./build/contracts/PolyTokenFaucet.json').toString()).abi;
cappedSTOFactoryABI = JSON.parse(require('fs').readFileSync('./build/contracts/CappedSTOFactory.json').toString()).abi;
usdTieredSTOFactoryABI = JSON.parse(require('fs').readFileSync('./build/contracts/USDTieredSTOFactory.json').toString()).abi;
erc20DividendCheckpointABI = JSON.parse(require('fs').readFileSync('./build/contracts/ERC20DividendCheckpoint.json').toString()).abi;
etherDividendCheckpointABI = JSON.parse(require('fs').readFileSync('./build/contracts/EtherDividendCheckpoint.json').toString()).abi;
moduleInterfaceABI = JSON.parse(require('fs').readFileSync('./build/contracts/IModule.json').toString()).abi;
ownableABI = JSON.parse(require('fs').readFileSync('./build/contracts/Ownable.json').toString()).abi;
moduleFactoryABI = JSON.parse(require('fs').readFileSync('./build/contracts/ModuleFactory.json').toString()).abi;
} catch (err) {
console.log('\x1b[31m%s\x1b[0m',"Couldn't find contracts' artifacts. Make sure you ran truffle compile first");
return;
throw err;
}

module.exports = {
Expand Down Expand Up @@ -65,6 +69,9 @@ module.exports = {
generalTransferManager: function () {
return generalTransferManagerABI;
},
generalPermissionManager: function () {
return generalPermissionManagerABI;
},
polyToken: function () {
return polyTokenABI;
},
Expand All @@ -80,6 +87,9 @@ module.exports = {
etherDividendCheckpoint: function () {
return etherDividendCheckpointABI;
},
moduleInterface: function () {
return moduleInterfaceABI;
},
ownable: function () {
return ownableABI;
},
Expand Down
222 changes: 222 additions & 0 deletions CLI/commands/permission_manager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
var readlineSync = require('readline-sync');
var chalk = require('chalk');
var common = require('./common/common_functions');
var global = require('./common/global');
var contracts = require('./helpers/contract_addresses');
var abis = require('./helpers/contract_abis');

// App flow
let tokenSymbol;
let securityTokenRegistry;
let securityToken;
let generalPermissionManager;

const MODULES_TYPES = {
PERMISSION: 1,
TRANSFER: 2,
STO: 3,
DIVIDEND: 4,
BURN: 5
}

async function executeApp(remoteNetwork) {
await global.initialize(remoteNetwork);

common.logAsciiBull();
console.log("***********************************************");
console.log("Welcome to the Command-Line Permission Manager.");
console.log("***********************************************");
console.log("Issuer Account: " + Issuer.address + "\n");

await setup();
try {
await selectST();
await addPermissionModule();
await changePermissionStep();
} catch (err) {
console.log(err);
return;
}
};

async function setup(){
try {
let securityTokenRegistryAddress = await contracts.securityTokenRegistry();
let securityTokenRegistryABI = abis.securityTokenRegistry();
securityTokenRegistry = new web3.eth.Contract(securityTokenRegistryABI, securityTokenRegistryAddress);
securityTokenRegistry.setProvider(web3.currentProvider);
} catch (err) {
console.log(err)
console.log('\x1b[31m%s\x1b[0m',"There was a problem getting the contracts. Make sure they are deployed to the selected network.");
process.exit(0);
}
}

async function selectST() {
if (!tokenSymbol)
tokenSymbol = readlineSync.question('Enter the token symbol: ');

let result = await securityTokenRegistry.methods.getSecurityTokenAddress(tokenSymbol).call();
if (result == "0x0000000000000000000000000000000000000000") {
tokenSymbol = undefined;
console.log(chalk.red(`Token symbol provided is not a registered Security Token.`));
await selectST();
} else {
let securityTokenABI = abis.securityToken();
securityToken = new web3.eth.Contract(securityTokenABI,result);
}
}

async function addPermissionModule() {
let generalPermissionManagerAddress;
let result = await securityToken.methods.getModulesByName(web3.utils.toHex('GeneralPermissionManager')).call();
if (result.length == 0) {
console.log(chalk.red(`General Permission Manager is not attached.`));
if (readlineSync.keyInYNStrict('Do you want to add General Permission Manager Module to your Security Token?')) {
let permissionManagerFactoryAddress = await contracts.getModuleFactoryAddressByName(securityToken.options.address, MODULES_TYPES.PERMISSION, 'GeneralPermissionManager');
let addModuleAction = securityToken.methods.addModule(permissionManagerFactoryAddress, web3.utils.fromAscii('', 16), 0, 0);
let receipt = await common.sendTransaction(Issuer, addModuleAction, defaultGasPrice);
let event = common.getEventFromLogs(securityToken._jsonInterface, receipt.logs, 'ModuleAdded');
console.log(`Module deployed at address: ${event._module}`);
generalPermissionManagerAddress = event._module;
} else {
process.exit(0);
}
} else {
generalPermissionManagerAddress = result[0];
}

let generalPermissionManagerABI = abis.generalPermissionManager();
generalPermissionManager = new web3.eth.Contract(generalPermissionManagerABI, generalPermissionManagerAddress);
generalPermissionManager.setProvider(web3.currentProvider);
}

async function changePermissionStep() {
console.log('\n\x1b[34m%s\x1b[0m',"Permission Manager - Change Permission");
let selectedDelegate = await selectDelegate();
let selectedModule = await selectModule();
let selectedPermission = await selectPermission(selectedModule.permissions);
let isValid = isPermissionValid();
await changePermission(selectedDelegate, selectedModule.address, selectedPermission, isValid);
}

// Helper functions
async function selectDelegate() {
let result;
let delegates = await getDelegates();

let options = ['Add new delegate'];
options = options.concat(delegates.map(function(d) {
return `Account: ${d.address}
Details: ${d.details}`
}));

let index = readlineSync.keyInSelect(options, 'Select a delegate:', {cancel: false});
if (index == 0) {
let newDelegate = await addNewDelegate();
result = newDelegate;
} else {
result = delegates[index - 1].address;
}

return result;
}

async function selectModule() {
let modules = await getModulesWithPermissions();
let options = modules.map(function(m) {
return m.name;
});
let index = readlineSync.keyInSelect(options, 'Select a module:', {cancel: false});
return modules[index];
}

async function selectPermission(permissions) {
let options = permissions.map(function(p) {
return p
});
let index = readlineSync.keyInSelect(options, 'Select a permission:', {cancel: false});
return permissions[index];
}

function isPermissionValid() {
let options = ['Grant permission', 'Revoke permission'];
let index = readlineSync.keyInSelect(options, 'What do you want to do?', {cancel: false});
return index == 0;
}

async function changePermission(delegate, moduleAddress, permission, isValid) {
let changePermissionAction = generalPermissionManager.methods.changePermission(delegate, moduleAddress, web3.utils.asciiToHex(permission), isValid);
let receipt = await common.sendTransaction(Issuer, changePermissionAction, defaultGasPrice, 0, 1.5);
common.getEventFromLogs(generalPermissionManager._jsonInterface, receipt.logs, 'ChangePermission');
console.log(`Permission changed succesfully,`);
}

async function getDelegates() {
let result = [];
/*
let events = await generalPermissionManager.getPastEvents('LogAddPermission', { fromBlock: 0});
for (let event of events) {
let delegate = {};
delegate.address = event.returnValues._delegate;
delegate.details = web3.utils.hexToAscii(event.returnValues._details);
result.push(delegate);
}
*/
let delegates = await generalPermissionManager.methods.getAllDelegates().call();
for (let d of delegates) {
let delegate = {};
delegate.address = d;
delegate.details = web3.utils.hexToAscii(await generalPermissionManager.methods.delegateDetails(d).call());
result.push(delegate);
}
return result;
}

async function addNewDelegate() {
let newDelegate = readlineSync.question('Enter the delegate address: ', {
limit: function (input) {
return web3.utils.isAddress(input);
},
limitMessage: "Must be a valid address"
});
let details = readlineSync.question('Enter the delegate details (i.e `Belongs to financial firm`): ', {
limit: function(input) {
return input.length > 0;
},
limitMessage: "Must be a valid string"
});
let addPermissionAction = generalPermissionManager.methods.addDelegate(newDelegate, web3.utils.asciiToHex(details));
let receipt = await common.sendTransaction(Issuer, addPermissionAction, defaultGasPrice);
let event = common.getEventFromLogs(generalPermissionManager._jsonInterface, receipt.logs, 'AddDelegate');
console.log(`Delegate added succesfully: ${event._delegate} - ${event._details}`);
return event._delegate;
}

async function getModulesWithPermissions() {
let modules = [];
let moduleABI = abis.moduleInterface();

for (const type in MODULES_TYPES) {
let modulesAttached = await securityToken.methods.getModulesByType(MODULES_TYPES[type]).call();
for (const m of modulesAttached) {
let contractTemp = new web3.eth.Contract(moduleABI, m);
let permissions = await contractTemp.methods.getPermissions().call();
if (permissions.length > 0) {
modules.push({
name: web3.utils.hexToAscii((await securityToken.methods.getModule(m).call())[0]),
address: m,
permissions: permissions.map(function (p) { return web3.utils.hexToAscii(p) })
})
}
}
}

return modules;
}

module.exports = {
executeApp: async function(remoteNetwork) {
return executeApp(remoteNetwork);
}
}
1 change: 1 addition & 0 deletions CLI/data/dividendsExclusions_data.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
0xee7ae74d964f2be7d72c1b187b38e2ed3615d4d1
0x49fc0b78238dab644698a90fa351b4c749e123d2
0x10223927009b8add0960359dd90d1449415b7ca9
0x3c65cfe3de848cf38e9d76e9c3e57a2f1140b399
Expand Down
Loading