From 4e9db982377e9858b0af7a474216b2f87ed5699b Mon Sep 17 00:00:00 2001 From: CodingYourLife Date: Thu, 29 Nov 2018 18:19:36 +0100 Subject: [PATCH 01/16] truffle init and copied contract from ds-test repo --- .gitmodules | 3 - Makefile | 2 - contracts/Migrations.sol | 23 +++++ contracts/ds-test/test.sol | 139 ++++++++++++++++++++++++++++++ {src => contracts}/math.sol | 0 {src => contracts}/math.t.sol | 2 +- default.nix | 5 -- lib/ds-test | 1 - migrations/1_initial_migration.js | 5 ++ truffle-config.js | 18 ++++ truffle.js | 18 ++++ 11 files changed, 204 insertions(+), 12 deletions(-) delete mode 100644 Makefile create mode 100644 contracts/Migrations.sol create mode 100644 contracts/ds-test/test.sol rename {src => contracts}/math.sol (100%) rename {src => contracts}/math.t.sol (99%) delete mode 100644 default.nix delete mode 160000 lib/ds-test create mode 100644 migrations/1_initial_migration.js create mode 100644 truffle-config.js create mode 100644 truffle.js diff --git a/.gitmodules b/.gitmodules index e124719..e69de29 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +0,0 @@ -[submodule "lib/ds-test"] - path = lib/ds-test - url = https://github.com/dapphub/ds-test diff --git a/Makefile b/Makefile deleted file mode 100644 index c5697bb..0000000 --- a/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -all:; dapp build -test:; dapp test diff --git a/contracts/Migrations.sol b/contracts/Migrations.sol new file mode 100644 index 0000000..c4efb65 --- /dev/null +++ b/contracts/Migrations.sol @@ -0,0 +1,23 @@ +pragma solidity ^0.4.23; + +contract Migrations { + address public owner; + uint public last_completed_migration; + + constructor() public { + owner = msg.sender; + } + + modifier restricted() { + if (msg.sender == owner) _; + } + + function setCompleted(uint completed) public restricted { + last_completed_migration = completed; + } + + function upgrade(address new_address) public restricted { + Migrations upgraded = Migrations(new_address); + upgraded.setCompleted(last_completed_migration); + } +} diff --git a/contracts/ds-test/test.sol b/contracts/ds-test/test.sol new file mode 100644 index 0000000..cb61bb8 --- /dev/null +++ b/contracts/ds-test/test.sol @@ -0,0 +1,139 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity >0.4.23; + +contract DSTest { + event eventListener (address target, bool exact); + event logs (bytes); + event log_bytes32 (bytes32); + event log_named_address (bytes32 key, address val); + event log_named_bytes32 (bytes32 key, bytes32 val); + event log_named_decimal_int (bytes32 key, int val, uint decimals); + event log_named_decimal_uint (bytes32 key, uint val, uint decimals); + event log_named_int (bytes32 key, int val); + event log_named_uint (bytes32 key, uint val); + + bool public IS_TEST; + bool public failed; + bool SUPPRESS_SETUP_WARNING; // hack for solc pure restriction warning + + constructor() internal { + IS_TEST = true; + } + + function setUp() public { + SUPPRESS_SETUP_WARNING = true; // totally unused by anything + } + + function fail() internal { + failed = true; + } + + function expectEventsExact(address target) internal { + emit eventListener(target, true); + } + + modifier logs_gas() { + uint startGas = gasleft(); + _; + uint endGas = gasleft(); + emit log_named_uint("gas", startGas - endGas); + } + + function assertTrue(bool condition) internal { + if (!condition) { + emit log_bytes32("Assertion failed"); + fail(); + } + } + + function assertEq(address a, address b) internal { + if (a != b) { + emit log_bytes32("Error: Wrong `address' value"); + emit log_named_address(" Expected", b); + emit log_named_address(" Actual", a); + fail(); + } + } + + function assertEq32(bytes32 a, bytes32 b) internal { + assertEq(a, b); + } + + function assertEq(bytes32 a, bytes32 b) internal { + if (a != b) { + emit log_bytes32("Error: Wrong `bytes32' value"); + emit log_named_bytes32(" Expected", b); + emit log_named_bytes32(" Actual", a); + fail(); + } + } + + function assertEqDecimal(int a, int b, uint decimals) internal { + if (a != b) { + emit log_bytes32("Error: Wrong fixed-point decimal"); + emit log_named_decimal_int(" Expected", b, decimals); + emit log_named_decimal_int(" Actual", a, decimals); + fail(); + } + } + + function assertEqDecimal(uint a, uint b, uint decimals) internal { + if (a != b) { + emit log_bytes32("Error: Wrong fixed-point decimal"); + emit log_named_decimal_uint(" Expected", b, decimals); + emit log_named_decimal_uint(" Actual", a, decimals); + fail(); + } + } + + function assertEq(int a, int b) internal { + if (a != b) { + emit log_bytes32("Error: Wrong `int' value"); + emit log_named_int(" Expected", b); + emit log_named_int(" Actual", a); + fail(); + } + } + + function assertEq(uint a, uint b) internal { + if (a != b) { + emit log_bytes32("Error: Wrong `uint' value"); + emit log_named_uint(" Expected", b); + emit log_named_uint(" Actual", a); + fail(); + } + } + + function assertEq0(bytes memory a, bytes memory b) internal { + bool ok = true; + + if (a.length == b.length) { + for (uint i = 0; i < a.length; i++) { + if (a[i] != b[i]) { + ok = false; + } + } + } else { + ok = false; + } + + if (!ok) { + emit log_bytes32("Error: Wrong `bytes' value"); + emit log_named_bytes32(" Expected", "[cannot show `bytes' value]"); + emit log_named_bytes32(" Actual", "[cannot show `bytes' value]"); + fail(); + } + } +} \ No newline at end of file diff --git a/src/math.sol b/contracts/math.sol similarity index 100% rename from src/math.sol rename to contracts/math.sol diff --git a/src/math.t.sol b/contracts/math.t.sol similarity index 99% rename from src/math.t.sol rename to contracts/math.t.sol index 3baca60..a814a4f 100644 --- a/src/math.t.sol +++ b/contracts/math.t.sol @@ -13,7 +13,7 @@ pragma solidity >0.4.13; -import "ds-test/test.sol"; +import "./ds-test/test.sol"; import "./math.sol"; contract DSMathTest is DSTest, DSMath { diff --git a/default.nix b/default.nix deleted file mode 100644 index 6de4023..0000000 --- a/default.nix +++ /dev/null @@ -1,5 +0,0 @@ -{ solidityPackage, dappsys }: solidityPackage { - name = "ds-math"; - deps = with dappsys; [ds-test]; - src = ./src; -} diff --git a/lib/ds-test b/lib/ds-test deleted file mode 160000 index b247145..0000000 --- a/lib/ds-test +++ /dev/null @@ -1 +0,0 @@ -Subproject commit b24714595775e8ef676493261508cc231e583a83 diff --git a/migrations/1_initial_migration.js b/migrations/1_initial_migration.js new file mode 100644 index 0000000..4d5f3f9 --- /dev/null +++ b/migrations/1_initial_migration.js @@ -0,0 +1,5 @@ +var Migrations = artifacts.require("./Migrations.sol"); + +module.exports = function(deployer) { + deployer.deploy(Migrations); +}; diff --git a/truffle-config.js b/truffle-config.js new file mode 100644 index 0000000..0855df1 --- /dev/null +++ b/truffle-config.js @@ -0,0 +1,18 @@ +/* + * NB: since truffle-hdwallet-provider 0.0.5 you must wrap HDWallet providers in a + * function when declaring them. Failure to do so will cause commands to hang. ex: + * ``` + * mainnet: { + * provider: function() { + * return new HDWalletProvider(mnemonic, 'https://mainnet.infura.io/') + * }, + * network_id: '1', + * gas: 4500000, + * gasPrice: 10000000000, + * }, + */ + +module.exports = { + // See + // to customize your Truffle configuration! +}; diff --git a/truffle.js b/truffle.js new file mode 100644 index 0000000..0855df1 --- /dev/null +++ b/truffle.js @@ -0,0 +1,18 @@ +/* + * NB: since truffle-hdwallet-provider 0.0.5 you must wrap HDWallet providers in a + * function when declaring them. Failure to do so will cause commands to hang. ex: + * ``` + * mainnet: { + * provider: function() { + * return new HDWalletProvider(mnemonic, 'https://mainnet.infura.io/') + * }, + * network_id: '1', + * gas: 4500000, + * gasPrice: 10000000000, + * }, + */ + +module.exports = { + // See + // to customize your Truffle configuration! +}; From 73b77a06b73e644d153c66fb2b7ab0e77b3464b9 Mon Sep 17 00:00:00 2001 From: CodingYourLife Date: Thu, 29 Nov 2018 18:20:19 +0100 Subject: [PATCH 02/16] added development network to truffle.js --- truffle.js | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/truffle.js b/truffle.js index 0855df1..061da5a 100644 --- a/truffle.js +++ b/truffle.js @@ -1,18 +1,11 @@ -/* - * NB: since truffle-hdwallet-provider 0.0.5 you must wrap HDWallet providers in a - * function when declaring them. Failure to do so will cause commands to hang. ex: - * ``` - * mainnet: { - * provider: function() { - * return new HDWalletProvider(mnemonic, 'https://mainnet.infura.io/') - * }, - * network_id: '1', - * gas: 4500000, - * gasPrice: 10000000000, - * }, - */ module.exports = { - // See - // to customize your Truffle configuration! -}; + networks: { + development: { + host: "localhost", + port: 8545, + network_id: "*", + gas: 4700000 //4700000 is same as ropsten + } + } +} \ No newline at end of file From 2d017bc417e49405da4ba294f75eb069bc391535 Mon Sep 17 00:00:00 2001 From: CodingYourLife Date: Thu, 29 Nov 2018 18:21:03 +0100 Subject: [PATCH 03/16] changed all functions from internal to public (no security risk and first step for library) --- contracts/math.sol | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/contracts/math.sol b/contracts/math.sol index 0d12e17..4c0035b 100644 --- a/contracts/math.sol +++ b/contracts/math.sol @@ -16,42 +16,42 @@ pragma solidity >0.4.13; contract DSMath { - function add(uint x, uint y) internal pure returns (uint z) { + function add(uint x, uint y) public pure returns (uint z) { require((z = x + y) >= x, "ds-math-add-overflow"); } - function sub(uint x, uint y) internal pure returns (uint z) { + function sub(uint x, uint y) public pure returns (uint z) { require((z = x - y) <= x, "ds-math-sub-underflow"); } - function mul(uint x, uint y) internal pure returns (uint z) { + function mul(uint x, uint y) public pure returns (uint z) { require(y == 0 || (z = x * y) / y == x, "ds-math-mul-overflow"); } - function min(uint x, uint y) internal pure returns (uint z) { + function min(uint x, uint y) public pure returns (uint z) { return x <= y ? x : y; } - function max(uint x, uint y) internal pure returns (uint z) { + function max(uint x, uint y) public pure returns (uint z) { return x >= y ? x : y; } - function imin(int x, int y) internal pure returns (int z) { + function imin(int x, int y) public pure returns (int z) { return x <= y ? x : y; } - function imax(int x, int y) internal pure returns (int z) { + function imax(int x, int y) public pure returns (int z) { return x >= y ? x : y; } uint constant WAD = 10 ** 18; uint constant RAY = 10 ** 27; - function wmul(uint x, uint y) internal pure returns (uint z) { + function wmul(uint x, uint y) public pure returns (uint z) { z = add(mul(x, y), WAD / 2) / WAD; } - function rmul(uint x, uint y) internal pure returns (uint z) { + function rmul(uint x, uint y) public pure returns (uint z) { z = add(mul(x, y), RAY / 2) / RAY; } - function wdiv(uint x, uint y) internal pure returns (uint z) { + function wdiv(uint x, uint y) public pure returns (uint z) { z = add(mul(x, WAD), y / 2) / y; } - function rdiv(uint x, uint y) internal pure returns (uint z) { + function rdiv(uint x, uint y) public pure returns (uint z) { z = add(mul(x, RAY), y / 2) / y; } @@ -70,7 +70,7 @@ contract DSMath { // Also, EVM division is flooring and // floor[(n-1) / 2] = floor[n / 2]. // - function rpow(uint x, uint n) internal pure returns (uint z) { + function rpow(uint x, uint n) public pure returns (uint z) { z = n % 2 != 0 ? x : RAY; for (n /= 2; n != 0; n /= 2) { From 0731df1e67630acec1b9ce1693bc76a043b2d9fd Mon Sep 17 00:00:00 2001 From: CodingYourLife Date: Thu, 29 Nov 2018 18:21:34 +0100 Subject: [PATCH 04/16] simple test added --- test/math.test.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 test/math.test.js diff --git a/test/math.test.js b/test/math.test.js new file mode 100644 index 0000000..5a5306d --- /dev/null +++ b/test/math.test.js @@ -0,0 +1,15 @@ +const DSTest = artifacts.require("DSMath") + +contract('Math', async (accounts) => { + let math = null + + before(async () => { + math = await DSTest.new() + }) + + it('add()', async() => { + const onePlusOne = await math.add(1, 1) + + assert.equal(onePlusOne, 2, "add incorrect") + }) +}) \ No newline at end of file From 49d5512120dfc1e0c1c2533b6565faba040b2fe1 Mon Sep 17 00:00:00 2001 From: CodingYourLife Date: Thu, 29 Nov 2018 18:22:08 +0100 Subject: [PATCH 05/16] made it an npm project (to use chai und such things) --- package-lock.json | 61 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 23 ++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 package-lock.json create mode 100644 package.json diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..b096e1a --- /dev/null +++ b/package-lock.json @@ -0,0 +1,61 @@ +{ + "name": "ds-math", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "assertion-error": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz", + "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==", + "dev": true + }, + "chai": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/chai/-/chai-4.2.0.tgz", + "integrity": "sha512-XQU3bhBukrOsQCuwZndwGcCVQHyZi53fQ6Ys1Fym7E4olpIqqZZhhoFJoaKVvV17lWQoXYwgWN2nF5crA8J2jw==", + "dev": true, + "requires": { + "assertion-error": "^1.1.0", + "check-error": "^1.0.2", + "deep-eql": "^3.0.1", + "get-func-name": "^2.0.0", + "pathval": "^1.1.0", + "type-detect": "^4.0.5" + } + }, + "check-error": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz", + "integrity": "sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=", + "dev": true + }, + "deep-eql": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-3.0.1.tgz", + "integrity": "sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw==", + "dev": true, + "requires": { + "type-detect": "^4.0.0" + } + }, + "get-func-name": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz", + "integrity": "sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=", + "dev": true + }, + "pathval": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.0.tgz", + "integrity": "sha1-uULm1L3mUwBe9rcTYd74cn0GReA=", + "dev": true + }, + "type-detect": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", + "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", + "dev": true + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..3a66185 --- /dev/null +++ b/package.json @@ -0,0 +1,23 @@ +{ + "name": "ds-math", + "version": "1.0.0", + "description": "

