From be63d5ca701c32e475ed4378fcd6cfd28dec67ce Mon Sep 17 00:00:00 2001 From: Jason Banks Date: Tue, 30 Apr 2019 08:14:00 +0200 Subject: [PATCH 01/19] Repo: update readme narrative information and installation and usage details --- README.md | 90 ++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 69 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index bdc4a38..b389384 100644 --- a/README.md +++ b/README.md @@ -2,56 +2,104 @@ ![Build master](https://img.shields.io/travis/OpenST/organization-contracts/master.svg?label=build%20master&style=flat) ![Build develop](https://img.shields.io/travis/OpenST/organization-contracts/develop.svg?label=build%20develop&style=flat) -![npm version](https://img.shields.io/npm/v/@openstfoundation/organization-contracts.svg?style=flat) [![Discuss on Discourse](https://img.shields.io/discourse/https/discuss.openst.org/topics.svg?style=flat)][discourse] -[![Chat on Gitter](https://img.shields.io/gitter/room/OpenSTFoundation/SimpleToken.svg?style=flat)][gitter] +[![Chat on Gitter](https://img.shields.io/gitter/room/ostdotcom/OST-Platform.svg?style=flat)][gitter] -Organization contracts manage application permissions. +An organization administers other contracts. For an individual contract or a system of contracts, an organization enables limiting execution of certain functions to the organization or other accounts it authorizes (e.g., "workers"). -## Instructions +## Getting Started -### Installation +These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. -> Please add +### Prerequisites -### Usage +Project requires [node] and [npm] to be installed. -> Please add +### Cloning -## Related Work - -[mosaic-contracts] and [openst-contracts] use this package to manage access control. +```bash +git clone git@github.com:OpenST/organization-contracts.git +``` -## Contributing +### Installing -### Set-up +Install npm packages: ```bash -git clone git@github.com:OpenST/organization-contracts.git cd organization-contracts npm install +``` +## Usage + +The contracts and interfaces in this repository are primarily intended for use in other OpenST projects. Please see [Related Work]. + +### Compiling the contracts + +The following npm script compiles updated contracts from the last call using [truffle]: + +```bash +npm run compile +``` + +To compile all contracts: + +```bash npm run compile-all -npm run ganache +``` + +### Testing the contracts + +We use the [ganache] blockchain for development. Before running the tests, start `ganache`: + +```bash +npm run ganache-cli +``` + +Test the contracts using [truffle]: + +```bash npm run test ``` -### Guidelines +### Linting + +[ESLint] is used to lint js files. + +To lint all js files within the `./test` and `./tool` directories, run: + +```bash +npm run lint +``` + +## Related Work + +OpenST uses organization contracts and interfaces in [mosaic-contracts], [brandedtoken-contracts], and [openst-contracts] to scale, create, and define blockchain token economies. + +## Contributing There are multiple ways to contribute to this project. However, before contributing, please first review the [Code of Conduct]. We track our [issues] on GitHub. -To contribute code, please ensure that your read the [developer guidelines] first. +To contribute code, please review our [Developer Guidelines] and ensure that your submissions adhere to the [Style Guide]; please also be aware, this project is under active development and we have not yet established firm contribution guidelines or acceptance criteria. ### Community * [Forum][discourse] -* [Gitter] +* [Gitter][gitter] -[code of conduct]: https://github.com/OpenST/developer-guidelines/blob/develop/CODE_OF_CONDUCT.md +[brandedtoken-contracts]: https://github.com/OpenSTFoundation/brandedtoken-contracts +[code of conduct]: https://github.com/OpenST/developer-guidelines/blob/master/CODE_OF_CONDUCT.md [developer guidelines]: https://github.com/OpenST/developer-guidelines [discourse]: https://discuss.openst.org/ -[gitter]: https://gitter.im/OpenSTFoundation/SimpleToken +[eslint]: https://eslint.org +[ganache]: https://github.com/trufflesuite/ganache +[gitter]: https://gitter.im/ostdotcom/OST-Platform +[issues]: https://github.com/OpenST/organization-contracts/issues [mosaic-contracts]: https://github.com/OpenSTFoundation/mosaic-contracts +[node]: https://nodejs.org/en/ +[npm]: https://www.npmjs.com/get-npm [openst-contracts]: https://github.com/OpenSTFoundation/openst-contracts -[issues]: https://github.com/OpenST/organization-contracts/issues +[related work]: #related-work +[style guide]: https://github.com/OpenST/developer-guidelines/blob/master/SOLIDITY_STYLE_GUIDE.md +[truffle]: https://github.com/trufflesuite/truffle \ No newline at end of file From f3c582fd751fd75d39ff0554e6a843fe75652916 Mon Sep 17 00:00:00 2001 From: Jason Banks Date: Thu, 2 May 2019 12:30:23 +0200 Subject: [PATCH 02/19] Repo: clarify certain comments and remove extraneous elements from readme --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b389384..ceaa084 100644 --- a/README.md +++ b/README.md @@ -35,13 +35,13 @@ The contracts and interfaces in this repository are primarily intended for use i ### Compiling the contracts -The following npm script compiles updated contracts from the last call using [truffle]: +The following npm script compiles updated contracts since the last compile using [truffle]: ```bash npm run compile ``` -To compile all contracts: +To compile all contracts, including the ones that haven't changed: ```bash npm run compile-all @@ -58,7 +58,7 @@ npm run ganache-cli Test the contracts using [truffle]: ```bash -npm run test +npm test ``` ### Linting @@ -86,7 +86,7 @@ To contribute code, please review our [Developer Guidelines] and ensure that you ### Community * [Forum][discourse] -* [Gitter][gitter] +* [Gitter] [brandedtoken-contracts]: https://github.com/OpenSTFoundation/brandedtoken-contracts [code of conduct]: https://github.com/OpenST/developer-guidelines/blob/master/CODE_OF_CONDUCT.md From a508b203cabd8d3f18e146263d963858e71e99f7 Mon Sep 17 00:00:00 2001 From: Sarvesh Jain Date: Fri, 3 May 2019 17:39:22 +0530 Subject: [PATCH 03/19] Added example of typechain --- package-lock.json | 170 ++++++++++++++++++ package.json | 2 + test/test_typechain.ts | 67 +++++++ ts-generator.json | 7 + types/truffle-contracts/index.d.ts | 142 +++++++++++++++ types/truffle-contracts/merge.d.ts | 20 +++ types/web3-contracts/Migrations.d.ts | 34 ++++ types/web3-contracts/Organization.d.ts | 97 ++++++++++ .../web3-contracts/OrganizationInterface.d.ts | 31 ++++ types/web3-contracts/Organized.d.ts | 29 +++ types/web3-contracts/TestSafeMath.d.ts | 35 ++++ types/web3-contracts/types.d.ts | 14 ++ 12 files changed, 648 insertions(+) create mode 100644 test/test_typechain.ts create mode 100644 ts-generator.json create mode 100644 types/truffle-contracts/index.d.ts create mode 100644 types/truffle-contracts/merge.d.ts create mode 100644 types/web3-contracts/Migrations.d.ts create mode 100644 types/web3-contracts/Organization.d.ts create mode 100644 types/web3-contracts/OrganizationInterface.d.ts create mode 100644 types/web3-contracts/Organized.d.ts create mode 100644 types/web3-contracts/TestSafeMath.d.ts create mode 100644 types/web3-contracts/types.d.ts diff --git a/package-lock.json b/package-lock.json index a2f9789..a7765df 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,12 +24,36 @@ "js-tokens": "^4.0.0" } }, + "@types/mkdirp": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/@types/mkdirp/-/mkdirp-0.5.2.tgz", + "integrity": "sha512-U5icWpv7YnZYGsN4/cmh3WD2onMY0aJIiTE6+51TwJCttdHvtCYmkBNOobHlXwrJRL0nkH9jH4kD+1FAdMN4Tg==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, "@types/node": { "version": "10.12.29", "resolved": "https://registry.npmjs.org/@types/node/-/node-10.12.29.tgz", "integrity": "sha512-J/tnbnj8HcsBgCe2apZbdUpQ7hs4d7oZNTYA5bekWdP0sr2NGsOpI/HRdDroEi209tEvTcTtxhD0FfED3DhEcw==", "dev": true }, + "@types/prettier": { + "version": "1.16.3", + "resolved": "https://registry.npmjs.org/@types/prettier/-/prettier-1.16.3.tgz", + "integrity": "sha512-5Ksgx9H/Yjz6oamDbmDZstWlJGPTao7shNfambjf8o7OkHxDwAi0AJLQcFwS9pDKI4gQPdiKZXze3nT1eCOViQ==", + "dev": true + }, + "@types/resolve": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-0.0.8.tgz", + "integrity": "sha512-auApPaJf3NPfe18hSoJkp8EbZzer2ISk7o8mCC3M9he/a04+gbMF97NkpD2S8riMGvm4BMRI59/SZQSaLTKpsQ==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, "abi-decoder": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/abi-decoder/-/abi-decoder-1.2.0.tgz", @@ -136,6 +160,15 @@ "sprintf-js": "~1.0.2" } }, + "array-back": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/array-back/-/array-back-2.0.0.tgz", + "integrity": "sha512-eJv4pLLufP3g5kcZry0j6WXpIbzYw9GUB4mVJZno9wfwiBxbizTnHCw3VJb07cBihbFX48Y7oSrW9y+gt4glyw==", + "dev": true, + "requires": { + "typical": "^2.6.1" + } + }, "array-flatten": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", @@ -615,6 +648,17 @@ "delayed-stream": "~1.0.0" } }, + "command-line-args": { + "version": "4.0.7", + "resolved": "https://registry.npmjs.org/command-line-args/-/command-line-args-4.0.7.tgz", + "integrity": "sha512-aUdPvQRAyBvQd2n7jXcsMDz68ckBJELXNzBybCHOibUWEg0mWTnaYCSRU8h9R+aNRSvDihJtssSRCiDRpLaezA==", + "dev": true, + "requires": { + "array-back": "^2.0.0", + "find-replace": "^1.0.3", + "typical": "^2.6.1" + } + }, "commander": { "version": "2.15.1", "resolved": "https://registry.npmjs.org/commander/-/commander-2.15.1.tgz", @@ -1641,6 +1685,27 @@ } } }, + "find-replace": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/find-replace/-/find-replace-1.0.3.tgz", + "integrity": "sha1-uI5zZNLZyVlVnziMZmcNYTBEH6A=", + "dev": true, + "requires": { + "array-back": "^1.0.4", + "test-value": "^2.1.0" + }, + "dependencies": { + "array-back": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/array-back/-/array-back-1.0.4.tgz", + "integrity": "sha1-ZEun8JX3/898Q7Xw3DnTwfA8Bjs=", + "dev": true, + "requires": { + "typical": "^2.6.0" + } + } + } + }, "find-up": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/find-up/-/find-up-2.1.0.tgz", @@ -3054,6 +3119,12 @@ "integrity": "sha1-1PRWKwzjaW5BrFLQ4ALlemNdxtw=", "dev": true }, + "prettier": { + "version": "1.17.0", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.17.0.tgz", + "integrity": "sha512-sXe5lSt2WQlCbydGETgfm1YBShgOX4HxQkFPvbxkcwgDvGDeqVau8h+12+lmSVlP3rHPz0oavfddSZg/q+Szjw==", + "dev": true + }, "process": { "version": "0.5.2", "resolved": "https://registry.npmjs.org/process/-/process-0.5.2.tgz", @@ -3897,6 +3968,27 @@ } } }, + "test-value": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/test-value/-/test-value-2.1.0.tgz", + "integrity": "sha1-Edpv9nDzRxpztiXKTz/c97t0gpE=", + "dev": true, + "requires": { + "array-back": "^1.0.3", + "typical": "^2.6.0" + }, + "dependencies": { + "array-back": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/array-back/-/array-back-1.0.4.tgz", + "integrity": "sha1-ZEun8JX3/898Q7Xw3DnTwfA8Bjs=", + "dev": true, + "requires": { + "typical": "^2.6.0" + } + } + } + }, "text-table": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", @@ -4066,6 +4158,29 @@ } } }, + "ts-essentials": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/ts-essentials/-/ts-essentials-1.0.4.tgz", + "integrity": "sha512-q3N1xS4vZpRouhYHDPwO0bDW3EZ6SK9CrrDHxi/D6BPReSjpVgWIOpLS2o0gSBZm+7q/wyKp6RVM1AeeW7uyfQ==", + "dev": true + }, + "ts-generator": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/ts-generator/-/ts-generator-0.0.8.tgz", + "integrity": "sha512-Gi+aZCELpVL7Mqb+GuMgM+n8JZ/arZZib1iD/R9Ok8JDjOCOCrqS9b1lr72ku7J45WeDCFZxyJoRsiQvhokCnw==", + "dev": true, + "requires": { + "@types/mkdirp": "^0.5.2", + "@types/prettier": "^1.13.2", + "@types/resolve": "^0.0.8", + "chalk": "^2.4.1", + "glob": "^7.1.2", + "mkdirp": "^0.5.1", + "prettier": "^1.14.2", + "resolve": "^1.8.1", + "ts-essentials": "^1.0.0" + } + }, "tslib": { "version": "1.9.3", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.3.tgz", @@ -4112,6 +4227,49 @@ "mime-types": "~2.1.18" } }, + "typechain": { + "version": "0.3.14", + "resolved": "https://registry.npmjs.org/typechain/-/typechain-0.3.14.tgz", + "integrity": "sha512-nOg7n7LngcA4Sx53q+4jjSpIEulEayZYnCMfyItnyxCX3nTCWVg8QXZppMDYNfITkJHex0v5dTgklOQzSbfUkw==", + "dev": true, + "requires": { + "command-line-args": "^4.0.7", + "debug": "^3.0.1", + "fs-extra": "^7.0.0", + "ts-generator": "^0.0.8" + }, + "dependencies": { + "debug": { + "version": "3.2.6", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz", + "integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==", + "dev": true, + "requires": { + "ms": "^2.1.1" + } + }, + "fs-extra": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-7.0.1.tgz", + "integrity": "sha512-YJDaCJZEnBmcbw13fvdAM9AwNOJwOzrE4pqMqBq5nFiEqXUqHwlK4B+3pUw6JNvfSPtX05xFHtYy/1ni01eGCw==", + "dev": true, + "requires": { + "graceful-fs": "^4.1.2", + "jsonfile": "^4.0.0", + "universalify": "^0.1.0" + } + }, + "jsonfile": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", + "integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=", + "dev": true, + "requires": { + "graceful-fs": "^4.1.6" + } + } + } + }, "typedarray-to-buffer": { "version": "3.1.5", "resolved": "https://registry.npmjs.org/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz", @@ -4121,6 +4279,12 @@ "is-typedarray": "^1.0.0" } }, + "typical": { + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/typical/-/typical-2.6.1.tgz", + "integrity": "sha1-XAgOXWYcu+OCWdLnCjxyU+hziB0=", + "dev": true + }, "ultron": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ultron/-/ultron-1.1.1.tgz", @@ -4143,6 +4307,12 @@ "integrity": "sha1-Tz+1OxBuYJf8+ctBCfKl6b36UCI=", "dev": true }, + "universalify": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", + "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==", + "dev": true + }, "unpipe": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", diff --git a/package.json b/package.json index fc3fc94..8766505 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,8 @@ "ganache-cli": "6.1.8", "mocha": "5.2.0", "truffle": "5.0.6", + "ts-generator": "0.0.8", + "typechain": "^0.3.14", "web3": "1.0.0-beta.36" } } diff --git a/test/test_typechain.ts b/test/test_typechain.ts new file mode 100644 index 0000000..316cbf0 --- /dev/null +++ b/test/test_typechain.ts @@ -0,0 +1,67 @@ +import {Organization} from "../types/web3-contracts/Organization"; + +const ganache = require("ganache-cli"); + +import Web3 = require("web3"); +import {join} from "path"; +import {readFileSync} from "fs"; + +const GAS_LIMIT_STANDARD = 1000000; + +let web3: Web3; +let accounts: string[]; + +async function createNewBlockchain() { + const web3 = new Web3(ganache.provider()); + const accounts = await web3.eth.getAccounts(); + return {web3, accounts}; +} + +async function setup() { + const r = await createNewBlockchain(); + web3 = r.web3; + accounts = r.accounts; + console.log("setup done"); +}; + +export async function deployContract(contractName: string): Promise { + const abiDirPath = join(__dirname, "../build/contracts"); + + const artifact = JSON.parse(readFileSync(join(abiDirPath, contractName + ".json"), "utf-8")); + + const abi = artifact.abi; + const code = artifact.bytecode; + + const Contract = new web3.eth.Contract(abi); + const t = Contract.deploy({arguments: [ + accounts[0], + accounts[0], + [accounts[0]], + 1000 + ], data: code}); + + + return (await (t.send({ + from: accounts[0], + gas: GAS_LIMIT_STANDARD, + }) as any)) as T; +} + +async function organizationContractTest() { + + await setup(); + + const contract = (await deployContract("Organization")) as Organization; + + let adminAddress = await contract.methods.admin().call(); + let isWorker = await contract.methods.isWorker(accounts[0]).call(); + + const receipt = await contract.methods.setAdmin(accounts[1]).send({from : accounts[0]}); + + console.log("admin Address ", adminAddress); + console.log("isWorker ", isWorker); + console.log('receipt ', receipt); +} + + +organizationContractTest(); diff --git a/ts-generator.json b/ts-generator.json new file mode 100644 index 0000000..d3efc88 --- /dev/null +++ b/ts-generator.json @@ -0,0 +1,7 @@ +[ + { + "generator": "typechain", + "files": "./build/**/*.json", + "target": "web3-1.0.0" + } +] \ No newline at end of file diff --git a/types/truffle-contracts/index.d.ts b/types/truffle-contracts/index.d.ts new file mode 100644 index 0000000..d868891 --- /dev/null +++ b/types/truffle-contracts/index.d.ts @@ -0,0 +1,142 @@ +/* Generated by ts-generator ver. 0.0.8 */ +/* tslint:disable */ + +/// +import { BigNumber } from "bignumber.js"; + +export interface MigrationsContract + extends Truffle.Contract { + "new"(meta?: Truffle.TransactionDetails): Promise; +} + +export interface OrganizationContract + extends Truffle.Contract { + "new"( + _owner: string | BigNumber, + _admin: string | BigNumber, + _workers: (string | BigNumber)[], + _expirationHeight: number | BigNumber | string, + meta?: Truffle.TransactionDetails + ): Promise; +} + +export interface OrganizationInterfaceContract + extends Truffle.Contract { + "new"( + meta?: Truffle.TransactionDetails + ): Promise; +} + +export interface OrganizedContract extends Truffle.Contract { + "new"( + _organization: string | BigNumber, + meta?: Truffle.TransactionDetails + ): Promise; +} + +export interface TestSafeMathContract + extends Truffle.Contract { + "new"(meta?: Truffle.TransactionDetails): Promise; +} + +export interface MigrationsInstance extends Truffle.ContractInstance { + setCompleted( + completed: number | BigNumber | string, + txDetails?: Truffle.TransactionDetails + ): Promise; + + upgrade( + new_address: string | BigNumber, + txDetails?: Truffle.TransactionDetails + ): Promise; + + last_completed_migration( + txDetails?: Truffle.TransactionDetails + ): Promise; + owner(txDetails?: Truffle.TransactionDetails): Promise; +} + +export interface OrganizationInstance extends Truffle.ContractInstance { + workers( + arg0: string | BigNumber, + txDetails?: Truffle.TransactionDetails + ): Promise; + + isOrganization( + _organization: string | BigNumber, + txDetails?: Truffle.TransactionDetails + ): Promise; + + isWorker( + _worker: string | BigNumber, + txDetails?: Truffle.TransactionDetails + ): Promise; + + initiateOwnershipTransfer( + _proposedOwner: string | BigNumber, + txDetails?: Truffle.TransactionDetails + ): Promise; + + completeOwnershipTransfer( + txDetails?: Truffle.TransactionDetails + ): Promise; + + setAdmin( + _admin: string | BigNumber, + txDetails?: Truffle.TransactionDetails + ): Promise; + + setWorker( + _worker: string | BigNumber, + _expirationHeight: number | BigNumber | string, + txDetails?: Truffle.TransactionDetails + ): Promise; + + unsetWorker( + _worker: string | BigNumber, + txDetails?: Truffle.TransactionDetails + ): Promise; + + owner(txDetails?: Truffle.TransactionDetails): Promise; + proposedOwner(txDetails?: Truffle.TransactionDetails): Promise; + admin(txDetails?: Truffle.TransactionDetails): Promise; +} + +export interface OrganizationInterfaceInstance + extends Truffle.ContractInstance { + isOrganization( + _organization: string | BigNumber, + txDetails?: Truffle.TransactionDetails + ): Promise; + + isWorker( + _worker: string | BigNumber, + txDetails?: Truffle.TransactionDetails + ): Promise; +} + +export interface OrganizedInstance extends Truffle.ContractInstance { + organization(txDetails?: Truffle.TransactionDetails): Promise; +} + +export interface TestSafeMathInstance extends Truffle.ContractInstance { + multiply( + a: number | BigNumber | string, + b: number | BigNumber | string, + txDetails?: Truffle.TransactionDetails + ): Promise; + + subtract( + a: number | BigNumber | string, + b: number | BigNumber | string, + txDetails?: Truffle.TransactionDetails + ): Promise; + + add( + a: number | BigNumber | string, + b: number | BigNumber | string, + txDetails?: Truffle.TransactionDetails + ): Promise; + + result(txDetails?: Truffle.TransactionDetails): Promise; +} diff --git a/types/truffle-contracts/merge.d.ts b/types/truffle-contracts/merge.d.ts new file mode 100644 index 0000000..d67ed14 --- /dev/null +++ b/types/truffle-contracts/merge.d.ts @@ -0,0 +1,20 @@ +/* Generated by ts-generator ver. 0.0.8 */ +/* tslint:disable */ + +/// + +import * as TruffleContracts from "."; + +declare global { + namespace Truffle { + interface Artifacts { + require(name: "Migrations"): TruffleContracts.MigrationsContract; + require(name: "Organization"): TruffleContracts.OrganizationContract; + require( + name: "OrganizationInterface" + ): TruffleContracts.OrganizationInterfaceContract; + require(name: "Organized"): TruffleContracts.OrganizedContract; + require(name: "TestSafeMath"): TruffleContracts.TestSafeMathContract; + } + } +} diff --git a/types/web3-contracts/Migrations.d.ts b/types/web3-contracts/Migrations.d.ts new file mode 100644 index 0000000..59f0058 --- /dev/null +++ b/types/web3-contracts/Migrations.d.ts @@ -0,0 +1,34 @@ +/* Generated by ts-generator ver. 0.0.8 */ +/* tslint:disable */ + +import { Contract, ContractOptions, Options } from "web3-eth-contract"; +import { Block } from "web3-eth"; +import { EventLog } from "web3-core"; +import { EventEmitter } from "events"; +import { Callback, TransactionObject } from "./types"; + +export class Migrations extends Contract { + constructor( + jsonInterface: any[], + address?: string, + options?: ContractOptions + ); + methods: { + setCompleted(completed: number | string): TransactionObject; + + upgrade(new_address: string): TransactionObject; + + last_completed_migration(): TransactionObject; + owner(): TransactionObject; + }; + events: { + allEvents: ( + options?: { + filter?: object; + fromBlock?: number | string; + topics?: (null | string)[]; + }, + cb?: Callback + ) => EventEmitter; + }; +} diff --git a/types/web3-contracts/Organization.d.ts b/types/web3-contracts/Organization.d.ts new file mode 100644 index 0000000..30998e8 --- /dev/null +++ b/types/web3-contracts/Organization.d.ts @@ -0,0 +1,97 @@ +/* Generated by ts-generator ver. 0.0.8 */ +/* tslint:disable */ + +import { Contract, ContractOptions, Options } from "web3-eth-contract"; +import { Block } from "web3-eth"; +import { EventLog } from "web3-core"; +import { EventEmitter } from "events"; +import { Callback, TransactionObject } from "./types"; + +export class Organization extends Contract { + constructor( + jsonInterface: any[], + address?: string, + options?: ContractOptions + ); + methods: { + workers(arg0: string): TransactionObject; + + isOrganization(_organization: string): TransactionObject; + + isWorker(_worker: string): TransactionObject; + + initiateOwnershipTransfer( + _proposedOwner: string + ): TransactionObject; + + completeOwnershipTransfer(): TransactionObject; + + setAdmin(_admin: string): TransactionObject; + + setWorker( + _worker: string, + _expirationHeight: number | string + ): TransactionObject; + + unsetWorker(_worker: string): TransactionObject; + + owner(): TransactionObject; + proposedOwner(): TransactionObject; + admin(): TransactionObject; + }; + events: { + OwnershipTransferInitiated( + options?: { + filter?: object; + fromBlock?: number | string; + topics?: (null | string)[]; + }, + cb?: Callback + ): EventEmitter; + + OwnershipTransferCompleted( + options?: { + filter?: object; + fromBlock?: number | string; + topics?: (null | string)[]; + }, + cb?: Callback + ): EventEmitter; + + AdminAddressChanged( + options?: { + filter?: object; + fromBlock?: number | string; + topics?: (null | string)[]; + }, + cb?: Callback + ): EventEmitter; + + WorkerSet( + options?: { + filter?: object; + fromBlock?: number | string; + topics?: (null | string)[]; + }, + cb?: Callback + ): EventEmitter; + + WorkerUnset( + options?: { + filter?: object; + fromBlock?: number | string; + topics?: (null | string)[]; + }, + cb?: Callback + ): EventEmitter; + + allEvents: ( + options?: { + filter?: object; + fromBlock?: number | string; + topics?: (null | string)[]; + }, + cb?: Callback + ) => EventEmitter; + }; +} diff --git a/types/web3-contracts/OrganizationInterface.d.ts b/types/web3-contracts/OrganizationInterface.d.ts new file mode 100644 index 0000000..cca207f --- /dev/null +++ b/types/web3-contracts/OrganizationInterface.d.ts @@ -0,0 +1,31 @@ +/* Generated by ts-generator ver. 0.0.8 */ +/* tslint:disable */ + +import { Contract, ContractOptions, Options } from "web3-eth-contract"; +import { Block } from "web3-eth"; +import { EventLog } from "web3-core"; +import { EventEmitter } from "events"; +import { Callback, TransactionObject } from "./types"; + +export class OrganizationInterface extends Contract { + constructor( + jsonInterface: any[], + address?: string, + options?: ContractOptions + ); + methods: { + isOrganization(_organization: string): TransactionObject; + + isWorker(_worker: string): TransactionObject; + }; + events: { + allEvents: ( + options?: { + filter?: object; + fromBlock?: number | string; + topics?: (null | string)[]; + }, + cb?: Callback + ) => EventEmitter; + }; +} diff --git a/types/web3-contracts/Organized.d.ts b/types/web3-contracts/Organized.d.ts new file mode 100644 index 0000000..2626c17 --- /dev/null +++ b/types/web3-contracts/Organized.d.ts @@ -0,0 +1,29 @@ +/* Generated by ts-generator ver. 0.0.8 */ +/* tslint:disable */ + +import { Contract, ContractOptions, Options } from "web3-eth-contract"; +import { Block } from "web3-eth"; +import { EventLog } from "web3-core"; +import { EventEmitter } from "events"; +import { Callback, TransactionObject } from "./types"; + +export class Organized extends Contract { + constructor( + jsonInterface: any[], + address?: string, + options?: ContractOptions + ); + methods: { + organization(): TransactionObject; + }; + events: { + allEvents: ( + options?: { + filter?: object; + fromBlock?: number | string; + topics?: (null | string)[]; + }, + cb?: Callback + ) => EventEmitter; + }; +} diff --git a/types/web3-contracts/TestSafeMath.d.ts b/types/web3-contracts/TestSafeMath.d.ts new file mode 100644 index 0000000..c5cf057 --- /dev/null +++ b/types/web3-contracts/TestSafeMath.d.ts @@ -0,0 +1,35 @@ +/* Generated by ts-generator ver. 0.0.8 */ +/* tslint:disable */ + +import { Contract, ContractOptions, Options } from "web3-eth-contract"; +import { Block } from "web3-eth"; +import { EventLog } from "web3-core"; +import { EventEmitter } from "events"; +import { Callback, TransactionObject } from "./types"; + +export class TestSafeMath extends Contract { + constructor( + jsonInterface: any[], + address?: string, + options?: ContractOptions + ); + methods: { + multiply(a: number | string, b: number | string): TransactionObject; + + subtract(a: number | string, b: number | string): TransactionObject; + + add(a: number | string, b: number | string): TransactionObject; + + result(): TransactionObject; + }; + events: { + allEvents: ( + options?: { + filter?: object; + fromBlock?: number | string; + topics?: (null | string)[]; + }, + cb?: Callback + ) => EventEmitter; + }; +} diff --git a/types/web3-contracts/types.d.ts b/types/web3-contracts/types.d.ts new file mode 100644 index 0000000..535ac04 --- /dev/null +++ b/types/web3-contracts/types.d.ts @@ -0,0 +1,14 @@ +/* Generated by ts-generator ver. 0.0.8 */ +/* tslint:disable */ + +import { Transaction } from "web3-core"; +// @ts-ignore +import PromiEvent from "web3-core-promievent"; +export type Callback = (error: Error, result: T) => void; +export interface TransactionObject { + arguments: any[]; + call(tx?: Transaction): Promise; + send(tx?: Transaction): PromiEvent; + estimateGas(tx?: Transaction): Promise; + encodeABI(): string; +} From 1bedfe4a9eb855fd98d063185ad3ef2d63cb61a3 Mon Sep 17 00:00:00 2001 From: Sarvesh Jain Date: Fri, 3 May 2019 20:27:15 +0530 Subject: [PATCH 04/19] Deleted commited contract wrappers --- types/truffle-contracts/index.d.ts | 142 ------------------ types/truffle-contracts/merge.d.ts | 20 --- types/web3-contracts/Migrations.d.ts | 34 ----- types/web3-contracts/Organization.d.ts | 97 ------------ .../web3-contracts/OrganizationInterface.d.ts | 31 ---- types/web3-contracts/Organized.d.ts | 29 ---- types/web3-contracts/TestSafeMath.d.ts | 35 ----- types/web3-contracts/types.d.ts | 14 -- 8 files changed, 402 deletions(-) delete mode 100644 types/truffle-contracts/index.d.ts delete mode 100644 types/truffle-contracts/merge.d.ts delete mode 100644 types/web3-contracts/Migrations.d.ts delete mode 100644 types/web3-contracts/Organization.d.ts delete mode 100644 types/web3-contracts/OrganizationInterface.d.ts delete mode 100644 types/web3-contracts/Organized.d.ts delete mode 100644 types/web3-contracts/TestSafeMath.d.ts delete mode 100644 types/web3-contracts/types.d.ts diff --git a/types/truffle-contracts/index.d.ts b/types/truffle-contracts/index.d.ts deleted file mode 100644 index d868891..0000000 --- a/types/truffle-contracts/index.d.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* Generated by ts-generator ver. 0.0.8 */ -/* tslint:disable */ - -/// -import { BigNumber } from "bignumber.js"; - -export interface MigrationsContract - extends Truffle.Contract { - "new"(meta?: Truffle.TransactionDetails): Promise; -} - -export interface OrganizationContract - extends Truffle.Contract { - "new"( - _owner: string | BigNumber, - _admin: string | BigNumber, - _workers: (string | BigNumber)[], - _expirationHeight: number | BigNumber | string, - meta?: Truffle.TransactionDetails - ): Promise; -} - -export interface OrganizationInterfaceContract - extends Truffle.Contract { - "new"( - meta?: Truffle.TransactionDetails - ): Promise; -} - -export interface OrganizedContract extends Truffle.Contract { - "new"( - _organization: string | BigNumber, - meta?: Truffle.TransactionDetails - ): Promise; -} - -export interface TestSafeMathContract - extends Truffle.Contract { - "new"(meta?: Truffle.TransactionDetails): Promise; -} - -export interface MigrationsInstance extends Truffle.ContractInstance { - setCompleted( - completed: number | BigNumber | string, - txDetails?: Truffle.TransactionDetails - ): Promise; - - upgrade( - new_address: string | BigNumber, - txDetails?: Truffle.TransactionDetails - ): Promise; - - last_completed_migration( - txDetails?: Truffle.TransactionDetails - ): Promise; - owner(txDetails?: Truffle.TransactionDetails): Promise; -} - -export interface OrganizationInstance extends Truffle.ContractInstance { - workers( - arg0: string | BigNumber, - txDetails?: Truffle.TransactionDetails - ): Promise; - - isOrganization( - _organization: string | BigNumber, - txDetails?: Truffle.TransactionDetails - ): Promise; - - isWorker( - _worker: string | BigNumber, - txDetails?: Truffle.TransactionDetails - ): Promise; - - initiateOwnershipTransfer( - _proposedOwner: string | BigNumber, - txDetails?: Truffle.TransactionDetails - ): Promise; - - completeOwnershipTransfer( - txDetails?: Truffle.TransactionDetails - ): Promise; - - setAdmin( - _admin: string | BigNumber, - txDetails?: Truffle.TransactionDetails - ): Promise; - - setWorker( - _worker: string | BigNumber, - _expirationHeight: number | BigNumber | string, - txDetails?: Truffle.TransactionDetails - ): Promise; - - unsetWorker( - _worker: string | BigNumber, - txDetails?: Truffle.TransactionDetails - ): Promise; - - owner(txDetails?: Truffle.TransactionDetails): Promise; - proposedOwner(txDetails?: Truffle.TransactionDetails): Promise; - admin(txDetails?: Truffle.TransactionDetails): Promise; -} - -export interface OrganizationInterfaceInstance - extends Truffle.ContractInstance { - isOrganization( - _organization: string | BigNumber, - txDetails?: Truffle.TransactionDetails - ): Promise; - - isWorker( - _worker: string | BigNumber, - txDetails?: Truffle.TransactionDetails - ): Promise; -} - -export interface OrganizedInstance extends Truffle.ContractInstance { - organization(txDetails?: Truffle.TransactionDetails): Promise; -} - -export interface TestSafeMathInstance extends Truffle.ContractInstance { - multiply( - a: number | BigNumber | string, - b: number | BigNumber | string, - txDetails?: Truffle.TransactionDetails - ): Promise; - - subtract( - a: number | BigNumber | string, - b: number | BigNumber | string, - txDetails?: Truffle.TransactionDetails - ): Promise; - - add( - a: number | BigNumber | string, - b: number | BigNumber | string, - txDetails?: Truffle.TransactionDetails - ): Promise; - - result(txDetails?: Truffle.TransactionDetails): Promise; -} diff --git a/types/truffle-contracts/merge.d.ts b/types/truffle-contracts/merge.d.ts deleted file mode 100644 index d67ed14..0000000 --- a/types/truffle-contracts/merge.d.ts +++ /dev/null @@ -1,20 +0,0 @@ -/* Generated by ts-generator ver. 0.0.8 */ -/* tslint:disable */ - -/// - -import * as TruffleContracts from "."; - -declare global { - namespace Truffle { - interface Artifacts { - require(name: "Migrations"): TruffleContracts.MigrationsContract; - require(name: "Organization"): TruffleContracts.OrganizationContract; - require( - name: "OrganizationInterface" - ): TruffleContracts.OrganizationInterfaceContract; - require(name: "Organized"): TruffleContracts.OrganizedContract; - require(name: "TestSafeMath"): TruffleContracts.TestSafeMathContract; - } - } -} diff --git a/types/web3-contracts/Migrations.d.ts b/types/web3-contracts/Migrations.d.ts deleted file mode 100644 index 59f0058..0000000 --- a/types/web3-contracts/Migrations.d.ts +++ /dev/null @@ -1,34 +0,0 @@ -/* Generated by ts-generator ver. 0.0.8 */ -/* tslint:disable */ - -import { Contract, ContractOptions, Options } from "web3-eth-contract"; -import { Block } from "web3-eth"; -import { EventLog } from "web3-core"; -import { EventEmitter } from "events"; -import { Callback, TransactionObject } from "./types"; - -export class Migrations extends Contract { - constructor( - jsonInterface: any[], - address?: string, - options?: ContractOptions - ); - methods: { - setCompleted(completed: number | string): TransactionObject; - - upgrade(new_address: string): TransactionObject; - - last_completed_migration(): TransactionObject; - owner(): TransactionObject; - }; - events: { - allEvents: ( - options?: { - filter?: object; - fromBlock?: number | string; - topics?: (null | string)[]; - }, - cb?: Callback - ) => EventEmitter; - }; -} diff --git a/types/web3-contracts/Organization.d.ts b/types/web3-contracts/Organization.d.ts deleted file mode 100644 index 30998e8..0000000 --- a/types/web3-contracts/Organization.d.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* Generated by ts-generator ver. 0.0.8 */ -/* tslint:disable */ - -import { Contract, ContractOptions, Options } from "web3-eth-contract"; -import { Block } from "web3-eth"; -import { EventLog } from "web3-core"; -import { EventEmitter } from "events"; -import { Callback, TransactionObject } from "./types"; - -export class Organization extends Contract { - constructor( - jsonInterface: any[], - address?: string, - options?: ContractOptions - ); - methods: { - workers(arg0: string): TransactionObject; - - isOrganization(_organization: string): TransactionObject; - - isWorker(_worker: string): TransactionObject; - - initiateOwnershipTransfer( - _proposedOwner: string - ): TransactionObject; - - completeOwnershipTransfer(): TransactionObject; - - setAdmin(_admin: string): TransactionObject; - - setWorker( - _worker: string, - _expirationHeight: number | string - ): TransactionObject; - - unsetWorker(_worker: string): TransactionObject; - - owner(): TransactionObject; - proposedOwner(): TransactionObject; - admin(): TransactionObject; - }; - events: { - OwnershipTransferInitiated( - options?: { - filter?: object; - fromBlock?: number | string; - topics?: (null | string)[]; - }, - cb?: Callback - ): EventEmitter; - - OwnershipTransferCompleted( - options?: { - filter?: object; - fromBlock?: number | string; - topics?: (null | string)[]; - }, - cb?: Callback - ): EventEmitter; - - AdminAddressChanged( - options?: { - filter?: object; - fromBlock?: number | string; - topics?: (null | string)[]; - }, - cb?: Callback - ): EventEmitter; - - WorkerSet( - options?: { - filter?: object; - fromBlock?: number | string; - topics?: (null | string)[]; - }, - cb?: Callback - ): EventEmitter; - - WorkerUnset( - options?: { - filter?: object; - fromBlock?: number | string; - topics?: (null | string)[]; - }, - cb?: Callback - ): EventEmitter; - - allEvents: ( - options?: { - filter?: object; - fromBlock?: number | string; - topics?: (null | string)[]; - }, - cb?: Callback - ) => EventEmitter; - }; -} diff --git a/types/web3-contracts/OrganizationInterface.d.ts b/types/web3-contracts/OrganizationInterface.d.ts deleted file mode 100644 index cca207f..0000000 --- a/types/web3-contracts/OrganizationInterface.d.ts +++ /dev/null @@ -1,31 +0,0 @@ -/* Generated by ts-generator ver. 0.0.8 */ -/* tslint:disable */ - -import { Contract, ContractOptions, Options } from "web3-eth-contract"; -import { Block } from "web3-eth"; -import { EventLog } from "web3-core"; -import { EventEmitter } from "events"; -import { Callback, TransactionObject } from "./types"; - -export class OrganizationInterface extends Contract { - constructor( - jsonInterface: any[], - address?: string, - options?: ContractOptions - ); - methods: { - isOrganization(_organization: string): TransactionObject; - - isWorker(_worker: string): TransactionObject; - }; - events: { - allEvents: ( - options?: { - filter?: object; - fromBlock?: number | string; - topics?: (null | string)[]; - }, - cb?: Callback - ) => EventEmitter; - }; -} diff --git a/types/web3-contracts/Organized.d.ts b/types/web3-contracts/Organized.d.ts deleted file mode 100644 index 2626c17..0000000 --- a/types/web3-contracts/Organized.d.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* Generated by ts-generator ver. 0.0.8 */ -/* tslint:disable */ - -import { Contract, ContractOptions, Options } from "web3-eth-contract"; -import { Block } from "web3-eth"; -import { EventLog } from "web3-core"; -import { EventEmitter } from "events"; -import { Callback, TransactionObject } from "./types"; - -export class Organized extends Contract { - constructor( - jsonInterface: any[], - address?: string, - options?: ContractOptions - ); - methods: { - organization(): TransactionObject; - }; - events: { - allEvents: ( - options?: { - filter?: object; - fromBlock?: number | string; - topics?: (null | string)[]; - }, - cb?: Callback - ) => EventEmitter; - }; -} diff --git a/types/web3-contracts/TestSafeMath.d.ts b/types/web3-contracts/TestSafeMath.d.ts deleted file mode 100644 index c5cf057..0000000 --- a/types/web3-contracts/TestSafeMath.d.ts +++ /dev/null @@ -1,35 +0,0 @@ -/* Generated by ts-generator ver. 0.0.8 */ -/* tslint:disable */ - -import { Contract, ContractOptions, Options } from "web3-eth-contract"; -import { Block } from "web3-eth"; -import { EventLog } from "web3-core"; -import { EventEmitter } from "events"; -import { Callback, TransactionObject } from "./types"; - -export class TestSafeMath extends Contract { - constructor( - jsonInterface: any[], - address?: string, - options?: ContractOptions - ); - methods: { - multiply(a: number | string, b: number | string): TransactionObject; - - subtract(a: number | string, b: number | string): TransactionObject; - - add(a: number | string, b: number | string): TransactionObject; - - result(): TransactionObject; - }; - events: { - allEvents: ( - options?: { - filter?: object; - fromBlock?: number | string; - topics?: (null | string)[]; - }, - cb?: Callback - ) => EventEmitter; - }; -} diff --git a/types/web3-contracts/types.d.ts b/types/web3-contracts/types.d.ts deleted file mode 100644 index 535ac04..0000000 --- a/types/web3-contracts/types.d.ts +++ /dev/null @@ -1,14 +0,0 @@ -/* Generated by ts-generator ver. 0.0.8 */ -/* tslint:disable */ - -import { Transaction } from "web3-core"; -// @ts-ignore -import PromiEvent from "web3-core-promievent"; -export type Callback = (error: Error, result: T) => void; -export interface TransactionObject { - arguments: any[]; - call(tx?: Transaction): Promise; - send(tx?: Transaction): PromiEvent; - estimateGas(tx?: Transaction): Promise; - encodeABI(): string; -} From b5805512992076ae9b153e29f06fbf90d69ec7d7 Mon Sep 17 00:00:00 2001 From: Sarvesh Jain Date: Fri, 3 May 2019 20:29:00 +0530 Subject: [PATCH 05/19] added script of generating wrapper and added types into git ignore --- .gitignore | 3 +++ package.json | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index d1b4182..9263a12 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,6 @@ build/ # NPM package generated files: dist/contracts.json + +# Do not track generated wrapper, it should be part of build script +types/*/* diff --git a/package.json b/package.json index 8766505..ca9b411 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,8 @@ "ganache": "sh tools/runGanacheCli.sh", "build-package": "node tools/build_package.js", "prepack": "npm run compile-all && npm run build-package", - "lint": "eslint test tools -c .eslintrc.json --ext js" + "lint": "eslint test tools -c .eslintrc.json --ext js", + "generate" : "ts-generator ts-generator.json" }, "repository": { "type": "git", From 2bf9cbc57fd0f56ec0167d128a385bcab0899a05 Mon Sep 17 00:00:00 2001 From: Sarvesh Jain Date: Fri, 3 May 2019 20:39:25 +0530 Subject: [PATCH 06/19] Added post install script --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index ca9b411..3f61127 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,8 @@ "build-package": "node tools/build_package.js", "prepack": "npm run compile-all && npm run build-package", "lint": "eslint test tools -c .eslintrc.json --ext js", - "generate" : "ts-generator ts-generator.json" + "generate": "ts-generator ts-generator.json", + "postinstall": "npm run compile-all && npm run generate" }, "repository": { "type": "git", From 636f6409e232a82efe2dde736c98816238d37ab8 Mon Sep 17 00:00:00 2001 From: Martin Schenck Date: Tue, 7 May 2019 15:17:00 +0200 Subject: [PATCH 07/19] Add SafeMath as npm dependency References https://github.com/OpenST/mosaic-contracts/issues/712 --- .gitignore | 2 + contracts/Organization.sol | 2 +- contracts/lib/SafeMath.sol | 143 ---------------------------- contracts/test/lib/TestSafeMath.sol | 85 ----------------- package-lock.json | 6 ++ package.json | 1 + test/lib/safe_math.js | 85 ----------------- 7 files changed, 10 insertions(+), 314 deletions(-) delete mode 100644 contracts/lib/SafeMath.sol delete mode 100644 contracts/test/lib/TestSafeMath.sol delete mode 100644 test/lib/safe_math.js diff --git a/.gitignore b/.gitignore index d1b4182..9a1a1c3 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,8 @@ .idea/ .vscode/ *.iml +*.swp +tags # don't commit node_modules node_modules diff --git a/contracts/Organization.sol b/contracts/Organization.sol index 90911fb..09bd292 100644 --- a/contracts/Organization.sol +++ b/contracts/Organization.sol @@ -20,7 +20,7 @@ pragma solidity ^0.5.0; // // ---------------------------------------------------------------------------- -import "./lib/SafeMath.sol"; +import "openzeppelin-solidity/contracts/math/SafeMath.sol"; import "./OrganizationInterface.sol"; diff --git a/contracts/lib/SafeMath.sol b/contracts/lib/SafeMath.sol deleted file mode 100644 index 755b950..0000000 --- a/contracts/lib/SafeMath.sol +++ /dev/null @@ -1,143 +0,0 @@ -pragma solidity ^0.5.0; - -// Copyright 2019 OpenST Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ---------------------------------------------------------------------------- -// -// http://www.simpletoken.org/ -// -// Based on the SafeMath library by the OpenZeppelin team. -// Copyright (c) 2018 Smart Contract Solutions, Inc. -// https://github.com/OpenZeppelin/zeppelin-solidity -// The MIT License. -// ---------------------------------------------------------------------------- - - -/** - * @title SafeMath library. - * - * @notice Based on the SafeMath library by the OpenZeppelin team. - * - * @dev Math operations with safety checks that revert on error. - */ -library SafeMath { - - /* Internal Functions */ - - /** - * @notice Multiplies two numbers, reverts on overflow. - * - * @param a Unsigned integer multiplicand. - * @param b Unsigned integer multiplier. - * - * @return uint256 Product. - */ - function mul(uint256 a, uint256 b) internal pure returns (uint256) { - /* - * Gas optimization: this is cheaper than requiring 'a' not being zero, - * but the benefit is lost if 'b' is also tested. - * See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522 - */ - if (a == 0) { - return 0; - } - - uint256 c = a * b; - require( - c / a == b, - "Overflow when multiplying." - ); - - return c; - } - - /** - * @notice Integer division of two numbers truncating the quotient, reverts - * on division by zero. - * - * @param a Unsigned integer dividend. - * @param b Unsigned integer divisor. - * - * @return uint256 Quotient. - */ - function div(uint256 a, uint256 b) internal pure returns (uint256) { - // Solidity only automatically asserts when dividing by 0. - require( - b > 0, - "Cannot do attempted division by less than or equal to zero." - ); - uint256 c = a / b; - - // There is no case in which the following doesn't hold: - // assert(a == b * c + a % b); - - return c; - } - - /** - * @notice Subtracts two numbers, reverts on underflow (i.e. if subtrahend - * is greater than minuend). - * - * @param a Unsigned integer minuend. - * @param b Unsigned integer subtrahend. - * - * @return uint256 Difference. - */ - function sub(uint256 a, uint256 b) internal pure returns (uint256) { - require( - b <= a, - "Underflow when subtracting." - ); - uint256 c = a - b; - - return c; - } - - /** - * @notice Adds two numbers, reverts on overflow. - * - * @param a Unsigned integer augend. - * @param b Unsigned integer addend. - * - * @return uint256 Sum. - */ - function add(uint256 a, uint256 b) internal pure returns (uint256) { - uint256 c = a + b; - require( - c >= a, - "Overflow when adding." - ); - - return c; - } - - /** - * @notice Divides two numbers and returns the remainder (unsigned integer - * modulo), reverts when dividing by zero. - * - * @param a Unsigned integer dividend. - * @param b Unsigned integer divisor. - * - * @return uint256 Remainder. - */ - function mod(uint256 a, uint256 b) internal pure returns (uint256) { - require( - b != 0, - "Cannot do attempted division by zero (in `mod()`)." - ); - - return a % b; - } -} diff --git a/contracts/test/lib/TestSafeMath.sol b/contracts/test/lib/TestSafeMath.sol deleted file mode 100644 index b4e7674..0000000 --- a/contracts/test/lib/TestSafeMath.sol +++ /dev/null @@ -1,85 +0,0 @@ -pragma solidity ^0.5.0; - -// Copyright 2019 OpenST Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ---------------------------------------------------------------------------- -// Common: SafeMath Library Implementation -// -// http://www.simpletoken.org/ -// -// Based on the SafeMath library by the OpenZeppelin team. -// Copyright (c) 2016 Smart Contract Solutions, Inc. -// https://github.com/OpenZeppelin/zeppelin-solidity -// The MIT License. -// ---------------------------------------------------------------------------- - -import "../../lib/SafeMath.sol"; - -/** - * @title TestSafeMath library. - * - * @notice Based on the SafeMath library by the OpenZeppelin team. - * Mock used for testing. - */ -contract TestSafeMath { - - /** Storage */ - - uint256 public result; - - /* Public functions */ - - /** - * @notice Public function multiply. - * - * @dev Public wrapper for SafeMath function mul. - * - * @param a Unsigned integer multiplicand. - * @param b Unsigned integer multiplier. - * - * @return uint256 Product. - */ - function multiply(uint256 a, uint256 b) public { - result = SafeMath.mul(a, b); - } - - /** - * @notice Public function subtract. - * - * @dev Public wrapper for SafeMath function sub. - * - * @param a Unsigned integer minuend. - * @param b Unsigned integer subtrahend. - * - * @return uint256 Difference. - */ - function subtract(uint256 a, uint256 b) public { - result = SafeMath.sub(a, b); - } - - /** - * @notice Public function add. - * - * @dev Public wrapper for SafeMath function add. - * - * @param a Unsigned integer augend. - * @param b Unsigned integer addend. - * - * @return uint256 Sum. - */ - function add(uint256 a, uint256 b) public { - result = SafeMath.add(a, b); - } -} diff --git a/package-lock.json b/package-lock.json index a2f9789..e30c907 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2809,6 +2809,12 @@ "mimic-fn": "^1.0.0" } }, + "openzeppelin-solidity": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/openzeppelin-solidity/-/openzeppelin-solidity-2.1.1.tgz", + "integrity": "sha512-kvVI/2n3oYfVYP53rUw+q6QNPlorwYRFaGu/Zs+TWFw2tKlnrz7UXh0UTWYd3Sfbq6eOo4XXnGv4bgcKguOrWg==", + "dev": true + }, "optionator": { "version": "0.8.2", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.8.2.tgz", diff --git a/package.json b/package.json index fc3fc94..f4119f1 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "eslint-plugin-import": "2.14.0", "ganache-cli": "6.1.8", "mocha": "5.2.0", + "openzeppelin-solidity": "2.1.1", "truffle": "5.0.6", "web3": "1.0.0-beta.36" } diff --git a/test/lib/safe_math.js b/test/lib/safe_math.js deleted file mode 100644 index aa68f7b..0000000 --- a/test/lib/safe_math.js +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright 2019 OpenST Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ---------------------------------------------------------------------------- -// Utility chain: OpenSTUtility -// -// http://www.simpletoken.org/ -// -// Based on the SafeMath library by the OpenZeppelin team. -// Copyright (c) 2016 Smart Contract Solutions, Inc. -// https://github.com/OpenZeppelin/zeppelin-solidity -// The MIT License. -// ---------------------------------------------------------------------------- - -const BN = require('bn.js'); -const Utils = require('../test_lib/utils.js'); - -const TestSafeMath = artifacts.require('TestSafeMath'); - -contract('SafeMath', () => { - let safeMath; - - before(async () => { - safeMath = await TestSafeMath.new(); - }); - - it('multiplies correctly', async () => { - const a = 5678; - const b = 1234; - await safeMath.multiply(a, b); - const result = await safeMath.result(); - assert.equal(result, a * b); - }); - - it('adds correctly', async () => { - const a = 5678; - const b = 1234; - await safeMath.add(a, b); - const result = await safeMath.result(); - - assert.equal(result, a + b); - }); - - it('subtracts correctly', async () => { - const a = 5678; - const b = 1234; - await safeMath.subtract(a, b); - const result = await safeMath.result(); - - assert.equal(result, a - b); - }); - - it('should throw an error if subtraction result would be negative', async () => { - const a = 1234; - const b = 5678; - await Utils.expectThrow(safeMath.subtract(a, b)); - }); - - it('should throw an error on addition overflow', async () => { - const a = new BN( - '115792089237316195423570985008687907853269984665640564039457584007913129639935', - ); - const b = new BN(1); - await Utils.expectThrow(safeMath.add(a, b)); - }); - - it('should throw an error on multiplication overflow', async () => { - const a = new BN( - '115792089237316195423570985008687907853269984665640564039457584007913129639933', - ); - const b = new BN(2); - await Utils.expectThrow(safeMath.multiply(a, b)); - }); -}); From c13786cf4430e53b569304bfac136062ee76d0f2 Mon Sep 17 00:00:00 2001 From: Sarvesh Jain Date: Thu, 9 May 2019 11:25:22 +0530 Subject: [PATCH 08/19] Added output directoryt and not generating interacts for Migrations --- .gitignore | 2 +- ts-generator.json | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 9263a12..3729bcb 100644 --- a/.gitignore +++ b/.gitignore @@ -16,4 +16,4 @@ build/ dist/contracts.json # Do not track generated wrapper, it should be part of build script -types/*/* +interacts/* diff --git a/ts-generator.json b/ts-generator.json index d3efc88..c3db12c 100644 --- a/ts-generator.json +++ b/ts-generator.json @@ -1,7 +1,8 @@ [ { "generator": "typechain", - "files": "./build/**/*.json", - "target": "web3-1.0.0" + "files": "./build/**/*/!(Migrations.json)", + "target": "web3-1.0.0", + "outDir" : "interacts" } ] \ No newline at end of file From 1591eabcd21bdc036e38f523c73539e2e256cd17 Mon Sep 17 00:00:00 2001 From: Sarvesh Jain Date: Thu, 9 May 2019 11:31:55 +0530 Subject: [PATCH 09/19] Removed script for manual test --- test/test_typechain.ts | 67 ------------------------------------------ 1 file changed, 67 deletions(-) delete mode 100644 test/test_typechain.ts diff --git a/test/test_typechain.ts b/test/test_typechain.ts deleted file mode 100644 index 316cbf0..0000000 --- a/test/test_typechain.ts +++ /dev/null @@ -1,67 +0,0 @@ -import {Organization} from "../types/web3-contracts/Organization"; - -const ganache = require("ganache-cli"); - -import Web3 = require("web3"); -import {join} from "path"; -import {readFileSync} from "fs"; - -const GAS_LIMIT_STANDARD = 1000000; - -let web3: Web3; -let accounts: string[]; - -async function createNewBlockchain() { - const web3 = new Web3(ganache.provider()); - const accounts = await web3.eth.getAccounts(); - return {web3, accounts}; -} - -async function setup() { - const r = await createNewBlockchain(); - web3 = r.web3; - accounts = r.accounts; - console.log("setup done"); -}; - -export async function deployContract(contractName: string): Promise { - const abiDirPath = join(__dirname, "../build/contracts"); - - const artifact = JSON.parse(readFileSync(join(abiDirPath, contractName + ".json"), "utf-8")); - - const abi = artifact.abi; - const code = artifact.bytecode; - - const Contract = new web3.eth.Contract(abi); - const t = Contract.deploy({arguments: [ - accounts[0], - accounts[0], - [accounts[0]], - 1000 - ], data: code}); - - - return (await (t.send({ - from: accounts[0], - gas: GAS_LIMIT_STANDARD, - }) as any)) as T; -} - -async function organizationContractTest() { - - await setup(); - - const contract = (await deployContract("Organization")) as Organization; - - let adminAddress = await contract.methods.admin().call(); - let isWorker = await contract.methods.isWorker(accounts[0]).call(); - - const receipt = await contract.methods.setAdmin(accounts[1]).send({from : accounts[0]}); - - console.log("admin Address ", adminAddress); - console.log("isWorker ", isWorker); - console.log('receipt ', receipt); -} - - -organizationContractTest(); From 853197673cb6991d79c097b110b1c34ab3ad107a Mon Sep 17 00:00:00 2001 From: Sarvesh Jain Date: Thu, 9 May 2019 16:12:22 +0530 Subject: [PATCH 10/19] Removed caret operator from the typeschain dependency --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3f61127..e7b698c 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "mocha": "5.2.0", "truffle": "5.0.6", "ts-generator": "0.0.8", - "typechain": "^0.3.14", + "typechain": "0.3.14", "web3": "1.0.0-beta.36" } } From 696c18fe07bc15e50d559d415e25d472797c4311 Mon Sep 17 00:00:00 2001 From: Paruyr Gevorgyan Date: Wed, 15 May 2019 13:41:47 +0400 Subject: [PATCH 11/19] Fixes lint-errors and integrates linting in Travis - Fixes lint erros. - Adds `npm run lint` as a check in .travis.yml - Runs `npm ci` instead of `npm i` - Slight improvements for package.json scripts section. Resolves: #14 --- .travis.yml | 7 +++-- package.json | 4 +-- test/organization/constructor.js | 1 + test/organization/is_worker.js | 2 ++ test/organization/set_worker.js | 1 + test/test_lib/event_decoder.js | 48 +++++++++++++------------------- 6 files changed, 29 insertions(+), 34 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8095f1f..18e1408 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,11 +21,12 @@ before_install: - sudo apt-get install nodejs - sudo apt-get install npm install: - - npm install + - npm ci before_script: - - ./tools/runGanacheCli.sh /dev/null 2>&1 & - - npm run compile + - npm run ganache + - npm run compile-all script: + - npm run lint - npm run test - npm run build-package after_script: diff --git a/package.json b/package.json index 39e7da8..cecdf84 100644 --- a/package.json +++ b/package.json @@ -8,9 +8,9 @@ }, "scripts": { "compile": "truffle compile", - "compile-all": "truffle compile --all", + "compile-all": "truffle compile --all --reset", "test": "truffle test", - "ganache": "sh tools/runGanacheCli.sh", + "ganache": "./tools/runGanacheCli.sh", "build-package": "node tools/build_package.js", "prepack": "npm run compile-all && npm run build-package", "lint": "eslint test tools -c .eslintrc.json --ext js", diff --git a/test/organization/constructor.js b/test/organization/constructor.js index 4991d2e..ea2b105 100644 --- a/test/organization/constructor.js +++ b/test/organization/constructor.js @@ -91,6 +91,7 @@ contract('Organization.constructor()', async (accounts) => { const count = workers.length; for (let i = 0; i < count; i += 1) { const worker = workers[i]; + // eslint-disable-next-line no-await-in-loop const setExpirationHeight = await organization.workers.call(worker); assert( setExpirationHeight.eqn(expirationHeight), diff --git a/test/organization/is_worker.js b/test/organization/is_worker.js index 3bcd9bf..893bddb 100644 --- a/test/organization/is_worker.js +++ b/test/organization/is_worker.js @@ -57,6 +57,7 @@ contract('Organization.isWorker()', async (accounts) => { // Dummy Transaction to increase block number. for (let i = 0; i < deltaExpirationHeight; i += 1) { + // eslint-disable-next-line no-await-in-loop await Utils.advanceBlock(); } assert.strictEqual( @@ -79,6 +80,7 @@ contract('Organization.isWorker()', async (accounts) => { */ for (let i = 0; i < deltaExpirationHeight - 1; i += 1) { assert.strictEqual( + // eslint-disable-next-line no-await-in-loop await organization.isWorker.call(worker), true, 'The worker should be active at this height.', diff --git a/test/organization/set_worker.js b/test/organization/set_worker.js index ba0e098..6636f12 100644 --- a/test/organization/set_worker.js +++ b/test/organization/set_worker.js @@ -68,6 +68,7 @@ contract('Organization.setWorker()', async (accounts) => { const blockNumber = await web3.eth.getBlockNumber(); expirationHeight = blockNumber + expirationHeightDelta; for (let i = 0; i < expirationHeightDelta; i += 1) { + // eslint-disable-next-line no-await-in-loop await Utils.advanceBlock(); } diff --git a/test/test_lib/event_decoder.js b/test/test_lib/event_decoder.js index 8f1c04d..8f63599 100644 --- a/test/test_lib/event_decoder.js +++ b/test/test_lib/event_decoder.js @@ -21,6 +21,8 @@ 'use strict'; +const abiDecoder = require('abi-decoder'); + class Web3EventsDecoder { static getFormattedEvents(eventsData) { const formattedEvents = {}; @@ -68,7 +70,7 @@ class Web3EventsDecoder { // Transaction receipt not found if (!txReceipt) { console.error(' Transaction receipt was not found.'); - return; + return {}; } // Block not yet mined @@ -76,52 +78,40 @@ class Web3EventsDecoder { console.error( ' Transaction not yet mined. Please try after some time. ', ); - return; + return {}; } let logs = []; // Backwards compatibility: if (txReceipt.logs.length > 0) { - logs = txReceipt.logs; + ({ logs } = txReceipt); } else if (txReceipt.rawLogs.length > 0) { logs = txReceipt.rawLogs; } if (logs.length > 0) { - const abiDecoder = require('abi-decoder'); - const relevantLogs = []; - for (let i = 0; i < logs.length; i++) { + for (let i = 0; i < logs.length; i += 1) { const log = logs[i]; const currContractAddrFromReceipt = log.address; - if (!currContractAddrFromReceipt) { - // No contract found for contract address. - continue; - } - - if (currContractAddrFromReceipt != contractAddr) { - // Skipping event of contract that is not under inspection. - continue; - } - - if (log.topics === undefined || log.topics.length === 0) { - // Logs that have an event already don't need to be encoded. - if (log.event !== undefined) { - decodedEvents.push(log); + if (currContractAddrFromReceipt && currContractAddrFromReceipt === contractAddr) { + if (log.topics === undefined || log.topics.length === 0) { + if (log.event !== undefined) { + decodedEvents.push(log); + } + } else { + if (!contractAbi) { + // ABI not found for contract. + return {}; + } + + relevantLogs.push(log); + abiDecoder.addABI(contractAbi); } - continue; - } - - if (!contractAbi) { - // ABI not found for contract. - return; } - - relevantLogs.push(log); - abiDecoder.addABI(contractAbi); } if (relevantLogs.length > 0) { From 6243f39cc44d73f7d571728c0903094eef43c6cc Mon Sep 17 00:00:00 2001 From: Paruyr Gevorgyan Date: Wed, 15 May 2019 13:55:15 +0400 Subject: [PATCH 12/19] Runs ganache in background in .travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 18e1408..246ade3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,7 +23,7 @@ before_install: install: - npm ci before_script: - - npm run ganache + - npm run ganache /dev/null 2>&1 & - npm run compile-all script: - npm run lint From 6145cdfd41731a2a3c71d2a4f288d1708ba36c28 Mon Sep 17 00:00:00 2001 From: Paruyr Gevorgyan Date: Wed, 15 May 2019 14:39:12 +0400 Subject: [PATCH 13/19] Aligns setAdmin() docs with implementation - Aligns documentation mismatch of setAdmin() function with implementation. - Requires a new admin not to be the same as the current owner in setAdmin. Adds a negative unit test case. - Remove premature optimization that was checking a new admin address to be different than the current one before emitting event. Resolves: #3 --- contracts/Organization.sol | 33 +++++++++++++++++---------------- test/organization/set_admin.js | 29 ++++++++++++++++++----------- 2 files changed, 35 insertions(+), 27 deletions(-) diff --git a/contracts/Organization.sol b/contracts/Organization.sol index 09bd292..81134c3 100644 --- a/contracts/Organization.sol +++ b/contracts/Organization.sol @@ -211,14 +211,16 @@ contract Organization is OrganizationInterface { } /** - * @notice Sets the admin address. Can only be called by owner or current - * admin. If called by the current admin, adminship is transferred - * to the given address immediately. - * It is discouraged to set the admin address to be the same as the - * address of the owner. The point of the admin is to act on behalf - * of the organization without requiring the possibly very safely - * stored owner key(s). - * Admin can be set to `address(0)` if no admin is desired. + * @notice Sets a new admin address. + * + * An admin address can be set to `address(0)` if no admin is + * desired. + * + * Requires: + * - Only owner or admin can call. + * - A new admin address is not the same as the current + * owner address. + * * * @param _admin Admin address to be set. * @@ -231,14 +233,13 @@ contract Organization is OrganizationInterface { onlyOwnerOrAdmin returns (bool success_) { - /* - * If the address does not change, the call is considered a success, - * but we don't need to emit an event as it did not actually change. - */ - if (admin != _admin) { - emit AdminAddressChanged(_admin, admin); - admin = _admin; - } + require( + owner != _admin, + "A new admin address is the same as the current owner." + ); + + emit AdminAddressChanged(_admin, admin); + admin = _admin; success_ = true; } diff --git a/test/organization/set_admin.js b/test/organization/set_admin.js index 41bfe6f..fd3dcd1 100644 --- a/test/organization/set_admin.js +++ b/test/organization/set_admin.js @@ -48,6 +48,13 @@ contract('Organization.setAdmin()', async (accounts) => { ); }); + it('reverts when new admin address is the same as the current owner address', async () => { + await Utils.expectRevert( + organization.setAdmin(owner, { from: owner }), + 'A new admin address is the same as the current owner.', + ); + }); + it('should pass when valid admin is passed by owner', async () => { const newAdmin = accounts[2]; await organization.setAdmin(newAdmin, { from: owner }); @@ -92,6 +99,7 @@ contract('Organization.setAdmin()', async (accounts) => { admin, 'The event should emit the correct admin address.', ); + assert.strictEqual( events.AdminAddressChanged.previousAdmin, previousAdmin, @@ -99,21 +107,20 @@ contract('Organization.setAdmin()', async (accounts) => { ); }); - it('Should not emit an event when the address did not change', async () => { - await organization.setAdmin(admin, { from: owner }); - - /* - * The address was already set before. This should pass, but not emit an - * event. - */ - const transaction = await organization.setAdmin(admin, { from: owner }); + it('Should emit an event when the address did not change', async () => { + const currentAdmin = await organization.admin.call(); + const transaction = await organization.setAdmin(currentAdmin, { from: owner }); const events = EventsDecoder.getEvents(transaction, organization); assert.strictEqual( - events.AdminAddressChanged, - undefined, - 'The event should not be emitted when the address does not change.', + events.AdminAddressChanged.previousAdmin, + currentAdmin, + ); + + assert.strictEqual( + events.AdminAddressChanged.newAdmin, + currentAdmin, ); }); }); From 562494f2d961ad7b059c5309028461291da328b4 Mon Sep 17 00:00:00 2001 From: Paruyr Gevorgyan Date: Wed, 15 May 2019 14:57:35 +0400 Subject: [PATCH 14/19] Removes --reset option from `truffle compile` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cecdf84..6e64890 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ }, "scripts": { "compile": "truffle compile", - "compile-all": "truffle compile --all --reset", + "compile-all": "truffle compile --all", "test": "truffle test", "ganache": "./tools/runGanacheCli.sh", "build-package": "node tools/build_package.js", From aebb3ac40ff6db54abb6a920f49774bd629cddf7 Mon Sep 17 00:00:00 2001 From: Martin Schenck Date: Wed, 29 May 2019 16:08:21 +0200 Subject: [PATCH 15/19] Update truffle dependency References https://github.com/OpenST/mosaic-contracts/issues/758 --- package-lock.json | 50 +++++++++++++++++++++++++++++++++++++---------- package.json | 6 ++++-- 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/package-lock.json b/package-lock.json index 11ae660..0bef2c6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1772,16 +1772,25 @@ "dev": true }, "fs-extra": { - "version": "0.30.0", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-0.30.0.tgz", - "integrity": "sha1-8jP/zAjU2n1DLapEl3aYnbHfk/A=", + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.0.1.tgz", + "integrity": "sha512-W+XLrggcDzlle47X/XnS7FXrXu9sDo+Ze9zpndeBxdgv88FHLm1HtmkhEwavruS6koanBjp098rUpHs65EmG7A==", "dev": true, "requires": { "graceful-fs": "^4.1.2", - "jsonfile": "^2.1.0", - "klaw": "^1.0.0", - "path-is-absolute": "^1.0.0", - "rimraf": "^2.2.8" + "jsonfile": "^4.0.0", + "universalify": "^0.1.0" + }, + "dependencies": { + "jsonfile": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", + "integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=", + "dev": true, + "requires": { + "graceful-fs": "^4.1.6" + } + } } }, "fs-promise": { @@ -3685,6 +3694,21 @@ "require-from-string": "^2.0.0", "semver": "^5.5.0", "yargs": "^11.0.0" + }, + "dependencies": { + "fs-extra": { + "version": "0.30.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-0.30.0.tgz", + "integrity": "sha1-8jP/zAjU2n1DLapEl3aYnbHfk/A=", + "dev": true, + "requires": { + "graceful-fs": "^4.1.2", + "jsonfile": "^2.1.0", + "klaw": "^1.0.0", + "path-is-absolute": "^1.0.0", + "rimraf": "^2.2.8" + } + } } }, "source-map": { @@ -4065,9 +4089,9 @@ } }, "truffle": { - "version": "5.0.6", - "resolved": "https://registry.npmjs.org/truffle/-/truffle-5.0.6.tgz", - "integrity": "sha512-SBk42qft5ElzdAoolHzy3TIzIrh/GmbEiI+kKoj2nj4GYZtHdXePWA+cp7AwzhNuXiMaR4UwYqVVhn8yxOiAXg==", + "version": "5.0.19", + "resolved": "https://registry.npmjs.org/truffle/-/truffle-5.0.19.tgz", + "integrity": "sha512-d4fxChHYCjccW33IO/4KLcGqjTDn+mw7vqdGvGi307CMo+KTtns+5c91+1iOKDQcSKiv8SHYgvtyF7cn/+FPAg==", "dev": true, "requires": { "app-module-path": "^2.2.0", @@ -4285,6 +4309,12 @@ "is-typedarray": "^1.0.0" } }, + "typescript": { + "version": "3.4.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.4.5.tgz", + "integrity": "sha512-YycBxUb49UUhdNMU5aJ7z5Ej2XGmaIBL0x34vZ82fn3hGvD+bgrMrVDpatgz2f7YxUMJxMkbWxJZeAvDxVe7Vw==", + "dev": true + }, "typical": { "version": "2.6.1", "resolved": "https://registry.npmjs.org/typical/-/typical-2.6.1.tgz", diff --git a/package.json b/package.json index 6e64890..66caf6b 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "test": "truffle test", "ganache": "./tools/runGanacheCli.sh", "build-package": "node tools/build_package.js", - "prepack": "npm run compile-all && npm run build-package", + "prepack": "npm run compile-all && npm run generate && npm run build-package && ./node_modules/.bin/tsc ./dist/*.ts", "lint": "eslint test tools -c .eslintrc.json --ext js", "generate": "ts-generator ts-generator.json", "postinstall": "npm run compile-all && npm run generate" @@ -46,12 +46,14 @@ "eslint": "5.10.0", "eslint-config-airbnb-base": "13.1.0", "eslint-plugin-import": "2.14.0", + "fs-extra": "8.0.1", "ganache-cli": "6.1.8", "mocha": "5.2.0", "openzeppelin-solidity": "2.1.1", - "truffle": "5.0.6", + "truffle": "5.0.19", "ts-generator": "0.0.8", "typechain": "0.3.14", + "typescript": "3.4.5", "web3": "1.0.0-beta.36" } } From abc1966019c3dc365db510c1c8da3d0dac32cd8a Mon Sep 17 00:00:00 2001 From: Gulshan Vasnani Date: Wed, 29 May 2019 21:03:48 +0530 Subject: [PATCH 16/19] Updated ganache-cli to 6.4.3 --- package-lock.json | 400 +++++++++++++++++++++++++++++++++++++++++++--- package.json | 2 +- 2 files changed, 375 insertions(+), 27 deletions(-) diff --git a/package-lock.json b/package-lock.json index 11ae660..d224710 100644 --- a/package-lock.json +++ b/package-lock.json @@ -488,12 +488,6 @@ "integrity": "sha1-+PeLdniYiO858gXNY39o5wISKyw=", "dev": true }, - "buffer-from": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz", - "integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==", - "dev": true - }, "buffer-to-arraybuffer": { "version": "0.0.5", "resolved": "https://registry.npmjs.org/buffer-to-arraybuffer/-/buffer-to-arraybuffer-0.0.5.tgz", @@ -1839,12 +1833,382 @@ "dev": true }, "ganache-cli": { - "version": "6.1.8", - "resolved": "https://registry.npmjs.org/ganache-cli/-/ganache-cli-6.1.8.tgz", - "integrity": "sha512-yXzteu4SIgUL31mnpm9j+x6dpHUw0p/nsRVkcySKq0w+1vDxH9jMErP1QhZAJuTVE6ni4nfvGSNkaQx5cD3jfg==", + "version": "6.4.3", + "resolved": "https://registry.npmjs.org/ganache-cli/-/ganache-cli-6.4.3.tgz", + "integrity": "sha512-3G+CK4ojipDvxQHlpX8PjqaOMRWVcaLZZSW97Bv7fdcPTXQwkji2yY5CY6J12Atiub4M4aJc0va+q3HXeerbIA==", "dev": true, "requires": { - "source-map-support": "^0.5.3" + "bn.js": "4.11.8", + "source-map-support": "0.5.9", + "yargs": "11.1.0" + }, + "dependencies": { + "ansi-regex": { + "version": "3.0.0", + "bundled": true, + "dev": true + }, + "bn.js": { + "version": "4.11.8", + "bundled": true, + "dev": true + }, + "buffer-from": { + "version": "1.1.1", + "bundled": true, + "dev": true + }, + "camelcase": { + "version": "4.1.0", + "bundled": true, + "dev": true + }, + "cliui": { + "version": "4.1.0", + "bundled": true, + "dev": true, + "requires": { + "string-width": "^2.1.1", + "strip-ansi": "^4.0.0", + "wrap-ansi": "^2.0.0" + } + }, + "code-point-at": { + "version": "1.1.0", + "bundled": true, + "dev": true + }, + "cross-spawn": { + "version": "5.1.0", + "bundled": true, + "dev": true, + "requires": { + "lru-cache": "^4.0.1", + "shebang-command": "^1.2.0", + "which": "^1.2.9" + } + }, + "decamelize": { + "version": "1.2.0", + "bundled": true, + "dev": true + }, + "execa": { + "version": "0.7.0", + "bundled": true, + "dev": true, + "requires": { + "cross-spawn": "^5.0.1", + "get-stream": "^3.0.0", + "is-stream": "^1.1.0", + "npm-run-path": "^2.0.0", + "p-finally": "^1.0.0", + "signal-exit": "^3.0.0", + "strip-eof": "^1.0.0" + } + }, + "find-up": { + "version": "2.1.0", + "bundled": true, + "dev": true, + "requires": { + "locate-path": "^2.0.0" + } + }, + "get-caller-file": { + "version": "1.0.3", + "bundled": true, + "dev": true + }, + "get-stream": { + "version": "3.0.0", + "bundled": true, + "dev": true + }, + "invert-kv": { + "version": "1.0.0", + "bundled": true, + "dev": true + }, + "is-fullwidth-code-point": { + "version": "2.0.0", + "bundled": true, + "dev": true + }, + "is-stream": { + "version": "1.1.0", + "bundled": true, + "dev": true + }, + "isexe": { + "version": "2.0.0", + "bundled": true, + "dev": true + }, + "lcid": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "requires": { + "invert-kv": "^1.0.0" + } + }, + "locate-path": { + "version": "2.0.0", + "bundled": true, + "dev": true, + "requires": { + "p-locate": "^2.0.0", + "path-exists": "^3.0.0" + } + }, + "lru-cache": { + "version": "4.1.4", + "bundled": true, + "dev": true, + "requires": { + "pseudomap": "^1.0.2", + "yallist": "^3.0.2" + } + }, + "mem": { + "version": "1.1.0", + "bundled": true, + "dev": true, + "requires": { + "mimic-fn": "^1.0.0" + } + }, + "mimic-fn": { + "version": "1.2.0", + "bundled": true, + "dev": true + }, + "npm-run-path": { + "version": "2.0.2", + "bundled": true, + "dev": true, + "requires": { + "path-key": "^2.0.0" + } + }, + "number-is-nan": { + "version": "1.0.1", + "bundled": true, + "dev": true + }, + "os-locale": { + "version": "2.1.0", + "bundled": true, + "dev": true, + "requires": { + "execa": "^0.7.0", + "lcid": "^1.0.0", + "mem": "^1.1.0" + } + }, + "p-finally": { + "version": "1.0.0", + "bundled": true, + "dev": true + }, + "p-limit": { + "version": "1.3.0", + "bundled": true, + "dev": true, + "requires": { + "p-try": "^1.0.0" + } + }, + "p-locate": { + "version": "2.0.0", + "bundled": true, + "dev": true, + "requires": { + "p-limit": "^1.1.0" + } + }, + "p-try": { + "version": "1.0.0", + "bundled": true, + "dev": true + }, + "path-exists": { + "version": "3.0.0", + "bundled": true, + "dev": true + }, + "path-key": { + "version": "2.0.1", + "bundled": true, + "dev": true + }, + "pseudomap": { + "version": "1.0.2", + "bundled": true, + "dev": true + }, + "require-directory": { + "version": "2.1.1", + "bundled": true, + "dev": true + }, + "require-main-filename": { + "version": "1.0.1", + "bundled": true, + "dev": true + }, + "set-blocking": { + "version": "2.0.0", + "bundled": true, + "dev": true + }, + "shebang-command": { + "version": "1.2.0", + "bundled": true, + "dev": true, + "requires": { + "shebang-regex": "^1.0.0" + } + }, + "shebang-regex": { + "version": "1.0.0", + "bundled": true, + "dev": true + }, + "signal-exit": { + "version": "3.0.2", + "bundled": true, + "dev": true + }, + "source-map": { + "version": "0.6.1", + "bundled": true, + "dev": true + }, + "source-map-support": { + "version": "0.5.9", + "bundled": true, + "dev": true, + "requires": { + "buffer-from": "^1.0.0", + "source-map": "^0.6.0" + } + }, + "string-width": { + "version": "2.1.1", + "bundled": true, + "dev": true, + "requires": { + "is-fullwidth-code-point": "^2.0.0", + "strip-ansi": "^4.0.0" + } + }, + "strip-ansi": { + "version": "4.0.0", + "bundled": true, + "dev": true, + "requires": { + "ansi-regex": "^3.0.0" + } + }, + "strip-eof": { + "version": "1.0.0", + "bundled": true, + "dev": true + }, + "which": { + "version": "1.3.1", + "bundled": true, + "dev": true, + "requires": { + "isexe": "^2.0.0" + } + }, + "which-module": { + "version": "2.0.0", + "bundled": true, + "dev": true + }, + "wrap-ansi": { + "version": "2.1.0", + "bundled": true, + "dev": true, + "requires": { + "string-width": "^1.0.1", + "strip-ansi": "^3.0.1" + }, + "dependencies": { + "ansi-regex": { + "version": "2.1.1", + "bundled": true, + "dev": true + }, + "is-fullwidth-code-point": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "requires": { + "number-is-nan": "^1.0.0" + } + }, + "string-width": { + "version": "1.0.2", + "bundled": true, + "dev": true, + "requires": { + "code-point-at": "^1.0.0", + "is-fullwidth-code-point": "^1.0.0", + "strip-ansi": "^3.0.0" + } + }, + "strip-ansi": { + "version": "3.0.1", + "bundled": true, + "dev": true, + "requires": { + "ansi-regex": "^2.0.0" + } + } + } + }, + "y18n": { + "version": "3.2.1", + "bundled": true, + "dev": true + }, + "yallist": { + "version": "3.0.2", + "bundled": true, + "dev": true + }, + "yargs": { + "version": "11.1.0", + "bundled": true, + "dev": true, + "requires": { + "cliui": "^4.0.0", + "decamelize": "^1.1.1", + "find-up": "^2.1.0", + "get-caller-file": "^1.0.1", + "os-locale": "^2.0.0", + "require-directory": "^2.1.1", + "require-main-filename": "^1.0.1", + "set-blocking": "^2.0.0", + "string-width": "^2.0.0", + "which-module": "^2.0.0", + "y18n": "^3.2.1", + "yargs-parser": "^9.0.2" + } + }, + "yargs-parser": { + "version": "9.0.2", + "bundled": true, + "dev": true, + "requires": { + "camelcase": "^4.1.0" + } + } } }, "get-caller-file": { @@ -3687,22 +4051,6 @@ "yargs": "^11.0.0" } }, - "source-map": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", - "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", - "dev": true - }, - "source-map-support": { - "version": "0.5.10", - "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.10.tgz", - "integrity": "sha512-YfQ3tQFTK/yzlGJuX8pTwa4tifQj4QS2Mj7UegOu8jAz59MqIiMGPXxQhVQiIMNzayuUSF/jEuVnfFF5JqybmQ==", - "dev": true, - "requires": { - "buffer-from": "^1.0.0", - "source-map": "^0.6.0" - } - }, "spdx-correct": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-3.1.0.tgz", diff --git a/package.json b/package.json index 6e64890..495ba78 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "eslint": "5.10.0", "eslint-config-airbnb-base": "13.1.0", "eslint-plugin-import": "2.14.0", - "ganache-cli": "6.1.8", + "ganache-cli": "6.4.3", "mocha": "5.2.0", "openzeppelin-solidity": "2.1.1", "truffle": "5.0.6", From daa193073e45947224ea5b9945e9659c0268c753 Mon Sep 17 00:00:00 2001 From: Gulshan Vasnani Date: Thu, 30 May 2019 14:28:14 +0530 Subject: [PATCH 17/19] Removed safemath import from organization contracts --- contracts/Organization.sol | 7 ------- 1 file changed, 7 deletions(-) diff --git a/contracts/Organization.sol b/contracts/Organization.sol index 81134c3..1d861a8 100644 --- a/contracts/Organization.sol +++ b/contracts/Organization.sol @@ -20,7 +20,6 @@ pragma solidity ^0.5.0; // // ---------------------------------------------------------------------------- -import "openzeppelin-solidity/contracts/math/SafeMath.sol"; import "./OrganizationInterface.sol"; @@ -36,12 +35,6 @@ import "./OrganizationInterface.sol"; */ contract Organization is OrganizationInterface { - - /* Using */ - - using SafeMath for uint256; - - /* Events */ /** Emitted when a current owner initiates a change of ownership. */ From 9ffc1aa782f832ffcf670f97750f15940f34d446 Mon Sep 17 00:00:00 2001 From: Gulshan Vasnani Date: Thu, 30 May 2019 19:36:22 +0530 Subject: [PATCH 18/19] Removed newline --- contracts/Organization.sol | 1 - 1 file changed, 1 deletion(-) diff --git a/contracts/Organization.sol b/contracts/Organization.sol index 1d861a8..a6955d1 100644 --- a/contracts/Organization.sol +++ b/contracts/Organization.sol @@ -22,7 +22,6 @@ pragma solidity ^0.5.0; import "./OrganizationInterface.sol"; - /** * @title Organization contract handles an organization and its workers. * From af019eec842c0a14720954f22982a121266d2a9e Mon Sep 17 00:00:00 2001 From: Puneet Khushwani Date: Mon, 3 Jun 2019 16:17:11 +0530 Subject: [PATCH 19/19] updating versions for vulnerable NPM modules --- package-lock.json | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index a88c2ef..f5ad4be 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1818,9 +1818,9 @@ "dev": true }, "fstream": { - "version": "1.0.11", - "resolved": "https://registry.npmjs.org/fstream/-/fstream-1.0.11.tgz", - "integrity": "sha1-XB+x8RdHcRTwYyoOtLcbPLD9MXE=", + "version": "1.0.12", + "resolved": "https://registry.npmjs.org/fstream/-/fstream-1.0.12.tgz", + "integrity": "sha512-WvJ193OHa0GHPEL+AycEJgxvBEwyfRkN1vhjca23OaPVMCaLCXTd5qAu82AjTcgP1UJmytkOKb63Ypde7raDIg==", "dev": true, "requires": { "graceful-fs": "^4.1.2", @@ -2688,9 +2688,9 @@ "dev": true }, "js-yaml": { - "version": "3.12.2", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.12.2.tgz", - "integrity": "sha512-QHn/Lh/7HhZ/Twc7vJYQTkjuCa0kaCcDcjK5Zlk2rvnUpy7DxMJ23+Jc2dcyvltwQVg1nygAVlB2oRDFHoRS5Q==", + "version": "3.13.1", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.1.tgz", + "integrity": "sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==", "dev": true, "requires": { "argparse": "^1.0.7", @@ -4300,13 +4300,13 @@ } }, "tar": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/tar/-/tar-2.2.1.tgz", - "integrity": "sha1-jk0qJWwOIYXGsYrWlK7JaLg8sdE=", + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/tar/-/tar-2.2.2.tgz", + "integrity": "sha512-FCEhQ/4rE1zYv9rYXJw/msRqsnmlje5jHP6huWeBZ704jUTy02c5AZyWujpMR1ax6mVw9NyJMfuK2CMDWVIfgA==", "dev": true, "requires": { "block-stream": "*", - "fstream": "^1.0.2", + "fstream": "^1.0.12", "inherits": "2" } },