DSMath

", + "main": "truffle-config.js", + "directories": { + "test": "test" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git@github.com-as-conda:dapphub/ds-math.git" + }, + "keywords": [], + "author": "", + "license": "ISC", + "devDependencies": { + "chai": "^4.2.0" + }, + "dependencies": {} +} From 64120641f9ed7e7ed67ccde20a6d42af1c3c8e5b Mon Sep 17 00:00:00 2001 From: CodingYourLife Date: Thu, 29 Nov 2018 18:22:51 +0100 Subject: [PATCH 06/16] added simple DSMathTest which required adding chai and borrowing shouldFail.js from openzeppelin (copied it) --- test/helpers/shouldFail.js | 39 ++++++++++++++++++++++++++++++++++++++ test/math.t.test.js | 14 ++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 test/helpers/shouldFail.js create mode 100644 test/math.t.test.js diff --git a/test/helpers/shouldFail.js b/test/helpers/shouldFail.js new file mode 100644 index 0000000..e8159e0 --- /dev/null +++ b/test/helpers/shouldFail.js @@ -0,0 +1,39 @@ +//copied from openzeppelin (https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/test/helpers/shouldFail.js) + +const should = require('chai') + .should(); + +async function shouldFailWithMessage (promise, message) { + try { + await promise; + } catch (error) { + if (message) { + error.message.should.include(message, `Wrong failure type, expected '${message}'`); + } + return; + } + + should.fail('Expected failure not received'); +} + +async function reverting (promise) { + await shouldFailWithMessage(promise, 'revert'); +} + +async function throwing (promise) { + await shouldFailWithMessage(promise, 'invalid opcode'); +} + +async function outOfGas (promise) { + await shouldFailWithMessage(promise, 'out of gas'); +} + +async function shouldFail (promise) { + await shouldFailWithMessage(promise); +} + +shouldFail.reverting = reverting; +shouldFail.throwing = throwing; +shouldFail.outOfGas = outOfGas; + +module.exports = shouldFail; diff --git a/test/math.t.test.js b/test/math.t.test.js new file mode 100644 index 0000000..0217750 --- /dev/null +++ b/test/math.t.test.js @@ -0,0 +1,14 @@ +const DSMathTest = artifacts.require("DSMathTest") +let shouldFail = require('./helpers/shouldFail.js') + +contract('DSMathTest', async (accounts) => { + let math = null + + before(async () => { + math = await DSMathTest.new() + }) + + it('testFail_add()', async() => { + await shouldFail.reverting(math.testFail_add()) + }) +}) \ No newline at end of file From 312ea50efbae8e4f1d152f804237166cdb571abf Mon Sep 17 00:00:00 2001 From: CodingYourLife Date: Thu, 29 Nov 2018 18:23:47 +0100 Subject: [PATCH 07/16] added tests for all functions of DSMathTest. note that one function fails even tough the name suggests it should not CRITICAL --- test/math.t.test.js | 64 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/test/math.t.test.js b/test/math.t.test.js index 0217750..feff089 100644 --- a/test/math.t.test.js +++ b/test/math.t.test.js @@ -11,4 +11,68 @@ contract('DSMathTest', async (accounts) => { it('testFail_add()', async() => { await shouldFail.reverting(math.testFail_add()) }) + + it('testFail_sub()', async() => { + await shouldFail.reverting(math.testFail_sub()) + }) + + it('test_sub()', async() => { + await math.test_sub() + }) + + it('testFail_mul()', async() => { + await shouldFail.reverting(math.testFail_mul()) + }) + + it('test_mul()', async() => { + await math.test_mul() + }) + + it('test_min()', async() => { + await math.test_min() + }) + + it('test_max()', async() => { + await math.test_max() + }) + + it('test_imin()', async() => { + await math.test_imin() + }) + + it('test_imax()', async() => { + await math.test_imax() + }) + + it('testFail_wmul_overflow()', async() => { + await shouldFail.reverting(math.testFail_wmul_overflow()) + }) + + it('test_wmul_trivial()', async() => { + await math.test_wmul_trivial() + }) + + it('test_wmul_fractions()', async() => { + await math.test_wmul_fractions() + }) + + it('testFail_wdiv_zero()', async() => { + await shouldFail.reverting(math.testFail_wdiv_zero()) + }) + + it('test_wdiv_trivial()', async() => { + await math.test_wdiv_trivial() + }) + + it('test_wdiv_fractions()', async() => { + await math.test_wdiv_fractions() + }) + + it('test_wmul_rounding()', async() => { + await math.test_wmul_rounding() + }) + + it('test_rmul_rounding()', async() => { + await math.test_rmul_rounding() + }) }) \ No newline at end of file From 4ee50516ab895f1b8047c46044458c78346f9a0f Mon Sep 17 00:00:00 2001 From: CodingYourLife Date: Thu, 29 Nov 2018 18:24:19 +0100 Subject: [PATCH 08/16] rename DSTest according to contract name --- contracts/ds-test/{test.sol => DSTest.sol} | 0 contracts/math.t.sol | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename contracts/ds-test/{test.sol => DSTest.sol} (100%) diff --git a/contracts/ds-test/test.sol b/contracts/ds-test/DSTest.sol similarity index 100% rename from contracts/ds-test/test.sol rename to contracts/ds-test/DSTest.sol diff --git a/contracts/math.t.sol b/contracts/math.t.sol index a814a4f..c3b1bd7 100644 --- a/contracts/math.t.sol +++ b/contracts/math.t.sol @@ -13,7 +13,7 @@ pragma solidity >0.4.13; -import "./ds-test/test.sol"; +import "./ds-test/DSTest.sol"; import "./math.sol"; contract DSMathTest is DSTest, DSMath { From c52262ffb21d98cc89329918d2d69a4356228835 Mon Sep 17 00:00:00 2001 From: CodingYourLife Date: Thu, 29 Nov 2018 18:24:45 +0100 Subject: [PATCH 09/16] renamed DSMath according to contract name --- contracts/{math.sol => DSMath.sol} | 0 contracts/math.t.sol | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename contracts/{math.sol => DSMath.sol} (100%) diff --git a/contracts/math.sol b/contracts/DSMath.sol similarity index 100% rename from contracts/math.sol rename to contracts/DSMath.sol diff --git a/contracts/math.t.sol b/contracts/math.t.sol index c3b1bd7..2d46729 100644 --- a/contracts/math.t.sol +++ b/contracts/math.t.sol @@ -14,7 +14,7 @@ pragma solidity >0.4.13; import "./ds-test/DSTest.sol"; -import "./math.sol"; +import "./DSMath.sol"; contract DSMathTest is DSTest, DSMath { function testFail_add() public pure { From ad4a0be241b58c0d9982c27eeb4a6d4e986c55ff Mon Sep 17 00:00:00 2001 From: CodingYourLife Date: Thu, 29 Nov 2018 18:25:30 +0100 Subject: [PATCH 10/16] renamed DSMathTest according to contract name --- contracts/{math.t.sol => DSMathTest.t.sol} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename contracts/{math.t.sol => DSMathTest.t.sol} (100%) diff --git a/contracts/math.t.sol b/contracts/DSMathTest.t.sol similarity index 100% rename from contracts/math.t.sol rename to contracts/DSMathTest.t.sol From 5456c765f3192b36842fca84519878103d382db8 Mon Sep 17 00:00:00 2001 From: CodingYourLife Date: Thu, 29 Nov 2018 18:26:01 +0100 Subject: [PATCH 11/16] moved DSMathTest into ds-test directory --- contracts/{ => ds-test}/DSMathTest.t.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename contracts/{ => ds-test}/DSMathTest.t.sol (98%) diff --git a/contracts/DSMathTest.t.sol b/contracts/ds-test/DSMathTest.t.sol similarity index 98% rename from contracts/DSMathTest.t.sol rename to contracts/ds-test/DSMathTest.t.sol index 2d46729..5324550 100644 --- a/contracts/DSMathTest.t.sol +++ b/contracts/ds-test/DSMathTest.t.sol @@ -13,8 +13,8 @@ pragma solidity >0.4.13; -import "./ds-test/DSTest.sol"; -import "./DSMath.sol"; +import "./DSTest.sol"; +import "../DSMath.sol"; contract DSMathTest is DSTest, DSMath { function testFail_add() public pure { From 600c1b72b05535d371b43cfacf4a762c3c5f2546 Mon Sep 17 00:00:00 2001 From: CodingYourLife Date: Thu, 29 Nov 2018 18:26:34 +0100 Subject: [PATCH 12/16] removed uneccessary truffle-config --- truffle-config.js | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 truffle-config.js diff --git a/truffle-config.js b/truffle-config.js deleted file mode 100644 index 0855df1..0000000 --- a/truffle-config.js +++ /dev/null @@ -1,18 +0,0 @@ -/* - * NB: since truffle-hdwallet-provider 0.0.5 you must wrap HDWallet providers in a - * function when declaring them. Failure to do so will cause commands to hang. ex: - * ``` - * mainnet: { - * provider: function() { - * return new HDWalletProvider(mnemonic, 'https://mainnet.infura.io/') - * }, - * network_id: '1', - * gas: 4500000, - * gasPrice: 10000000000, - * }, - */ - -module.exports = { - // See - // to customize your Truffle configuration! -}; From 4918e12c22da554e4ce26b93fb3e37ce3cb4b9d9 Mon Sep 17 00:00:00 2001 From: CodingYourLife Date: Thu, 29 Nov 2018 18:27:05 +0100 Subject: [PATCH 13/16] added truffle as package and extended scripts section --- package-lock.json | 664 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 4 +- 2 files changed, 667 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index b096e1a..48da2a3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,12 +4,52 @@ "lockfileVersion": 1, "requires": true, "dependencies": { + "ansi-regex": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", + "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", + "dev": true + }, "assertion-error": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz", "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==", "dev": true }, + "balanced-match": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", + "dev": true + }, + "brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dev": true, + "requires": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "browser-stdout": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.0.tgz", + "integrity": "sha1-81HTKWnTL6XXpVZxVCY9korjvR8=", + "dev": true + }, + "builtin-modules": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-1.1.1.tgz", + "integrity": "sha1-Jw8HbFpywC9bZaR9+Uxf46J4iS8=", + "dev": true + }, + "camelcase": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-3.0.0.tgz", + "integrity": "sha1-MvxLn82vhF/N9+c7uXysImHwqwo=", + "dev": true + }, "chai": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/chai/-/chai-4.2.0.tgz", @@ -30,6 +70,50 @@ "integrity": "sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=", "dev": true }, + "cliui": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-3.2.0.tgz", + "integrity": "sha1-EgYBU3qRbSmUD5NNo7SNWFo5IT0=", + "dev": true, + "requires": { + "string-width": "^1.0.1", + "strip-ansi": "^3.0.1", + "wrap-ansi": "^2.0.0" + } + }, + "code-point-at": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz", + "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=", + "dev": true + }, + "commander": { + "version": "2.11.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.11.0.tgz", + "integrity": "sha512-b0553uYA5YAEGgyYIGYROzKQ7X5RAqedkfjiZxwi0kL1g3bOaBNNZfYkzt/CL0umgD5wc9Jec2FbB98CjkMRvQ==", + "dev": true + }, + "concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", + "dev": true + }, + "debug": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", + "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", + "dev": true, + "requires": { + "ms": "2.0.0" + } + }, + "decamelize": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", + "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=", + "dev": true + }, "deep-eql": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-3.0.1.tgz", @@ -39,23 +123,603 @@ "type-detect": "^4.0.0" } }, + "diff": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/diff/-/diff-3.3.1.tgz", + "integrity": "sha512-MKPHZDMB0o6yHyDryUOScqZibp914ksXwAMYMTHj6KO8UeKsRYNJD3oNCKjTqZon+V488P7N/HzXF8t7ZR95ww==", + "dev": true + }, + "error-ex": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz", + "integrity": "sha512-7dFHNmqeFSEt2ZBsCriorKnn3Z2pj+fd9kmI6QoWw4//DL+icEBfc0U7qJCisqrTsKTjw4fNFy2pW9OqStD84g==", + "dev": true, + "requires": { + "is-arrayish": "^0.2.1" + } + }, + "escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", + "dev": true + }, + "find-up": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-1.1.2.tgz", + "integrity": "sha1-ay6YIrGizgpgq2TWEOzK1TyyTQ8=", + "dev": true, + "requires": { + "path-exists": "^2.0.0", + "pinkie-promise": "^2.0.0" + } + }, + "fs-extra": { + "version": "0.30.0", + "resolved": "http://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" + } + }, + "fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", + "dev": true + }, + "get-caller-file": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-1.0.3.tgz", + "integrity": "sha512-3t6rVToeoZfYSGd8YoLFR2DJkiQrIiUrGcjvFX2mDw3bn6k2OtwHN0TNCLbBO+w8qTvimhDkv+LSscbJY1vE6w==", + "dev": true + }, "get-func-name": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz", "integrity": "sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=", "dev": true }, + "glob": { + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", + "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", + "dev": true, + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, + "graceful-fs": { + "version": "4.1.15", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.15.tgz", + "integrity": "sha512-6uHUhOPEBgQ24HM+r6b/QwWfZq+yiFcipKFrOFiBEnWdy5sdzYoi+pJeQaPI5qOLRFqWmAXUPQNsielzdLoecA==", + "dev": true + }, + "growl": { + "version": "1.10.3", + "resolved": "https://registry.npmjs.org/growl/-/growl-1.10.3.tgz", + "integrity": "sha512-hKlsbA5Vu3xsh1Cg3J7jSmX/WaW6A5oBeqzM88oNbCRQFz+zUaXm6yxS4RVytp1scBoJzSYl4YAEOQIt6O8V1Q==", + "dev": true + }, + "has-flag": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-2.0.0.tgz", + "integrity": "sha1-6CB68cx7MNRGzHC3NLXovhj4jVE=", + "dev": true + }, + "he": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/he/-/he-1.1.1.tgz", + "integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0=", + "dev": true + }, + "hosted-git-info": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.7.1.tgz", + "integrity": "sha512-7T/BxH19zbcCTa8XkMlbK5lTo1WtgkFi3GvdWEyNuc4Vex7/9Dqbnpsf4JMydcfj9HCg4zUWFTL3Za6lapg5/w==", + "dev": true + }, + "inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "dev": true, + "requires": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", + "dev": true + }, + "invert-kv": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/invert-kv/-/invert-kv-1.0.0.tgz", + "integrity": "sha1-EEqOSqym09jNFXqO+L+rLXo//bY=", + "dev": true + }, + "is-arrayish": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz", + "integrity": "sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0=", + "dev": true + }, + "is-builtin-module": { + "version": "1.0.0", + "resolved": "http://registry.npmjs.org/is-builtin-module/-/is-builtin-module-1.0.0.tgz", + "integrity": "sha1-VAVy0096wxGfj3bDDLwbHgN6/74=", + "dev": true, + "requires": { + "builtin-modules": "^1.0.0" + } + }, + "is-fullwidth-code-point": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", + "integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=", + "dev": true, + "requires": { + "number-is-nan": "^1.0.0" + } + }, + "is-utf8": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/is-utf8/-/is-utf8-0.2.1.tgz", + "integrity": "sha1-Sw2hRCEE0bM2NA6AeX6GXPOffXI=", + "dev": true + }, + "jsonfile": { + "version": "2.4.0", + "resolved": "http://registry.npmjs.org/jsonfile/-/jsonfile-2.4.0.tgz", + "integrity": "sha1-NzaitCi4e72gzIO1P6PWM6NcKug=", + "dev": true, + "requires": { + "graceful-fs": "^4.1.6" + } + }, + "klaw": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/klaw/-/klaw-1.3.1.tgz", + "integrity": "sha1-QIhDO0azsbolnXh4XY6W9zugJDk=", + "dev": true, + "requires": { + "graceful-fs": "^4.1.9" + } + }, + "lcid": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/lcid/-/lcid-1.0.0.tgz", + "integrity": "sha1-MIrMr6C8SDo4Z7S28rlQYlHRuDU=", + "dev": true, + "requires": { + "invert-kv": "^1.0.0" + } + }, + "load-json-file": { + "version": "1.1.0", + "resolved": "http://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz", + "integrity": "sha1-lWkFcI1YtLq0wiYbBPWfMcmTdMA=", + "dev": true, + "requires": { + "graceful-fs": "^4.1.2", + "parse-json": "^2.2.0", + "pify": "^2.0.0", + "pinkie-promise": "^2.0.0", + "strip-bom": "^2.0.0" + } + }, + "lodash.assign": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/lodash.assign/-/lodash.assign-4.2.0.tgz", + "integrity": "sha1-DZnzzNem0mHRm9rrkkUAXShYCOc=", + "dev": true + }, + "memorystream": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/memorystream/-/memorystream-0.3.1.tgz", + "integrity": "sha1-htcJCzDORV1j+64S3aUaR93K+bI=", + "dev": true + }, + "minimatch": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "dev": true, + "requires": { + "brace-expansion": "^1.1.7" + } + }, + "minimist": { + "version": "0.0.8", + "resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", + "dev": true + }, + "mkdirp": { + "version": "0.5.1", + "resolved": "http://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", + "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "dev": true, + "requires": { + "minimist": "0.0.8" + } + }, + "mocha": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/mocha/-/mocha-4.1.0.tgz", + "integrity": "sha512-0RVnjg1HJsXY2YFDoTNzcc1NKhYuXKRrBAG2gDygmJJA136Cs2QlRliZG1mA0ap7cuaT30mw16luAeln+4RiNA==", + "dev": true, + "requires": { + "browser-stdout": "1.3.0", + "commander": "2.11.0", + "debug": "3.1.0", + "diff": "3.3.1", + "escape-string-regexp": "1.0.5", + "glob": "7.1.2", + "growl": "1.10.3", + "he": "1.1.1", + "mkdirp": "0.5.1", + "supports-color": "4.4.0" + } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", + "dev": true + }, + "normalize-package-data": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.4.0.tgz", + "integrity": "sha512-9jjUFbTPfEy3R/ad/2oNbKtW9Hgovl5O1FvFWKkKblNXoN/Oou6+9+KKohPK13Yc3/TyunyWhJp6gvRNR/PPAw==", + "dev": true, + "requires": { + "hosted-git-info": "^2.1.4", + "is-builtin-module": "^1.0.0", + "semver": "2 || 3 || 4 || 5", + "validate-npm-package-license": "^3.0.1" + } + }, + "number-is-nan": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", + "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=", + "dev": true + }, + "once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "dev": true, + "requires": { + "wrappy": "1" + } + }, + "original-require": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/original-require/-/original-require-1.0.1.tgz", + "integrity": "sha1-DxMEcVhM0zURxew4yNWSE/msXiA=", + "dev": true + }, + "os-locale": { + "version": "1.4.0", + "resolved": "http://registry.npmjs.org/os-locale/-/os-locale-1.4.0.tgz", + "integrity": "sha1-IPnxeuKe00XoveWDsT0gCYA8FNk=", + "dev": true, + "requires": { + "lcid": "^1.0.0" + } + }, + "parse-json": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-2.2.0.tgz", + "integrity": "sha1-9ID0BDTvgHQfhGkJn43qGPVaTck=", + "dev": true, + "requires": { + "error-ex": "^1.2.0" + } + }, + "path-exists": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-2.1.0.tgz", + "integrity": "sha1-D+tsZPD8UY2adU3V77YscCJ2H0s=", + "dev": true, + "requires": { + "pinkie-promise": "^2.0.0" + } + }, + "path-is-absolute": { + "version": "1.0.1", + "resolved": "http://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", + "dev": true + }, + "path-type": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/path-type/-/path-type-1.1.0.tgz", + "integrity": "sha1-WcRPfuSR2nBNpBXaWkBwuk+P5EE=", + "dev": true, + "requires": { + "graceful-fs": "^4.1.2", + "pify": "^2.0.0", + "pinkie-promise": "^2.0.0" + } + }, "pathval": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.0.tgz", "integrity": "sha1-uULm1L3mUwBe9rcTYd74cn0GReA=", "dev": true }, + "pify": { + "version": "2.3.0", + "resolved": "http://registry.npmjs.org/pify/-/pify-2.3.0.tgz", + "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=", + "dev": true + }, + "pinkie": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/pinkie/-/pinkie-2.0.4.tgz", + "integrity": "sha1-clVrgM+g1IqXToDnckjoDtT3+HA=", + "dev": true + }, + "pinkie-promise": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/pinkie-promise/-/pinkie-promise-2.0.1.tgz", + "integrity": "sha1-ITXW36ejWMBprJsXh3YogihFD/o=", + "dev": true, + "requires": { + "pinkie": "^2.0.0" + } + }, + "read-pkg": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-1.1.0.tgz", + "integrity": "sha1-9f+qXs0pyzHAR0vKfXVra7KePyg=", + "dev": true, + "requires": { + "load-json-file": "^1.0.0", + "normalize-package-data": "^2.3.2", + "path-type": "^1.0.0" + } + }, + "read-pkg-up": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/read-pkg-up/-/read-pkg-up-1.0.1.tgz", + "integrity": "sha1-nWPBMnbAZZGNV/ACpX9AobZD+wI=", + "dev": true, + "requires": { + "find-up": "^1.0.0", + "read-pkg": "^1.0.0" + } + }, + "require-directory": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", + "integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I=", + "dev": true + }, + "require-from-string": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-1.2.1.tgz", + "integrity": "sha1-UpyczvJzgK3+yaL5ZbZJu+5jZBg=", + "dev": true + }, + "require-main-filename": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-1.0.1.tgz", + "integrity": "sha1-l/cXtp1IeE9fUmpsWqj/3aBVpNE=", + "dev": true + }, + "rimraf": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.2.tgz", + "integrity": "sha512-lreewLK/BlghmxtfH36YYVg1i8IAce4TI7oao75I1g245+6BctqTVQiBP3YUJ9C6DQOXJmkYR9X9fCLtCOJc5w==", + "dev": true, + "requires": { + "glob": "^7.0.5" + } + }, + "semver": { + "version": "5.6.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.6.0.tgz", + "integrity": "sha512-RS9R6R35NYgQn++fkDWaOmqGoj4Ek9gGs+DPxNUZKuwE183xjJroKvyo1IzVFeXvUrvmALy6FWD5xrdJT25gMg==", + "dev": true + }, + "set-blocking": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", + "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=", + "dev": true + }, + "solc": { + "version": "0.4.24", + "resolved": "https://registry.npmjs.org/solc/-/solc-0.4.24.tgz", + "integrity": "sha512-2xd7Cf1HeVwrIb6Bu1cwY2/TaLRodrppCq3l7rhLimFQgmxptXhTC3+/wesVLpB09F1A2kZgvbMOgH7wvhFnBQ==", + "dev": true, + "requires": { + "fs-extra": "^0.30.0", + "memorystream": "^0.3.1", + "require-from-string": "^1.1.0", + "semver": "^5.3.0", + "yargs": "^4.7.1" + } + }, + "spdx-correct": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-3.0.2.tgz", + "integrity": "sha512-q9hedtzyXHr5S0A1vEPoK/7l8NpfkFYTq6iCY+Pno2ZbdZR6WexZFtqeVGkGxW3TEJMN914Z55EnAGMmenlIQQ==", + "dev": true, + "requires": { + "spdx-expression-parse": "^3.0.0", + "spdx-license-ids": "^3.0.0" + } + }, + "spdx-exceptions": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/spdx-exceptions/-/spdx-exceptions-2.2.0.tgz", + "integrity": "sha512-2XQACfElKi9SlVb1CYadKDXvoajPgBVPn/gOQLrTvHdElaVhr7ZEbqJaRnJLVNeaI4cMEAgVCeBMKF6MWRDCRA==", + "dev": true + }, + "spdx-expression-parse": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/spdx-expression-parse/-/spdx-expression-parse-3.0.0.tgz", + "integrity": "sha512-Yg6D3XpRD4kkOmTpdgbUiEJFKghJH03fiC1OPll5h/0sO6neh2jqRDVHOQ4o/LMea0tgCkbMgea5ip/e+MkWyg==", + "dev": true, + "requires": { + "spdx-exceptions": "^2.1.0", + "spdx-license-ids": "^3.0.0" + } + }, + "spdx-license-ids": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.2.tgz", + "integrity": "sha512-qky9CVt0lVIECkEsYbNILVnPvycuEBkXoMFLRWsREkomQLevYhtRKC+R91a5TOAQ3bCMjikRwhyaRqj1VYatYg==", + "dev": true + }, + "string-width": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", + "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", + "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", + "resolved": "http://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", + "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "dev": true, + "requires": { + "ansi-regex": "^2.0.0" + } + }, + "strip-bom": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-2.0.0.tgz", + "integrity": "sha1-YhmoVhZSBJHzV4i9vxRHqZx+aw4=", + "dev": true, + "requires": { + "is-utf8": "^0.2.0" + } + }, + "supports-color": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.4.0.tgz", + "integrity": "sha512-rKC3+DyXWgK0ZLKwmRsrkyHVZAjNkfzeehuFWdGGcqGDTZFH73+RH6S/RDAAxl9GusSjZSUWYLmT9N5pzXFOXQ==", + "dev": true, + "requires": { + "has-flag": "^2.0.0" + } + }, + "truffle": { + "version": "4.1.14", + "resolved": "https://registry.npmjs.org/truffle/-/truffle-4.1.14.tgz", + "integrity": "sha512-e7tTLvKP3bN9dE7MagfWyFjy4ZgoEGbeujECy1me1ENBzbj/aO/+45gs72qsL3+3IkCNNcWNOJjjrm8BYZZNNg==", + "dev": true, + "requires": { + "mocha": "^4.1.0", + "original-require": "1.0.1", + "solc": "0.4.24" + } + }, "type-detect": { "version": "4.0.8", "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", "dev": true + }, + "validate-npm-package-license": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz", + "integrity": "sha512-DpKm2Ui/xN7/HQKCtpZxoRWBhZ9Z0kqtygG8XCgNQ8ZlDnxuQmWhj566j8fN4Cu3/JmbhsDo7fcAJq4s9h27Ew==", + "dev": true, + "requires": { + "spdx-correct": "^3.0.0", + "spdx-expression-parse": "^3.0.0" + } + }, + "which-module": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/which-module/-/which-module-1.0.0.tgz", + "integrity": "sha1-u6Y8qGGUiZT/MHc2CJ47lgJsKk8=", + "dev": true + }, + "window-size": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/window-size/-/window-size-0.2.0.tgz", + "integrity": "sha1-tDFbtCFKPXBY6+7okuE/ok2YsHU=", + "dev": true + }, + "wrap-ansi": { + "version": "2.1.0", + "resolved": "http://registry.npmjs.org/wrap-ansi/-/wrap-ansi-2.1.0.tgz", + "integrity": "sha1-2Pw9KE3QV5T+hJc8rs3Rz4JP3YU=", + "dev": true, + "requires": { + "string-width": "^1.0.1", + "strip-ansi": "^3.0.1" + } + }, + "wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", + "dev": true + }, + "y18n": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-3.2.1.tgz", + "integrity": "sha1-bRX7qITAhnnA136I53WegR4H+kE=", + "dev": true + }, + "yargs": { + "version": "4.8.1", + "resolved": "http://registry.npmjs.org/yargs/-/yargs-4.8.1.tgz", + "integrity": "sha1-wMQpJMpKqmsObaFznfshZDn53cA=", + "dev": true, + "requires": { + "cliui": "^3.2.0", + "decamelize": "^1.1.1", + "get-caller-file": "^1.0.1", + "lodash.assign": "^4.0.3", + "os-locale": "^1.4.0", + "read-pkg-up": "^1.0.1", + "require-directory": "^2.1.1", + "require-main-filename": "^1.0.1", + "set-blocking": "^2.0.0", + "string-width": "^1.0.1", + "which-module": "^1.0.0", + "window-size": "^0.2.0", + "y18n": "^3.2.1", + "yargs-parser": "^2.4.1" + } + }, + "yargs-parser": { + "version": "2.4.1", + "resolved": "http://registry.npmjs.org/yargs-parser/-/yargs-parser-2.4.1.tgz", + "integrity": "sha1-hVaN488VD/SfpRgl8DqMiA3cxcQ=", + "dev": true, + "requires": { + "camelcase": "^3.0.0", + "lodash.assign": "^4.0.6" + } } } } diff --git a/package.json b/package.json index 3a66185..0e95224 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "test": "test" }, "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "./node_modules/.bin/truffle test", + "compile": "./node_modules/.bin/truffle compile" }, "repository": { "type": "git", @@ -17,6 +18,7 @@ "author": "", "license": "ISC", "devDependencies": { + "truffle": "^4.1.14", "chai": "^4.2.0" }, "dependencies": {} From 8dfab26cdaefa58d80955cd8f813fa806f79c7bc Mon Sep 17 00:00:00 2001 From: CodingYourLife Date: Thu, 29 Nov 2018 18:27:35 +0100 Subject: [PATCH 14/16] increased all pragmas to newer version --- contracts/DSMath.sol | 2 +- contracts/Migrations.sol | 32 +++++++++++++++--------------- contracts/ds-test/DSMathTest.t.sol | 2 +- contracts/ds-test/DSTest.sol | 2 +- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/contracts/DSMath.sol b/contracts/DSMath.sol index 4c0035b..a40c7f3 100644 --- a/contracts/DSMath.sol +++ b/contracts/DSMath.sol @@ -13,7 +13,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -pragma solidity >0.4.13; +pragma solidity 0.4.24; contract DSMath { function add(uint x, uint y) public pure returns (uint z) { diff --git a/contracts/Migrations.sol b/contracts/Migrations.sol index c4efb65..69c127d 100644 --- a/contracts/Migrations.sol +++ b/contracts/Migrations.sol @@ -1,23 +1,23 @@ -pragma solidity ^0.4.23; +pragma solidity 0.4.24; contract Migrations { - address public owner; - uint public last_completed_migration; + address public owner; + uint public last_completed_migration; - constructor() public { - owner = msg.sender; - } + constructor() public { + owner = msg.sender; + } - modifier restricted() { - if (msg.sender == owner) _; - } + modifier restricted() { + if (msg.sender == owner) _; + } - function setCompleted(uint completed) public restricted { - last_completed_migration = completed; - } + function setCompleted(uint completed) public restricted { + last_completed_migration = completed; + } - function upgrade(address new_address) public restricted { - Migrations upgraded = Migrations(new_address); - upgraded.setCompleted(last_completed_migration); - } + function upgrade(address new_address) public restricted { + Migrations upgraded = Migrations(new_address); + upgraded.setCompleted(last_completed_migration); + } } diff --git a/contracts/ds-test/DSMathTest.t.sol b/contracts/ds-test/DSMathTest.t.sol index 5324550..4c00968 100644 --- a/contracts/ds-test/DSMathTest.t.sol +++ b/contracts/ds-test/DSMathTest.t.sol @@ -11,7 +11,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -pragma solidity >0.4.13; +pragma solidity 0.4.24; import "./DSTest.sol"; import "../DSMath.sol"; diff --git a/contracts/ds-test/DSTest.sol b/contracts/ds-test/DSTest.sol index cb61bb8..e3b7997 100644 --- a/contracts/ds-test/DSTest.sol +++ b/contracts/ds-test/DSTest.sol @@ -11,7 +11,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -pragma solidity >0.4.23; +pragma solidity 0.4.24; contract DSTest { event eventListener (address target, bool exact); From df46ff794a7e47b051392c38519f2ce5b98b936e Mon Sep 17 00:00:00 2001 From: CodingYourLife Date: Thu, 29 Nov 2018 18:28:05 +0100 Subject: [PATCH 15/16] fake async await support added to migration --- migrations/1_initial_migration.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/migrations/1_initial_migration.js b/migrations/1_initial_migration.js index 4d5f3f9..2847679 100644 --- a/migrations/1_initial_migration.js +++ b/migrations/1_initial_migration.js @@ -1,5 +1,7 @@ var Migrations = artifacts.require("./Migrations.sol"); module.exports = function(deployer) { - deployer.deploy(Migrations); + deployer.then(async () => { //fake async await support: https://github.com/trufflesuite/truffle/issues/501 + await deployer.deploy(Migrations) + }) }; From 3e8583b79ba4b10f2572dbb880ec68cf765be375 Mon Sep 17 00:00:00 2001 From: CodingYourLife Date: Thu, 29 Nov 2018 18:29:45 +0100 Subject: [PATCH 16/16] created DSMathL library and used it in DSMath. in custom project just DSMathL can be copied and used via using exactly like in DSMath.sol contract. tests now all work as expected --- contracts/DSMath.sol | 76 ++++++++++++---------------- contracts/DSMathL.sol | 84 +++++++++++++++++++++++++++++++ migrations/2_initial_migration.js | 14 ++++++ 3 files changed, 131 insertions(+), 43 deletions(-) create mode 100644 contracts/DSMathL.sol create mode 100644 migrations/2_initial_migration.js diff --git a/contracts/DSMath.sol b/contracts/DSMath.sol index a40c7f3..5a02943 100644 --- a/contracts/DSMath.sol +++ b/contracts/DSMath.sol @@ -15,70 +15,60 @@ pragma solidity 0.4.24; +import "./DSMathL.sol"; + contract DSMath { + using DSMathL for uint; + using DSMathL for int; + + uint constant WAD = 10 ** 18; + uint constant RAY = 10 ** 27; + function add(uint x, uint y) public pure returns (uint z) { - require((z = x + y) >= x, "ds-math-add-overflow"); + return x.ds_add(y); } + function sub(uint x, uint y) public pure returns (uint z) { - require((z = x - y) <= x, "ds-math-sub-underflow"); + return x.ds_sub(y); } + function mul(uint x, uint y) public pure returns (uint z) { - require(y == 0 || (z = x * y) / y == x, "ds-math-mul-overflow"); + return x.ds_mul(y); } function min(uint x, uint y) public pure returns (uint z) { - return x <= y ? x : y; + return x.ds_min(y); } + function max(uint x, uint y) public pure returns (uint z) { - return x >= y ? x : y; + return x.ds_max(y); } + function imin(int x, int y) public pure returns (int z) { - return x <= y ? x : y; + return x.ds_imin(y); } + function imax(int x, int y) public pure returns (int z) { - return x >= y ? x : y; + return x.ds_imax(y); } - uint constant WAD = 10 ** 18; - uint constant RAY = 10 ** 27; - - function wmul(uint x, uint y) public pure returns (uint z) { - z = add(mul(x, y), WAD / 2) / WAD; + function wmul(uint x, uint y) public pure returns (uint) { + return x.ds_wmul(y); } - function rmul(uint x, uint y) public pure returns (uint z) { - z = add(mul(x, y), RAY / 2) / RAY; + + function rmul(uint x, uint y) public pure returns (uint) { + return x.ds_rmul(y); } - function wdiv(uint x, uint y) public pure returns (uint z) { - z = add(mul(x, WAD), y / 2) / y; + + function wdiv(uint x, uint y) public pure returns (uint) { + return x.ds_wdiv(y); } - function rdiv(uint x, uint y) public pure returns (uint z) { - z = add(mul(x, RAY), y / 2) / y; + + function rdiv(uint x, uint y) public pure returns (uint) { + return x.ds_rdiv(y); } - // This famous algorithm is called "exponentiation by squaring" - // and calculates x^n with x as fixed-point and n as regular unsigned. - // - // It's O(log n), instead of O(n) for naive repeated multiplication. - // - // These facts are why it works: - // - // If n is even, then x^n = (x^2)^(n/2). - // If n is odd, then x^n = x * x^(n-1), - // and applying the equation for even x gives - // x^n = x * (x^2)^((n-1) / 2). - // - // Also, EVM division is flooring and - // floor[(n-1) / 2] = floor[n / 2]. - // - function rpow(uint x, uint n) public pure returns (uint z) { - z = n % 2 != 0 ? x : RAY; - - for (n /= 2; n != 0; n /= 2) { - x = rmul(x, x); - - if (n % 2 != 0) { - z = rmul(z, x); - } - } + function rpow(uint x, uint n) public pure returns (uint) { + return x.ds_rpow(n); } } diff --git a/contracts/DSMathL.sol b/contracts/DSMathL.sol new file mode 100644 index 0000000..8fd31c6 --- /dev/null +++ b/contracts/DSMathL.sol @@ -0,0 +1,84 @@ +/// math.sol -- mixin for inline numerical wizardry + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.4.24; + +library DSMathL { + function ds_add(uint x, uint y) public pure returns (uint z) { + require((z = x + y) >= x, "ds-math-add-overflow"); + } + function ds_sub(uint x, uint y) public pure returns (uint z) { + require((z = x - y) <= x, "ds-math-sub-underflow"); + } + function ds_mul(uint x, uint y) public pure returns (uint z) { + require(y == 0 || (z = x * y) / y == x, "ds-math-mul-overflow"); + } + + function ds_min(uint x, uint y) public pure returns (uint z) { + return x <= y ? x : y; + } + function ds_max(uint x, uint y) public pure returns (uint z) { + return x >= y ? x : y; + } + function ds_imin(int x, int y) public pure returns (int z) { + return x <= y ? x : y; + } + function ds_imax(int x, int y) public pure returns (int z) { + return x >= y ? x : y; + } + + uint constant WAD = 10 ** 18; + uint constant RAY = 10 ** 27; + + function ds_wmul(uint x, uint y) public pure returns (uint z) { + z = ds_add(ds_mul(x, y), WAD / 2) / WAD; + } + function ds_rmul(uint x, uint y) public pure returns (uint z) { + z = ds_add(ds_mul(x, y), RAY / 2) / RAY; + } + function ds_wdiv(uint x, uint y) public pure returns (uint z) { + z = ds_add(ds_mul(x, WAD), y / 2) / y; + } + function ds_rdiv(uint x, uint y) public pure returns (uint z) { + z = ds_add(ds_mul(x, RAY), y / 2) / y; + } + + // This famous algorithm is called "exponentiation by squaring" + // and calculates x^n with x as fixed-point and n as regular unsigned. + // + // It's O(log n), instead of O(n) for naive repeated multiplication. + // + // These facts are why it works: + // + // If n is even, then x^n = (x^2)^(n/2). + // If n is odd, then x^n = x * x^(n-1), + // and applying the equation for even x gives + // x^n = x * (x^2)^((n-1) / 2). + // + // Also, EVM division is flooring and + // floor[(n-1) / 2] = floor[n / 2]. + // + function ds_rpow(uint x, uint n) public pure returns (uint z) { + z = n % 2 != 0 ? x : RAY; + + for (n /= 2; n != 0; n /= 2) { + x = ds_rmul(x, x); + + if (n % 2 != 0) { + z = ds_rmul(z, x); + } + } + } +} diff --git a/migrations/2_initial_migration.js b/migrations/2_initial_migration.js new file mode 100644 index 0000000..8797000 --- /dev/null +++ b/migrations/2_initial_migration.js @@ -0,0 +1,14 @@ +var DSMathL = artifacts.require("./DSMathL.sol"); +var DSMath = artifacts.require("./DSMath.sol"); +var DSMathTest = artifacts.require("./DSMathTest.sol"); + +module.exports = function(deployer) { + deployer.then(async () => { //fake async await support: https://github.com/trufflesuite/truffle/issues/501 + //deploy library + await deployer.deploy(DSMathL) + + //link library + await deployer.link(DSMathL, DSMath) + await deployer.link(DSMathL, DSMathTest) + }) +}