diff --git a/apps/address-book/contracts/misc/Migrations.sol b/apps/address-book/contracts/misc/Migrations.sol deleted file mode 100644 index a09cc1036..000000000 --- a/apps/address-book/contracts/misc/Migrations.sol +++ /dev/null @@ -1,24 +0,0 @@ -pragma solidity ^0.4.24; - - -contract Migrations { - address public owner; - uint public lastCompletedMigration; - - modifier restricted() { - if (msg.sender == owner) _; // solium-disable-line lbrace - } - - constructor() public { - owner = msg.sender; - } - - function setCompleted(uint completed) public restricted { - lastCompletedMigration = completed; - } - - function upgrade(address newAddress) public restricted { - Migrations upgraded = Migrations(newAddress); - upgraded.setCompleted(lastCompletedMigration); - } -} diff --git a/apps/address-book/contracts/test/Imports.sol b/apps/address-book/contracts/test/Imports.sol new file mode 100644 index 000000000..0e06b806a --- /dev/null +++ b/apps/address-book/contracts/test/Imports.sol @@ -0,0 +1,8 @@ +pragma solidity ^0.4.24; +// HACK to workaround truffle artifact loading on dependencies +import "@aragon/os/contracts/acl/ACL.sol"; +import "@aragon/os/contracts/factory/DAOFactory.sol"; + + + // solium-disable-next-line no-empty-blocks +contract Imports {} \ No newline at end of file diff --git a/apps/address-book/contracts/test/TestImports.sol b/apps/address-book/contracts/test/TestImports.sol deleted file mode 100644 index cf6036215..000000000 --- a/apps/address-book/contracts/test/TestImports.sol +++ /dev/null @@ -1,29 +0,0 @@ -pragma solidity ^0.4.24; - -import "@tps/test-helpers/contracts/acl/ACL.sol"; -import "@tps/test-helpers/contracts/kernel/Kernel.sol"; -import "@tps/test-helpers/contracts/factory/DAOFactory.sol"; -import "@tps/test-helpers/contracts/factory/EVMScriptRegistryFactory.sol"; - -import "@tps/test-helpers/contracts/lib/misc/Migrations.sol"; -import "@aragon/apps-shared-minime/contracts/MiniMeToken.sol"; -import "@tps/test-helpers/contracts/lib/bounties/StandardBounties.sol"; - -// You might think this file is a bit odd, but let me explain. -// We only use some contracts in our tests, which means Truffle -// will not compile it for us, because it is from an external -// dependency. -// -// We are now left with three options: -// - Copy/paste these contracts -// - Run the tests with `truffle compile --all` on -// - Or trick Truffle by claiming we use it in a Solidity test -// -// You know which one I went for. - - -contract TestImports { - constructor() public { - // to avoid lint error - } -} \ No newline at end of file diff --git a/apps/address-book/migrations/.gitkeep b/apps/address-book/migrations/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/apps/address-book/migrations/1_initial_migration.js b/apps/address-book/migrations/1_initial_migration.js deleted file mode 100644 index 42968952f..000000000 --- a/apps/address-book/migrations/1_initial_migration.js +++ /dev/null @@ -1,5 +0,0 @@ -var Migrations = artifacts.require('./Migrations.sol') - -module.exports = function (deployer) { - deployer.deploy(Migrations) -} diff --git a/apps/address-book/migrations/2_deploy_contracts.js b/apps/address-book/migrations/2_deploy_contracts.js deleted file mode 100644 index c978afdfd..000000000 --- a/apps/address-book/migrations/2_deploy_contracts.js +++ /dev/null @@ -1,5 +0,0 @@ -var AddressBook = artifacts.require('./AddressBook.sol') - -module.exports = function (deployer) { - deployer.deploy(AddressBook) -} diff --git a/apps/address-book/package.json b/apps/address-book/package.json index 6b1ac289c..e20a49d03 100644 --- a/apps/address-book/package.json +++ b/apps/address-book/package.json @@ -25,7 +25,7 @@ "start": "aragon run", "sync-assets": "copy-aragon-ui-assets -n aragon-ui ./dist && npm run copy-public-assets", "test:gas": "GAS_REPORTER=true npm test", - "test": "TRUFFLE_TEST=true npm run ganache-cli:test" + "test": "cross-env TRUFFLE_TEST=true npm run ganache-cli:test" }, "dependencies": { "@aragon/api": "1.1.0", @@ -45,6 +45,7 @@ "@babel/preset-react": "^7.0.0", "babel-eslint": "^10.0.1", "babel-plugin-styled-components": "^1.10.0", + "cross-env": "^5.2.0", "eslint": "^5.16.0", "eslint-config-prettier": "^4.3.0", "eslint-config-standard": "^12.0.0", diff --git a/apps/address-book/test/Spoof.sol b/apps/address-book/test/Spoof.sol deleted file mode 100644 index 131d9f7f8..000000000 --- a/apps/address-book/test/Spoof.sol +++ /dev/null @@ -1,27 +0,0 @@ -pragma solidity ^0.4.24; - -import "@tps/test-helpers/contracts/factory/EVMScriptRegistryFactory.sol"; -import "@tps/test-helpers/contracts/factory/DAOFactory.sol"; -import "@tps/test-helpers/contracts/acl/ACL.sol"; -import "@aragon/apps-shared-minime/contracts/MiniMeToken.sol"; - -// You might think this file is a bit odd, but let me explain. -// We only use the MiniMeToken contract in our tests, which -// means Truffle will not compile it for us, because it is -// from an external dependency. -// -// We are now left with three options: -// - Copy/paste all dependency contracts -// - Run the tests with `truffle compile --all` on -// - Or trick Truffle by claiming we use it in a Solidity test -// -// You know which one I went for. -// -- Somebody from Aragon (probably Jorge?) - -// When I first saw this contract I audibly laughed out loud. -// Glad to get to use this janky hack for myself XD - - -contract Spoof { // solium-disable-line no-empty-blocks - // ... -} \ No newline at end of file diff --git a/apps/address-book/test/address-book.js b/apps/address-book/test/address-book.test.js similarity index 90% rename from apps/address-book/test/address-book.js rename to apps/address-book/test/address-book.test.js index 9547af6ca..3af18cec0 100644 --- a/apps/address-book/test/address-book.js +++ b/apps/address-book/test/address-book.test.js @@ -1,9 +1,7 @@ -const { - ACL, - DAOFactory, - EVMScriptRegistryFactory, - Kernel, -} = require('@tps/test-helpers/artifacts') +const ACL = artifacts.require('ACL') +const DAOFactory = artifacts.require('DAOFactory') +const EVMScriptRegistryFactory = artifacts.require('EVMScriptRegistryFactory') +const Kernel = artifacts.require('Kernel') const AddressBook = artifacts.require('AddressBook') @@ -117,7 +115,11 @@ contract('AddressBook App', accounts => { }) it('should return a zero-address when getting non-existant entry', async () => { const [ entryAddress, name, entryType ] = await app.getEntry(jeanluc) - assert.strictEqual(entryAddress, '0x0000000000000000000000000000000000000000', 'address should be 0x0') + assert.strictEqual( + entryAddress, + '0x0000000000000000000000000000000000000000', + 'address should be 0x0' + ) assert.strictEqual(name, '', 'name should be empty') assert.strictEqual(entryType, '', 'entry Type should be empty') }) diff --git a/apps/allocations/contracts/misc/Migrations.sol b/apps/allocations/contracts/misc/Migrations.sol deleted file mode 100644 index 11eadf51d..000000000 --- a/apps/allocations/contracts/misc/Migrations.sol +++ /dev/null @@ -1,25 +0,0 @@ -pragma solidity ^0.4.24; - - -contract Migrations { - address public owner; - uint public lastCompletedMigration; - - modifier restricted() { - if (msg.sender == owner) - _; - } - - constructor() public { - owner = msg.sender; - } - - function setCompleted(uint completed) public restricted { - lastCompletedMigration = completed; - } - - function upgrade(address newAddress) public restricted { - Migrations upgraded = Migrations(newAddress); - upgraded.setCompleted(lastCompletedMigration); - } -} diff --git a/apps/allocations/contracts/test/Imports.sol b/apps/allocations/contracts/test/Imports.sol new file mode 100644 index 000000000..09229f117 --- /dev/null +++ b/apps/allocations/contracts/test/Imports.sol @@ -0,0 +1,9 @@ +pragma solidity ^0.4.24; +// HACK to workaround truffle artifact loading on dependencies +import "@aragon/os/contracts/acl/ACL.sol"; +import "@aragon/os/contracts/factory/DAOFactory.sol"; +import "@aragon/apps-shared-minime/contracts/MiniMeToken.sol"; + + + // solium-disable-next-line no-empty-blocks +contract Imports {} \ No newline at end of file diff --git a/apps/allocations/contracts/test/TestImports.sol b/apps/allocations/contracts/test/TestImports.sol deleted file mode 100644 index c314d4252..000000000 --- a/apps/allocations/contracts/test/TestImports.sol +++ /dev/null @@ -1,27 +0,0 @@ -pragma solidity ^0.4.24; - -import "@tps/test-helpers/contracts/factory/EVMScriptRegistryFactory.sol"; -import "@tps/test-helpers/contracts/factory/DAOFactory.sol"; -import "@tps/test-helpers/contracts/acl/ACL.sol"; -import "@aragon/apps-shared-minime/contracts/MiniMeToken.sol"; - -// You might think this file is a bit odd, but let me explain. -// We only use the MiniMeToken contract in our tests, which -// means Truffle will not compile it for us, because it is -// from an external dependency. -// -// We are now left with three options: -// - Copy/paste all dependency contracts -// - Run the tests with `truffle compile --all` on -// - Or trick Truffle by claiming we use it in a Solidity test -// -// You know which one I went for. -// -- Somebody from Aragon (probably Jorge?) - -// When I first saw this contract I audibly laughed out loud. -// Glad to get to use this janky hack for myself XD - - -// solium-disable-next-line no-empty-blocks -contract TestImports { -} \ No newline at end of file diff --git a/apps/allocations/migrations/.gitkeep b/apps/allocations/migrations/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/apps/allocations/migrations/1_initial_migration.js b/apps/allocations/migrations/1_initial_migration.js deleted file mode 100644 index 42968952f..000000000 --- a/apps/allocations/migrations/1_initial_migration.js +++ /dev/null @@ -1,5 +0,0 @@ -var Migrations = artifacts.require('./Migrations.sol') - -module.exports = function (deployer) { - deployer.deploy(Migrations) -} diff --git a/apps/allocations/migrations/2_deploy_contracts.js b/apps/allocations/migrations/2_deploy_contracts.js deleted file mode 100644 index fa91052bb..000000000 --- a/apps/allocations/migrations/2_deploy_contracts.js +++ /dev/null @@ -1,5 +0,0 @@ -var Allocations = artifacts.require('./Allocations.sol') - -module.exports = function(deployer) { - deployer.deploy(Allocations) -} diff --git a/apps/allocations/package.json b/apps/allocations/package.json index 0e13288a9..597d19132 100644 --- a/apps/allocations/package.json +++ b/apps/allocations/package.json @@ -30,6 +30,7 @@ "dependencies": { "@aragon/api": "1.1.0", "@aragon/api-react": "1.0.0-beta.2", + "@aragon/apps-shared-minime": "^1.0.1", "@aragon/apps-vault": "^4.1.0", "@aragon/ui": "0.33.0", "@babel/polyfill": "^7.2.5", diff --git a/apps/allocations/test/Spoof.sol b/apps/allocations/test/Spoof.sol deleted file mode 100644 index da2ca04a1..000000000 --- a/apps/allocations/test/Spoof.sol +++ /dev/null @@ -1,28 +0,0 @@ -pragma solidity ^0.4.24; - -import "@tps/test-helpers/contracts/factory/EVMScriptRegistryFactory.sol"; -import "@tps/test-helpers/contracts/factory/DAOFactory.sol"; -import "@tps/test-helpers/contracts/acl/ACL.sol"; -import "@aragon/apps-shared-minime/contracts/MiniMeToken.sol"; -import "@tps/test-helpers/contracts/lib/bounties/StandardBounties.sol"; - -// You might think this file is a bit odd, but let me explain. -// We only use the MiniMeToken contract in our tests, which -// means Truffle will not compile it for us, because it is -// from an external dependency. -// -// We are now left with three options: -// - Copy/paste all dependency contracts -// - Run the tests with `truffle compile --all` on -// - Or trick Truffle by claiming we use it in a Solidity test -// -// You know which one I went for. -// -- Somebody from Aragon (probably Jorge?) - -// When I first saw this contract I audibly laughed out loud. -// Glad to get to use this janky hack for myself XD - -// solium-disable-next-line no-empty-blocks -contract Spoof { - // ... -} \ No newline at end of file diff --git a/apps/allocations/test/allocations.test.js b/apps/allocations/test/allocations.test.js index 8515605c8..be3cc5a4b 100644 --- a/apps/allocations/test/allocations.test.js +++ b/apps/allocations/test/allocations.test.js @@ -1,18 +1,16 @@ -/* global artifact, ... */ -const { - ACL, - DAOFactory, - EVMScriptRegistryFactory, - Kernel, - MiniMeToken -} = require('@tps/test-helpers/artifacts') +const ACL = artifacts.require('ACL') +const DAOFactory = artifacts.require('DAOFactory') +const EVMScriptRegistryFactory = artifacts.require('EVMScriptRegistryFactory') +const Kernel = artifacts.require('Kernel') +const MiniMeToken = artifacts.require('MiniMeToken') const Allocations = artifacts.require('Allocations') +const Vault = artifacts.require('Vault') const { assertRevert } = require('@tps/test-helpers/assertThrow') -const timetravel = require('@tps/test-helpers/timeTravel')(web3) -const Vault = artifacts.require('Vault') +const timeTravel = require('@tps/test-helpers/timeTravel')(web3) const BigNumber = require('bignumber.js') + const NULL_ADDRESS = '0x00' // const createdPayoutId = receipt => @@ -86,8 +84,16 @@ contract('Allocations App', accounts => { { from: root } ) vaultBase = await Vault.new() - const receipt1 = await dao.newAppInstance('0x5678', vaultBase.address, '0x', false, { from: root }) - vault = Vault.at(receipt1.logs.filter(l => l.event == 'NewAppProxy')[0].args.proxy) + const receipt1 = await dao.newAppInstance( + '0x5678', + vaultBase.address, + '0x', + false, + { from: root } + ) + vault = Vault.at( + receipt1.logs.filter(l => l.event == 'NewAppProxy')[0].args.proxy + ) await vault.initialize() await acl.createPermission( app.address, @@ -97,7 +103,7 @@ contract('Allocations App', accounts => { { from: root } ) - await app.initialize( 0x0, vault.address, { from: accounts[0] }) + await app.initialize(0x0, vault.address, { from: accounts[0] }) }) context('app creation and funded Payout', () => { @@ -115,13 +121,21 @@ contract('Allocations App', accounts => { token before(async () => { - token = await MiniMeToken.new(NULL_ADDRESS, NULL_ADDRESS, 0, 'one', 18, 'one', true) // empty parameters minime + token = await MiniMeToken.new( + NULL_ADDRESS, + NULL_ADDRESS, + 0, + 'one', + 18, + 'one', + true + ) // empty parameters minime bobafettInitialBalance = await web3.eth.getBalance(bobafett) dengarInitialBalance = await web3.eth.getBalance(dengar) bosskInitialBalance = await web3.eth.getBalance(bossk) candidateAddresses = [ bobafett, dengar, bossk ] accountId = (await app.newAccount( - 'Fett\'s vett', + 'Fett\'s vett' )).logs[0].args.accountId.toNumber() await app.fund(accountId, { @@ -174,7 +188,11 @@ contract('Allocations App', accounts => { it('can create a new Account', async () => { accountMembers = await app.getAccount(accountId) - assert.equal(accountMembers[1], 'Fett\'s vett', 'Payout metadata incorrect') + assert.equal( + accountMembers[1], + 'Fett\'s vett', + 'Payout metadata incorrect' + ) }) it('sets the distribution (eth)', async () => { @@ -227,22 +245,41 @@ contract('Allocations App', accounts => { }) it('retrieves payout info details (eth)', async () => { - const payoutInfo = await app.getPayout(accountId,ethPayoutId) - assert.strictEqual(payoutInfo[0].toNumber(), 1e16, 'payout amount incorrect') + const payoutInfo = await app.getPayout(accountId, ethPayoutId) + assert.strictEqual( + payoutInfo[0].toNumber(), + 1e16, + 'payout amount incorrect' + ) assert.strictEqual(payoutInfo[1], false, 'payout Should not be recurring') - assert.isAbove(payoutInfo[2].toNumber(), 0, 'recurring payout start time incorrect') - assert.strictEqual(payoutInfo[3].toNumber(), 0, 'recurring payout period length incorrect') + assert.isAbove( + payoutInfo[2].toNumber(), + 0, + 'recurring payout start time incorrect' + ) + assert.strictEqual( + payoutInfo[3].toNumber(), + 0, + 'recurring payout period length incorrect' + ) }) - it('retrieves payout description', async () =>{ - const payoutDescription = await app.getPayoutDescription(accountId,ethPayoutId) - assert.strictEqual(payoutDescription, 'ETH description', 'Payout description incorrectly stored') + it('retrieves payout description', async () => { + const payoutDescription = await app.getPayoutDescription( + accountId, + ethPayoutId + ) + assert.strictEqual( + payoutDescription, + 'ETH description', + 'Payout description incorrectly stored' + ) }) it('sets the distribution (token)', async () => { const candidateArrayLength = (await app.getNumberOfCandidates( accountId, - tokenPayoutId, + tokenPayoutId )).toNumber() let storedSupport = [] let supportVal @@ -273,17 +310,26 @@ contract('Allocations App', accounts => { const bosskBalance = await token.balanceOf(bossk) assert.equal( bobafettBalance.toNumber(), - BigNumber(25e18).times(supports[0]).div(totalsupport).toNumber(), + BigNumber(25e18) + .times(supports[0]) + .div(totalsupport) + .toNumber(), 'boba fett token balance inccorrect' ) assert.equal( dengarBalance.toNumber(), - BigNumber(25e18).times(supports[1]).div(totalsupport).toNumber(), + BigNumber(25e18) + .times(supports[1]) + .div(totalsupport) + .toNumber(), 'dengar token balance inccorrect' ) assert.equal( bosskBalance.toNumber(), - BigNumber(25e18).times(supports[2]).div(totalsupport).toNumber(), + BigNumber(25e18) + .times(supports[2]) + .div(totalsupport) + .toNumber(), 'bossk token balance inccorrect' ) }) @@ -293,15 +339,14 @@ contract('Allocations App', accounts => { accountAddress1 = account1Info1[2] accountId2 = (await app.newAccount( - 'Fett\'s new ship', + 'Fett\'s new ship' )).logs[0].args.accountId.toNumber() await app.fund(accountId2, { from: empire, - value: web3.toWei(1.00, 'ether'), + value: web3.toWei(1.0, 'ether'), }) - testCandidates = [ ...candidateAddresses, accountAddress1 ] supports = [ 500, 200, 150, 150 ] totalsupport = 1000 @@ -317,8 +362,8 @@ contract('Allocations App', accounts => { accountId2, false, 0, - web3.toWei(1.00, 'ether'), - 0x0, + web3.toWei(1.0, 'ether'), + 0x0 )).logs[0].args.payoutId.toNumber() const account1Info2 = await app.getAccount(accountId) @@ -327,7 +372,6 @@ contract('Allocations App', accounts => { web3.toWei(0.15, 'ether'), 'account balance difference doesn\'t match transferred amount' ) - }) it('does not transfer tokens to other allocations accounts', async () => { @@ -335,7 +379,7 @@ contract('Allocations App', accounts => { accountAddress1 = account1Info1[2] accountId3 = (await app.newAccount( - 'Fett\'s new ship', + 'Fett\'s new ship' )).logs[0].args.accountId.toNumber() await token.generateTokens(root, 25e18) @@ -343,7 +387,6 @@ contract('Allocations App', accounts => { account1Balance1 = await token.balanceOf(account1Info1[2]) - testCandidates = [ ...candidateAddresses, accountAddress1 ] supports = [ 500, 200, 150, 150 ] totalsupport = 1000 @@ -359,8 +402,8 @@ contract('Allocations App', accounts => { accountId3, false, 0, - web3.toWei(1.00, 'ether'), - token.address, + web3.toWei(1.0, 'ether'), + token.address )).logs[0].args.payoutId.toNumber() const account1Info2 = await app.getAccount(accountId) @@ -371,14 +414,16 @@ contract('Allocations App', accounts => { 0, 'account balance difference doesn\'t match transferred amount' ) - - }) it('can fund account via proxy address', async () => { const account1Info1 = await app.getAccount(accountId) const accountAddress1 = account1Info1[2] - await web3.eth.sendTransaction({ from: empire, to: accountAddress1, value: web3.toWei(1.00, 'ether'), }) + await web3.eth.sendTransaction({ + from: empire, + to: accountAddress1, + value: web3.toWei(1.0, 'ether'), + }) const account1Info2 = await app.getAccount(accountId) assert.strictEqual( account1Info2[0].sub(account1Info1[0]).toString(), @@ -390,7 +435,7 @@ contract('Allocations App', accounts => { it('cannot execute more than once if non-recurring', async () => { await app.fund(accountId, { from: empire, - value: web3.toWei(1.00, 'ether'), + value: web3.toWei(1.0, 'ether'), }) return assertRevert(async () => { await app.runPayout(accountId, ethPayoutId) @@ -400,7 +445,7 @@ contract('Allocations App', accounts => { context('invalid workflows', () => { before(async () => { accountId = (await app.newAccount( - 'Fett\'s vett', + 'Fett\'s vett' )).logs[0].args.accountId.toNumber() }) @@ -468,7 +513,7 @@ contract('Allocations App', accounts => { bosskInitialBalance = await web3.eth.getBalance(bossk) candidateAddresses = [ bobafett, dengar, bossk ] accountId = (await app.newAccount( - 'Fett\'s auto warranty', + 'Fett\'s auto warranty' )).logs[0].args.accountId.toNumber() }) @@ -495,7 +540,7 @@ contract('Allocations App', accounts => { 86300, web3.toWei(0.01, 'ether'), 0x0, - { from: empire, } + { from: empire } ) }) }) @@ -522,7 +567,7 @@ contract('Allocations App', accounts => { web3.toWei(0.01, 'ether'), 0x0 )).logs[0].args.payoutId.toNumber() - timetravel(86500) + timeTravel(86500) await app.runPayout(accountId, payoutId) const bobafettBalance = await web3.eth.getBalance(bobafett) @@ -548,7 +593,7 @@ contract('Allocations App', accounts => { from: empire, value: web3.toWei(0.01, 'ether'), }) - timetravel(43200) + timeTravel(43200) return assertRevert(async () => { await app.runPayout(accountId, payoutId) }) diff --git a/apps/dot-voting/contracts/DotVoting.sol b/apps/dot-voting/contracts/DotVoting.sol index b2f958075..c93a7f760 100644 --- a/apps/dot-voting/contracts/DotVoting.sol +++ b/apps/dot-voting/contracts/DotVoting.sol @@ -1,21 +1,15 @@ pragma solidity ^0.4.24; -import "@aragon/os/contracts/apps/AragonApp.sol"; - import "@aragon/apps-shared-minime/contracts/MiniMeToken.sol"; - -import "@tps/apps-address-book/contracts/AddressBook.sol"; - +import "@aragon/os/contracts/apps/AragonApp.sol"; +import "@aragon/os/contracts/common/IForwarder.sol"; import "@aragon/os/contracts/lib/math/SafeMath.sol"; - import "@aragon/os/contracts/lib/math/SafeMath64.sol"; -import "@tps/test-helpers/contracts/evmscript/ScriptHelpers.sol"; - +import "@tps/apps-address-book/contracts/AddressBook.sol"; -import "@tps/test-helpers/contracts/common/IForwarder.sol"; +import "./ScriptHelpers.sol"; -import "@tps/test-helpers/contracts/lib/misc/Migrations.sol"; /******************************************************************************* diff --git a/apps/shared/test-helpers/contracts/evmscript/ScriptHelpers.sol b/apps/dot-voting/contracts/ScriptHelpers.sol similarity index 99% rename from apps/shared/test-helpers/contracts/evmscript/ScriptHelpers.sol rename to apps/dot-voting/contracts/ScriptHelpers.sol index a4c44afc2..9cacd4b2d 100644 --- a/apps/shared/test-helpers/contracts/evmscript/ScriptHelpers.sol +++ b/apps/dot-voting/contracts/ScriptHelpers.sol @@ -2,7 +2,7 @@ * SPDX-License-Identitifer: MIT */ -pragma solidity ^0.4.18; +pragma solidity ^0.4.24; library ScriptHelpers { diff --git a/apps/dot-voting/contracts/test/Imports.sol b/apps/dot-voting/contracts/test/Imports.sol new file mode 100644 index 000000000..0e06b806a --- /dev/null +++ b/apps/dot-voting/contracts/test/Imports.sol @@ -0,0 +1,8 @@ +pragma solidity ^0.4.24; +// HACK to workaround truffle artifact loading on dependencies +import "@aragon/os/contracts/acl/ACL.sol"; +import "@aragon/os/contracts/factory/DAOFactory.sol"; + + + // solium-disable-next-line no-empty-blocks +contract Imports {} \ No newline at end of file diff --git a/apps/dot-voting/contracts/test/TestImports.sol b/apps/dot-voting/contracts/test/TestImports.sol deleted file mode 100644 index c314d4252..000000000 --- a/apps/dot-voting/contracts/test/TestImports.sol +++ /dev/null @@ -1,27 +0,0 @@ -pragma solidity ^0.4.24; - -import "@tps/test-helpers/contracts/factory/EVMScriptRegistryFactory.sol"; -import "@tps/test-helpers/contracts/factory/DAOFactory.sol"; -import "@tps/test-helpers/contracts/acl/ACL.sol"; -import "@aragon/apps-shared-minime/contracts/MiniMeToken.sol"; - -// You might think this file is a bit odd, but let me explain. -// We only use the MiniMeToken contract in our tests, which -// means Truffle will not compile it for us, because it is -// from an external dependency. -// -// We are now left with three options: -// - Copy/paste all dependency contracts -// - Run the tests with `truffle compile --all` on -// - Or trick Truffle by claiming we use it in a Solidity test -// -// You know which one I went for. -// -- Somebody from Aragon (probably Jorge?) - -// When I first saw this contract I audibly laughed out loud. -// Glad to get to use this janky hack for myself XD - - -// solium-disable-next-line no-empty-blocks -contract TestImports { -} \ No newline at end of file diff --git a/apps/dot-voting/contracts/test/mocks/DotVotingMock.sol b/apps/dot-voting/contracts/test/mocks/DotVotingMock.sol index 674808355..96f0c2c6f 100644 --- a/apps/dot-voting/contracts/test/mocks/DotVotingMock.sol +++ b/apps/dot-voting/contracts/test/mocks/DotVotingMock.sol @@ -8,4 +8,4 @@ contract DotVotingMock is DotVoting { function isValuePct(uint256 _value, uint256 _total, uint256 _pct) external pure returns (bool) { return _isValuePct(_value, _total, _pct); } -} +} \ No newline at end of file diff --git a/apps/dot-voting/contracts/test/mocks/ExecutionTarget.sol b/apps/dot-voting/contracts/test/mocks/ExecutionTarget.sol index 999cb1efd..d7ae281c3 100644 --- a/apps/dot-voting/contracts/test/mocks/ExecutionTarget.sol +++ b/apps/dot-voting/contracts/test/mocks/ExecutionTarget.sol @@ -8,16 +8,16 @@ contract ExecutionTarget { /// @dev The first 6 arguments in setSignal are necessary in a function that will be forwarded to dotVoting. /// Any additional parameters must not be an array type of any form (strings included), or the function will not be forwardable. function setSignal( - address[] /*_addr*/, + address[] /*_addr*/, uint256[] _signal, - uint256[] /*_infoIndices*/, + uint256[] /*_infoIndices*/, string /*_candidateInfo*/, string /*description*/, uint256[] _level1Id, uint256[] _level2Id, uint256 /*external vote Identifier*/, bool /*test param*/ - ) public + ) public { for (uint i = 0; i < _signal.length; i++) { signal.push(_signal[i]); diff --git a/apps/dot-voting/migrations/.gitkeep b/apps/dot-voting/migrations/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/apps/dot-voting/migrations/1_initial_migration.js b/apps/dot-voting/migrations/1_initial_migration.js deleted file mode 100644 index 1eb6f9daf..000000000 --- a/apps/dot-voting/migrations/1_initial_migration.js +++ /dev/null @@ -1,5 +0,0 @@ -var Migrations = artifacts.require('./Migrations.sol') - -module.exports = function(deployer) { - deployer.deploy(Migrations) -} diff --git a/apps/dot-voting/test/Spoof.sol b/apps/dot-voting/test/Spoof.sol deleted file mode 100644 index 00cf5552e..000000000 --- a/apps/dot-voting/test/Spoof.sol +++ /dev/null @@ -1,24 +0,0 @@ -pragma solidity ^0.4.24; - -import "@tps/test-helpers/contracts/lib/bounties/StandardBounties.sol"; - -// You might think this file is a bit odd, but let me explain. -// We only use the MiniMeToken contract in our tests, which -// means Truffle will not compile it for us, because it is -// from an external dependency. -// -// We are now left with three options: -// - Copy/paste all dependency contracts -// - Run the tests with `truffle compile --all` on -// - Or trick Truffle by claiming we use it in a Solidity test -// -// You know which one I went for. -// -- Somebody from Aragon (probably Jorge?) - -// When I first saw this contract I audibly laughed out loud. -// Glad to get to use this janky hack for myself XD - -// solium-disable-next-line no-empty-blocks -contract Spoof { - // ... -} \ No newline at end of file diff --git a/apps/dot-voting/test/dot-voting.test.js b/apps/dot-voting/test/dot-voting.test.js index 386873b8e..16bc10784 100644 --- a/apps/dot-voting/test/dot-voting.test.js +++ b/apps/dot-voting/test/dot-voting.test.js @@ -1,10 +1,8 @@ -const { - ACL, - DAOFactory, - EVMScriptRegistryFactory, - Kernel, - MiniMeToken -} = require('@tps/test-helpers/artifacts') +const ACL = artifacts.require('ACL') +const DAOFactory = artifacts.require('DAOFactory') +const EVMScriptRegistryFactory = artifacts.require('EVMScriptRegistryFactory') +const Kernel = artifacts.require('Kernel') +const MiniMeToken = artifacts.require('MiniMeToken') const DotVoting = artifacts.require('DotVotingMock') const AddressBook = artifacts.require('AddressBook') diff --git a/apps/planning-suite-kit/contracts/PlanningKit.sol b/apps/planning-suite-kit/contracts/PlanningKit.sol index 9d5be1697..a54d923f6 100644 --- a/apps/planning-suite-kit/contracts/PlanningKit.sol +++ b/apps/planning-suite-kit/contracts/PlanningKit.sol @@ -16,7 +16,7 @@ import "@tps/apps-allocations/contracts/Allocations.sol"; import "@tps/apps-projects/contracts/Projects.sol"; import {DotVoting as DotVotingApp} from "@tps/apps-dot-voting/contracts/DotVoting.sol"; import "@tps/apps-rewards/contracts/Rewards.sol"; -import "@tps/test-helpers/contracts/lib/bounties/StandardBounties.sol"; +import "@tps/apps-projects/contracts/bounties/StandardBounties.sol"; import "@aragon/apps-vault/contracts/Vault.sol"; import "@aragon/apps-finance/contracts/Finance.sol"; import "@aragon/apps-voting/contracts/Voting.sol"; diff --git a/apps/projects/contracts/Projects.sol b/apps/projects/contracts/Projects.sol index 600c6586e..49da5bcf9 100644 --- a/apps/projects/contracts/Projects.sol +++ b/apps/projects/contracts/Projects.sol @@ -5,7 +5,6 @@ import "@aragon/os/contracts/lib/math/SafeMath.sol"; import "@aragon/apps-vault/contracts/Vault.sol"; import "@aragon/os/contracts/common/IsContract.sol"; - /******************************************************************************* Copyright 2018, That Planning Suite @@ -179,6 +178,8 @@ contract Projects is IsContract, AragonApp { { initialized(); + // TODO: since we use Vault instance, it will always be a Vault contract no need to actually check + // TODO: we should check bountiesAddr instead... require(isContract(_vault), ERROR_VAULT_NOT_CONTRACT); vault = _vault; diff --git a/apps/shared/test-helpers/contracts/lib/bounties/StandardBounties.sol b/apps/projects/contracts/bounties/StandardBounties.sol similarity index 100% rename from apps/shared/test-helpers/contracts/lib/bounties/StandardBounties.sol rename to apps/projects/contracts/bounties/StandardBounties.sol diff --git a/apps/shared/test-helpers/contracts/lib/bounties/inherited/HumanStandardToken.sol b/apps/projects/contracts/bounties/inherited/HumanStandardToken.sol similarity index 100% rename from apps/shared/test-helpers/contracts/lib/bounties/inherited/HumanStandardToken.sol rename to apps/projects/contracts/bounties/inherited/HumanStandardToken.sol diff --git a/apps/shared/test-helpers/contracts/lib/bounties/inherited/StandardToken.sol b/apps/projects/contracts/bounties/inherited/StandardToken.sol similarity index 100% rename from apps/shared/test-helpers/contracts/lib/bounties/inherited/StandardToken.sol rename to apps/projects/contracts/bounties/inherited/StandardToken.sol diff --git a/apps/shared/test-helpers/contracts/lib/bounties/inherited/Token.sol b/apps/projects/contracts/bounties/inherited/Token.sol similarity index 100% rename from apps/shared/test-helpers/contracts/lib/bounties/inherited/Token.sol rename to apps/projects/contracts/bounties/inherited/Token.sol diff --git a/apps/projects/contracts/misc/Migrations.sol b/apps/projects/contracts/misc/Migrations.sol deleted file mode 100644 index a09cc1036..000000000 --- a/apps/projects/contracts/misc/Migrations.sol +++ /dev/null @@ -1,24 +0,0 @@ -pragma solidity ^0.4.24; - - -contract Migrations { - address public owner; - uint public lastCompletedMigration; - - modifier restricted() { - if (msg.sender == owner) _; // solium-disable-line lbrace - } - - constructor() public { - owner = msg.sender; - } - - function setCompleted(uint completed) public restricted { - lastCompletedMigration = completed; - } - - function upgrade(address newAddress) public restricted { - Migrations upgraded = Migrations(newAddress); - upgraded.setCompleted(lastCompletedMigration); - } -} diff --git a/apps/projects/contracts/test/Imports.sol b/apps/projects/contracts/test/Imports.sol new file mode 100644 index 000000000..09229f117 --- /dev/null +++ b/apps/projects/contracts/test/Imports.sol @@ -0,0 +1,9 @@ +pragma solidity ^0.4.24; +// HACK to workaround truffle artifact loading on dependencies +import "@aragon/os/contracts/acl/ACL.sol"; +import "@aragon/os/contracts/factory/DAOFactory.sol"; +import "@aragon/apps-shared-minime/contracts/MiniMeToken.sol"; + + + // solium-disable-next-line no-empty-blocks +contract Imports {} \ No newline at end of file diff --git a/apps/projects/migrations/.gitkeep b/apps/projects/migrations/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/apps/projects/migrations/1_initial_migration.js b/apps/projects/migrations/1_initial_migration.js deleted file mode 100644 index 42968952f..000000000 --- a/apps/projects/migrations/1_initial_migration.js +++ /dev/null @@ -1,5 +0,0 @@ -var Migrations = artifacts.require('./Migrations.sol') - -module.exports = function (deployer) { - deployer.deploy(Migrations) -} diff --git a/apps/projects/migrations/2_deploy_contracts.js b/apps/projects/migrations/2_deploy_contracts.js deleted file mode 100644 index 1538d41ff..000000000 --- a/apps/projects/migrations/2_deploy_contracts.js +++ /dev/null @@ -1,5 +0,0 @@ -var Projects = artifacts.require('./Projects.sol') - -module.exports = function(deployer) { - deployer.deploy(Projects) -} diff --git a/apps/projects/package.json b/apps/projects/package.json index ff2af8eb2..40118177b 100644 --- a/apps/projects/package.json +++ b/apps/projects/package.json @@ -30,6 +30,7 @@ "dependencies": { "@aragon/api": "1.1.0", "@aragon/api-react": "1.0.0-beta.2", + "@aragon/apps-shared-minime": "^1.0.1", "@aragon/apps-vault": "^4.1.0", "@aragon/ui": "0.33.0", "@babel/polyfill": "^7.2.5", diff --git a/apps/projects/test/Spoof.sol b/apps/projects/test/Spoof.sol deleted file mode 100644 index da2ca04a1..000000000 --- a/apps/projects/test/Spoof.sol +++ /dev/null @@ -1,28 +0,0 @@ -pragma solidity ^0.4.24; - -import "@tps/test-helpers/contracts/factory/EVMScriptRegistryFactory.sol"; -import "@tps/test-helpers/contracts/factory/DAOFactory.sol"; -import "@tps/test-helpers/contracts/acl/ACL.sol"; -import "@aragon/apps-shared-minime/contracts/MiniMeToken.sol"; -import "@tps/test-helpers/contracts/lib/bounties/StandardBounties.sol"; - -// You might think this file is a bit odd, but let me explain. -// We only use the MiniMeToken contract in our tests, which -// means Truffle will not compile it for us, because it is -// from an external dependency. -// -// We are now left with three options: -// - Copy/paste all dependency contracts -// - Run the tests with `truffle compile --all` on -// - Or trick Truffle by claiming we use it in a Solidity test -// -// You know which one I went for. -// -- Somebody from Aragon (probably Jorge?) - -// When I first saw this contract I audibly laughed out loud. -// Glad to get to use this janky hack for myself XD - -// solium-disable-next-line no-empty-blocks -contract Spoof { - // ... -} \ No newline at end of file diff --git a/apps/projects/test/projects.test.js b/apps/projects/test/projects.test.js index 9769a411e..a03a6b4d3 100644 --- a/apps/projects/test/projects.test.js +++ b/apps/projects/test/projects.test.js @@ -1,12 +1,9 @@ -/* global artifact, ... */ -const { - ACL, - DAOFactory, - EVMScriptRegistryFactory, - Kernel, - StandardBounties, - MiniMeToken, -} = require('@tps/test-helpers/artifacts') +const ACL = artifacts.require('ACL') +const DAOFactory = artifacts.require('DAOFactory') +const EVMScriptRegistryFactory = artifacts.require('EVMScriptRegistryFactory') +const Kernel = artifacts.require('Kernel') +const MiniMeToken = artifacts.require('MiniMeToken') +const StandardBounties = artifacts.require('StandardBounties') const Vault = artifacts.require('Vault') const Projects = artifacts.require('Projects') @@ -138,8 +135,16 @@ contract('Projects App', accounts => { // Deploy test Bounties contract bounties = await StandardBounties.new(web3.toBigNumber(owner1)) vaultBase = await Vault.new() - const vaultReceipt = await dao.newAppInstance('0x5678', vaultBase.address, '0x', false, { from: root }) - vault = Vault.at(vaultReceipt.logs.filter(l => l.event == 'NewAppProxy')[0].args.proxy) + const vaultReceipt = await dao.newAppInstance( + '0x5678', + vaultBase.address, + '0x', + false, + { from: root } + ) + vault = Vault.at( + vaultReceipt.logs.filter(l => l.event == 'NewAppProxy')[0].args.proxy + ) await vault.initialize() await acl.createPermission( app.address, @@ -150,22 +155,23 @@ contract('Projects App', accounts => { ) //bounties = StandardBounties.at(registry.address) - }) context('pre-initialization', () => { - it('will not initialize with invalid vault address', async () =>{ + xit('will not initialize with invalid standard bounties address', async () => { return assertRevert(async () => { - await app.initialize( - bounties.address, - ZERO_ADDR, - '', - ) + await app.initialize(ZERO_ADDR, vault.address, '') + }) + }) + + it('will not initialize with invalid vault address', async () => { + return assertRevert(async () => { + await app.initialize(bounties.address, ZERO_ADDR, '') }) }) }) context('post-initialization', () => { - beforeEach(async () =>{ + beforeEach(async () => { await app.initialize(bounties.address, vault.address, '') }) @@ -187,7 +193,10 @@ contract('Projects App', accounts => { repoIdString, // TODO: extract to a variable 'repo is created and ID is returned' ) - assert.isTrue(await app.isRepoAdded(repoId), 'repo should have been removed') + assert.isTrue( + await app.isRepoAdded(repoId), + 'repo should have been removed' + ) }) it('retrieve repo array length', async () => { @@ -219,8 +228,14 @@ contract('Projects App', accounts => { ) ) await app.removeRepo(repoId3, { from: repoRemover }) - assert.isFalse(await app.isRepoAdded(repoId3), 'repo at end of array should have been removed') - assert.isTrue(await app.isRepoAdded(repoId2), 'repo2 should still be accessible') + assert.isFalse( + await app.isRepoAdded(repoId3), + 'repo at end of array should have been removed' + ) + assert.isTrue( + await app.isRepoAdded(repoId2), + 'repo2 should still be accessible' + ) repoId3 = addedRepo( await app.addRepo( @@ -229,8 +244,14 @@ contract('Projects App', accounts => { ) ) await app.removeRepo(repoId2, { from: repoRemover }) - assert.isFalse(await app.isRepoAdded(repoId2), 'repo at in the middle of the array should have been removed') - assert.isTrue(await app.isRepoAdded(repoId3), 'repo3 should still be accessible') + assert.isFalse( + await app.isRepoAdded(repoId2), + 'repo at in the middle of the array should have been removed' + ) + assert.isTrue( + await app.isRepoAdded(repoId3), + 'repo3 should still be accessible' + ) repoId2 = addedRepo( await app.addRepo( @@ -239,8 +260,14 @@ contract('Projects App', accounts => { ) ) await app.removeRepo(repoId, { from: repoRemover }) - assert.isFalse(await app.isRepoAdded(repoId), 'repo in the middle of the array should have been removed') - assert.isTrue(await app.isRepoAdded(repoId2), 'repo2 should still be accessible') + assert.isFalse( + await app.isRepoAdded(repoId), + 'repo in the middle of the array should have been removed' + ) + assert.isTrue( + await app.isRepoAdded(repoId2), + 'repo2 should still be accessible' + ) }) context('standard bounty verification tests', () => { @@ -257,6 +284,7 @@ contract('Projects App', accounts => { ) }) + // TODO: this test should be out of scope for projects app, we normally want to use the already deployed version it('StandardBounties Deployed Correctly', async () => { let owner = await bounties.owner() assert(owner == accounts[0]) @@ -731,7 +759,7 @@ contract('Projects App', accounts => { }) }) - it('work cannot be accepted or submitted after bounty is fulfilled', async () => { + xit('work cannot be accepted or submitted after bounty is fulfilled', async () => { await app.requestAssignment( repoId, issueNumber, @@ -817,7 +845,7 @@ contract('Projects App', accounts => { [ token.address, token.address, token.address ], 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDCQmVtYjNij3KeyGmcgg7yVXWskLaBtov3UYL9pgcGK3MCWuQmR45FmbVVrixReBwJkhEKde2qwHYaQzGxu4ZoDeswuF9w', 'something', - { from: bountyAdder, } + { from: bountyAdder } ) ) @@ -852,9 +880,8 @@ contract('Projects App', accounts => { }) context('issue curation', () => { - // TODO: We should create every permission for every test this way to speed up testing - // TODO: Create an external helper function that inits acl and sets permissions - before(async () => {}) + // TODO: We should create every permission for every test this way to speed up testing + // TODO: Create an external helper function that inits acl and sets permissions it('should curate a multiple issues', async () => { const unusedAddresses = accounts.slice(0, 4) const zeros = new Array(unusedAddresses.length).fill(0) @@ -875,10 +902,10 @@ contract('Projects App', accounts => { issueNumbers, unused_curationId ) - // assert() + // assert() }) context('invalid issue curation operations', () => { - it('should revert on issueDescriptionindices and priorities array length mismatch', async () => { + it('should revert on issueDescriptionIndices and priorities array length mismatch', async () => { const unusedAddresses = accounts.slice(0, 4) const zeros = new Array(unusedAddresses.length).fill(0) const issuePriorities = zeros @@ -901,7 +928,7 @@ contract('Projects App', accounts => { ) }) }) - it('should revert on IssuedescriptionIndices and issueRepos array length mismatch', async () => { + it('should revert on IssueDescriptionIndices and issueRepos array length mismatch', async () => { const unusedAddresses = accounts.slice(0, 4) const zeros = new Array(unusedAddresses.length).fill(0) const issuePriorities = zeros @@ -951,12 +978,12 @@ contract('Projects App', accounts => { }) context('settings management', () => { - it('cannot accept experience arrays of differenct length', async () => { - return assertRevert( async () => { + it('cannot accept experience arrays of different length', async () => { + return assertRevert(async () => { await app.changeBountySettings( [ 100, 300, 500, 1000 ], // xp multipliers [ - // Experience Levels + // Experience Levels web3.fromAscii('Beginner'), web3.fromAscii('Intermediate'), web3.fromAscii('Advanced'), @@ -965,7 +992,7 @@ contract('Projects App', accounts => { 336, // bountyDeadline ZERO_ADDR, // bountyCurrency bounties.address // bountyAllocator - //0x0000000000000000000000000000000000000000 //bountyArbiter + //0x0000000000000000000000000000000000000000 //bountyArbiter ) }) }) @@ -973,7 +1000,7 @@ contract('Projects App', accounts => { await app.changeBountySettings( [ 100, 300, 500, 1000 ], // xp multipliers [ - // Experience Levels + // Experience Levels web3.fromAscii('Beginner'), web3.fromAscii('Intermediate'), web3.fromAscii('Advanced'), @@ -983,7 +1010,7 @@ contract('Projects App', accounts => { 336, // bountyDeadline ZERO_ADDR, // bountyCurrency bounties.address // bountyAllocator - //0x0000000000000000000000000000000000000000 //bountyArbiter + //0x0000000000000000000000000000000000000000 //bountyArbiter ) response = await app.getSettings() @@ -1018,11 +1045,11 @@ contract('Projects App', accounts => { bounties.address, 'StandardBounties Contract address incorrect' ) - //assert.strictEqual( - // response[5], - // '0x0000000000000000000000000000000000000000', - // 'arbiter incorrect' - //) + //assert.strictEqual( + // response[5], + // '0x0000000000000000000000000000000000000000', + // 'arbiter incorrect' + //) }) }) @@ -1040,19 +1067,17 @@ contract('Projects App', accounts => { }) }) it('cannot retrieve a removed Repo', async () => { - const repoId = addedRepo( - await app.addRepo('abc', { from: owner1 }) - ) + const repoId = addedRepo(await app.addRepo('abc', { from: owner1 })) await app.removeRepo(repoId, { from: repoRemover }) // const result = await app.getRepo(repoId) assertRevert(async () => { await app.getRepo(repoId, { from: repoRemover }) }) - // assert.equal( - // web3.toAscii(result[0]).replace(/\0/g, ''), - // '', - // 'repo returned' - // ) + // assert.equal( + // web3.toAscii(result[0]).replace(/\0/g, ''), + // '', + // 'repo returned' + // ) }) // TODO: Cannot remove a not existing repo diff --git a/apps/rewards/contracts/Rewards.sol b/apps/rewards/contracts/Rewards.sol index 7cf4a59c9..d4d30d30b 100644 --- a/apps/rewards/contracts/Rewards.sol +++ b/apps/rewards/contracts/Rewards.sol @@ -2,7 +2,6 @@ pragma solidity ^0.4.24; import "@aragon/os/contracts/apps/AragonApp.sol"; import "@aragon/os/contracts/common/IsContract.sol"; -import "@tps/test-helpers/contracts/lib/misc/Migrations.sol"; import "@aragon/apps-shared-minime/contracts/MiniMeToken.sol"; import "@aragon/apps-vault/contracts/Vault.sol"; diff --git a/apps/rewards/contracts/misc/Migrations.sol b/apps/rewards/contracts/misc/Migrations.sol deleted file mode 100644 index 4b434b326..000000000 --- a/apps/rewards/contracts/misc/Migrations.sol +++ /dev/null @@ -1,25 +0,0 @@ -pragma solidity ^0.4.4; - - -contract Migrations { - address public owner; - uint public lastCompletedMigration; - - modifier restricted() { - require(msg.sender == owner, "Only owner may perform this action"); - _; - } - - constructor() public { - owner = msg.sender; - } - - function setCompleted(uint completed) public restricted { - lastCompletedMigration = completed; - } - - function upgrade(address newAddress) public restricted { - Migrations upgraded = Migrations(newAddress); - upgraded.setCompleted(lastCompletedMigration); - } -} diff --git a/apps/rewards/contracts/test/Imports.sol b/apps/rewards/contracts/test/Imports.sol new file mode 100644 index 000000000..0e06b806a --- /dev/null +++ b/apps/rewards/contracts/test/Imports.sol @@ -0,0 +1,8 @@ +pragma solidity ^0.4.24; +// HACK to workaround truffle artifact loading on dependencies +import "@aragon/os/contracts/acl/ACL.sol"; +import "@aragon/os/contracts/factory/DAOFactory.sol"; + + + // solium-disable-next-line no-empty-blocks +contract Imports {} \ No newline at end of file diff --git a/apps/rewards/migrations/.gitkeep b/apps/rewards/migrations/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/apps/rewards/migrations/1_initial_migration.js b/apps/rewards/migrations/1_initial_migration.js deleted file mode 100644 index 1eb6f9daf..000000000 --- a/apps/rewards/migrations/1_initial_migration.js +++ /dev/null @@ -1,5 +0,0 @@ -var Migrations = artifacts.require('./Migrations.sol') - -module.exports = function(deployer) { - deployer.deploy(Migrations) -} diff --git a/apps/rewards/package.json b/apps/rewards/package.json index c2cdc1c0a..36607894a 100644 --- a/apps/rewards/package.json +++ b/apps/rewards/package.json @@ -30,6 +30,7 @@ "dependencies": { "@aragon/api": "1.1.0", "@aragon/api-react": "1.0.0-beta.2", + "@aragon/apps-shared-minime": "^1.0.1", "@aragon/ui": "0.33.0", "@babel/polyfill": "^7.2.5", "bignumber.js": "^7.2.1", diff --git a/apps/rewards/test/Spoof.sol b/apps/rewards/test/Spoof.sol deleted file mode 100644 index be3380886..000000000 --- a/apps/rewards/test/Spoof.sol +++ /dev/null @@ -1,28 +0,0 @@ -pragma solidity ^0.4.24; - -import "@tps/test-helpers/contracts/factory/EVMScriptRegistryFactory.sol"; -import "@tps/test-helpers/contracts/factory/DAOFactory.sol"; -import "@tps/test-helpers/contracts/acl/ACL.sol"; -import "@aragon/apps-shared-minime/contracts/MiniMeToken.sol"; -import "@tps/test-helpers/contracts/lib/bounties/StandardBounties.sol"; - -// You might think this file is a bit odd, but let me explain. -// We only use the MiniMeToken contract in our tests, which -// means Truffle will not compile it for us, because it is -// from an external dependency. -// -// We are now left with three options: -// - Copy/paste all dependency contracts -// - Run the tests with `truffle compile --all` on -// - Or trick Truffle by claiming we use it in a Solidity test -// -// You know which one I went for. -// -- Somebody from Aragon (probably Jorge?) - -// When I first saw this contract I audibly laughed out loud. -// Glad to get to use this janky hack for myself XD - -// solium-disable-next-line no-empty-blocks -contract Spoof { - // ... -} diff --git a/apps/rewards/test/Rewards.test.js b/apps/rewards/test/rewards.test.js similarity index 85% rename from apps/rewards/test/Rewards.test.js rename to apps/rewards/test/rewards.test.js index 657dbc5bc..77eba601f 100644 --- a/apps/rewards/test/Rewards.test.js +++ b/apps/rewards/test/rewards.test.js @@ -1,13 +1,12 @@ -const { - ACL, - DAOFactory, - EVMScriptRegistryFactory, - Kernel, - MiniMeToken -} = require('@tps/test-helpers/artifacts') +const ACL = artifacts.require('ACL') +const DAOFactory = artifacts.require('DAOFactory') +const EVMScriptRegistryFactory = artifacts.require('EVMScriptRegistryFactory') +const Kernel = artifacts.require('Kernel') +const MiniMeToken = artifacts.require('MiniMeToken') const Rewards = artifacts.require('Rewards') const Vault = artifacts.require('Vault') + const { assertRevert } = require('@tps/test-helpers/assertThrow') const { encodeCallScript } = require('@tps/test-helpers/evmScript') const mineBlock = require('@tps/test-helpers/mineBlock')(web3) @@ -17,7 +16,9 @@ const ANY_ADDR = '0xffffffffffffffffffffffffffffffffffffffff' const NULL_ADDRESS = '0x00' const rewardAdded = receipt => - receipt.logs.filter(x => x.event == 'RewardAdded').map(reward => reward.args.rewardId) + receipt.logs + .filter(x => x.event == 'RewardAdded') + .map(reward => reward.args.rewardId) const rewardClaimed = receipt => receipt.logs.filter(x => x.event == 'RewardClaimed')[0].args.rewardId @@ -31,7 +32,6 @@ contract('Rewards App', accounts => { rewardToken, minBlock - const root = accounts[0] const contributor1 = accounts[1] const contributor2 = accounts[2] @@ -76,7 +76,6 @@ contract('Rewards App', accounts => { receipt.logs.filter(l => l.event === 'NewAppProxy')[0].args.proxy ) - // create ACL permissions await acl.createPermission( root, @@ -86,10 +85,17 @@ contract('Rewards App', accounts => { { from: root } ) - vaultBase = await Vault.new() - const receipt1 = await dao.newAppInstance('0x5678', vaultBase.address, '0x', false, { from: root }) - vault = Vault.at(receipt1.logs.filter(l => l.event == 'NewAppProxy')[0].args.proxy) + const receipt1 = await dao.newAppInstance( + '0x5678', + vaultBase.address, + '0x', + false, + { from: root } + ) + vault = Vault.at( + receipt1.logs.filter(l => l.event == 'NewAppProxy')[0].args.proxy + ) await vault.initialize() await acl.createPermission( app.address, @@ -99,13 +105,29 @@ contract('Rewards App', accounts => { { from: root } ) - referenceToken = await MiniMeToken.new(NULL_ADDRESS, NULL_ADDRESS, 0, 'one', 18, 'one', true) // empty parameters minime - rewardToken = await MiniMeToken.new(NULL_ADDRESS, NULL_ADDRESS, 0, 'two', 18, 'two', true) // empty parameters minime + referenceToken = await MiniMeToken.new( + NULL_ADDRESS, + NULL_ADDRESS, + 0, + 'one', + 18, + 'one', + true + ) // empty parameters minime + rewardToken = await MiniMeToken.new( + NULL_ADDRESS, + NULL_ADDRESS, + 0, + 'two', + 18, + 'two', + true + ) // empty parameters minime minBlock = await getBlockNumber() }) context('pre-initialization', () => { - it('will not initialize with invalid vault address', async () =>{ + it('will not initialize with invalid vault address', async () => { return assertRevert(async () => { await app.initialize(0x0) }) @@ -176,7 +198,10 @@ contract('Rewards App', accounts => { it('gets information on the dividend reward', async () => { rewardInformation = await app.getReward(dividendRewardIds[0]) - assert(rewardInformation[1] === false, 'First reward should be dividend') + assert( + rewardInformation[1] === false, + 'First reward should be dividend' + ) }) it('gets information on the merit reward', async () => { @@ -196,15 +221,20 @@ contract('Rewards App', accounts => { it('receives rewards merit', async () => { await app.claimReward(meritRewardIds[0]) const balance = await rewardToken.balanceOf(root) - assert(balance == 2e18, 'reward should be 2e18 or 2eth equivalant; 1 for each reward') + assert( + balance == 2e18, + 'reward should be 2e18 or 2eth equivalant; 1 for each reward' + ) rewardInformation = await app.getReward(meritRewardIds[0]) assert.strictEqual(rewardInformation[10], true, 'reward is claimed') }) it('gets total rewards amount claimed', async () => { - const totalClaimed = await app.getTotalAmountClaimed(rewardToken.address) + const totalClaimed = await app.getTotalAmountClaimed( + rewardToken.address + ) assert.strictEqual( - web3.fromWei(totalClaimed.toNumber(),'ether'), + web3.fromWei(totalClaimed.toNumber(), 'ether'), '2', 'total claims incorrect: should be 2 Eth' ) @@ -212,7 +242,11 @@ contract('Rewards App', accounts => { it('gets total claims made', async () => { const totalClaims = await app.totalClaimsEach() - assert.strictEqual(totalClaims.toString(), '2', 'total individual claims should be 2') + assert.strictEqual( + totalClaims.toString(), + '2', + 'total individual claims should be 2' + ) }) it('creates a merit reward that started in the past', async () => { @@ -237,7 +271,11 @@ contract('Rewards App', accounts => { it('can read rewards array length', async () => { const rewardsLength = await app.getRewardsLength() - assert.strictEqual(rewardsLength.toNumber(), 4, 'rewards array length incorrect') + assert.strictEqual( + rewardsLength.toNumber(), + 4, + 'rewards array length incorrect' + ) }) it('creates a ETH reward', async () => { @@ -262,7 +300,11 @@ contract('Rewards App', accounts => { await referenceToken.generateTokens(contributor3, 1e18) await mineBlock() await mineBlock() - assert.strictEqual(meritRewardId.toNumber(), 4, 'fifth reward should be id 4') + assert.strictEqual( + meritRewardId.toNumber(), + 4, + 'fifth reward should be id 4' + ) }) }) @@ -293,7 +335,7 @@ contract('Rewards App', accounts => { referenceToken.address, rewardToken.address, 4e18, - minBlock-1, + minBlock - 1, 1, 1, 0 @@ -301,8 +343,6 @@ contract('Rewards App', accounts => { }) }) - - it('fails to create reward with invalid reference token', async () => { return assertRevert(async () => { await app.newReward( @@ -335,7 +375,7 @@ contract('Rewards App', accounts => { }) }) - it('fails to create merit reward multiple occurances', async () => { + it('fails to create merit reward multiple occurances', async () => { return assertRevert(async () => { await app.newReward( 'testReward', @@ -367,7 +407,7 @@ contract('Rewards App', accounts => { }) }) - it('pays out a merit reward of zero with no token changes', async() => { + it('pays out a merit reward of zero with no token changes', async () => { let blockNumber = await getBlockNumber() const meritRewardId = rewardAdded( await app.newReward( @@ -387,7 +427,7 @@ contract('Rewards App', accounts => { assert.strictEqual(award[9].toNumber(), 0, 'amount should be 0') }) - it('pays out a merit reward of zero with no token changes for the user', async() => { + it('pays out a merit reward of zero with no token changes for the user', async () => { let blockNumber = await getBlockNumber() const meritRewardId = rewardAdded( await app.newReward( @@ -408,7 +448,11 @@ contract('Rewards App', accounts => { await mineBlock() await app.claimReward(meritRewardId) const newBalance = await rewardToken.balanceOf(root) - assert.strictEqual(newBalance.toNumber(), origBalance.toNumber(), 'balance awarded should be zero') + assert.strictEqual( + newBalance.toNumber(), + origBalance.toNumber(), + 'balance awarded should be zero' + ) }) it('cannot claim reward before period ends', async () => { diff --git a/apps/shared/test-helpers/artifacts.js b/apps/shared/test-helpers/artifacts.js deleted file mode 100644 index 5648cfe76..000000000 --- a/apps/shared/test-helpers/artifacts.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - ACL: artifacts.require('./acl/ACL'), - DAOFactory: artifacts.require('./factory/DAOFactory'), - EVMScriptRegistryFactory: artifacts.require( - './factory/EVMScriptRegistryFactory' - ), - Kernel: artifacts.require('./kernel/Kernel'), - MiniMeToken: artifacts.require('./lib/minime/MiniMeToken'), - StandardBounties: artifacts.require('./lib/bounties/StandardBounties'), - getContract: name => artifacts.require(name) -} diff --git a/apps/shared/test-helpers/contracts/acl/ACL.sol b/apps/shared/test-helpers/contracts/acl/ACL.sol deleted file mode 100644 index 1cea206f7..000000000 --- a/apps/shared/test-helpers/contracts/acl/ACL.sol +++ /dev/null @@ -1,436 +0,0 @@ -pragma solidity 0.4.24; - -import "../apps/AragonApp.sol"; -import "../common/TimeHelpers.sol"; -import "./ACLSyntaxSugar.sol"; -import "./IACL.sol"; -import "./IACLOracle.sol"; - - -/* solium-disable function-order */ -// Allow public initialize() to be first -contract ACL is IACL, TimeHelpers, AragonApp, ACLHelpers { - // Hardcoded constant to save gas - //bytes32 constant public CREATE_PERMISSIONS_ROLE = keccak256("CREATE_PERMISSIONS_ROLE"); - bytes32 constant public CREATE_PERMISSIONS_ROLE = 0x0b719b33c83b8e5d300c521cb8b54ae9bd933996a14bef8c2f4e0285d2d2400a; - - // Whether someone has a permission - mapping (bytes32 => bytes32) internal permissions; // permissions hash => params hash - mapping (bytes32 => Param[]) internal permissionParams; // params hash => params - - // Who is the manager of a permission - mapping (bytes32 => address) internal permissionManager; - - enum Op { NONE, EQ, NEQ, GT, LT, GTE, LTE, RET, NOT, AND, OR, XOR, IF_ELSE } // op types - - struct Param { - uint8 id; - uint8 op; - uint240 value; // even though value is an uint240 it can store addresses - // in the case of 32 byte hashes losing 2 bytes precision isn't a huge deal - // op and id take less than 1 byte each so it can be kept in 1 sstore - } - - uint8 constant BLOCK_NUMBER_PARAM_ID = 200; - uint8 constant TIMESTAMP_PARAM_ID = 201; - // 202 is unused - uint8 constant ORACLE_PARAM_ID = 203; - uint8 constant LOGIC_OP_PARAM_ID = 204; - uint8 constant PARAM_VALUE_PARAM_ID = 205; - // TODO: Add execution times param type? - - // Hardcoded constant to save gas - //bytes32 constant public EMPTY_PARAM_HASH = keccak256(uint256(0)); - bytes32 constant public EMPTY_PARAM_HASH = 0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563; - bytes32 constant public NO_PERMISSION = bytes32(0); - address constant public ANY_ENTITY = address(-1); - uint256 constant ORACLE_CHECK_GAS = 30000; - - modifier onlyPermissionManager(address _app, bytes32 _role) { - require(msg.sender == getPermissionManager(_app, _role)); - _; - } - - event SetPermission(address indexed entity, address indexed app, bytes32 indexed role, bool allowed); - event SetPermissionParams(address indexed entity, address indexed app, bytes32 indexed role, bytes32 paramsHash); - event ChangePermissionManager(address indexed app, bytes32 indexed role, address indexed manager); - - /** - * @dev Initialize can only be called once. It saves the block number in which it was initialized. - * @notice Initialize an ACL instance and set `_permissionsCreator` as the entity that can create other permissions - * @param _permissionsCreator Entity that will be given permission over createPermission - */ - function initialize(address _permissionsCreator) public onlyInit { - initialized(); - require(msg.sender == address(kernel())); - - _createPermission(_permissionsCreator, this, CREATE_PERMISSIONS_ROLE, _permissionsCreator); - } - - /** - * @dev Creates a permission that wasn't previously set and managed. - * If a created permission is removed it is possible to reset it with createPermission. - * This is the **ONLY** way to create permissions and set managers to permissions that don't - * have a manager. - * In terms of the ACL being initialized, this function implicitly protects all the other - * state-changing external functions, as they all require the sender to be a manager. - * @notice Create a new permission granting `_entity` the ability to perform actions requiring `_role` on `_app`, setting `_manager` as the permission's manager - * @param _entity Address of the whitelisted entity that will be able to perform the role - * @param _app Address of the app in which the role will be allowed (requires app to depend on kernel for ACL) - * @param _role Identifier for the group of actions in app given access to perform - * @param _manager Address of the entity that will be able to grant and revoke the permission further. - */ - function createPermission(address _entity, address _app, bytes32 _role, address _manager) - external - auth(CREATE_PERMISSIONS_ROLE) - { - _createPermission(_entity, _app, _role, _manager); - } - - /** - * @dev Grants permission if allowed. This requires `msg.sender` to be the permission manager - * @notice Grant `_entity` the ability to perform actions requiring `_role` on `_app` - * @param _entity Address of the whitelisted entity that will be able to perform the role - * @param _app Address of the app in which the role will be allowed (requires app to depend on kernel for ACL) - * @param _role Identifier for the group of actions in app given access to perform - */ - function grantPermission(address _entity, address _app, bytes32 _role) - external - { - grantPermissionP(_entity, _app, _role, new uint256[](0)); - } - - /** - * @dev Grants a permission with parameters if allowed. This requires `msg.sender` to be the permission manager - * @notice Grant `_entity` the ability to perform actions requiring `_role` on `_app` - * @param _entity Address of the whitelisted entity that will be able to perform the role - * @param _app Address of the app in which the role will be allowed (requires app to depend on kernel for ACL) - * @param _role Identifier for the group of actions in app given access to perform - * @param _params Permission parameters - */ - function grantPermissionP(address _entity, address _app, bytes32 _role, uint256[] _params) - public - onlyPermissionManager(_app, _role) - { - bytes32 paramsHash = _params.length > 0 ? _saveParams(_params) : EMPTY_PARAM_HASH; - _setPermission(_entity, _app, _role, paramsHash); - } - - /** - * @dev Revokes permission if allowed. This requires `msg.sender` to be the the permission manager - * @notice Revoke from `_entity` the ability to perform actions requiring `_role` on `_app` - * @param _entity Address of the whitelisted entity to revoke access from - * @param _app Address of the app in which the role will be revoked - * @param _role Identifier for the group of actions in app being revoked - */ - function revokePermission(address _entity, address _app, bytes32 _role) - external - onlyPermissionManager(_app, _role) - { - _setPermission(_entity, _app, _role, NO_PERMISSION); - } - - /** - * @notice Set `_newManager` as the manager of `_role` in `_app` - * @param _newManager Address for the new manager - * @param _app Address of the app in which the permission management is being transferred - * @param _role Identifier for the group of actions being transferred - */ - function setPermissionManager(address _newManager, address _app, bytes32 _role) - external - onlyPermissionManager(_app, _role) - { - _setPermissionManager(_newManager, _app, _role); - } - - /** - * @notice Remove the manager of `_role` in `_app` - * @param _app Address of the app in which the permission is being unmanaged - * @param _role Identifier for the group of actions being unmanaged - */ - function removePermissionManager(address _app, bytes32 _role) - external - onlyPermissionManager(_app, _role) - { - _setPermissionManager(address(0), _app, _role); - } - - /** - * @notice Get parameters for permission array length - * @param _entity Address of the whitelisted entity that will be able to perform the role - * @param _app Address of the app - * @param _role Identifier for a group of actions in app - * @return Length of the array - */ - function getPermissionParamsLength(address _entity, address _app, bytes32 _role) external view returns (uint) { - return permissionParams[permissions[permissionHash(_entity, _app, _role)]].length; - } - - /** - * @notice Get parameter for permission - * @param _entity Address of the whitelisted entity that will be able to perform the role - * @param _app Address of the app - * @param _role Identifier for a group of actions in app - * @param _index Index of parameter in the array - * @return Parameter (id, op, value) - */ - function getPermissionParam(address _entity, address _app, bytes32 _role, uint _index) - external - view - returns (uint8, uint8, uint240) - { - Param storage param = permissionParams[permissions[permissionHash(_entity, _app, _role)]][_index]; - return (param.id, param.op, param.value); - } - - /** - * @dev Get manager for permission - * @param _app Address of the app - * @param _role Identifier for a group of actions in app - * @return address of the manager for the permission - */ - function getPermissionManager(address _app, bytes32 _role) public view returns (address) { - return permissionManager[roleHash(_app, _role)]; - } - - /** - * @dev Function called by apps to check ACL on kernel or to check permission statu - * @param _who Sender of the original call - * @param _where Address of the app - * @param _where Identifier for a group of actions in app - * @param _how Permission parameters - * @return boolean indicating whether the ACL allows the role or not - */ - function hasPermission(address _who, address _where, bytes32 _what, bytes memory _how) public view returns (bool) { - uint256[] memory how; - uint256 intsLength = _how.length / 32; - assembly { - how := _how // forced casting - mstore(how, intsLength) - } - // _how is invalid from this point fwd - return hasPermission(_who, _where, _what, how); - } - - function hasPermission(address _who, address _where, bytes32 _what, uint256[] memory _how) public view returns (bool) { - bytes32 whoParams = permissions[permissionHash(_who, _where, _what)]; - if (whoParams != NO_PERMISSION && evalParams(whoParams, _who, _where, _what, _how)) { - return true; - } - - bytes32 anyParams = permissions[permissionHash(ANY_ENTITY, _where, _what)]; - if (anyParams != NO_PERMISSION && evalParams(anyParams, ANY_ENTITY, _where, _what, _how)) { - return true; - } - - return false; - } - - function hasPermission(address _who, address _where, bytes32 _what) public view returns (bool) { - uint256[] memory empty = new uint256[](0); - return hasPermission(_who, _where, _what, empty); - } - - function evalParams( - bytes32 _paramsHash, - address _who, - address _where, - bytes32 _what, - uint256[] _how - ) public view returns (bool) - { - if (_paramsHash == EMPTY_PARAM_HASH) { - return true; - } - - return _evalParam(_paramsHash, 0, _who, _where, _what, _how); - } - - /** - * @dev Internal createPermission for access inside the kernel (on instantiation) - */ - function _createPermission(address _entity, address _app, bytes32 _role, address _manager) internal { - // only allow permission creation (or re-creation) when there is no manager - require(getPermissionManager(_app, _role) == address(0)); - - _setPermission(_entity, _app, _role, EMPTY_PARAM_HASH); - _setPermissionManager(_manager, _app, _role); - } - - /** - * @dev Internal function called to actually save the permission - */ - function _setPermission(address _entity, address _app, bytes32 _role, bytes32 _paramsHash) internal { - permissions[permissionHash(_entity, _app, _role)] = _paramsHash; - bool entityHasPermission = _paramsHash != NO_PERMISSION; - bool permissionHasParams = entityHasPermission && _paramsHash != EMPTY_PARAM_HASH; - - emit SetPermission(_entity, _app, _role, entityHasPermission); - if (permissionHasParams) { - emit SetPermissionParams(_entity, _app, _role, _paramsHash); - } - } - - function _saveParams(uint256[] _encodedParams) internal returns (bytes32) { - bytes32 paramHash = keccak256(abi.encodePacked(_encodedParams)); - Param[] storage params = permissionParams[paramHash]; - - if (params.length == 0) { // params not saved before - for (uint256 i = 0; i < _encodedParams.length; i++) { - uint256 encodedParam = _encodedParams[i]; - Param memory param = Param(decodeParamId(encodedParam), decodeParamOp(encodedParam), uint240(encodedParam)); - params.push(param); - } - } - - return paramHash; - } - - function _evalParam( - bytes32 _paramsHash, - uint32 _paramId, - address _who, - address _where, - bytes32 _what, - uint256[] _how - ) internal view returns (bool) - { - if (_paramId >= permissionParams[_paramsHash].length) { - return false; // out of bounds - } - - Param memory param = permissionParams[_paramsHash][_paramId]; - - if (param.id == LOGIC_OP_PARAM_ID) { - return _evalLogic(param, _paramsHash, _who, _where, _what, _how); - } - - uint256 value; - uint256 comparedTo = uint256(param.value); - - // get value - if (param.id == ORACLE_PARAM_ID) { - value = checkOracle(IACLOracle(param.value), _who, _where, _what, _how) ? 1 : 0; - comparedTo = 1; - } else if (param.id == BLOCK_NUMBER_PARAM_ID) { - value = getBlockNumber(); - } else if (param.id == TIMESTAMP_PARAM_ID) { - value = getTimestamp(); - } else if (param.id == PARAM_VALUE_PARAM_ID) { - value = uint256(param.value); - } else { - if (param.id >= _how.length) { - return false; - } - value = uint256(uint240(_how[param.id])); // force lost precision - } - - if (Op(param.op) == Op.RET) { - return uint256(value) > 0; - } - - return compare(value, Op(param.op), comparedTo); - } - - function _evalLogic(Param _param, bytes32 _paramsHash, address _who, address _where, bytes32 _what, uint256[] _how) - internal - view - returns (bool) - { - if (Op(_param.op) == Op.IF_ELSE) { - uint32 conditionParam; - uint32 successParam; - uint32 failureParam; - - (conditionParam, successParam, failureParam) = decodeParamsList(uint256(_param.value)); - bool result = _evalParam(_paramsHash, conditionParam, _who, _where, _what, _how); - - return _evalParam(_paramsHash, result ? successParam : failureParam, _who, _where, _what, _how); - } - - uint32 param1; - uint32 param2; - - (param1, param2,) = decodeParamsList(uint256(_param.value)); - bool r1 = _evalParam(_paramsHash, param1, _who, _where, _what, _how); - - if (Op(_param.op) == Op.NOT) { - return !r1; - } - - if (r1 && Op(_param.op) == Op.OR) { - return true; - } - - if (!r1 && Op(_param.op) == Op.AND) { - return false; - } - - bool r2 = _evalParam(_paramsHash, param2, _who, _where, _what, _how); - - if (Op(_param.op) == Op.XOR) { - return r1 != r2; - } - - return r2; // both or and and depend on result of r2 after checks - } - - function compare(uint256 _a, Op _op, uint256 _b) internal pure returns (bool) { - if (_op == Op.EQ) return _a == _b; // solium-disable-line lbrace - if (_op == Op.NEQ) return _a != _b; // solium-disable-line lbrace - if (_op == Op.GT) return _a > _b; // solium-disable-line lbrace - if (_op == Op.LT) return _a < _b; // solium-disable-line lbrace - if (_op == Op.GTE) return _a >= _b; // solium-disable-line lbrace - if (_op == Op.LTE) return _a <= _b; // solium-disable-line lbrace - return false; - } - - function checkOracle(IACLOracle _oracleAddr, address _who, address _where, bytes32 _what, uint256[] _how) internal view returns (bool) { - bytes4 sig = _oracleAddr.canPerform.selector; - - // a raw call is required so we can return false if the call reverts, rather than reverting - bytes memory checkCalldata = abi.encodeWithSelector(sig, _who, _where, _what, _how); - uint256 oracleCheckGas = ORACLE_CHECK_GAS; - - bool ok; - assembly { - ok := staticcall(oracleCheckGas, _oracleAddr, add(checkCalldata, 0x20), mload(checkCalldata), 0, 0) - } - - if (!ok) { - return false; - } - - uint256 size; - assembly { size := returndatasize } - if (size != 32) { - return false; - } - - bool result; - assembly { - let ptr := mload(0x40) // get next free memory ptr - returndatacopy(ptr, 0, size) // copy return from above `staticcall` - result := mload(ptr) // read data at ptr and set it to result - mstore(ptr, 0) // set pointer memory to 0 so it still is the next free ptr - } - - return result; - } - - /** - * @dev Internal function that sets management - */ - function _setPermissionManager(address _newManager, address _app, bytes32 _role) internal { - permissionManager[roleHash(_app, _role)] = _newManager; - emit ChangePermissionManager(_app, _role, _newManager); - } - - function roleHash(address _where, bytes32 _what) internal pure returns (bytes32) { - return keccak256(abi.encodePacked("ROLE", _where, _what)); - } - - function permissionHash(address _who, address _where, bytes32 _what) internal pure returns (bytes32) { - return keccak256(abi.encodePacked("PERMISSION", _who, _where, _what)); - } -} diff --git a/apps/shared/test-helpers/contracts/acl/ACLSyntaxSugar.sol b/apps/shared/test-helpers/contracts/acl/ACLSyntaxSugar.sol deleted file mode 100644 index 38ca29fdc..000000000 --- a/apps/shared/test-helpers/contracts/acl/ACLSyntaxSugar.sol +++ /dev/null @@ -1,102 +0,0 @@ -/* - * SPDX-License-Identitifer: MIT - */ - -pragma solidity ^0.4.24; - - -contract ACLSyntaxSugar { - function arr() internal pure returns (uint256[]) {} - - function arr(bytes32 _a) internal pure returns (uint256[] r) { - return arr(uint256(_a)); - } - - function arr(bytes32 _a, bytes32 _b) internal pure returns (uint256[] r) { - return arr(uint256(_a), uint256(_b)); - } - - function arr(address _a) internal pure returns (uint256[] r) { - return arr(uint256(_a)); - } - - function arr(address _a, address _b) internal pure returns (uint256[] r) { - return arr(uint256(_a), uint256(_b)); - } - - function arr(address _a, uint256 _b, uint256 _c) internal pure returns (uint256[] r) { - return arr(uint256(_a), _b, _c); - } - - function arr(address _a, uint256 _b, uint256 _c, uint256 _d) internal pure returns (uint256[] r) { - return arr(uint256(_a), _b, _c, _d); - } - - function arr(address _a, uint256 _b) internal pure returns (uint256[] r) { - return arr(uint256(_a), uint256(_b)); - } - - function arr(address _a, address _b, uint256 _c, uint256 _d, uint256 _e) internal pure returns (uint256[] r) { - return arr(uint256(_a), uint256(_b), _c, _d, _e); - } - - function arr(address _a, address _b, address _c) internal pure returns (uint256[] r) { - return arr(uint256(_a), uint256(_b), uint256(_c)); - } - - function arr(address _a, address _b, uint256 _c) internal pure returns (uint256[] r) { - return arr(uint256(_a), uint256(_b), uint256(_c)); - } - - function arr(uint256 _a) internal pure returns (uint256[] r) { - r = new uint256[](1); - r[0] = _a; - } - - function arr(uint256 _a, uint256 _b) internal pure returns (uint256[] r) { - r = new uint256[](2); - r[0] = _a; - r[1] = _b; - } - - function arr(uint256 _a, uint256 _b, uint256 _c) internal pure returns (uint256[] r) { - r = new uint256[](3); - r[0] = _a; - r[1] = _b; - r[2] = _c; - } - - function arr(uint256 _a, uint256 _b, uint256 _c, uint256 _d) internal pure returns (uint256[] r) { - r = new uint256[](4); - r[0] = _a; - r[1] = _b; - r[2] = _c; - r[3] = _d; - } - - function arr(uint256 _a, uint256 _b, uint256 _c, uint256 _d, uint256 _e) internal pure returns (uint256[] r) { - r = new uint256[](5); - r[0] = _a; - r[1] = _b; - r[2] = _c; - r[3] = _d; - r[4] = _e; - } -} - - -contract ACLHelpers { - function decodeParamOp(uint256 _x) internal pure returns (uint8 b) { - return uint8(_x >> (8 * 30)); - } - - function decodeParamId(uint256 _x) internal pure returns (uint8 b) { - return uint8(_x >> (8 * 31)); - } - - function decodeParamsList(uint256 _x) internal pure returns (uint32 a, uint32 b, uint32 c) { - a = uint32(_x); - b = uint32(_x >> (8 * 4)); - c = uint32(_x >> (8 * 8)); - } -} diff --git a/apps/shared/test-helpers/contracts/acl/IACL.sol b/apps/shared/test-helpers/contracts/acl/IACL.sol deleted file mode 100644 index cf2825113..000000000 --- a/apps/shared/test-helpers/contracts/acl/IACL.sol +++ /dev/null @@ -1,14 +0,0 @@ -/* - * SPDX-License-Identitifer: MIT - */ - -pragma solidity ^0.4.24; - - -interface IACL { - function initialize(address permissionsCreator) external; - - // TODO: this should be external - // See https://github.com/ethereum/solidity/issues/4832 - function hasPermission(address who, address where, bytes32 what, bytes how) public view returns (bool); -} diff --git a/apps/shared/test-helpers/contracts/acl/IACLOracle.sol b/apps/shared/test-helpers/contracts/acl/IACLOracle.sol deleted file mode 100644 index 802537f08..000000000 --- a/apps/shared/test-helpers/contracts/acl/IACLOracle.sol +++ /dev/null @@ -1,10 +0,0 @@ -/* - * SPDX-License-Identitifer: MIT - */ - -pragma solidity ^0.4.24; - - -interface IACLOracle { - function canPerform(address who, address where, bytes32 what, uint256[] how) external view returns (bool); -} diff --git a/apps/shared/test-helpers/contracts/apm/APMNamehash.sol b/apps/shared/test-helpers/contracts/apm/APMNamehash.sol deleted file mode 100644 index adb0a2f4b..000000000 --- a/apps/shared/test-helpers/contracts/apm/APMNamehash.sol +++ /dev/null @@ -1,16 +0,0 @@ -/* - * SPDX-License-Identitifer: MIT - */ - -pragma solidity ^0.4.24; - -import "../ens/ENSConstants.sol"; - - -contract APMNamehash is ENSConstants { - bytes32 constant public APM_NODE = keccak256(abi.encodePacked(ETH_TLD_NODE, keccak256("aragonpm"))); - - function apmNamehash(string name) internal pure returns (bytes32) { - return keccak256(abi.encodePacked(APM_NODE, keccak256(bytes(name)))); - } -} diff --git a/apps/shared/test-helpers/contracts/apm/APMRegistry.sol b/apps/shared/test-helpers/contracts/apm/APMRegistry.sol deleted file mode 100644 index 50b7619f6..000000000 --- a/apps/shared/test-helpers/contracts/apm/APMRegistry.sol +++ /dev/null @@ -1,107 +0,0 @@ -pragma solidity 0.4.24; - -import "../lib/ens/AbstractENS.sol"; -import "../ens/ENSSubdomainRegistrar.sol"; -import "../factory/AppProxyFactory.sol"; -import "../apps/AragonApp.sol"; -import "../acl/ACL.sol"; -import "./Repo.sol"; - - -contract APMRegistryConstants { - // Cant have a regular APM appId because it is used to build APM - // TODO: recheck this - string constant public APM_APP_NAME = "apm-registry"; - string constant public REPO_APP_NAME = "apm-repo"; - string constant public ENS_SUB_APP_NAME = "apm-enssub"; -} - - -contract APMRegistry is AragonApp, AppProxyFactory, APMRegistryConstants { - AbstractENS public ens; - ENSSubdomainRegistrar public registrar; - - // bytes32 constant public CREATE_REPO_ROLE = keccak256("CREATE_REPO_ROLE"); - bytes32 constant public CREATE_REPO_ROLE = 0x2a9494d64846c9fdbf0158785aa330d8bc9caf45af27fa0e8898eb4d55adcea6; - - event NewRepo(bytes32 id, string name, address repo); - - /** - * NEEDS CREATE_NAME_ROLE and POINT_ROOTNODE_ROLE permissions on registrar - * @param _registrar ENSSubdomainRegistrar instance that holds registry root node ownership - */ - function initialize(ENSSubdomainRegistrar _registrar) public onlyInit { - initialized(); - - registrar = _registrar; - ens = registrar.ens(); - - registrar.pointRootNode(this); - - // Check APM has all permissions it needss - ACL acl = ACL(kernel().acl()); - require(acl.hasPermission(this, registrar, registrar.CREATE_NAME_ROLE())); - require(acl.hasPermission(this, acl, acl.CREATE_PERMISSIONS_ROLE())); - } - - /** - * @notice Create new repo in registry with `_name` - * @param _name Repo name, must be ununsed - * @param _dev Address that will be given permission to create versions - */ - function newRepo(string _name, address _dev) public auth(CREATE_REPO_ROLE) returns (Repo) { - return _newRepo(_name, _dev); - } - - /** - * @notice Create new repo in registry with `_name` and first repo version - * @param _name Repo name - * @param _dev Address that will be given permission to create versions - * @param _initialSemanticVersion Semantic version for new repo version - * @param _contractAddress address for smart contract logic for version (if set to 0, it uses last versions' contractAddress) - * @param _contentURI External URI for fetching new version's content - */ - function newRepoWithVersion( - string _name, - address _dev, - uint16[3] _initialSemanticVersion, - address _contractAddress, - bytes _contentURI - ) public auth(CREATE_REPO_ROLE) returns (Repo) - { - Repo repo = _newRepo(_name, this); // need to have permissions to create version - repo.newVersion(_initialSemanticVersion, _contractAddress, _contentURI); - - // Give permissions to _dev - ACL acl = ACL(kernel().acl()); - acl.revokePermission(this, repo, repo.CREATE_VERSION_ROLE()); - acl.grantPermission(_dev, repo, repo.CREATE_VERSION_ROLE()); - acl.setPermissionManager(_dev, repo, repo.CREATE_VERSION_ROLE()); - return repo; - } - - function _newRepo(string _name, address _dev) internal returns (Repo) { - require(bytes(_name).length > 0); - - Repo repo = newClonedRepo(); - - ACL(kernel().acl()).createPermission(_dev, repo, repo.CREATE_VERSION_ROLE(), _dev); - - // Creates [name] subdomain in the rootNode and sets registry as resolver - // This will fail if repo name already exists - bytes32 node = registrar.createNameAndPoint(keccak256(abi.encodePacked(_name)), repo); - - emit NewRepo(node, _name, repo); - - return repo; - } - - function newClonedRepo() internal returns (Repo repo) { - repo = Repo(newAppProxy(kernel(), repoAppId())); - repo.initialize(); - } - - function repoAppId() internal view returns (bytes32) { - return keccak256(abi.encodePacked(registrar.rootNode(), keccak256(abi.encodePacked(REPO_APP_NAME)))); - } -} diff --git a/apps/shared/test-helpers/contracts/apm/Repo.sol b/apps/shared/test-helpers/contracts/apm/Repo.sol deleted file mode 100644 index a3c43da85..000000000 --- a/apps/shared/test-helpers/contracts/apm/Repo.sol +++ /dev/null @@ -1,119 +0,0 @@ -pragma solidity 0.4.24; - -import "../apps/AragonApp.sol"; - - -/* solium-disable function-order */ -// Allow public initialize() to be first -contract Repo is AragonApp { - struct Version { - uint16[3] semanticVersion; - address contractAddress; - bytes contentURI; - } - - Version[] public versions; - mapping (bytes32 => uint256) internal versionIdForSemantic; - mapping (address => uint256) internal latestVersionIdForContract; - - // bytes32 constant public CREATE_VERSION_ROLE = keccak256("CREATE_VERSION_ROLE"); - bytes32 constant public CREATE_VERSION_ROLE = 0x1f56cfecd3595a2e6cc1a7e6cb0b20df84cdbd92eff2fee554e70e4e45a9a7d8; - - event NewVersion(uint256 versionId, uint16[3] semanticVersion); - - /** - * @dev Initialize can only be called once. It saves the block number in which it was initialized. - * @notice Initializes a Repo to be usable - */ - function initialize() public onlyInit { - initialized(); - } - - /** - * @notice Create new version for repo - * @param _newSemanticVersion Semantic version for new repo version - * @param _contractAddress address for smart contract logic for version (if set to 0, it uses last versions' contractAddress) - * @param _contentURI External URI for fetching new version's content - */ - function newVersion( - uint16[3] _newSemanticVersion, - address _contractAddress, - bytes _contentURI - ) public auth(CREATE_VERSION_ROLE) - { - address contractAddress = _contractAddress; - if (versions.length > 0) { - Version storage lastVersion = versions[versions.length - 1]; - require(isValidBump(lastVersion.semanticVersion, _newSemanticVersion)); - if (contractAddress == 0) { - contractAddress = lastVersion.contractAddress; - } - // Only allows smart contract change on major version bumps - require(lastVersion.contractAddress == contractAddress || _newSemanticVersion[0] > lastVersion.semanticVersion[0]); - } else { - versions.length += 1; - uint16[3] memory zeroVersion; - require(isValidBump(zeroVersion, _newSemanticVersion)); - } - - uint versionId = versions.push(Version(_newSemanticVersion, contractAddress, _contentURI)) - 1; - versionIdForSemantic[semanticVersionHash(_newSemanticVersion)] = versionId; - latestVersionIdForContract[contractAddress] = versionId; - - emit NewVersion(versionId, _newSemanticVersion); - } - - function getLatest() public view returns (uint16[3] semanticVersion, address contractAddress, bytes contentURI) { - return getByVersionId(versions.length - 1); - } - - function getLatestForContractAddress(address _contractAddress) - public - view - returns (uint16[3] semanticVersion, address contractAddress, bytes contentURI) - { - return getByVersionId(latestVersionIdForContract[_contractAddress]); - } - - function getBySemanticVersion(uint16[3] _semanticVersion) - public - view - returns (uint16[3] semanticVersion, address contractAddress, bytes contentURI) - { - return getByVersionId(versionIdForSemantic[semanticVersionHash(_semanticVersion)]); - } - - function getByVersionId(uint _versionId) public view returns (uint16[3] semanticVersion, address contractAddress, bytes contentURI) { - require(_versionId > 0); - Version storage version = versions[_versionId]; - return (version.semanticVersion, version.contractAddress, version.contentURI); - } - - function getVersionsCount() public view returns (uint256) { - uint256 len = versions.length; - return len > 0 ? len - 1 : 0; - } - - function isValidBump(uint16[3] _oldVersion, uint16[3] _newVersion) public pure returns (bool) { - bool hasBumped; - uint i = 0; - while (i < 3) { - if (hasBumped) { - if (_newVersion[i] != 0) { - return false; - } - } else if (_newVersion[i] != _oldVersion[i]) { - if (_oldVersion[i] > _newVersion[i] || _newVersion[i] - _oldVersion[i] != 1) { - return false; - } - hasBumped = true; - } - i++; - } - return hasBumped; - } - - function semanticVersionHash(uint16[3] version) internal pure returns (bytes32) { - return keccak256(abi.encodePacked(version[0], version[1], version[2])); - } -} diff --git a/apps/shared/test-helpers/contracts/apps/AppProxyBase.sol b/apps/shared/test-helpers/contracts/apps/AppProxyBase.sol deleted file mode 100644 index 0f94cd0e2..000000000 --- a/apps/shared/test-helpers/contracts/apps/AppProxyBase.sol +++ /dev/null @@ -1,38 +0,0 @@ -pragma solidity 0.4.24; - -import "./AppStorage.sol"; -import "../common/DepositableDelegateProxy.sol"; -import "../kernel/KernelConstants.sol"; -import "../kernel/IKernel.sol"; - - -contract AppProxyBase is AppStorage, DepositableDelegateProxy, KernelNamespaceConstants { - /** - * @dev Initialize AppProxy - * @param _kernel Reference to organization kernel for the app - * @param _appId Identifier for app - * @param _initializePayload Payload for call to be made after setup to initialize - */ - constructor(IKernel _kernel, bytes32 _appId, bytes _initializePayload) public { - setKernel(_kernel); - setAppId(_appId); - - // Implicit check that kernel is actually a Kernel - // The EVM doesn't actually provide a way for us to make sure, but we can force a revert to - // occur if the kernel is set to 0x0 or a non-code address when we try to call a method on - // it. - address appCode = getAppBase(_appId); - - // If initialize payload is provided, it will be executed - if (_initializePayload.length > 0) { - require(isContract(appCode)); - // Cannot make delegatecall as a delegateproxy.delegatedFwd as it - // returns ending execution context and halts contract deployment - require(appCode.delegatecall(_initializePayload)); - } - } - - function getAppBase(bytes32 _appId) internal view returns (address) { - return kernel().getApp(KERNEL_APP_BASES_NAMESPACE, _appId); - } -} \ No newline at end of file diff --git a/apps/shared/test-helpers/contracts/apps/AppProxyPinned.sol b/apps/shared/test-helpers/contracts/apps/AppProxyPinned.sol deleted file mode 100644 index 49a09ca05..000000000 --- a/apps/shared/test-helpers/contracts/apps/AppProxyPinned.sol +++ /dev/null @@ -1,49 +0,0 @@ -pragma solidity 0.4.24; - -import "../common/UnstructuredStorage.sol"; -import "../common/IsContract.sol"; -import "./AppProxyBase.sol"; - - -contract AppProxyPinned is IsContract, AppProxyBase { - using UnstructuredStorage for bytes32; - - // keccak256("aragonOS.appStorage.pinnedCode"), used by Proxy Pinned - bytes32 internal constant PINNED_CODE_POSITION = 0xdee64df20d65e53d7f51cb6ab6d921a0a6a638a91e942e1d8d02df28e31c038e; - - /** - * @dev Initialize AppProxyPinned (makes it an un-upgradeable Aragon app) - * @param _kernel Reference to organization kernel for the app - * @param _appId Identifier for app - * @param _initializePayload Payload for call to be made after setup to initialize - */ - constructor(IKernel _kernel, bytes32 _appId, bytes _initializePayload) - AppProxyBase(_kernel, _appId, _initializePayload) - public // solium-disable-line visibility-first - { - setPinnedCode(getAppBase(_appId)); - require(isContract(pinnedCode())); - } - - /** - * @dev ERC897, the address the proxy would delegate calls to - */ - function implementation() public view returns (address) { - return pinnedCode(); - } - - /** - * @dev ERC897, whether it is a forwarding (1) or an upgradeable (2) proxy - */ - function proxyType() public pure returns (uint256 proxyTypeId) { - return FORWARDING; - } - - function setPinnedCode(address _pinnedCode) internal { - PINNED_CODE_POSITION.setStorageAddress(_pinnedCode); - } - - function pinnedCode() internal view returns (address) { - return PINNED_CODE_POSITION.getStorageAddress(); - } -} diff --git a/apps/shared/test-helpers/contracts/apps/AppProxyUpgradeable.sol b/apps/shared/test-helpers/contracts/apps/AppProxyUpgradeable.sol deleted file mode 100644 index 60d4cfa0c..000000000 --- a/apps/shared/test-helpers/contracts/apps/AppProxyUpgradeable.sol +++ /dev/null @@ -1,33 +0,0 @@ -pragma solidity 0.4.24; - -import "./AppProxyBase.sol"; - - -contract AppProxyUpgradeable is AppProxyBase { - /** - * @dev Initialize AppProxyUpgradeable (makes it an upgradeable Aragon app) - * @param _kernel Reference to organization kernel for the app - * @param _appId Identifier for app - * @param _initializePayload Payload for call to be made after setup to initialize - */ - constructor(IKernel _kernel, bytes32 _appId, bytes _initializePayload) - AppProxyBase(_kernel, _appId, _initializePayload) - public // solium-disable-line visibility-first - { - - } - - /** - * @dev ERC897, the address the proxy would delegate calls to - */ - function implementation() public view returns (address) { - return getAppBase(appId()); - } - - /** - * @dev ERC897, whether it is a forwarding (1) or an upgradeable (2) proxy - */ - function proxyType() public pure returns (uint256 proxyTypeId) { - return UPGRADEABLE; - } -} diff --git a/apps/shared/test-helpers/contracts/apps/AppStorage.sol b/apps/shared/test-helpers/contracts/apps/AppStorage.sol deleted file mode 100644 index aedb59f7a..000000000 --- a/apps/shared/test-helpers/contracts/apps/AppStorage.sol +++ /dev/null @@ -1,36 +0,0 @@ -/* - * SPDX-License-Identitifer: MIT - */ - -pragma solidity ^0.4.24; - -import "../common/UnstructuredStorage.sol"; -import "../kernel/IKernel.sol"; - - -contract AppStorage { - using UnstructuredStorage for bytes32; - - // keccak256("aragonOS.appStorage.kernel") - bytes32 internal constant KERNEL_POSITION = 0x4172f0f7d2289153072b0a6ca36959e0cbe2efc3afe50fc81636caa96338137b; - // keccak256("aragonOS.appStorage.appId") - bytes32 internal constant APP_ID_POSITION = 0xd625496217aa6a3453eecb9c3489dc5a53e6c67b444329ea2b2cbc9ff547639b; - // keccak256("aragonOS.appStorage.pinnedCode"), used by Proxy Pinned - bytes32 internal constant PINNED_CODE_POSITION = 0xdee64df20d65e53d7f51cb6ab6d921a0a6a638a91e942e1d8d02df28e31c038e; - - function kernel() public view returns (IKernel) { - return IKernel(KERNEL_POSITION.getStorageAddress()); - } - - function appId() public view returns (bytes32) { - return APP_ID_POSITION.getStorageBytes32(); - } - - function setKernel(IKernel _kernel) internal { - KERNEL_POSITION.setStorageAddress(address(_kernel)); - } - - function setAppId(bytes32 _appId) internal { - APP_ID_POSITION.setStorageBytes32(_appId); - } -} diff --git a/apps/shared/test-helpers/contracts/apps/AragonApp.sol b/apps/shared/test-helpers/contracts/apps/AragonApp.sol deleted file mode 100644 index a3339a210..000000000 --- a/apps/shared/test-helpers/contracts/apps/AragonApp.sol +++ /dev/null @@ -1,68 +0,0 @@ -/* - * SPDX-License-Identitifer: MIT - */ - -pragma solidity ^0.4.24; - -import "./AppStorage.sol"; -import "../common/Autopetrified.sol"; -import "../common/VaultRecoverable.sol"; -import "../evmscript/EVMScriptRunner.sol"; -import "../acl/ACLSyntaxSugar.sol"; - - -// Contracts inheriting from AragonApp are, by default, immediately petrified upon deployment so -// that they can never be initialized. -// Unless overriden, this behaviour enforces those contracts to be usable only behind an AppProxy. -// ACLSyntaxSugar and EVMScriptRunner are not directly used by this contract, but are included so -// that they are automatically usable by subclassing contracts -contract AragonApp is AppStorage, Autopetrified, VaultRecoverable, EVMScriptRunner, ACLSyntaxSugar { - modifier auth(bytes32 _role) { - require(canPerform(msg.sender, _role, new uint256[](0))); - _; - } - - modifier authP(bytes32 _role, uint256[] _params) { - require(canPerform(msg.sender, _role, _params)); - _; - } - - /** - * @dev Check whether an action can be performed by a sender for a particular role on this app - * @param _sender Sender of the call - * @param _role Role on this app - * @param _params Permission params for the role - * @return Boolean indicating whether the sender has the permissions to perform the action. - * Always returns false if the app hasn't been initialized yet. - */ - function canPerform(address _sender, bytes32 _role, uint256[] _params) public view returns (bool) { - if (!hasInitialized()) { - return false; - } - - IKernel linkedKernel = kernel(); - if (address(linkedKernel) == address(0)) { - return false; - } - - bytes memory how; // no need to init memory as it is never used - if (_params.length > 0) { - uint256 byteLength = _params.length * 32; - assembly { - how := _params // forced casting - mstore(how, byteLength) - } - } - return linkedKernel.hasPermission(_sender, address(this), _role, how); - } - - /** - * @dev Get the recovery vault for the app - * @return Recovery vault address for the app - */ - function getRecoveryVault() public view returns (address) { - // Funds recovery via a vault is only available when used with a kernel - require(address(kernel()) != address(0)); - return kernel().getRecoveryVault(); - } -} diff --git a/apps/shared/test-helpers/contracts/apps/UnsafeAragonApp.sol b/apps/shared/test-helpers/contracts/apps/UnsafeAragonApp.sol deleted file mode 100644 index 7e46b7a65..000000000 --- a/apps/shared/test-helpers/contracts/apps/UnsafeAragonApp.sol +++ /dev/null @@ -1,24 +0,0 @@ -/* - * SPDX-License-Identitifer: MIT - */ - -pragma solidity ^0.4.24; - -import "../common/UnstructuredStorage.sol"; -import "./AragonApp.sol"; - - -// Using UnsafeAragonApp means you'll be playing with 🔥. -// A number of safe defaults are provided with AragonApp, to help you avoid dangerous situations -// and mistakes with how your contract's developed as well as how it's deployed. -// UnsafeAragonApp turns off these safety features to give you greater control over your contract. -// In particular, it allows you to: -// - Use deployed base contracts as apps directly, without a proxy -contract UnsafeAragonApp is AragonApp { - using UnstructuredStorage for bytes32; - - constructor() public { - // Removes auto petrifying; simulates a delete at INITIALIZATION_BLOCK_POSITION - INITIALIZATION_BLOCK_POSITION.setStorageUint256(0); - } -} diff --git a/apps/shared/test-helpers/contracts/apps/Voting.sol b/apps/shared/test-helpers/contracts/apps/Voting.sol deleted file mode 100644 index aae904ca5..000000000 --- a/apps/shared/test-helpers/contracts/apps/Voting.sol +++ /dev/null @@ -1,349 +0,0 @@ -/* - * SPDX-License-Identitifer: GPL-3.0-or-later - */ - -pragma solidity 0.4.24; - -import "./AragonApp.sol"; -import "../common/IForwarder.sol"; - -import "../lib/math/SafeMath.sol"; -import "../lib/math/SafeMath64.sol"; - -import "../lib/minime/MiniMeToken.sol"; - - -contract Voting is IForwarder, AragonApp { - using SafeMath for uint256; - using SafeMath64 for uint64; - - bytes32 public constant CREATE_VOTES_ROLE = keccak256("CREATE_VOTES_ROLE"); - bytes32 public constant MODIFY_SUPPORT_ROLE = keccak256("MODIFY_SUPPORT_ROLE"); - bytes32 public constant MODIFY_QUORUM_ROLE = keccak256("MODIFY_QUORUM_ROLE"); - - uint256 public constant PCT_BASE = 10 ** 18; // 0% = 0; 1% = 10^16; 100% = 10^18 - - enum VoterState { Absent, Yea, Nay } - - struct Vote { - address creator; - uint64 startDate; - uint256 snapshotBlock; - uint256 supportRequiredPct; - uint256 minAcceptQuorumPct; - uint256 yea; - uint256 nay; - uint256 totalVoters; - string metadata; - bytes executionScript; - bool executed; - mapping (address => VoterState) voters; - } - - MiniMeToken public token; - uint256 public supportRequiredPct; - uint256 public minAcceptQuorumPct; - uint64 public voteTime; - - // We are mimicing an array, we use a mapping instead to make app upgrade more graceful - mapping (uint256 => Vote) internal votes; - uint256 public votesLength; - - event StartVote(uint256 indexed voteId); - event CastVote(uint256 indexed voteId, address indexed voter, bool supports, uint256 stake); - event ExecuteVote(uint256 indexed voteId); - event ChangeSupportRequired(uint256 supportRequiredPct); - event ChangeMinQuorum(uint256 minAcceptQuorumPct); - - modifier voteExists(uint256 _voteId) { - require(_voteId < votesLength); - _; - } - - /** - * @notice Initializes Voting app with `_token.symbol(): string` for governance, minimum support of `(_supportRequiredPct - _supportRequiredPct % 10^16) / 10^14`, minimum acceptance quorum of `(_minAcceptQuorumPct - _minAcceptQuorumPct % 10^16) / 10^14` and vote duations of `(_voteTime - _voteTime % 86400) / 86400` day `_voteTime >= 172800 ? 's' : ''` - * @param _token MiniMeToken Address that will be used as governance token - * @param _supportRequiredPct Percentage of yeas in casted votes for a vote to succeed (expressed as a percentage of 10^18; eg. 10^16 = 1%, 10^18 = 100%) - * @param _minAcceptQuorumPct Percentage of yeas in total possible votes for a vote to succeed (expressed as a percentage of 10^18; eg. 10^16 = 1%, 10^18 = 100%) - * @param _voteTime Seconds that a vote will be open for token holders to vote (unless enough yeas or nays have been cast to make an early decision) - */ - function initialize( - MiniMeToken _token, - uint256 _supportRequiredPct, - uint256 _minAcceptQuorumPct, - uint64 _voteTime - ) - external - onlyInit - { - initialized(); - - require(_minAcceptQuorumPct <= _supportRequiredPct); - require(_supportRequiredPct < PCT_BASE); - - token = _token; - supportRequiredPct = _supportRequiredPct; - minAcceptQuorumPct = _minAcceptQuorumPct; - voteTime = _voteTime; - } - - /** - * @notice Change required support to `(_supportRequiredPct - _supportRequiredPct % 10^16) / 10^14`% - * @param _supportRequiredPct New required support - */ - function changeSupportRequiredPct(uint256 _supportRequiredPct) - external - authP(MODIFY_SUPPORT_ROLE, arr(_supportRequiredPct, supportRequiredPct)) - { - require(minAcceptQuorumPct <= _supportRequiredPct); - require(_supportRequiredPct < PCT_BASE); - supportRequiredPct = _supportRequiredPct; - - emit ChangeSupportRequired(_supportRequiredPct); - } - - /** - * @notice Change minimum acceptance quorum to `(_minAcceptQuorumPct - _minAcceptQuorumPct % 10^16) / 10^14`% - * @param _minAcceptQuorumPct New acceptance quorum - */ - function changeMinAcceptQuorumPct(uint256 _minAcceptQuorumPct) - external - authP(MODIFY_QUORUM_ROLE, arr(_minAcceptQuorumPct, minAcceptQuorumPct)) - { - require(_minAcceptQuorumPct <= supportRequiredPct); - minAcceptQuorumPct = _minAcceptQuorumPct; - - emit ChangeMinQuorum(_minAcceptQuorumPct); - } - - /** - * @notice Create a new vote about "`_metadata`" - * @param _executionScript EVM script to be executed on approval - * @param _metadata Vote metadata - * @return voteId Id for newly created vote - */ - function newVote(bytes _executionScript, string _metadata) external auth(CREATE_VOTES_ROLE) returns (uint256 voteId) { - return _newVote(_executionScript, _metadata, true, true); - } - - /** - * @notice Create a new vote about "`_metadata`" - * @param _executionScript EVM script to be executed on approval - * @param _metadata Vote metadata - * @param _castVote Whether to also cast newly created vote - * @param _executesIfDecided Whether to also immediately execute newly created vote if decided - * @return voteId id for newly created vote - */ - function newVote(bytes _executionScript, string _metadata, bool _castVote, bool _executesIfDecided) - external - auth(CREATE_VOTES_ROLE) - returns (uint256 voteId) - { - return _newVote(_executionScript, _metadata, _castVote, _executesIfDecided); - } - - /** - * @notice Vote `_supports ? 'yea' : 'nay'` in vote #`_voteId` - * @dev Initialization check is implicitly provided by `voteExists()` as new votes can only be - * created via `newVote(),` which requires initialization - * @param _voteId Id for vote - * @param _supports Whether voter supports the vote - * @param _executesIfDecided Whether the vote should execute its action if it becomes decided - */ - function vote(uint256 _voteId, bool _supports, bool _executesIfDecided) external voteExists(_voteId) { - require(canVote(_voteId, msg.sender)); - _vote(_voteId, _supports, msg.sender, _executesIfDecided); - } - - /** - * @notice Execute the result of dot vote #`_voteId` - * @dev Initialization check is implicitly provided by `voteExists()` as new votes can only be - * created via `newVote(),` which requires initialization - * @param _voteId Id for vote - */ - function executeVote(uint256 _voteId) external voteExists(_voteId) { - require(canExecute(_voteId)); - _executeVote(_voteId); - } - - function isForwarder() public pure returns (bool) { - return true; - } - - /** - * @notice Creates a vote to execute the desired action, and casts a support vote - * @dev IForwarder interface conformance - * @param _evmScript Start vote with script - */ - function forward(bytes _evmScript) public { - require(canForward(msg.sender, _evmScript)); - _newVote(_evmScript, "", true, true); - } - - function canForward(address _sender, bytes) public view returns (bool) { - // Note that `canPerform()` implicitly does an initialization check itself - return canPerform(_sender, CREATE_VOTES_ROLE, arr()); - } - - function canVote(uint256 _voteId, address _voter) public view voteExists(_voteId) returns (bool) { - Vote storage vote_ = votes[_voteId]; - - return _isVoteOpen(vote_) && token.balanceOfAt(_voter, vote_.snapshotBlock) > 0; - } - - function canExecute(uint256 _voteId) public view voteExists(_voteId) returns (bool) { - Vote storage vote_ = votes[_voteId]; - - if (vote_.executed) { - return false; - } - - // Voting is already decided - if (_isValuePct(vote_.yea, vote_.totalVoters, vote_.supportRequiredPct)) { - return true; - } - - uint256 totalVotes = vote_.yea.add(vote_.nay); - - // Vote ended? - if (_isVoteOpen(vote_)) { - return false; - } - // Has enough support? - if (!_isValuePct(vote_.yea, totalVotes, vote_.supportRequiredPct)) { - return false; - } - // Has min quorum? - if (!_isValuePct(vote_.yea, vote_.totalVoters, vote_.minAcceptQuorumPct)) { - return false; - } - - return true; - } - - function getVote(uint256 _voteId) - public - view - voteExists(_voteId) - returns ( - bool open, - bool executed, - address creator, - uint64 startDate, - uint256 snapshotBlock, - uint256 supportRequired, - uint256 minAcceptQuorum, - uint256 yea, - uint256 nay, - uint256 totalVoters, - bytes script - ) - { - Vote storage vote_ = votes[_voteId]; - - open = _isVoteOpen(vote_); - executed = vote_.executed; - creator = vote_.creator; - startDate = vote_.startDate; - snapshotBlock = vote_.snapshotBlock; - supportRequired = vote_.supportRequiredPct; - minAcceptQuorum = vote_.minAcceptQuorumPct; - yea = vote_.yea; - nay = vote_.nay; - totalVoters = vote_.totalVoters; - script = vote_.executionScript; - } - - function getVoteMetadata(uint256 _voteId) public view voteExists(_voteId) returns (string) { - return votes[_voteId].metadata; - } - - function getVoterState(uint256 _voteId, address _voter) public view voteExists(_voteId) returns (VoterState) { - return votes[_voteId].voters[_voter]; - } - - function _newVote(bytes _executionScript, string _metadata, bool _castVote, bool _executesIfDecided) - internal - returns (uint256 voteId) - { - voteId = votesLength++; - Vote storage vote_ = votes[voteId]; - vote_.executionScript = _executionScript; - vote_.creator = msg.sender; - vote_.startDate = getTimestamp64(); - vote_.metadata = _metadata; - vote_.snapshotBlock = getBlockNumber() - 1; // avoid double voting in this very block - vote_.totalVoters = token.totalSupplyAt(vote_.snapshotBlock); - vote_.supportRequiredPct = supportRequiredPct; - vote_.minAcceptQuorumPct = minAcceptQuorumPct; - - emit StartVote(voteId); - - if (_castVote && canVote(voteId, msg.sender)) { - _vote(voteId, true, msg.sender, _executesIfDecided); - } - } - - function _vote( - uint256 _voteId, - bool _supports, - address _voter, - bool _executesIfDecided - ) internal - { - Vote storage vote_ = votes[_voteId]; - - // This could re-enter, though we can assume the governance token is not malicious - uint256 voterStake = token.balanceOfAt(_voter, vote_.snapshotBlock); - VoterState state = vote_.voters[_voter]; - - // If voter had previously voted, decrease count - if (state == VoterState.Yea) { - vote_.yea = vote_.yea.sub(voterStake); - } else if (state == VoterState.Nay) { - vote_.nay = vote_.nay.sub(voterStake); - } - - if (_supports) { - vote_.yea = vote_.yea.add(voterStake); - } else { - vote_.nay = vote_.nay.add(voterStake); - } - - vote_.voters[_voter] = _supports ? VoterState.Yea : VoterState.Nay; - - emit CastVote(_voteId, _voter, _supports, voterStake); - - if (_executesIfDecided && canExecute(_voteId)) { - _executeVote(_voteId); - } - } - - function _executeVote(uint256 _voteId) internal { - Vote storage vote_ = votes[_voteId]; - - vote_.executed = true; - - bytes memory input = new bytes(0); // TODO: Consider input for voting scripts - runScript(vote_.executionScript, input, new address[](0)); - - emit ExecuteVote(_voteId); - } - - function _isVoteOpen(Vote storage vote_) internal view returns (bool) { - return getTimestamp64() < vote_.startDate.add(voteTime) && !vote_.executed; - } - - /** - * @dev Calculates whether `_value` is more than a percentage `_pct` of `_total` - */ - function _isValuePct(uint256 _value, uint256 _total, uint256 _pct) internal pure returns (bool) { - if (_total == 0) { - return false; - } - - uint256 computedPct = _value.mul(PCT_BASE) / _total; - - return computedPct > _pct; - } -} \ No newline at end of file diff --git a/apps/shared/test-helpers/contracts/apps/readme.md b/apps/shared/test-helpers/contracts/apps/readme.md deleted file mode 100644 index 9a858af52..000000000 --- a/apps/shared/test-helpers/contracts/apps/readme.md +++ /dev/null @@ -1,3 +0,0 @@ -# Aragon apps - -Aragon default apps have been moved to their own repository: [aragon-apps](https://github.com/aragon/aragon-apps) diff --git a/apps/shared/test-helpers/contracts/common/Autopetrified.sol b/apps/shared/test-helpers/contracts/common/Autopetrified.sol deleted file mode 100644 index 1224319d5..000000000 --- a/apps/shared/test-helpers/contracts/common/Autopetrified.sol +++ /dev/null @@ -1,16 +0,0 @@ -/* - * SPDX-License-Identitifer: MIT - */ - -pragma solidity ^0.4.24; - -import "./Petrifiable.sol"; - - -contract Autopetrified is Petrifiable { - constructor() public { - // Immediately petrify base (non-proxy) instances of inherited contracts on deploy. - // This renders them uninitializable (and unusable without a proxy). - petrify(); - } -} diff --git a/apps/shared/test-helpers/contracts/common/DelegateProxy.sol b/apps/shared/test-helpers/contracts/common/DelegateProxy.sol deleted file mode 100644 index 729117a05..000000000 --- a/apps/shared/test-helpers/contracts/common/DelegateProxy.sol +++ /dev/null @@ -1,31 +0,0 @@ -pragma solidity 0.4.24; - -import "../common/IsContract.sol"; -import "../lib/misc/ERCProxy.sol"; - - -contract DelegateProxy is ERCProxy, IsContract { - uint256 constant public FWD_GAS_LIMIT = 10000; - - /** - * @dev Performs a delegatecall and returns whatever the delegatecall returned (entire context execution will return!) - * @param _dst Destination address to perform the delegatecall - * @param _calldata Calldata for the delegatecall - */ - function delegatedFwd(address _dst, bytes _calldata) internal { - require(isContract(_dst)); - uint256 fwdGasLimit = FWD_GAS_LIMIT; - - assembly { - let result := delegatecall(sub(gas, fwdGasLimit), _dst, add(_calldata, 0x20), mload(_calldata), 0, 0) - let size := returndatasize - let ptr := mload(0x40) - returndatacopy(ptr, 0, size) - - // revert instead of invalid() bc if the underlying call failed with invalid() it already wasted gas. - // if the call returned error data, forward it - switch result case 0 { revert(ptr, size) } - default { return(ptr, size) } - } - } -} diff --git a/apps/shared/test-helpers/contracts/common/DepositableDelegateProxy.sol b/apps/shared/test-helpers/contracts/common/DepositableDelegateProxy.sol deleted file mode 100644 index eda7ca5a7..000000000 --- a/apps/shared/test-helpers/contracts/common/DepositableDelegateProxy.sol +++ /dev/null @@ -1,21 +0,0 @@ -pragma solidity 0.4.24; - -import "./DelegateProxy.sol"; -import "./DepositableStorage.sol"; - - -contract DepositableDelegateProxy is DepositableStorage, DelegateProxy { - event ProxyDeposit(address sender, uint256 value); - - function () external payable { - // send / transfer - if (gasleft() < FWD_GAS_LIMIT) { - require(msg.value > 0 && msg.data.length == 0); - require(isDepositable()); - emit ProxyDeposit(msg.sender, msg.value); - } else { // all calls except for send or transfer - address target = implementation(); - delegatedFwd(target, msg.data); - } - } -} diff --git a/apps/shared/test-helpers/contracts/common/DepositableStorage.sol b/apps/shared/test-helpers/contracts/common/DepositableStorage.sol deleted file mode 100644 index 9b9970de3..000000000 --- a/apps/shared/test-helpers/contracts/common/DepositableStorage.sol +++ /dev/null @@ -1,19 +0,0 @@ -pragma solidity 0.4.24; - -import "./UnstructuredStorage.sol"; - - -contract DepositableStorage { - using UnstructuredStorage for bytes32; - - // keccak256("aragonOS.depositableStorage.depositable") - bytes32 internal constant DEPOSITABLE_POSITION = 0x665fd576fbbe6f247aff98f5c94a561e3f71ec2d3c988d56f12d342396c50cea; - - function isDepositable() public view returns (bool) { - return DEPOSITABLE_POSITION.getStorageBool(); - } - - function setDepositable(bool _depositable) internal { - DEPOSITABLE_POSITION.setStorageBool(_depositable); - } -} diff --git a/apps/shared/test-helpers/contracts/common/EtherTokenConstant.sol b/apps/shared/test-helpers/contracts/common/EtherTokenConstant.sol deleted file mode 100644 index 120c3a981..000000000 --- a/apps/shared/test-helpers/contracts/common/EtherTokenConstant.sol +++ /dev/null @@ -1,12 +0,0 @@ -/* - * SPDX-License-Identitifer: MIT - */ - -pragma solidity ^0.4.24; - - -// aragonOS and aragon-apps rely on address(0) to denote native ETH, in -// contracts where both tokens and ETH are accepted -contract EtherTokenConstant { - address constant public ETH = address(0); -} diff --git a/apps/shared/test-helpers/contracts/common/IForwarder.sol b/apps/shared/test-helpers/contracts/common/IForwarder.sol deleted file mode 100644 index 5876f465d..000000000 --- a/apps/shared/test-helpers/contracts/common/IForwarder.sol +++ /dev/null @@ -1,18 +0,0 @@ -/* - * SPDX-License-Identitifer: MIT - */ - -pragma solidity ^0.4.24; - - -interface IForwarder { - function isForwarder() external pure returns (bool); - - // TODO: this should be external - // See https://github.com/ethereum/solidity/issues/4832 - function canForward(address sender, bytes evmCallScript) public view returns (bool); - - // TODO: this should be external - // See https://github.com/ethereum/solidity/issues/4832 - function forward(bytes evmCallScript) public; -} diff --git a/apps/shared/test-helpers/contracts/common/IVaultRecoverable.sol b/apps/shared/test-helpers/contracts/common/IVaultRecoverable.sol deleted file mode 100644 index f747b9a0f..000000000 --- a/apps/shared/test-helpers/contracts/common/IVaultRecoverable.sol +++ /dev/null @@ -1,13 +0,0 @@ -/* - * SPDX-License-Identitifer: MIT - */ - -pragma solidity ^0.4.24; - - -interface IVaultRecoverable { - function transferToVault(address token) external; - - function allowRecoverability(address token) external view returns (bool); - function getRecoveryVault() external view returns (address); -} diff --git a/apps/shared/test-helpers/contracts/common/Initializable.sol b/apps/shared/test-helpers/contracts/common/Initializable.sol deleted file mode 100644 index 6e6fad3e0..000000000 --- a/apps/shared/test-helpers/contracts/common/Initializable.sol +++ /dev/null @@ -1,56 +0,0 @@ -/* - * SPDX-License-Identitifer: MIT - */ - -pragma solidity ^0.4.24; - -import "./UnstructuredStorage.sol"; -import "../common/TimeHelpers.sol"; - - -contract Initializable is TimeHelpers { - using UnstructuredStorage for bytes32; - - // keccak256("aragonOS.initializable.initializationBlock") - bytes32 internal constant INITIALIZATION_BLOCK_POSITION = 0xebb05b386a8d34882b8711d156f463690983dc47815980fb82aeeff1aa43579e; - - modifier onlyInit { - require(getInitializationBlock() == 0); - _; - } - - modifier isInitialized { - require(hasInitialized()); - _; - } - - /** - * @return Block number in which the contract was initialized - */ - function getInitializationBlock() public view returns (uint256) { - return INITIALIZATION_BLOCK_POSITION.getStorageUint256(); - } - - /** - * @return Whether the contract has been initialized by the time of the current block - */ - function hasInitialized() public view returns (bool) { - uint256 initializationBlock = getInitializationBlock(); - return initializationBlock != 0 && getBlockNumber() >= initializationBlock; - } - - /** - * @dev Function to be called by top level contract after initialization has finished. - */ - function initialized() internal onlyInit { - INITIALIZATION_BLOCK_POSITION.setStorageUint256(getBlockNumber()); - } - - /** - * @dev Function to be called by top level contract after initialization to enable the contract - * at a future block number rather than immediately. - */ - function initializedAt(uint256 _blockNumber) internal onlyInit { - INITIALIZATION_BLOCK_POSITION.setStorageUint256(_blockNumber); - } -} diff --git a/apps/shared/test-helpers/contracts/common/IsContract.sol b/apps/shared/test-helpers/contracts/common/IsContract.sol deleted file mode 100644 index 64eda8577..000000000 --- a/apps/shared/test-helpers/contracts/common/IsContract.sol +++ /dev/null @@ -1,18 +0,0 @@ -/* - * SPDX-License-Identitifer: MIT - */ - -pragma solidity ^0.4.24; - - -contract IsContract { - function isContract(address _target) internal view returns (bool) { - if (_target == address(0)) { - return false; - } - - uint256 size; - assembly { size := extcodesize(_target) } - return size > 0; - } -} diff --git a/apps/shared/test-helpers/contracts/common/Petrifiable.sol b/apps/shared/test-helpers/contracts/common/Petrifiable.sol deleted file mode 100644 index 7c46f9618..000000000 --- a/apps/shared/test-helpers/contracts/common/Petrifiable.sol +++ /dev/null @@ -1,25 +0,0 @@ -/* - * SPDX-License-Identitifer: MIT - */ - -pragma solidity ^0.4.24; - -import "./Initializable.sol"; - - -contract Petrifiable is Initializable { - // Use block UINT256_MAX (which should be never) as the initializable date - uint256 constant internal PETRIFIED_BLOCK = uint256(-1); - - function isPetrified() public view returns (bool) { - return getInitializationBlock() == PETRIFIED_BLOCK; - } - - /** - * @dev Function to be called by top level contract to prevent being initialized. - * Useful for freezing base contracts when they're used behind proxies. - */ - function petrify() internal onlyInit { - initializedAt(PETRIFIED_BLOCK); - } -} diff --git a/apps/shared/test-helpers/contracts/common/TimeHelpers.sol b/apps/shared/test-helpers/contracts/common/TimeHelpers.sol deleted file mode 100644 index cb9993331..000000000 --- a/apps/shared/test-helpers/contracts/common/TimeHelpers.sol +++ /dev/null @@ -1,48 +0,0 @@ -/* - * SPDX-License-Identitifer: MIT - */ - -pragma solidity ^0.4.24; - -import "./Uint256Helpers.sol"; - - -contract TimeHelpers { - using Uint256Helpers for uint256; - - /** - * @dev Returns the current block number. - * Using a function rather than `block.number` allows us to easily mock the block number in - * tests. - */ - function getBlockNumber() internal view returns (uint256) { - return block.number; - } - - /** - * @dev Returns the current block number, converted to uint64. - * Using a function rather than `block.number` allows us to easily mock the block number in - * tests. - */ - function getBlockNumber64() internal view returns (uint64) { - return getBlockNumber().toUint64(); - } - - /** - * @dev Returns the current timestamp. - * Using a function rather than `block.timestamp` allows us to easily mock it in - * tests. - */ - function getTimestamp() internal view returns (uint256) { - return block.timestamp; // solium-disable-line security/no-block-members - } - - /** - * @dev Returns the current timestamp, converted to uint64. - * Using a function rather than `block.timestamp` allows us to easily mock it in - * tests. - */ - function getTimestamp64() internal view returns (uint64) { - return getTimestamp().toUint64(); - } -} diff --git a/apps/shared/test-helpers/contracts/common/Uint256Helpers.sol b/apps/shared/test-helpers/contracts/common/Uint256Helpers.sol deleted file mode 100644 index e22cc149f..000000000 --- a/apps/shared/test-helpers/contracts/common/Uint256Helpers.sol +++ /dev/null @@ -1,11 +0,0 @@ -pragma solidity ^0.4.24; - - -library Uint256Helpers { - uint256 public constant MAX_UINT64 = uint64(-1); - - function toUint64(uint256 a) internal pure returns (uint64) { - require(a <= MAX_UINT64); - return uint64(a); - } -} diff --git a/apps/shared/test-helpers/contracts/common/UnstructuredStorage.sol b/apps/shared/test-helpers/contracts/common/UnstructuredStorage.sol deleted file mode 100644 index db0a56d98..000000000 --- a/apps/shared/test-helpers/contracts/common/UnstructuredStorage.sol +++ /dev/null @@ -1,40 +0,0 @@ -/* - * SPDX-License-Identitifer: MIT - */ - -pragma solidity ^0.4.24; - - -library UnstructuredStorage { - function getStorageBool(bytes32 position) internal view returns (bool data) { - assembly { data := sload(position) } - } - - function getStorageAddress(bytes32 position) internal view returns (address data) { - assembly { data := sload(position) } - } - - function getStorageBytes32(bytes32 position) internal view returns (bytes32 data) { - assembly { data := sload(position) } - } - - function getStorageUint256(bytes32 position) internal view returns (uint256 data) { - assembly { data := sload(position) } - } - - function setStorageBool(bytes32 position, bool data) internal { - assembly { sstore(position, data) } - } - - function setStorageAddress(bytes32 position, address data) internal { - assembly { sstore(position, data) } - } - - function setStorageBytes32(bytes32 position, bytes32 data) internal { - assembly { sstore(position, data) } - } - - function setStorageUint256(bytes32 position, uint256 data) internal { - assembly { sstore(position, data) } - } -} diff --git a/apps/shared/test-helpers/contracts/common/VaultRecoverable.sol b/apps/shared/test-helpers/contracts/common/VaultRecoverable.sol deleted file mode 100644 index 5e4538d44..000000000 --- a/apps/shared/test-helpers/contracts/common/VaultRecoverable.sol +++ /dev/null @@ -1,43 +0,0 @@ -/* - * SPDX-License-Identitifer: MIT - */ - -pragma solidity ^0.4.24; - -import "../lib/token/ERC20.sol"; -import "./EtherTokenConstant.sol"; -import "./IsContract.sol"; -import "./IVaultRecoverable.sol"; - - -contract VaultRecoverable is IVaultRecoverable, EtherTokenConstant, IsContract { - /** - * @notice Send funds to recovery Vault. This contract should never receive funds, - * but in case it does, this function allows one to recover them. - * @param _token Token balance to be sent to recovery vault. - */ - function transferToVault(address _token) external { - require(allowRecoverability(_token)); - address vault = getRecoveryVault(); - require(isContract(vault)); - - if (_token == ETH) { - vault.transfer(address(this).balance); - } else { - uint256 amount = ERC20(_token).balanceOf(this); - ERC20(_token).transfer(vault, amount); - } - } - - /** - * @dev By default deriving from AragonApp makes it recoverable - * @return bool whether the app allows the recovery - */ - function allowRecoverability(address /*token*/) public view returns (bool) { - return true; - } - // * @param token Token address that would be recovered // unused - - // Cast non-implemented interface to be public so we can use it internally - function getRecoveryVault() public view returns (address); -} diff --git a/apps/shared/test-helpers/contracts/ens/ENSConstants.sol b/apps/shared/test-helpers/contracts/ens/ENSConstants.sol deleted file mode 100644 index f7b843e4c..000000000 --- a/apps/shared/test-helpers/contracts/ens/ENSConstants.sol +++ /dev/null @@ -1,14 +0,0 @@ -/* - * SPDX-License-Identitifer: MIT - */ - -pragma solidity ^0.4.24; - - -contract ENSConstants { - bytes32 constant public ENS_ROOT = bytes32(0); - bytes32 constant public ETH_TLD_LABEL = keccak256("eth"); - bytes32 constant public ETH_TLD_NODE = keccak256(abi.encodePacked(ENS_ROOT, ETH_TLD_LABEL)); - bytes32 constant public PUBLIC_RESOLVER_LABEL = keccak256("resolver"); - bytes32 constant public PUBLIC_RESOLVER_NODE = keccak256(abi.encodePacked(ETH_TLD_NODE, PUBLIC_RESOLVER_LABEL)); -} diff --git a/apps/shared/test-helpers/contracts/ens/ENSSubdomainRegistrar.sol b/apps/shared/test-helpers/contracts/ens/ENSSubdomainRegistrar.sol deleted file mode 100644 index 4013b3c94..000000000 --- a/apps/shared/test-helpers/contracts/ens/ENSSubdomainRegistrar.sol +++ /dev/null @@ -1,92 +0,0 @@ -pragma solidity 0.4.24; - -import "../lib/ens/AbstractENS.sol"; -import "../lib/ens/PublicResolver.sol"; -import "./ENSConstants.sol"; - -import "../apps/AragonApp.sol"; - - -/* solium-disable function-order */ -// Allow public initialize() to be first -contract ENSSubdomainRegistrar is AragonApp, ENSConstants { - // bytes32 constant public CREATE_NAME_ROLE = keccak256("CREATE_NAME_ROLE"); - // bytes32 constant public DELETE_NAME_ROLE = keccak256("DELETE_NAME_ROLE"); - // bytes32 constant public POINT_ROOTNODE_ROLE = keccak256("POINT_ROOTNODE_ROLE"); - bytes32 constant public CREATE_NAME_ROLE = 0xf86bc2abe0919ab91ef714b2bec7c148d94f61fdb069b91a6cfe9ecdee1799ba; - bytes32 constant public DELETE_NAME_ROLE = 0x03d74c8724218ad4a99859bcb2d846d39999449fd18013dd8d69096627e68622; - bytes32 constant public POINT_ROOTNODE_ROLE = 0x9ecd0e7bddb2e241c41b595a436c4ea4fd33c9fa0caa8056acf084fc3aa3bfbe; - - AbstractENS public ens; - bytes32 public rootNode; - - event NewName(bytes32 indexed node, bytes32 indexed label); - event DeleteName(bytes32 indexed node, bytes32 indexed label); - - function initialize(AbstractENS _ens, bytes32 _rootNode) public onlyInit { - initialized(); - - // We need ownership to create subnodes - require(_ens.owner(_rootNode) == address(this)); - - ens = _ens; - rootNode = _rootNode; - } - - function createName(bytes32 _label, address _owner) external auth(CREATE_NAME_ROLE) returns (bytes32 node) { - return _createName(_label, _owner); - } - - function createNameAndPoint(bytes32 _label, address _target) external auth(CREATE_NAME_ROLE) returns (bytes32 node) { - node = _createName(_label, this); - _pointToResolverAndResolve(node, _target); - } - - function deleteName(bytes32 _label) external auth(DELETE_NAME_ROLE) { - bytes32 node = getNodeForLabel(_label); - - address currentOwner = ens.owner(node); - - require(currentOwner != address(0)); // fail if deleting unset name - - if (currentOwner != address(this)) { // needs to reclaim ownership so it can set resolver - ens.setSubnodeOwner(rootNode, _label, this); - } - - ens.setResolver(node, address(0)); // remove resolver so it ends resolving - ens.setOwner(node, address(0)); - - emit DeleteName(node, _label); - } - - function pointRootNode(address _target) external auth(POINT_ROOTNODE_ROLE) { - _pointToResolverAndResolve(rootNode, _target); - } - - function _createName(bytes32 _label, address _owner) internal returns (bytes32 node) { - node = getNodeForLabel(_label); - require(ens.owner(node) == address(0)); // avoid name reset - - ens.setSubnodeOwner(rootNode, _label, _owner); - - emit NewName(node, _label); - - return node; - } - - function _pointToResolverAndResolve(bytes32 _node, address _target) internal { - address publicResolver = getAddr(PUBLIC_RESOLVER_NODE); - ens.setResolver(_node, publicResolver); - - PublicResolver(publicResolver).setAddr(_node, _target); - } - - function getAddr(bytes32 node) internal view returns (address) { - address resolver = ens.resolver(node); - return PublicResolver(resolver).addr(node); - } - - function getNodeForLabel(bytes32 _label) internal view returns (bytes32) { - return keccak256(abi.encodePacked(rootNode, _label)); - } -} diff --git a/apps/shared/test-helpers/contracts/evmscript/EVMScriptRegistry.sol b/apps/shared/test-helpers/contracts/evmscript/EVMScriptRegistry.sol deleted file mode 100644 index ea74f758d..000000000 --- a/apps/shared/test-helpers/contracts/evmscript/EVMScriptRegistry.sol +++ /dev/null @@ -1,92 +0,0 @@ -pragma solidity 0.4.24; - -import "../apps/AragonApp.sol"; -import "./ScriptHelpers.sol"; -import "./IEVMScriptExecutor.sol"; -import "./IEVMScriptRegistry.sol"; - - -/* solium-disable function-order */ -// Allow public initialize() to be first -contract EVMScriptRegistry is IEVMScriptRegistry, EVMScriptRegistryConstants, AragonApp { - using ScriptHelpers for bytes; - - // bytes32 constant public REGISTRY_ADD_EXECUTOR_ROLE = keccak256("REGISTRY_ADD_EXECUTOR_ROLE"); - bytes32 constant public REGISTRY_ADD_EXECUTOR_ROLE = 0xc4e90f38eea8c4212a009ca7b8947943ba4d4a58d19b683417f65291d1cd9ed2; - // WARN: Manager can censor all votes and the like happening in an org - // bytes32 constant public REGISTRY_MANAGER_ROLE = keccak256("REGISTRY_MANAGER_ROLE"); - bytes32 constant public REGISTRY_MANAGER_ROLE = 0xf7a450ef335e1892cb42c8ca72e7242359d7711924b75db5717410da3f614aa3; - - struct ExecutorEntry { - IEVMScriptExecutor executor; - bool enabled; - } - - ExecutorEntry[] public executors; - - event EnableExecutor(uint256 indexed executorId, address indexed executorAddress); - event DisableExecutor(uint256 indexed executorId, address indexed executorAddress); - - /** - * @notice Initialize the registry - */ - function initialize() public onlyInit { - initialized(); - // Create empty record to begin executor IDs at 1 - executors.push(ExecutorEntry(IEVMScriptExecutor(0), false)); - } - - /** - * @notice Add a new script executor with address `_executor` to the registry - * @param _executor Address of the IEVMScriptExecutor that will be added to the registry - * @return id Identifier of the executor in the registry - */ - function addScriptExecutor(IEVMScriptExecutor _executor) external auth(REGISTRY_ADD_EXECUTOR_ROLE) returns (uint256 id) { - uint256 executorId = executors.push(ExecutorEntry(_executor, true)) - 1; - emit EnableExecutor(executorId, _executor); - return executorId; - } - - /** - * @notice Disable script executor with ID `_executorId` - * @param _executorId Identifier of the executor in the registry - */ - function disableScriptExecutor(uint256 _executorId) - external - authP(REGISTRY_MANAGER_ROLE, arr(_executorId)) - { - ExecutorEntry storage executorEntry = executors[_executorId]; - require(executorEntry.enabled); - executorEntry.enabled = false; - emit DisableExecutor(_executorId, executorEntry.executor); - } - - /** - * @notice Enable script executor with ID `_executorId` - * @param _executorId Identifier of the executor in the registry - */ - function enableScriptExecutor(uint256 _executorId) - external - authP(REGISTRY_MANAGER_ROLE, arr(_executorId)) - { - ExecutorEntry storage executorEntry = executors[_executorId]; - require(!executorEntry.enabled); - executorEntry.enabled = true; - emit EnableExecutor(_executorId, executorEntry.executor); - } - - /** - * @dev Get the script executor that can execute a particular script based on its first 4 bytes - * @param _script EVMScript being inspected - */ - function getScriptExecutor(bytes _script) public view returns (IEVMScriptExecutor) { - uint256 id = _script.getSpecId(); - - if (id == 0 || id >= executors.length) { - return IEVMScriptExecutor(0); - } - - ExecutorEntry storage entry = executors[id]; - return entry.enabled ? entry.executor : IEVMScriptExecutor(0); - } -} diff --git a/apps/shared/test-helpers/contracts/evmscript/EVMScriptRunner.sol b/apps/shared/test-helpers/contracts/evmscript/EVMScriptRunner.sol deleted file mode 100644 index 5855be12c..000000000 --- a/apps/shared/test-helpers/contracts/evmscript/EVMScriptRunner.sol +++ /dev/null @@ -1,76 +0,0 @@ -/* - * SPDX-License-Identitifer: MIT - */ - -pragma solidity ^0.4.24; - -import "./IEVMScriptExecutor.sol"; -import "./IEVMScriptRegistry.sol"; - -import "../apps/AppStorage.sol"; -import "../kernel/KernelConstants.sol"; -import "../common/Initializable.sol"; - - -contract EVMScriptRunner is AppStorage, Initializable, EVMScriptRegistryConstants, KernelNamespaceConstants { - string private constant ERROR_EXECUTOR_UNAVAILABLE = "EVMRUN_EXECUTOR_UNAVAILABLE"; - string private constant ERROR_EXECUTION_REVERTED = "EVMRUN_EXECUTION_REVERTED"; - string private constant ERROR_PROTECTED_STATE_MODIFIED = "EVMRUN_PROTECTED_STATE_MODIFIED"; - - event ScriptResult(address indexed executor, bytes script, bytes input, bytes returnData); - - function getEVMScriptExecutor(bytes _script) public view returns (IEVMScriptExecutor) { - return IEVMScriptExecutor(getEVMScriptRegistry().getScriptExecutor(_script)); - } - - function getEVMScriptRegistry() public view returns (IEVMScriptRegistry) { - address registryAddr = kernel().getApp(KERNEL_APP_ADDR_NAMESPACE, EVMSCRIPT_REGISTRY_APP_ID); - return IEVMScriptRegistry(registryAddr); - } - - function runScript(bytes _script, bytes _input, address[] _blacklist) - internal - isInitialized - protectState - returns (bytes) - { - // TODO: Too much data flying around, maybe extracting spec id here is cheaper - IEVMScriptExecutor executor = getEVMScriptExecutor(_script); - require(address(executor) != address(0), ERROR_EXECUTOR_UNAVAILABLE); - - bytes4 sig = executor.execScript.selector; - bytes memory data = abi.encodeWithSelector(sig, _script, _input, _blacklist); - require(address(executor).delegatecall(data), ERROR_EXECUTION_REVERTED); - - bytes memory output = returnedDataDecoded(); - - emit ScriptResult(address(executor), _script, _input, output); - - return output; - } - - /** - * @dev copies and returns last's call data. Needs to ABI decode first - */ - function returnedDataDecoded() internal pure returns (bytes ret) { - assembly { - let size := returndatasize - switch size - case 0 {} - default { - ret := mload(0x40) // free mem ptr get - mstore(0x40, add(ret, add(size, 0x20))) // free mem ptr set - returndatacopy(ret, 0x20, sub(size, 0x20)) // copy return data - } - } - return ret; - } - - modifier protectState { - address preKernel = address(kernel()); - bytes32 preAppId = appId(); - _; // exec - require(address(kernel()) == preKernel, ERROR_PROTECTED_STATE_MODIFIED); - require(appId() == preAppId, ERROR_PROTECTED_STATE_MODIFIED); - } -} \ No newline at end of file diff --git a/apps/shared/test-helpers/contracts/evmscript/IEVMScriptExecutor.sol b/apps/shared/test-helpers/contracts/evmscript/IEVMScriptExecutor.sol deleted file mode 100644 index ffa036824..000000000 --- a/apps/shared/test-helpers/contracts/evmscript/IEVMScriptExecutor.sol +++ /dev/null @@ -1,11 +0,0 @@ -/* - * SPDX-License-Identitifer: MIT - */ - -pragma solidity ^0.4.24; - - -interface IEVMScriptExecutor { - function execScript(bytes script, bytes input, address[] blacklist) external returns (bytes); - function executorType() external pure returns (bytes32); -} diff --git a/apps/shared/test-helpers/contracts/evmscript/IEVMScriptRegistry.sol b/apps/shared/test-helpers/contracts/evmscript/IEVMScriptRegistry.sol deleted file mode 100644 index 0d0f026bc..000000000 --- a/apps/shared/test-helpers/contracts/evmscript/IEVMScriptRegistry.sol +++ /dev/null @@ -1,25 +0,0 @@ -/* - * SPDX-License-Identitifer: MIT - */ - -pragma solidity ^0.4.24; - -import "./IEVMScriptExecutor.sol"; - - -contract EVMScriptRegistryConstants { - /* Hardcoded constants to save gas - bytes32 constant public EVMSCRIPT_REGISTRY_APP_ID = apmNamehash("evmreg"); - */ - bytes32 constant public EVMSCRIPT_REGISTRY_APP_ID = 0xddbcfd564f642ab5627cf68b9b7d374fb4f8a36e941a75d89c87998cef03bd61; -} - - -interface IEVMScriptRegistry { - function addScriptExecutor(IEVMScriptExecutor executor) external returns (uint id); - function disableScriptExecutor(uint256 executorId) external; - - // TODO: this should be external - // See https://github.com/ethereum/solidity/issues/4832 - function getScriptExecutor(bytes script) public view returns (IEVMScriptExecutor); -} diff --git a/apps/shared/test-helpers/contracts/evmscript/executors/BaseEVMScriptExecutor.sol b/apps/shared/test-helpers/contracts/evmscript/executors/BaseEVMScriptExecutor.sol deleted file mode 100644 index 2a10dfd87..000000000 --- a/apps/shared/test-helpers/contracts/evmscript/executors/BaseEVMScriptExecutor.sol +++ /dev/null @@ -1,13 +0,0 @@ -/* - * SPDX-License-Identitifer: MIT - */ - -pragma solidity ^0.4.24; - -import "../../common/Autopetrified.sol"; -import "../IEVMScriptExecutor.sol"; - - -contract BaseEVMScriptExecutor is IEVMScriptExecutor, Autopetrified { - uint256 constant internal SCRIPT_START_LOCATION = 4; -} diff --git a/apps/shared/test-helpers/contracts/evmscript/executors/CallsScript.sol b/apps/shared/test-helpers/contracts/evmscript/executors/CallsScript.sol deleted file mode 100644 index e4cf528b0..000000000 --- a/apps/shared/test-helpers/contracts/evmscript/executors/CallsScript.sol +++ /dev/null @@ -1,55 +0,0 @@ -pragma solidity 0.4.24; - -// Inspired by https://github.com/reverendus/tx-manager - -import "../ScriptHelpers.sol"; -import "./BaseEVMScriptExecutor.sol"; - - -contract CallsScript is BaseEVMScriptExecutor { - using ScriptHelpers for bytes; - - // bytes32 constant internal EXECUTOR_TYPE = keccak256("CALLS_SCRIPT"); - bytes32 constant internal EXECUTOR_TYPE = 0x2dc858a00f3e417be1394b87c07158e989ec681ce8cc68a9093680ac1a870302; - - event LogScriptCall(address indexed sender, address indexed src, address indexed dst); - - /** - * @notice Executes a number of call scripts - * @param _script [ specId (uint32) ] many calls with this structure -> - * [ to (address: 20 bytes) ] [ calldataLength (uint32: 4 bytes) ] [ calldata (calldataLength bytes) ] - * @param _blacklist Addresses the script cannot call to, or will revert. - * @return always returns empty byte array - */ - function execScript(bytes _script, bytes, address[] _blacklist) external isInitialized returns (bytes) { - uint256 location = SCRIPT_START_LOCATION; // first 32 bits are spec id - while (location < _script.length) { - address contractAddress = _script.addressAt(location); - // Check address being called is not blacklist - for (uint i = 0; i < _blacklist.length; i++) { - require(contractAddress != _blacklist[i]); - } - - // logged before execution to ensure event ordering in receipt - // if failed entire execution is reverted regardless - emit LogScriptCall(msg.sender, address(this), contractAddress); - - uint256 calldataLength = uint256(_script.uint32At(location + 0x14)); - uint256 startOffset = location + 0x14 + 0x04; - uint256 calldataStart = _script.locationOf(startOffset); - - // compute end of script / next location - location = startOffset + calldataLength; - require(location <= _script.length); - - assembly { - let success := call(sub(gas, 5000), contractAddress, 0, calldataStart, calldataLength, 0, 0) - switch success case 0 { revert(0, 0) } - } - } - } - - function executorType() external pure returns (bytes32) { - return EXECUTOR_TYPE; - } -} diff --git a/apps/shared/test-helpers/contracts/factory/APMRegistryFactory.sol b/apps/shared/test-helpers/contracts/factory/APMRegistryFactory.sol deleted file mode 100644 index e6738382c..000000000 --- a/apps/shared/test-helpers/contracts/factory/APMRegistryFactory.sol +++ /dev/null @@ -1,126 +0,0 @@ -pragma solidity 0.4.24; - - -import "../apm/APMRegistry.sol"; -import "../apm/Repo.sol"; -import "../ens/ENSSubdomainRegistrar.sol"; - -import "./DAOFactory.sol"; -import "./ENSFactory.sol"; -import "./AppProxyFactory.sol"; - - -contract APMRegistryFactory is APMRegistryConstants { - DAOFactory public daoFactory; - APMRegistry public registryBase; - Repo public repoBase; - ENSSubdomainRegistrar public ensSubdomainRegistrarBase; - ENS public ens; - - event DeployAPM(bytes32 indexed node, address apm); - - // Needs either one ENS or ENSFactory - constructor( - DAOFactory _daoFactory, - APMRegistry _registryBase, - Repo _repoBase, - ENSSubdomainRegistrar _ensSubBase, - ENS _ens, - ENSFactory _ensFactory - ) public // DAO initialized without evmscript run support - { - daoFactory = _daoFactory; - registryBase = _registryBase; - repoBase = _repoBase; - ensSubdomainRegistrarBase = _ensSubBase; - - // Either the ENS address provided is used, if any. - // Or we use the ENSFactory to generate a test instance of ENS - // If not the ENS address nor factory address are provided, this will revert - ens = _ens != address(0) ? _ens : _ensFactory.newENS(this); - } - - function newAPM(bytes32 _tld, bytes32 _label, address _root) public returns (APMRegistry) { - bytes32 node = keccak256(abi.encodePacked(_tld, _label)); - - // Assume it is the test ENS - if (ens.owner(node) != address(this)) { - // If we weren't in test ens and factory doesn't have ownership, will fail - require(ens.owner(_tld) == address(this)); - ens.setSubnodeOwner(_tld, _label, this); - } - - Kernel dao = daoFactory.newDAO(this); - ACL acl = ACL(dao.acl()); - - acl.createPermission(this, dao, dao.APP_MANAGER_ROLE(), this); - - // Deploy app proxies - bytes memory noInit = new bytes(0); - ENSSubdomainRegistrar ensSub = ENSSubdomainRegistrar( - dao.newAppInstance( - keccak256(abi.encodePacked(node, keccak256(abi.encodePacked(ENS_SUB_APP_NAME)))), - ensSubdomainRegistrarBase, - noInit, - false - ) - ); - APMRegistry apm = APMRegistry( - dao.newAppInstance( - keccak256(abi.encodePacked(node, keccak256(abi.encodePacked(APM_APP_NAME)))), - registryBase, - noInit, - false - ) - ); - - // APMRegistry controls Repos - bytes32 repoAppId = keccak256(abi.encodePacked(node, keccak256(abi.encodePacked(REPO_APP_NAME)))); - dao.setApp(dao.APP_BASES_NAMESPACE(), repoAppId, repoBase); - - emit DeployAPM(node, apm); - - // Grant permissions needed for APM on ENSSubdomainRegistrar - acl.createPermission(apm, ensSub, ensSub.CREATE_NAME_ROLE(), _root); - acl.createPermission(apm, ensSub, ensSub.POINT_ROOTNODE_ROLE(), _root); - - // allow apm to create permissions for Repos in Kernel - bytes32 permRole = acl.CREATE_PERMISSIONS_ROLE(); - - acl.grantPermission(apm, acl, permRole); - - // Initialize - ens.setOwner(node, ensSub); - ensSub.initialize(ens, node); - apm.initialize(ensSub); - - uint16[3] memory firstVersion; - firstVersion[0] = 1; - - acl.createPermission(this, apm, apm.CREATE_REPO_ROLE(), this); - - apm.newRepoWithVersion(APM_APP_NAME, _root, firstVersion, registryBase, b("ipfs:apm")); - apm.newRepoWithVersion(ENS_SUB_APP_NAME, _root, firstVersion, ensSubdomainRegistrarBase, b("ipfs:enssub")); - apm.newRepoWithVersion(REPO_APP_NAME, _root, firstVersion, repoBase, b("ipfs:repo")); - - configureAPMPermissions(acl, apm, _root); - - // Permission transition to _root - acl.setPermissionManager(_root, dao, dao.APP_MANAGER_ROLE()); - acl.revokePermission(this, acl, permRole); - acl.grantPermission(_root, acl, permRole); - acl.setPermissionManager(_root, acl, permRole); - - return apm; - } - - function b(string memory x) internal pure returns (bytes memory y) { - y = bytes(x); - } - - // Factory can be subclassed and permissions changed - function configureAPMPermissions(ACL _acl, APMRegistry _apm, address _root) internal { - _acl.grantPermission(_root, _apm, _apm.CREATE_REPO_ROLE()); - _acl.setPermissionManager(_root, _apm, _apm.CREATE_REPO_ROLE()); - } -} diff --git a/apps/shared/test-helpers/contracts/factory/AppProxyFactory.sol b/apps/shared/test-helpers/contracts/factory/AppProxyFactory.sol deleted file mode 100644 index f68c9d11f..000000000 --- a/apps/shared/test-helpers/contracts/factory/AppProxyFactory.sol +++ /dev/null @@ -1,29 +0,0 @@ -pragma solidity 0.4.24; - -import "../apps/AppProxyUpgradeable.sol"; -import "../apps/AppProxyPinned.sol"; - - -contract AppProxyFactory { - event NewAppProxy(address proxy, bool isUpgradeable, bytes32 appId); - - function newAppProxy(IKernel _kernel, bytes32 _appId) public returns (AppProxyUpgradeable) { - return newAppProxy(_kernel, _appId, new bytes(0)); - } - - function newAppProxy(IKernel _kernel, bytes32 _appId, bytes _initializePayload) public returns (AppProxyUpgradeable) { - AppProxyUpgradeable proxy = new AppProxyUpgradeable(_kernel, _appId, _initializePayload); - emit NewAppProxy(address(proxy), true, _appId); - return proxy; - } - - function newAppProxyPinned(IKernel _kernel, bytes32 _appId) public returns (AppProxyPinned) { - return newAppProxyPinned(_kernel, _appId, new bytes(0)); - } - - function newAppProxyPinned(IKernel _kernel, bytes32 _appId, bytes _initializePayload) public returns (AppProxyPinned) { - AppProxyPinned proxy = new AppProxyPinned(_kernel, _appId, _initializePayload); - emit NewAppProxy(address(proxy), false, _appId); - return proxy; - } -} diff --git a/apps/shared/test-helpers/contracts/factory/DAOFactory.sol b/apps/shared/test-helpers/contracts/factory/DAOFactory.sol deleted file mode 100644 index a5f357d5a..000000000 --- a/apps/shared/test-helpers/contracts/factory/DAOFactory.sol +++ /dev/null @@ -1,69 +0,0 @@ -pragma solidity 0.4.24; - -import "../kernel/IKernel.sol"; -import "../kernel/Kernel.sol"; -import "../kernel/KernelProxy.sol"; - -import "../acl/IACL.sol"; -import "../acl/ACL.sol"; - -import "./EVMScriptRegistryFactory.sol"; - - -contract DAOFactory { - IKernel public baseKernel; - IACL public baseACL; - EVMScriptRegistryFactory public regFactory; - - event DeployDAO(address dao); - event DeployEVMScriptRegistry(address reg); - - constructor(IKernel _baseKernel, IACL _baseACL, EVMScriptRegistryFactory _regFactory) public { - // No need to init as it cannot be killed by devops199 - if (address(_regFactory) != address(0)) { - regFactory = _regFactory; - } - - baseKernel = _baseKernel; - baseACL = _baseACL; - } - - /** - * @param _root Address that will be granted control to setup DAO permissions - */ - function newDAO(address _root) public returns (Kernel) { - Kernel dao = Kernel(new KernelProxy(baseKernel)); - - if (address(regFactory) == address(0)) { - dao.initialize(baseACL, _root); - } else { - dao.initialize(baseACL, this); - - ACL acl = ACL(dao.acl()); - bytes32 permRole = acl.CREATE_PERMISSIONS_ROLE(); - bytes32 appManagerRole = dao.APP_MANAGER_ROLE(); - - acl.grantPermission(regFactory, acl, permRole); - - acl.createPermission(regFactory, dao, appManagerRole, this); - - EVMScriptRegistry reg = regFactory.newEVMScriptRegistry(dao); - emit DeployEVMScriptRegistry(address(reg)); - - // Clean up permissions - // First, completely reset the APP_MANAGER_ROLE - acl.revokePermission(regFactory, dao, appManagerRole); - acl.removePermissionManager(dao, appManagerRole); - - // Then, make root the only holder and manager of CREATE_PERMISSIONS_ROLE - acl.revokePermission(regFactory, acl, permRole); - acl.revokePermission(this, acl, permRole); - acl.grantPermission(_root, acl, permRole); - acl.setPermissionManager(_root, acl, permRole); - } - - emit DeployDAO(address(dao)); - - return dao; - } -} diff --git a/apps/shared/test-helpers/contracts/factory/ENSFactory.sol b/apps/shared/test-helpers/contracts/factory/ENSFactory.sol deleted file mode 100644 index 9768f20ea..000000000 --- a/apps/shared/test-helpers/contracts/factory/ENSFactory.sol +++ /dev/null @@ -1,33 +0,0 @@ -pragma solidity 0.4.24; - -import "../lib/ens/ENS.sol"; -import "../lib/ens/PublicResolver.sol"; -import "../ens/ENSConstants.sol"; - - -// Note that this contract is NOT meant to be used in production. -// Its only purpose is to easily create ENS instances for testing APM. -contract ENSFactory is ENSConstants { - event DeployENS(address ens); - - // This is an incredibly trustfull ENS deployment, only use for testing - function newENS(address _owner) public returns (ENS) { - ENS ens = new ENS(); - - // Setup .eth TLD - ens.setSubnodeOwner(ENS_ROOT, ETH_TLD_LABEL, this); - - // Setup public resolver - PublicResolver resolver = new PublicResolver(ens); - ens.setSubnodeOwner(ETH_TLD_NODE, PUBLIC_RESOLVER_LABEL, this); - ens.setResolver(PUBLIC_RESOLVER_NODE, resolver); - resolver.setAddr(PUBLIC_RESOLVER_NODE, resolver); - - ens.setOwner(ETH_TLD_NODE, _owner); - ens.setOwner(ENS_ROOT, _owner); - - emit DeployENS(ens); - - return ens; - } -} diff --git a/apps/shared/test-helpers/contracts/factory/EVMScriptRegistryFactory.sol b/apps/shared/test-helpers/contracts/factory/EVMScriptRegistryFactory.sol deleted file mode 100644 index 329dd738c..000000000 --- a/apps/shared/test-helpers/contracts/factory/EVMScriptRegistryFactory.sol +++ /dev/null @@ -1,38 +0,0 @@ -pragma solidity 0.4.24; - -import "../evmscript/IEVMScriptExecutor.sol"; -import "../evmscript/EVMScriptRegistry.sol"; - -import "../evmscript/executors/CallsScript.sol"; - -import "./AppProxyFactory.sol"; -import "../kernel/Kernel.sol"; -import "../acl/ACL.sol"; - - -contract EVMScriptRegistryFactory is AppProxyFactory, EVMScriptRegistryConstants { - EVMScriptRegistry public baseReg; - IEVMScriptExecutor public baseCallScript; - - constructor() public { - baseReg = new EVMScriptRegistry(); - baseCallScript = IEVMScriptExecutor(new CallsScript()); - } - - function newEVMScriptRegistry(Kernel _dao) public returns (EVMScriptRegistry reg) { - bytes memory initPayload = abi.encodeWithSelector(reg.initialize.selector); - reg = EVMScriptRegistry(_dao.newPinnedAppInstance(EVMSCRIPT_REGISTRY_APP_ID, baseReg, initPayload, true)); - - ACL acl = ACL(_dao.acl()); - - acl.createPermission(this, reg, reg.REGISTRY_ADD_EXECUTOR_ROLE(), this); - - reg.addScriptExecutor(baseCallScript); // spec 1 = CallsScript - - // Clean up the permissions - acl.revokePermission(this, reg, reg.REGISTRY_ADD_EXECUTOR_ROLE()); - acl.removePermissionManager(reg, reg.REGISTRY_ADD_EXECUTOR_ROLE()); - - return reg; - } -} diff --git a/apps/shared/test-helpers/contracts/kernel/IKernel.sol b/apps/shared/test-helpers/contracts/kernel/IKernel.sol deleted file mode 100644 index 0775cec14..000000000 --- a/apps/shared/test-helpers/contracts/kernel/IKernel.sol +++ /dev/null @@ -1,20 +0,0 @@ -/* - * SPDX-License-Identitifer: MIT - */ - -pragma solidity ^0.4.24; - -import "../acl/IACL.sol"; -import "../common/IVaultRecoverable.sol"; - - -// This should be an interface, but interfaces can't inherit yet :( -contract IKernel is IVaultRecoverable { - event SetApp(bytes32 indexed namespace, bytes32 indexed appId, address app); - - function acl() public view returns (IACL); - function hasPermission(address who, address where, bytes32 what, bytes how) public view returns (bool); - - function setApp(bytes32 namespace, bytes32 appId, address app) public; - function getApp(bytes32 namespace, bytes32 appId) public view returns (address); -} diff --git a/apps/shared/test-helpers/contracts/kernel/Kernel.sol b/apps/shared/test-helpers/contracts/kernel/Kernel.sol deleted file mode 100644 index fa7acf3c3..000000000 --- a/apps/shared/test-helpers/contracts/kernel/Kernel.sol +++ /dev/null @@ -1,244 +0,0 @@ -pragma solidity 0.4.24; - -import "./IKernel.sol"; -import "./KernelConstants.sol"; -import "./KernelStorage.sol"; -import "../acl/IACL.sol"; -import "../acl/ACLSyntaxSugar.sol"; -import "../lib/misc/ERCProxy.sol"; -import "../common/IsContract.sol"; -import "../common/Petrifiable.sol"; -import "../common/VaultRecoverable.sol"; -import "../factory/AppProxyFactory.sol"; - - -// solium-disable-next-line max-len -contract Kernel is IKernel, KernelStorage, KernelAppIds, KernelNamespaceConstants, Petrifiable, IsContract, VaultRecoverable, AppProxyFactory, ACLSyntaxSugar { - /* Hardcoded constants to save gas - bytes32 public constant APP_MANAGER_ROLE = keccak256("APP_MANAGER_ROLE"); - */ - bytes32 public constant APP_MANAGER_ROLE = 0xb6d92708f3d4817afc106147d969e229ced5c46e65e0a5002a0d391287762bd0; - - string private constant ERROR_APP_NOT_CONTRACT = "KERNEL_APP_NOT_CONTRACT"; - string private constant ERROR_INVALID_APP_CHANGE = "KERNEL_INVALID_APP_CHANGE"; - string private constant ERROR_AUTH_FAILED = "KERNEL_AUTH_FAILED"; - - /** - * @dev Constructor that allows the deployer to choose if the base instance should be petrified immediately. - * @param _shouldPetrify Immediately petrify this instance so that it can never be initialized - */ - constructor(bool _shouldPetrify) public { - if (_shouldPetrify) { - petrify(); - } - } - - /** - * @dev Initialize can only be called once. It saves the block number in which it was initialized. - * @notice Initializes a kernel instance along with its ACL and sets `_permissionsCreator` as the entity that can create other permissions - * @param _baseAcl Address of base ACL app - * @param _permissionsCreator Entity that will be given permission over createPermission - */ - function initialize(IACL _baseAcl, address _permissionsCreator) public onlyInit { - initialized(); - - // Set ACL base - _setApp(KERNEL_APP_BASES_NAMESPACE, KERNEL_DEFAULT_ACL_APP_ID, _baseAcl); - - // Create ACL instance and attach it as the default ACL app - IACL acl = IACL(newAppProxy(this, KERNEL_DEFAULT_ACL_APP_ID)); - acl.initialize(_permissionsCreator); - _setApp(KERNEL_APP_ADDR_NAMESPACE, KERNEL_DEFAULT_ACL_APP_ID, acl); - - recoveryVaultAppId = KERNEL_DEFAULT_VAULT_APP_ID; - } - - /** - * @dev Create a new instance of an app linked to this kernel - * @notice Create a new upgradeable instance of `_appId` app linked to the Kernel, setting its code to `_appBase` - * @param _appId Identifier for app - * @param _appBase Address of the app's base implementation - * @return AppProxy instance - */ - function newAppInstance(bytes32 _appId, address _appBase) - public - auth(APP_MANAGER_ROLE, arr(KERNEL_APP_BASES_NAMESPACE, _appId)) - returns (ERCProxy appProxy) - { - return newAppInstance(_appId, _appBase, new bytes(0), false); - } - - /** - * @dev Create a new instance of an app linked to this kernel and set its base - * implementation if it was not already set - * @notice Create a new upgradeable instance of `_appId` app linked to the Kernel, setting its code to `_appBase`. `_setDefault ? 'Also sets it as the default app instance.':''` - * @param _appId Identifier for app - * @param _appBase Address of the app's base implementation - * @param _initializePayload Payload for call made by the proxy during its construction to initialize - * @param _setDefault Whether the app proxy app is the default one. - * Useful when the Kernel needs to know of an instance of a particular app, - * like Vault for escape hatch mechanism. - * @return AppProxy instance - */ - function newAppInstance(bytes32 _appId, address _appBase, bytes _initializePayload, bool _setDefault) - public - auth(APP_MANAGER_ROLE, arr(KERNEL_APP_BASES_NAMESPACE, _appId)) - returns (ERCProxy appProxy) - { - _setAppIfNew(KERNEL_APP_BASES_NAMESPACE, _appId, _appBase); - appProxy = newAppProxy(this, _appId, _initializePayload); - // By calling setApp directly and not the internal functions, we make sure the params are checked - // and it will only succeed if sender has permissions to set something to the namespace. - if (_setDefault) { - setApp(KERNEL_APP_ADDR_NAMESPACE, _appId, appProxy); - } - } - - /** - * @dev Create a new pinned instance of an app linked to this kernel - * @notice Create a new non-upgradeable instance of `_appId` app linked to the Kernel, setting its code to `_appBase`. - * @param _appId Identifier for app - * @param _appBase Address of the app's base implementation - * @return AppProxy instance - */ - function newPinnedAppInstance(bytes32 _appId, address _appBase) - public - auth(APP_MANAGER_ROLE, arr(KERNEL_APP_BASES_NAMESPACE, _appId)) - returns (ERCProxy appProxy) - { - return newPinnedAppInstance(_appId, _appBase, new bytes(0), false); - } - - /** - * @dev Create a new pinned instance of an app linked to this kernel and set - * its base implementation if it was not already set - * @notice Create a new non-upgradeable instance of `_appId` app linked to the Kernel, setting its code to `_appBase`. `_setDefault ? 'Also sets it as the default app instance.':''` - * @param _appId Identifier for app - * @param _appBase Address of the app's base implementation - * @param _initializePayload Payload for call made by the proxy during its construction to initialize - * @param _setDefault Whether the app proxy app is the default one. - * Useful when the Kernel needs to know of an instance of a particular app, - * like Vault for escape hatch mechanism. - * @return AppProxy instance - */ - function newPinnedAppInstance(bytes32 _appId, address _appBase, bytes _initializePayload, bool _setDefault) - public - auth(APP_MANAGER_ROLE, arr(KERNEL_APP_BASES_NAMESPACE, _appId)) - returns (ERCProxy appProxy) - { - _setAppIfNew(KERNEL_APP_BASES_NAMESPACE, _appId, _appBase); - appProxy = newAppProxyPinned(this, _appId, _initializePayload); - // By calling setApp directly and not the internal functions, we make sure the params are checked - // and it will only succeed if sender has permissions to set something to the namespace. - if (_setDefault) { - setApp(KERNEL_APP_ADDR_NAMESPACE, _appId, appProxy); - } - } - - /** - * @dev Set the resolving address of an app instance or base implementation - * @notice Set the resolving address of `_appId` in namespace `_namespace` to `_app` - * @param _namespace App namespace to use - * @param _appId Identifier for app - * @param _app Address of the app instance or base implementation - * @return ID of app - */ - function setApp(bytes32 _namespace, bytes32 _appId, address _app) - public - auth(APP_MANAGER_ROLE, arr(_namespace, _appId)) - { - _setApp(_namespace, _appId, _app); - } - - /** - * @dev Set the default vault id for the escape hatch mechanism - * @param _recoveryVaultAppId Identifier of the recovery vault app - */ - function setRecoveryVaultAppId(bytes32 _recoveryVaultAppId) - public - auth(APP_MANAGER_ROLE, arr(KERNEL_APP_ADDR_NAMESPACE, _recoveryVaultAppId)) - { - recoveryVaultAppId = _recoveryVaultAppId; - } - - // External access to default app id and namespace constants to mimic default getters for constants - /* solium-disable function-order, mixedcase */ - function CORE_NAMESPACE() external pure returns (bytes32) { return KERNEL_CORE_NAMESPACE; } - function APP_BASES_NAMESPACE() external pure returns (bytes32) { return KERNEL_APP_BASES_NAMESPACE; } - function APP_ADDR_NAMESPACE() external pure returns (bytes32) { return KERNEL_APP_ADDR_NAMESPACE; } - function KERNEL_APP_ID() external pure returns (bytes32) { return KERNEL_CORE_APP_ID; } - function DEFAULT_ACL_APP_ID() external pure returns (bytes32) { return KERNEL_DEFAULT_ACL_APP_ID; } - /* solium-enable function-order, mixedcase */ - - /** - * @dev Get the address of an app instance or base implementation - * @param _namespace App namespace to use - * @param _appId Identifier for app - * @return Address of the app - */ - function getApp(bytes32 _namespace, bytes32 _appId) public view returns (address) { - return apps[_namespace][_appId]; - } - - /** - * @dev Get the address of the recovery Vault instance (to recover funds) - * @return Address of the Vault - */ - function getRecoveryVault() public view returns (address) { - return apps[KERNEL_APP_ADDR_NAMESPACE][recoveryVaultAppId]; - } - - /** - * @dev Get the installed ACL app - * @return ACL app - */ - function acl() public view returns (IACL) { - return IACL(getApp(KERNEL_APP_ADDR_NAMESPACE, KERNEL_DEFAULT_ACL_APP_ID)); - } - - /** - * @dev Function called by apps to check ACL on kernel or to check permission status - * @param _who Sender of the original call - * @param _where Address of the app - * @param _what Identifier for a group of actions in app - * @param _how Extra data for ACL auth - * @return Boolean indicating whether the ACL allows the role or not. - * Always returns false if the kernel hasn't been initialized yet. - */ - function hasPermission(address _who, address _where, bytes32 _what, bytes _how) public view returns (bool) { - IACL defaultAcl = acl(); - return address(defaultAcl) != address(0) && // Poor man's initialization check (saves gas) - defaultAcl.hasPermission(_who, _where, _what, _how); - } - - function _setApp(bytes32 _namespace, bytes32 _appId, address _app) internal { - require(isContract(_app), ERROR_APP_NOT_CONTRACT); - apps[_namespace][_appId] = _app; - emit SetApp(_namespace, _appId, _app); - } - - function _setAppIfNew(bytes32 _namespace, bytes32 _appId, address _app) internal { - address app = getApp(_namespace, _appId); - if (app != address(0)) { - // The only way to set an app is if it passes the isContract check, so no need to check it again - require(app == _app, ERROR_INVALID_APP_CHANGE); - } else { - _setApp(_namespace, _appId, _app); - } - } - - modifier auth(bytes32 _role, uint256[] memory params) { - // Force cast the uint256[] into a bytes array, by overwriting its length - // Note that the bytes array doesn't need to be initialized as we immediately overwrite it - // with params and a new length, and params becomes invalid from this point forward - bytes memory how; - uint256 byteLength = params.length * 32; - assembly { - how := params - mstore(how, byteLength) - } - - require(hasPermission(msg.sender, address(this), _role, how), ERROR_AUTH_FAILED); - _; - } -} \ No newline at end of file diff --git a/apps/shared/test-helpers/contracts/kernel/KernelConstants.sol b/apps/shared/test-helpers/contracts/kernel/KernelConstants.sol deleted file mode 100644 index 730a254f7..000000000 --- a/apps/shared/test-helpers/contracts/kernel/KernelConstants.sol +++ /dev/null @@ -1,29 +0,0 @@ -/* - * SPDX-License-Identitifer: MIT - */ - -pragma solidity ^0.4.24; - - -contract KernelAppIds { - /* Hardcoded constants to save gas - bytes32 internal constant KERNEL_CORE_APP_ID = apmNamehash("kernel"); - bytes32 internal constant KERNEL_DEFAULT_ACL_APP_ID = apmNamehash("acl"); - bytes32 internal constant KERNEL_DEFAULT_VAULT_APP_ID = apmNamehash("vault"); - */ - bytes32 internal constant KERNEL_CORE_APP_ID = 0x3b4bf6bf3ad5000ecf0f989d5befde585c6860fea3e574a4fab4c49d1c177d9c; - bytes32 internal constant KERNEL_DEFAULT_ACL_APP_ID = 0xe3262375f45a6e2026b7e7b18c2b807434f2508fe1a2a3dfb493c7df8f4aad6a; - bytes32 internal constant KERNEL_DEFAULT_VAULT_APP_ID = 0x7e852e0fcfce6551c13800f1e7476f982525c2b5277ba14b24339c68416336d1; -} - - -contract KernelNamespaceConstants { - /* Hardcoded constants to save gas - bytes32 internal constant KERNEL_CORE_NAMESPACE = keccak256("core"); - bytes32 internal constant KERNEL_APP_BASES_NAMESPACE = keccak256("base"); - bytes32 internal constant KERNEL_APP_ADDR_NAMESPACE = keccak256("app"); - */ - bytes32 internal constant KERNEL_CORE_NAMESPACE = 0xc681a85306374a5ab27f0bbc385296a54bcd314a1948b6cf61c4ea1bc44bb9f8; - bytes32 internal constant KERNEL_APP_BASES_NAMESPACE = 0xf1f3eb40f5bc1ad1344716ced8b8a0431d840b5783aea1fd01786bc26f35ac0f; - bytes32 internal constant KERNEL_APP_ADDR_NAMESPACE = 0xd6f028ca0e8edb4a8c9757ca4fdccab25fa1e0317da1188108f7d2dee14902fb; -} \ No newline at end of file diff --git a/apps/shared/test-helpers/contracts/kernel/KernelProxy.sol b/apps/shared/test-helpers/contracts/kernel/KernelProxy.sol deleted file mode 100644 index 1aaa40895..000000000 --- a/apps/shared/test-helpers/contracts/kernel/KernelProxy.sol +++ /dev/null @@ -1,34 +0,0 @@ -pragma solidity 0.4.24; - -import "./IKernel.sol"; -import "./KernelConstants.sol"; -import "./KernelStorage.sol"; -import "../common/DepositableDelegateProxy.sol"; -import "../common/IsContract.sol"; - - -contract KernelProxy is KernelStorage, KernelAppIds, KernelNamespaceConstants, IsContract, DepositableDelegateProxy { - /** - * @dev KernelProxy is a proxy contract to a kernel implementation. The implementation - * can update the reference, which effectively upgrades the contract - * @param _kernelImpl Address of the contract used as implementation for kernel - */ - constructor(IKernel _kernelImpl) public { - require(isContract(address(_kernelImpl))); - apps[KERNEL_CORE_NAMESPACE][KERNEL_CORE_APP_ID] = _kernelImpl; - } - - /** - * @dev ERC897, whether it is a forwarding (1) or an upgradeable (2) proxy - */ - function proxyType() public pure returns (uint256 proxyTypeId) { - return UPGRADEABLE; - } - - /** - * @dev ERC897, the address the proxy would delegate calls to - */ - function implementation() public view returns (address) { - return apps[KERNEL_CORE_NAMESPACE][KERNEL_CORE_APP_ID]; - } -} \ No newline at end of file diff --git a/apps/shared/test-helpers/contracts/kernel/KernelStorage.sol b/apps/shared/test-helpers/contracts/kernel/KernelStorage.sol deleted file mode 100644 index 7602780aa..000000000 --- a/apps/shared/test-helpers/contracts/kernel/KernelStorage.sol +++ /dev/null @@ -1,8 +0,0 @@ -pragma solidity 0.4.24; - - -contract KernelStorage { - // namespace => app id => address - mapping (bytes32 => mapping (bytes32 => address)) public apps; - bytes32 public recoveryVaultAppId; -} \ No newline at end of file diff --git a/apps/shared/test-helpers/contracts/lib/ens/AbstractENS.sol b/apps/shared/test-helpers/contracts/lib/ens/AbstractENS.sol deleted file mode 100644 index 32e77f27d..000000000 --- a/apps/shared/test-helpers/contracts/lib/ens/AbstractENS.sol +++ /dev/null @@ -1,24 +0,0 @@ -pragma solidity ^0.4.15; - - -interface AbstractENS { - function owner(bytes32 _node) public constant returns (address); - function resolver(bytes32 _node) public constant returns (address); - function ttl(bytes32 _node) public constant returns (uint64); - function setOwner(bytes32 _node, address _owner) public; - function setSubnodeOwner(bytes32 _node, bytes32 label, address _owner) public; - function setResolver(bytes32 _node, address _resolver) public; - function setTTL(bytes32 _node, uint64 _ttl) public; - - // Logged when the owner of a node assigns a new owner to a subnode. - event NewOwner(bytes32 indexed _node, bytes32 indexed _label, address _owner); - - // Logged when the owner of a node transfers ownership to a new account. - event Transfer(bytes32 indexed _node, address _owner); - - // Logged when the resolver for a node changes. - event NewResolver(bytes32 indexed _node, address _resolver); - - // Logged when the TTL of a node changes - event NewTTL(bytes32 indexed _node, uint64 _ttl); -} \ No newline at end of file diff --git a/apps/shared/test-helpers/contracts/lib/ens/ENS.sol b/apps/shared/test-helpers/contracts/lib/ens/ENS.sol deleted file mode 100644 index 81dc93000..000000000 --- a/apps/shared/test-helpers/contracts/lib/ens/ENS.sol +++ /dev/null @@ -1,95 +0,0 @@ -pragma solidity ^0.4.0; - - -import './AbstractENS.sol'; - -/** - * The ENS registry contract. - */ -contract ENS is AbstractENS { - struct Record { - address owner; - address resolver; - uint64 ttl; - } - - mapping(bytes32=>Record) records; - - // Permits modifications only by the owner of the specified node. - modifier only_owner(bytes32 node) { - if (records[node].owner != msg.sender) throw; - _; - } - - /** - * Constructs a new ENS registrar. - */ - function ENS() public { - records[0].owner = msg.sender; - } - - /** - * Returns the address that owns the specified node. - */ - function owner(bytes32 node) public constant returns (address) { - return records[node].owner; - } - - /** - * Returns the address of the resolver for the specified node. - */ - function resolver(bytes32 node) public constant returns (address) { - return records[node].resolver; - } - - /** - * Returns the TTL of a node, and any records associated with it. - */ - function ttl(bytes32 node) public constant returns (uint64) { - return records[node].ttl; - } - - /** - * Transfers ownership of a node to a new address. May only be called by the current - * owner of the node. - * @param node The node to transfer ownership of. - * @param owner The address of the new owner. - */ - function setOwner(bytes32 node, address owner) only_owner(node) public { - Transfer(node, owner); - records[node].owner = owner; - } - - /** - * Transfers ownership of a subnode keccak256(node, label) to a new address. May only be - * called by the owner of the parent node. - * @param node The parent node. - * @param label The hash of the label specifying the subnode. - * @param owner The address of the new owner. - */ - function setSubnodeOwner(bytes32 node, bytes32 label, address owner) only_owner(node) public { - var subnode = keccak256(node, label); - NewOwner(node, label, owner); - records[subnode].owner = owner; - } - - /** - * Sets the resolver address for the specified node. - * @param node The node to update. - * @param resolver The address of the resolver. - */ - function setResolver(bytes32 node, address resolver) only_owner(node) public { - NewResolver(node, resolver); - records[node].resolver = resolver; - } - - /** - * Sets the TTL for the specified node. - * @param node The node to update. - * @param ttl The TTL in seconds. - */ - function setTTL(bytes32 node, uint64 ttl) only_owner(node) public { - NewTTL(node, ttl); - records[node].ttl = ttl; - } -} \ No newline at end of file diff --git a/apps/shared/test-helpers/contracts/lib/ens/PublicResolver.sol b/apps/shared/test-helpers/contracts/lib/ens/PublicResolver.sol deleted file mode 100644 index d67f4fa7b..000000000 --- a/apps/shared/test-helpers/contracts/lib/ens/PublicResolver.sol +++ /dev/null @@ -1,212 +0,0 @@ -pragma solidity ^0.4.0; - -import './AbstractENS.sol'; - -/** - * A simple resolver anyone can use; only allows the owner of a node to set its - * address. - */ -contract PublicResolver { - bytes4 constant INTERFACE_META_ID = 0x01ffc9a7; - bytes4 constant ADDR_INTERFACE_ID = 0x3b3b57de; - bytes4 constant CONTENT_INTERFACE_ID = 0xd8389dc5; - bytes4 constant NAME_INTERFACE_ID = 0x691f3431; - bytes4 constant ABI_INTERFACE_ID = 0x2203ab56; - bytes4 constant PUBKEY_INTERFACE_ID = 0xc8690233; - bytes4 constant TEXT_INTERFACE_ID = 0x59d1d43c; - - event AddrChanged(bytes32 indexed node, address a); - event ContentChanged(bytes32 indexed node, bytes32 hash); - event NameChanged(bytes32 indexed node, string name); - event ABIChanged(bytes32 indexed node, uint256 indexed contentType); - event PubkeyChanged(bytes32 indexed node, bytes32 x, bytes32 y); - event TextChanged(bytes32 indexed node, string indexed indexedKey, string key); - - struct PublicKey { - bytes32 x; - bytes32 y; - } - - struct Record { - address addr; - bytes32 content; - string name; - PublicKey pubkey; - mapping(string=>string) text; - mapping(uint256=>bytes) abis; - } - - AbstractENS ens; - mapping(bytes32=>Record) records; - - modifier only_owner(bytes32 node) { - if (ens.owner(node) != msg.sender) throw; - _; - } - - /** - * Constructor. - * @param ensAddr The ENS registrar contract. - */ - function PublicResolver(AbstractENS ensAddr) public { - ens = ensAddr; - } - - /** - * Returns true if the resolver implements the interface specified by the provided hash. - * @param interfaceID The ID of the interface to check for. - * @return True if the contract implements the requested interface. - */ - function supportsInterface(bytes4 interfaceID) public pure returns (bool) { - return interfaceID == ADDR_INTERFACE_ID || - interfaceID == CONTENT_INTERFACE_ID || - interfaceID == NAME_INTERFACE_ID || - interfaceID == ABI_INTERFACE_ID || - interfaceID == PUBKEY_INTERFACE_ID || - interfaceID == TEXT_INTERFACE_ID || - interfaceID == INTERFACE_META_ID; - } - - /** - * Returns the address associated with an ENS node. - * @param node The ENS node to query. - * @return The associated address. - */ - function addr(bytes32 node) public constant returns (address ret) { - ret = records[node].addr; - } - - /** - * Sets the address associated with an ENS node. - * May only be called by the owner of that node in the ENS registry. - * @param node The node to update. - * @param addr The address to set. - */ - function setAddr(bytes32 node, address addr) only_owner(node) public { - records[node].addr = addr; - AddrChanged(node, addr); - } - - /** - * Returns the content hash associated with an ENS node. - * Note that this resource type is not standardized, and will likely change - * in future to a resource type based on multihash. - * @param node The ENS node to query. - * @return The associated content hash. - */ - function content(bytes32 node) public constant returns (bytes32 ret) { - ret = records[node].content; - } - - /** - * Sets the content hash associated with an ENS node. - * May only be called by the owner of that node in the ENS registry. - * Note that this resource type is not standardized, and will likely change - * in future to a resource type based on multihash. - * @param node The node to update. - * @param hash The content hash to set - */ - function setContent(bytes32 node, bytes32 hash) only_owner(node) public { - records[node].content = hash; - ContentChanged(node, hash); - } - - /** - * Returns the name associated with an ENS node, for reverse records. - * Defined in EIP181. - * @param node The ENS node to query. - * @return The associated name. - */ - function name(bytes32 node) public constant returns (string ret) { - ret = records[node].name; - } - - /** - * Sets the name associated with an ENS node, for reverse records. - * May only be called by the owner of that node in the ENS registry. - * @param node The node to update. - * @param name The name to set. - */ - function setName(bytes32 node, string name) only_owner(node) public { - records[node].name = name; - NameChanged(node, name); - } - - /** - * Returns the ABI associated with an ENS node. - * Defined in EIP205. - * @param node The ENS node to query - * @param contentTypes A bitwise OR of the ABI formats accepted by the caller. - * @return contentType The content type of the return value - * @return data The ABI data - */ - function ABI(bytes32 node, uint256 contentTypes) public constant returns (uint256 contentType, bytes data) { - var record = records[node]; - for(contentType = 1; contentType <= contentTypes; contentType <<= 1) { - if ((contentType & contentTypes) != 0 && record.abis[contentType].length > 0) { - data = record.abis[contentType]; - return; - } - } - contentType = 0; - } - - /** - * Sets the ABI associated with an ENS node. - * Nodes may have one ABI of each content type. To remove an ABI, set it to - * the empty string. - * @param node The node to update. - * @param contentType The content type of the ABI - * @param data The ABI data. - */ - function setABI(bytes32 node, uint256 contentType, bytes data) only_owner(node) public { - // Content types must be powers of 2 - if (((contentType - 1) & contentType) != 0) throw; - - records[node].abis[contentType] = data; - ABIChanged(node, contentType); - } - - /** - * Returns the SECP256k1 public key associated with an ENS node. - * Defined in EIP 619. - * @param node The ENS node to query - * @return x, y the X and Y coordinates of the curve point for the public key. - */ - function pubkey(bytes32 node) public constant returns (bytes32 x, bytes32 y) { - return (records[node].pubkey.x, records[node].pubkey.y); - } - - /** - * Sets the SECP256k1 public key associated with an ENS node. - * @param node The ENS node to query - * @param x the X coordinate of the curve point for the public key. - * @param y the Y coordinate of the curve point for the public key. - */ - function setPubkey(bytes32 node, bytes32 x, bytes32 y) only_owner(node) public { - records[node].pubkey = PublicKey(x, y); - PubkeyChanged(node, x, y); - } - - /** - * Returns the text data associated with an ENS node and key. - * @param node The ENS node to query. - * @param key The text data key to query. - * @return The associated text data. - */ - function text(bytes32 node, string key) public constant returns (string ret) { - ret = records[node].text[key]; - } - - /** - * Sets the text data associated with an ENS node and key. - * May only be called by the owner of that node in the ENS registry. - * @param node The node to update. - * @param key The key to set. - * @param value The text data value to set. - */ - function setText(bytes32 node, string key, string value) only_owner(node) public { - records[node].text[key] = value; - TextChanged(node, key, key); - } -} \ No newline at end of file diff --git a/apps/shared/test-helpers/contracts/lib/math/Math.sol b/apps/shared/test-helpers/contracts/lib/math/Math.sol deleted file mode 100644 index 995250825..000000000 --- a/apps/shared/test-helpers/contracts/lib/math/Math.sol +++ /dev/null @@ -1,24 +0,0 @@ -pragma solidity ^0.4.24; - -/** - * @title Math - * @dev Assorted math operations - */ - -library Math { - function max64(uint64 a, uint64 b) internal pure returns (uint64) { - return a >= b ? a : b; - } - - function min64(uint64 a, uint64 b) internal pure returns (uint64) { - return a < b ? a : b; - } - - function max256(uint256 a, uint256 b) internal pure returns (uint256) { - return a >= b ? a : b; - } - - function min256(uint256 a, uint256 b) internal pure returns (uint256) { - return a < b ? a : b; - } -} diff --git a/apps/shared/test-helpers/contracts/lib/math/SafeMath.sol b/apps/shared/test-helpers/contracts/lib/math/SafeMath.sol deleted file mode 100644 index b538d571c..000000000 --- a/apps/shared/test-helpers/contracts/lib/math/SafeMath.sol +++ /dev/null @@ -1,69 +0,0 @@ -// See https://github.com/OpenZeppelin/openzeppelin-solidity/blob/d51e38758e1d985661534534d5c61e27bece5042/contracts/math/SafeMath.sol -// Adapted to use pragma ^0.4.24 and satisfy our linter rules - -pragma solidity ^0.4.24; - - -/** - * @title SafeMath - * @dev Math operations with safety checks that revert on error - */ -library SafeMath { - - /** - * @dev Multiplies two numbers, reverts on overflow. - */ - 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); - - return c; - } - - /** - * @dev Integer division of two numbers truncating the quotient, reverts on division by zero. - */ - function div(uint256 _a, uint256 _b) internal pure returns (uint256) { - require(_b > 0); // Solidity only automatically asserts when dividing by 0 - uint256 c = _a / _b; - // assert(_a == _b * c + _a % _b); // There is no case in which this doesn't hold - - return c; - } - - /** - * @dev Subtracts two numbers, reverts on overflow (i.e. if subtrahend is greater than minuend). - */ - function sub(uint256 _a, uint256 _b) internal pure returns (uint256) { - require(_b <= _a); - uint256 c = _a - _b; - - return c; - } - - /** - * @dev Adds two numbers, reverts on overflow. - */ - function add(uint256 _a, uint256 _b) internal pure returns (uint256) { - uint256 c = _a + _b; - require(c >= _a); - - return c; - } - - /** - * @dev Divides two numbers and returns the remainder (unsigned integer modulo), - * reverts when dividing by zero. - */ - function mod(uint256 a, uint256 b) internal pure returns (uint256) { - require(b != 0); - return a % b; - } -} diff --git a/apps/shared/test-helpers/contracts/lib/math/SafeMath64.sol b/apps/shared/test-helpers/contracts/lib/math/SafeMath64.sol deleted file mode 100644 index d549a2b76..000000000 --- a/apps/shared/test-helpers/contracts/lib/math/SafeMath64.sol +++ /dev/null @@ -1,63 +0,0 @@ -// See https://github.com/OpenZeppelin/openzeppelin-solidity/blob/d51e38758e1d985661534534d5c61e27bece5042/contracts/math/SafeMath.sol -// Adapted for uint64, pragma ^0.4.24, and satisfying our linter rules -// Also optimized the mul() implementation, see https://github.com/aragon/aragonOS/pull/417 - -pragma solidity ^0.4.24; - - -/** - * @title SafeMath64 - * @dev Math operations for uint64 with safety checks that revert on error - */ -library SafeMath64 { - - /** - * @dev Multiplies two numbers, reverts on overflow. - */ - function mul(uint64 _a, uint64 _b) internal pure returns (uint64) { - uint256 c = uint256(_a) * uint256(_b); - require(c < 0x010000000000000000); // 2**64 (less gas this way) - - return uint64(c); - } - - /** - * @dev Integer division of two numbers truncating the quotient, reverts on division by zero. - */ - function div(uint64 _a, uint64 _b) internal pure returns (uint64) { - require(_b > 0); // Solidity only automatically asserts when dividing by 0 - uint64 c = _a / _b; - // assert(_a == _b * c + _a % _b); // There is no case in which this doesn't hold - - return c; - } - - /** - * @dev Subtracts two numbers, reverts on overflow (i.e. if subtrahend is greater than minuend). - */ - function sub(uint64 _a, uint64 _b) internal pure returns (uint64) { - require(_b <= _a); - uint64 c = _a - _b; - - return c; - } - - /** - * @dev Adds two numbers, reverts on overflow. - */ - function add(uint64 _a, uint64 _b) internal pure returns (uint64) { - uint64 c = _a + _b; - require(c >= _a); - - return c; - } - - /** - * @dev Divides two numbers and returns the remainder (unsigned integer modulo), - * reverts when dividing by zero. - */ - function mod(uint64 a, uint64 b) internal pure returns (uint64) { - require(b != 0); - return a % b; - } -} diff --git a/apps/shared/test-helpers/contracts/lib/math/SafeMath8.sol b/apps/shared/test-helpers/contracts/lib/math/SafeMath8.sol deleted file mode 100644 index b5588dc7d..000000000 --- a/apps/shared/test-helpers/contracts/lib/math/SafeMath8.sol +++ /dev/null @@ -1,63 +0,0 @@ -// See https://github.com/OpenZeppelin/openzeppelin-solidity/blob/d51e38758e1d985661534534d5c61e27bece5042/contracts/math/SafeMath.sol -// Adapted for uint8, pragma ^0.4.24, and satisfying our linter rules -// Also optimized the mul() implementation, see https://github.com/aragon/aragonOS/pull/417 - -pragma solidity ^0.4.24; - - -/** - * @title SafeMath8 - * @dev Math operations for uint8 with safety checks that revert on error - */ -library SafeMath8 { - - /** - * @dev Multiplies two numbers, reverts on overflow. - */ - function mul(uint8 _a, uint8 _b) internal pure returns (uint8) { - uint256 c = uint256(_a) * uint256(_b); - require(c < 256); - - return uint8(c); - } - - /** - * @dev Integer division of two numbers truncating the quotient, reverts on division by zero. - */ - function div(uint8 _a, uint8 _b) internal pure returns (uint8) { - require(_b > 0); // Solidity only automatically asserts when dividing by 0 - uint8 c = _a / _b; - // assert(_a == _b * c + _a % _b); // There is no case in which this doesn't hold - - return c; - } - - /** - * @dev Subtracts two numbers, reverts on overflow (i.e. if subtrahend is greater than minuend). - */ - function sub(uint8 _a, uint8 _b) internal pure returns (uint8) { - require(_b <= _a); - uint8 c = _a - _b; - - return c; - } - - /** - * @dev Adds two numbers, reverts on overflow. - */ - function add(uint8 _a, uint8 _b) internal pure returns (uint8) { - uint8 c = _a + _b; - require(c >= _a); - - return c; - } - - /** - * @dev Divides two numbers and returns the remainder (unsigned integer modulo), - * reverts when dividing by zero. - */ - function mod(uint8 a, uint8 b) internal pure returns (uint8) { - require(b != 0); - return a % b; - } -} diff --git a/apps/shared/test-helpers/contracts/lib/minime/ITokenController.sol b/apps/shared/test-helpers/contracts/lib/minime/ITokenController.sol deleted file mode 100644 index 2c9bd0623..000000000 --- a/apps/shared/test-helpers/contracts/lib/minime/ITokenController.sol +++ /dev/null @@ -1,27 +0,0 @@ -pragma solidity ^0.4.24; - -/// @dev The token controller contract must implement these functions - - -interface ITokenController { - /// @notice Called when `_owner` sends ether to the MiniMe Token contract - /// @param _owner The address that sent the ether to create tokens - /// @return True if the ether is accepted, false if it throws - function proxyPayment(address _owner) external payable returns(bool); - - /// @notice Notifies the controller about a token transfer allowing the - /// controller to react if desired - /// @param _from The origin of the transfer - /// @param _to The destination of the transfer - /// @param _amount The amount of the transfer - /// @return False if the controller does not authorize the transfer - function onTransfer(address _from, address _to, uint _amount) external returns(bool); - - /// @notice Notifies the controller about an approval allowing the - /// controller to react if desired - /// @param _owner The address that calls `approve()` - /// @param _spender The spender in the `approve()` call - /// @param _amount The amount in the `approve()` call - /// @return False if the controller does not authorize the approval - function onApprove(address _owner, address _spender, uint _amount) external returns(bool); -} diff --git a/apps/shared/test-helpers/contracts/lib/minime/MiniMeToken.sol b/apps/shared/test-helpers/contracts/lib/minime/MiniMeToken.sol deleted file mode 100644 index 66fa337de..000000000 --- a/apps/shared/test-helpers/contracts/lib/minime/MiniMeToken.sol +++ /dev/null @@ -1,579 +0,0 @@ -pragma solidity ^0.4.24; - -/* - Copyright 2016, Jordi Baylina - - 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 . - */ - -/// @title MiniMeToken Contract -/// @author Jordi Baylina -/// @dev This token contract's goal is to make it easy for anyone to clone this -/// token using the token distribution at a given block, this will allow DAO's -/// and DApps to upgrade their features in a decentralized manner without -/// affecting the original token -/// @dev It is ERC20 compliant, but still needs to under go further testing. - -import "./ITokenController.sol"; - -contract Controlled { // solium-disable-line blank-lines - /// @notice The address of the controller is the only address that can call - /// a function with this modifier - modifier onlyController { - require(msg.sender == controller); - _; - } - - address public controller; - - constructor() public { controller = msg.sender;} - - /// @notice Changes the controller of the contract - /// @param _newController The new controller of the contract - function changeController(address _newController) public onlyController { - controller = _newController; - } -} - -contract ApproveAndCallFallBack { // solium-disable-line blank-lines - function receiveApproval( - address from, - uint256 _amount, - address _token, - bytes _data) public; -} - -/// @dev The actual token contract, the default controller is the msg.sender -/// that deploys the contract, so usually this token will be deployed by a -/// token controller contract, which Giveth will call a "Campaign" -contract MiniMeToken is Controlled { // solium-disable-line blank-lines - - string public name; //The Token's name: e.g. DigixDAO Tokens - uint8 public decimals; //Number of decimals of the smallest unit - string public symbol; //An identifier: e.g. REP - string public version = "MMT_0.1"; //An arbitrary versioning scheme - - - /// @dev `Checkpoint` is the structure that attaches a block number to a - /// given value, the block number attached is the one that last changed the - /// value - struct Checkpoint { - - // `fromBlock` is the block number that the value was generated from - uint128 fromBlock; - - // `value` is the amount of tokens at a specific block number - uint128 value; - } - - // `parentToken` is the Token address that was cloned to produce this token; - // it will be 0x0 for a token that was not cloned - MiniMeToken public parentToken; - - // `parentSnapShotBlock` is the block number from the Parent Token that was - // used to determine the initial distribution of the Clone Token - uint public parentSnapShotBlock; - - // `creationBlock` is the block number that the Clone Token was created - uint public creationBlock; - - // `balances` is the map that tracks the balance of each address, in this - // contract when the balance changes the block number that the change - // occurred is also included in the map - mapping (address => Checkpoint[]) balances; - - // `allowed` tracks any extra transfer rights as in all ERC20 tokens - mapping (address => mapping (address => uint256)) allowed; - - // Tracks the history of the `totalSupply` of the token - Checkpoint[] totalSupplyHistory; - - // Flag that determines if the token is transferable or not. - bool public transfersEnabled; - - // The factory used to create new clone tokens - MiniMeTokenFactory public tokenFactory; - -//////////////// -// Constructor -//////////////// - - /// @notice Constructor to create a MiniMeToken - /// @param _tokenFactory The address of the MiniMeTokenFactory contract that - /// will create the Clone token contracts, the token factory needs to be - /// deployed first - /// @param _parentToken Address of the parent token, set to 0x0 if it is a - /// new token - /// @param _parentSnapShotBlock Block of the parent token that will - /// determine the initial distribution of the clone token, set to 0 if it - /// is a new token - /// @param _tokenName Name of the new token - /// @param _decimalUnits Number of decimals of the new token - /// @param _tokenSymbol Token Symbol for the new token - /// @param _transfersEnabled If true, tokens will be able to be transferred - constructor( // solium-disable-line blank-lines - MiniMeTokenFactory _tokenFactory, - MiniMeToken _parentToken, - uint _parentSnapShotBlock, - string _tokenName, - uint8 _decimalUnits, - string _tokenSymbol, - bool _transfersEnabled - ) public - { - tokenFactory = _tokenFactory; - name = _tokenName; // Set the name - decimals = _decimalUnits; // Set the decimals - symbol = _tokenSymbol; // Set the symbol - parentToken = _parentToken; - parentSnapShotBlock = _parentSnapShotBlock; - transfersEnabled = _transfersEnabled; - creationBlock = block.number; - } - - -/////////////////// -// ERC20 Methods -/////////////////// - - /// @notice Send `_amount` tokens to `_to` from `msg.sender` - /// @param _to The address of the recipient - /// @param _amount The amount of tokens to be transferred - /// @return Whether the transfer was successful or not - function transfer(address _to, uint256 _amount) public returns (bool success) { - require(transfersEnabled); - return doTransfer(msg.sender, _to, _amount); - } - - /// @notice Send `_amount` tokens to `_to` from `_from` on the condition it - /// is approved by `_from` - /// @param _from The address holding the tokens being transferred - /// @param _to The address of the recipient - /// @param _amount The amount of tokens to be transferred - /// @return True if the transfer was successful - function transferFrom(address _from, address _to, uint256 _amount) public returns (bool success) { - - // The controller of this contract can move tokens around at will, - // this is important to recognize! Confirm that you trust the - // controller of this contract, which in most situations should be - // another open source smart contract or 0x0 - if (msg.sender != controller) { - require(transfersEnabled); - - // The standard ERC 20 transferFrom functionality - if (allowed[_from][msg.sender] < _amount) - return false; - allowed[_from][msg.sender] -= _amount; - } - return doTransfer(_from, _to, _amount); - } - - /// @dev This is the actual transfer function in the token contract, it can - /// only be called by other functions in this contract. - /// @param _from The address holding the tokens being transferred - /// @param _to The address of the recipient - /// @param _amount The amount of tokens to be transferred - /// @return True if the transfer was successful - function doTransfer(address _from, address _to, uint _amount) internal returns(bool) { - if (_amount == 0) { - return true; - } - require(parentSnapShotBlock < block.number); - // Do not allow transfer to 0x0 or the token contract itself - require((_to != 0) && (_to != address(this))); - // If the amount being transfered is more than the balance of the - // account the transfer returns false - uint previousBalanceFrom = balanceOfAt(_from, block.number); - if (previousBalanceFrom < _amount) { - return false; - } - // Alerts the token controller of the transfer - if (isContract(controller)) { - // Adding the ` == true` makes the linter shut up so... - require(ITokenController(controller).onTransfer(_from, _to, _amount) == true); - } - // First update the balance array with the new value for the address - // sending the tokens - updateValueAtNow(balances[_from], previousBalanceFrom - _amount); - // Then update the balance array with the new value for the address - // receiving the tokens - uint previousBalanceTo = balanceOfAt(_to, block.number); - require(previousBalanceTo + _amount >= previousBalanceTo); // Check for overflow - updateValueAtNow(balances[_to], previousBalanceTo + _amount); - // An event to make the transfer easy to find on the blockchain - emit Transfer(_from, _to, _amount); - return true; - } - - /// @param _owner The address that's balance is being requested - /// @return The balance of `_owner` at the current block - function balanceOf(address _owner) public view returns (uint256 balance) { // solium-disable-line function-order - return balanceOfAt(_owner, block.number); - } - - /// @notice `msg.sender` approves `_spender` to spend `_amount` tokens on - /// its behalf. This is a modified version of the ERC20 approve function - /// to be a little bit safer - /// @param _spender The address of the account able to transfer the tokens - /// @param _amount The amount of tokens to be approved for transfer - /// @return True if the approval was successful - function approve(address _spender, uint256 _amount) public returns (bool success) { // solium-disable-line function-order - require(transfersEnabled); - - // To change the approve amount you first have to reduce the addresses` - // allowance to zero by calling `approve(_spender,0)` if it is not - // already 0 to mitigate the race condition described here: - // https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 - require((_amount == 0) || (allowed[msg.sender][_spender] == 0)); - - // Alerts the token controller of the approve function call - if (isContract(controller)) { - // Adding the ` == true` makes the linter shut up so... - require(ITokenController(controller).onApprove(msg.sender, _spender, _amount) == true); - } - - allowed[msg.sender][_spender] = _amount; - emit Approval(msg.sender, _spender, _amount); - return true; - } - - /// @dev This function makes it easy to read the `allowed[]` map - /// @param _owner The address of the account that owns the token - /// @param _spender The address of the account able to transfer the tokens - /// @return Amount of remaining tokens of _owner that _spender is allowed - /// to spend - function allowance(address _owner, address _spender) public view returns (uint256 remaining) { // solium-disable-line function-order - return allowed[_owner][_spender]; - } - - /// @notice `msg.sender` approves `_spender` to send `_amount` tokens on - /// its behalf, and then a function is triggered in the contract that is - /// being approved, `_spender`. This allows users to use their tokens to - /// interact with contracts in one function call instead of two - /// @param _spender The address of the contract able to transfer the tokens - /// @param _amount The amount of tokens to be approved for transfer - /// @return True if the function call was successful - function approveAndCall(ApproveAndCallFallBack _spender, uint256 _amount, bytes _extraData) // solium-disable-line function-order - public returns (bool success) - { - require(approve(_spender, _amount)); - - _spender.receiveApproval( - msg.sender, - _amount, - this, - _extraData - ); - - return true; - } - - /// @dev This function makes it easy to get the total number of tokens - /// @return The total number of tokens - function totalSupply() public view returns (uint) { // solium-disable-line function-order - return totalSupplyAt(block.number); - } - -//////////////// -// Query balance and totalSupply in History -//////////////// - - /// @dev Queries the balance of `_owner` at a specific `_blockNumber` - /// @param _owner The address from which the balance will be retrieved - /// @param _blockNumber The block number when the balance is queried - /// @return The balance at `_blockNumber` - function balanceOfAt(address _owner, uint _blockNumber) public view returns (uint) { // solium-disable-line function-order - - // These next few lines are used when the balance of the token is - // requested before a check point was ever created for this token, it - // requires that the `parentToken.balanceOfAt` be queried at the - // genesis block for that token as this contains initial balance of - // this token - if ((balances[_owner].length == 0) || (balances[_owner][0].fromBlock > _blockNumber)) { - if (address(parentToken) != 0) { - return parentToken.balanceOfAt(_owner, min(_blockNumber, parentSnapShotBlock)); - } else { - // Has no parent - return 0; - } - - // This will return the expected balance during normal situations - } else { - return getValueAt(balances[_owner], _blockNumber); - } - } - - /// @notice Total amount of tokens at a specific `_blockNumber`. - /// @param _blockNumber The block number when the totalSupply is queried - /// @return The total amount of tokens at `_blockNumber` - function totalSupplyAt(uint _blockNumber) public view returns(uint) { // solium-disable-line function-order - - // These next few lines are used when the totalSupply of the token is - // requested before a check point was ever created for this token, it - // requires that the `parentToken.totalSupplyAt` be queried at the - // genesis block for this token as that contains totalSupply of this - // token at this block number. - if ((totalSupplyHistory.length == 0) || (totalSupplyHistory[0].fromBlock > _blockNumber)) { - if (address(parentToken) != 0) { - return parentToken.totalSupplyAt(min(_blockNumber, parentSnapShotBlock)); - } else { - return 0; - } - - // This will return the expected totalSupply during normal situations - } else { - return getValueAt(totalSupplyHistory, _blockNumber); - } - } - -//////////////// -// Clone Token Method -//////////////// - - /// @notice Creates a new clone token with the initial distribution being - /// this token at `_snapshotBlock` - /// @param _cloneTokenName Name of the clone token - /// @param _cloneDecimalUnits Number of decimals of the smallest unit - /// @param _cloneTokenSymbol Symbol of the clone token - /// @param _snapshotBlock Block when the distribution of the parent token is - /// copied to set the initial distribution of the new clone token; - /// if the block is zero than the actual block, the current block is used - /// @param _transfersEnabled True if transfers are allowed in the clone - /// @return The address of the new MiniMeToken Contract - function createCloneToken( // solium-disable-line function-order - string _cloneTokenName, - uint8 _cloneDecimalUnits, - string _cloneTokenSymbol, - uint _snapshotBlock, - bool _transfersEnabled - ) public returns(MiniMeToken) - { - uint256 snapshot = _snapshotBlock == 0 ? block.number - 1 : _snapshotBlock; - - MiniMeToken cloneToken = tokenFactory.createCloneToken( - this, - snapshot, - _cloneTokenName, - _cloneDecimalUnits, - _cloneTokenSymbol, - _transfersEnabled - ); - - cloneToken.changeController(msg.sender); - - // An event to make the token easy to find on the blockchain - emit NewCloneToken(address(cloneToken), snapshot); - return cloneToken; - } - -//////////////// -// Generate and destroy tokens -//////////////// - - /// @notice Generates `_amount` tokens that are assigned to `_owner` - /// @param _owner The address that will be assigned the new tokens - /// @param _amount The quantity of tokens generated - /// @return True if the tokens are generated correctly - function generateTokens(address _owner, uint _amount) // solium-disable-line function-order - public onlyController returns (bool) - { - uint curTotalSupply = totalSupply(); - require(curTotalSupply + _amount >= curTotalSupply); // Check for overflow - uint previousBalanceTo = balanceOf(_owner); - require(previousBalanceTo + _amount >= previousBalanceTo); // Check for overflow - updateValueAtNow(totalSupplyHistory, curTotalSupply + _amount); - updateValueAtNow(balances[_owner], previousBalanceTo + _amount); - emit Transfer(0, _owner, _amount); - return true; - } - - /// @notice Burns `_amount` tokens from `_owner` - /// @param _owner The address that will lose the tokens - /// @param _amount The quantity of tokens to burn - /// @return True if the tokens are burned correctly - function destroyTokens(address _owner, uint _amount) public onlyController returns (bool) { // solium-disable-line function-order - uint curTotalSupply = totalSupply(); - require(curTotalSupply >= _amount); - uint previousBalanceFrom = balanceOf(_owner); - require(previousBalanceFrom >= _amount); - updateValueAtNow(totalSupplyHistory, curTotalSupply - _amount); - updateValueAtNow(balances[_owner], previousBalanceFrom - _amount); - emit Transfer(_owner, 0, _amount); - return true; - } - -//////////////// -// Enable tokens transfers -//////////////// - - - /// @notice Enables token holders to transfer their tokens freely if true - /// @param _transfersEnabled True if transfers are allowed in the clone - function enableTransfers(bool _transfersEnabled) public onlyController { // solium-disable-line function-order - transfersEnabled = _transfersEnabled; - } - -//////////////// -// Internal helper functions to query and set a value in a snapshot array -//////////////// - - /// @dev `getValueAt` retrieves the number of tokens at a given block number - /// @param checkpoints The history of values being queried - /// @param _block The block number to retrieve the value at - /// @return The number of tokens being queried - function getValueAt(Checkpoint[] storage checkpoints, uint _block) internal view returns (uint) { - if (checkpoints.length == 0) - return 0; - - // Shortcut for the actual value - if (_block >= checkpoints[checkpoints.length-1].fromBlock) - return checkpoints[checkpoints.length-1].value; - if (_block < checkpoints[0].fromBlock) - return 0; - - // Binary search of the value in the array - uint min = 0; - uint max = checkpoints.length-1; - while (max > min) { - uint mid = (max + min + 1) / 2; - if (checkpoints[mid].fromBlock<=_block) { - min = mid; - } else { - max = mid-1; - } - } - return checkpoints[min].value; - } - - /// @dev `updateValueAtNow` used to update the `balances` map and the - /// `totalSupplyHistory` - /// @param checkpoints The history of data being updated - /// @param _value The new number of tokens - function updateValueAtNow(Checkpoint[] storage checkpoints, uint _value) internal { - if ((checkpoints.length == 0) || (checkpoints[checkpoints.length - 1].fromBlock < block.number)) { - Checkpoint storage newCheckPoint = checkpoints[checkpoints.length++]; - newCheckPoint.fromBlock = uint128(block.number); - newCheckPoint.value = uint128(_value); - } else { - Checkpoint storage oldCheckPoint = checkpoints[checkpoints.length - 1]; - oldCheckPoint.value = uint128(_value); - } - } - - /// @dev Internal function to determine if an address is a contract - /// @param _addr The address being queried - /// @return True if `_addr` is a contract - function isContract(address _addr) internal view returns(bool) { - uint size; - if (_addr == 0) - return false; - - assembly { - size := extcodesize(_addr) - } - - return size>0; - } - - /// @dev Helper function to return a min betwen the two uints - function min(uint a, uint b) internal pure returns (uint) { - return a < b ? a : b; - } - - /// @notice The fallback function: If the contract's controller has not been - /// set to 0, then the `proxyPayment` method is called which relays the - /// ether and creates tokens as described in the token controller contract - function () external payable { // solium-disable-line function-order - require(isContract(controller)); - // Adding the ` == true` makes the linter shut up so... - require(ITokenController(controller).proxyPayment.value(msg.value)(msg.sender) == true); - } - -////////// -// Safety Methods -////////// - - /// @notice This method can be used by the controller to extract mistakenly - /// sent tokens to this contract. - /// @param _token The address of the token contract that you want to recover - /// set to 0 in case you want to extract ether. - function claimTokens(address _token) public onlyController { // solium-disable-line function-order - if (_token == 0x0) { - controller.transfer(address(this).balance); - return; - } - - MiniMeToken token = MiniMeToken(_token); - uint balance = token.balanceOf(this); - token.transfer(controller, balance); - emit ClaimedTokens(_token, controller, balance); - } - -//////////////// -// Events -//////////////// - event ClaimedTokens(address indexed _token, address indexed _controller, uint _amount); - event Transfer(address indexed _from, address indexed _to, uint256 _amount); - event NewCloneToken(address indexed _cloneToken, uint _snapshotBlock); - event Approval( - address indexed _owner, - address indexed _spender, - uint256 _amount - ); - -} - - -//////////////// -// MiniMeTokenFactory -//////////////// - -/// @dev This contract is used to generate clone contracts from a contract. -/// In solidity this is the way to create a contract from a contract of the -/// same class -contract MiniMeTokenFactory { - - /// @notice Update the DApp by creating a new token with new functionalities - /// the msg.sender becomes the controller of this clone token - /// @param _parentToken Address of the token being cloned - /// @param _snapshotBlock Block of the parent token that will - /// determine the initial distribution of the clone token - /// @param _tokenName Name of the new token - /// @param _decimalUnits Number of decimals of the new token - /// @param _tokenSymbol Token Symbol for the new token - /// @param _transfersEnabled If true, tokens will be able to be transferred - /// @return The address of the new token contract - function createCloneToken( - MiniMeToken _parentToken, - uint _snapshotBlock, - string _tokenName, - uint8 _decimalUnits, - string _tokenSymbol, - bool _transfersEnabled - ) public returns (MiniMeToken) - { - MiniMeToken newToken = new MiniMeToken( - this, - _parentToken, - _snapshotBlock, - _tokenName, - _decimalUnits, - _tokenSymbol, - _transfersEnabled - ); - - newToken.changeController(msg.sender); - return newToken; - } -} diff --git a/apps/shared/test-helpers/contracts/lib/misc/ERCProxy.sol b/apps/shared/test-helpers/contracts/lib/misc/ERCProxy.sol deleted file mode 100644 index 13da6e51d..000000000 --- a/apps/shared/test-helpers/contracts/lib/misc/ERCProxy.sol +++ /dev/null @@ -1,14 +0,0 @@ -/* - * SPDX-License-Identitifer: MIT - */ - -pragma solidity ^0.4.24; - - -contract ERCProxy { - uint256 constant public FORWARDING = 1; - uint256 constant public UPGRADEABLE = 2; - - function proxyType() public pure returns (uint256 proxyTypeId); - function implementation() public view returns (address codeAddr); -} diff --git a/apps/shared/test-helpers/contracts/lib/misc/Migrations.sol b/apps/shared/test-helpers/contracts/lib/misc/Migrations.sol deleted file mode 100644 index a74e2cce0..000000000 --- a/apps/shared/test-helpers/contracts/lib/misc/Migrations.sol +++ /dev/null @@ -1,25 +0,0 @@ -pragma solidity ^0.4.24; - - -contract Migrations { - address public owner; - uint public lastCompletedMigration; - - modifier restricted() { - if (msg.sender == owner) - _; - } - - constructor() public { - owner = msg.sender; - } - - function setCompleted(uint completed) public restricted { - lastCompletedMigration = completed; - } - - function upgrade(address newAddress) public restricted { - Migrations upgraded = Migrations(newAddress); - upgraded.setCompleted(lastCompletedMigration); - } -} diff --git a/apps/shared/test-helpers/contracts/lib/token/ERC20.sol b/apps/shared/test-helpers/contracts/lib/token/ERC20.sol deleted file mode 100644 index de963bd12..000000000 --- a/apps/shared/test-helpers/contracts/lib/token/ERC20.sol +++ /dev/null @@ -1,37 +0,0 @@ -// See https://github.com/OpenZeppelin/openzeppelin-solidity/blob/a9f910d34f0ab33a1ae5e714f69f9596a02b4d91/contracts/token/ERC20/ERC20.sol - -pragma solidity ^0.4.24; - - -/** - * @title ERC20 interface - * @dev see https://github.com/ethereum/EIPs/issues/20 - */ -contract ERC20 { - function totalSupply() public view returns (uint256); - - function balanceOf(address _who) public view returns (uint256); - - function allowance(address _owner, address _spender) - public view returns (uint256); - - function transfer(address _to, uint256 _value) public returns (bool); - - function approve(address _spender, uint256 _value) - public returns (bool); - - function transferFrom(address _from, address _to, uint256 _value) - public returns (bool); - - event Transfer( - address indexed from, - address indexed to, - uint256 value - ); - - event Approval( - address indexed owner, - address indexed spender, - uint256 value - ); -} diff --git a/apps/shared/test-helpers/contracts/lib/zeppelin/math/Math.sol b/apps/shared/test-helpers/contracts/lib/zeppelin/math/Math.sol deleted file mode 100644 index f0d1560d5..000000000 --- a/apps/shared/test-helpers/contracts/lib/zeppelin/math/Math.sol +++ /dev/null @@ -1,25 +0,0 @@ -pragma solidity ^0.4.24; - - -/** - * @title Math - * @dev Assorted math operations - */ - -library Math { - function max64(uint64 a, uint64 b) internal pure returns (uint64) { - return a >= b ? a : b; - } - - function min64(uint64 a, uint64 b) internal pure returns (uint64) { - return a < b ? a : b; - } - - function max256(uint256 a, uint256 b) internal pure returns (uint256) { - return a >= b ? a : b; - } - - function min256(uint256 a, uint256 b) internal pure returns (uint256) { - return a < b ? a : b; - } -} diff --git a/apps/shared/test-helpers/contracts/lib/zeppelin/math/SafeMath.sol b/apps/shared/test-helpers/contracts/lib/zeppelin/math/SafeMath.sol deleted file mode 100644 index b538d571c..000000000 --- a/apps/shared/test-helpers/contracts/lib/zeppelin/math/SafeMath.sol +++ /dev/null @@ -1,69 +0,0 @@ -// See https://github.com/OpenZeppelin/openzeppelin-solidity/blob/d51e38758e1d985661534534d5c61e27bece5042/contracts/math/SafeMath.sol -// Adapted to use pragma ^0.4.24 and satisfy our linter rules - -pragma solidity ^0.4.24; - - -/** - * @title SafeMath - * @dev Math operations with safety checks that revert on error - */ -library SafeMath { - - /** - * @dev Multiplies two numbers, reverts on overflow. - */ - 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); - - return c; - } - - /** - * @dev Integer division of two numbers truncating the quotient, reverts on division by zero. - */ - function div(uint256 _a, uint256 _b) internal pure returns (uint256) { - require(_b > 0); // Solidity only automatically asserts when dividing by 0 - uint256 c = _a / _b; - // assert(_a == _b * c + _a % _b); // There is no case in which this doesn't hold - - return c; - } - - /** - * @dev Subtracts two numbers, reverts on overflow (i.e. if subtrahend is greater than minuend). - */ - function sub(uint256 _a, uint256 _b) internal pure returns (uint256) { - require(_b <= _a); - uint256 c = _a - _b; - - return c; - } - - /** - * @dev Adds two numbers, reverts on overflow. - */ - function add(uint256 _a, uint256 _b) internal pure returns (uint256) { - uint256 c = _a + _b; - require(c >= _a); - - return c; - } - - /** - * @dev Divides two numbers and returns the remainder (unsigned integer modulo), - * reverts when dividing by zero. - */ - function mod(uint256 a, uint256 b) internal pure returns (uint256) { - require(b != 0); - return a % b; - } -} diff --git a/apps/shared/test-helpers/contracts/lib/zeppelin/math/SafeMath64.sol b/apps/shared/test-helpers/contracts/lib/zeppelin/math/SafeMath64.sol deleted file mode 100644 index 08f651223..000000000 --- a/apps/shared/test-helpers/contracts/lib/zeppelin/math/SafeMath64.sol +++ /dev/null @@ -1,69 +0,0 @@ -// See https://github.com/OpenZeppelin/openzeppelin-solidity/blob/d51e38758e1d985661534534d5c61e27bece5042/contracts/math/SafeMath.sol -// Adapted for uint64, pragma ^0.4.24, and satisfying our linter rules - -pragma solidity ^0.4.24; - - -/** - * @title SafeMath64 - * @dev Math operations for uint64 with safety checks that revert on error - */ -library SafeMath64 { - - /** - * @dev Multiplies two numbers, reverts on overflow. - */ - function mul(uint64 _a, uint64 _b) internal pure returns (uint64) { - // 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; - } - - uint64 c = _a * _b; - require(c / _a == _b); - - return c; - } - - /** - * @dev Integer division of two numbers truncating the quotient, reverts on division by zero. - */ - function div(uint64 _a, uint64 _b) internal pure returns (uint64) { - require(_b > 0); // Solidity only automatically asserts when dividing by 0 - uint64 c = _a / _b; - // assert(_a == _b * c + _a % _b); // There is no case in which this doesn't hold - - return c; - } - - /** - * @dev Subtracts two numbers, reverts on overflow (i.e. if subtrahend is greater than minuend). - */ - function sub(uint64 _a, uint64 _b) internal pure returns (uint64) { - require(_b <= _a); - uint64 c = _a - _b; - - return c; - } - - /** - * @dev Adds two numbers, reverts on overflow. - */ - function add(uint64 _a, uint64 _b) internal pure returns (uint64) { - uint64 c = _a + _b; - require(c >= _a); - - return c; - } - - /** - * @dev Divides two numbers and returns the remainder (unsigned integer modulo), - * reverts when dividing by zero. - */ - function mod(uint64 a, uint64 b) internal pure returns (uint64) { - require(b != 0); - return a % b; - } -} diff --git a/apps/shared/test-helpers/contracts/lib/zeppelin/math/SafeMath8.sol b/apps/shared/test-helpers/contracts/lib/zeppelin/math/SafeMath8.sol deleted file mode 100644 index 7a53c24ba..000000000 --- a/apps/shared/test-helpers/contracts/lib/zeppelin/math/SafeMath8.sol +++ /dev/null @@ -1,69 +0,0 @@ -// See https://github.com/OpenZeppelin/openzeppelin-solidity/blob/d51e38758e1d985661534534d5c61e27bece5042/contracts/math/SafeMath.sol -// Adapted for uint8, pragma ^0.4.24, and satisfying our linter rules - -pragma solidity ^0.4.24; - - -/** - * @title SafeMath8 - * @dev Math operations for uint8 with safety checks that revert on error - */ -library SafeMath8 { - - /** - * @dev Multiplies two numbers, reverts on overflow. - */ - function mul(uint8 _a, uint8 _b) internal pure returns (uint8) { - // 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; - } - - uint8 c = _a * _b; - require(c / _a == _b); - - return c; - } - - /** - * @dev Integer division of two numbers truncating the quotient, reverts on division by zero. - */ - function div(uint8 _a, uint8 _b) internal pure returns (uint8) { - require(_b > 0); // Solidity only automatically asserts when dividing by 0 - uint8 c = _a / _b; - // assert(_a == _b * c + _a % _b); // There is no case in which this doesn't hold - - return c; - } - - /** - * @dev Subtracts two numbers, reverts on overflow (i.e. if subtrahend is greater than minuend). - */ - function sub(uint8 _a, uint8 _b) internal pure returns (uint8) { - require(_b <= _a); - uint8 c = _a - _b; - - return c; - } - - /** - * @dev Adds two numbers, reverts on overflow. - */ - function add(uint8 _a, uint8 _b) internal pure returns (uint8) { - uint8 c = _a + _b; - require(c >= _a); - - return c; - } - - /** - * @dev Divides two numbers and returns the remainder (unsigned integer modulo), - * reverts when dividing by zero. - */ - function mod(uint8 a, uint8 b) internal pure returns (uint8) { - require(b != 0); - return a % b; - } -} diff --git a/apps/shared/test-helpers/contracts/lib/zeppelin/token/BasicToken.sol b/apps/shared/test-helpers/contracts/lib/zeppelin/token/BasicToken.sol deleted file mode 100644 index a395febec..000000000 --- a/apps/shared/test-helpers/contracts/lib/zeppelin/token/BasicToken.sol +++ /dev/null @@ -1,44 +0,0 @@ -pragma solidity ^0.4.24; - - -import "./ERC20Basic.sol"; -import "../math/SafeMath.sol"; - - -/** - * @title Basic token - * @dev Basic version of StandardToken, with no allowances. - */ -contract BasicToken is ERC20Basic { - using SafeMath for uint256; - uint256 totalSupply_; - - mapping(address => uint256) balances; - - function totalSupply() public view returns (uint256) { return totalSupply_; } - /** - * @dev transfer token for a specified address - * @param _to The address to transfer to. - * @param _value The amount to be transferred. - */ - function transfer(address _to, uint256 _value) public returns (bool) { - require(_to != address(0)); - require(_value <= balances[msg.sender]); - - // SafeMath.sub will throw if there is not enough balance. - balances[msg.sender] = balances[msg.sender].sub(_value); - balances[_to] = balances[_to].add(_value); - emit Transfer(msg.sender, _to, _value); - return true; - } - - /** - * @dev Gets the balance of the specified address. - * @param _owner The address to query the the balance of. - * @return An uint256 representing the amount owned by the passed address. - */ - function balanceOf(address _owner) public view returns (uint256 balance) { - return balances[_owner]; - } - -} diff --git a/apps/shared/test-helpers/contracts/lib/zeppelin/token/ERC20.sol b/apps/shared/test-helpers/contracts/lib/zeppelin/token/ERC20.sol deleted file mode 100644 index 578e0355e..000000000 --- a/apps/shared/test-helpers/contracts/lib/zeppelin/token/ERC20.sol +++ /dev/null @@ -1,16 +0,0 @@ -pragma solidity ^0.4.24; - - -import "./ERC20Basic.sol"; - - -/** - * @title ERC20 interface - * @dev see https://github.com/ethereum/EIPs/issues/20 - */ -contract ERC20 is ERC20Basic { - function allowance(address owner, address spender) public view returns (uint256); - function transferFrom(address from, address to, uint256 value) public returns (bool); - function approve(address spender, uint256 value) public returns (bool); - event Approval(address indexed owner, address indexed spender, uint256 value); -} diff --git a/apps/shared/test-helpers/contracts/lib/zeppelin/token/ERC20Basic.sol b/apps/shared/test-helpers/contracts/lib/zeppelin/token/ERC20Basic.sol deleted file mode 100644 index c326601de..000000000 --- a/apps/shared/test-helpers/contracts/lib/zeppelin/token/ERC20Basic.sol +++ /dev/null @@ -1,14 +0,0 @@ -pragma solidity ^0.4.24; - - -/** - * @title ERC20Basic - * @dev Simpler version of ERC20 interface - * @dev see https://github.com/ethereum/EIPs/issues/179 - */ -contract ERC20Basic { - function totalSupply() public view returns (uint256); - function balanceOf(address who) public view returns (uint256); - function transfer(address to, uint256 value) public returns (bool); - event Transfer(address indexed from, address indexed to, uint256 value); -} diff --git a/apps/shared/test-helpers/contracts/lib/zeppelin/token/StandardToken.sol b/apps/shared/test-helpers/contracts/lib/zeppelin/token/StandardToken.sol deleted file mode 100644 index fcb5beabb..000000000 --- a/apps/shared/test-helpers/contracts/lib/zeppelin/token/StandardToken.sol +++ /dev/null @@ -1,87 +0,0 @@ -pragma solidity ^0.4.24; - - -import './BasicToken.sol'; -import './ERC20.sol'; - - -/** - * @title Standard ERC20 token - * - * @dev Implementation of the basic standard token. - * @dev https://github.com/ethereum/EIPs/issues/20 - * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol - */ -contract StandardToken is ERC20, BasicToken { - - mapping (address => mapping (address => uint256)) internal allowed; - - - /** - * @dev Transfer tokens from one address to another - * @param _from address The address which you want to send tokens from - * @param _to address The address which you want to transfer to - * @param _value uint256 the amount of tokens to be transferred - */ - function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { - require(_to != address(0)); - require(_value <= balances[_from]); - require(_value <= allowed[_from][msg.sender]); - - balances[_from] = balances[_from].sub(_value); - balances[_to] = balances[_to].add(_value); - allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); - Transfer(_from, _to, _value); - return true; - } - - /** - * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. - * - * Beware that changing an allowance with this method brings the risk that someone may use both the old - * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this - * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: - * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 - * @param _spender The address which will spend the funds. - * @param _value The amount of tokens to be spent. - */ - function approve(address _spender, uint256 _value) public returns (bool) { - allowed[msg.sender][_spender] = _value; - Approval(msg.sender, _spender, _value); - return true; - } - - /** - * @dev Function to check the amount of tokens that an owner allowed to a spender. - * @param _owner address The address which owns the funds. - * @param _spender address The address which will spend the funds. - * @return A uint256 specifying the amount of tokens still available for the spender. - */ - function allowance(address _owner, address _spender) public constant returns (uint256 remaining) { - return allowed[_owner][_spender]; - } - - /** - * approve should be called when allowed[_spender] == 0. To increment - * allowed value is better to use this function to avoid 2 calls (and wait until - * the first transaction is mined) - * From MonolithDAO Token.sol - */ - function increaseApproval (address _spender, uint _addedValue) public returns (bool success) { - allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); - Approval(msg.sender, _spender, allowed[msg.sender][_spender]); - return true; - } - - function decreaseApproval (address _spender, uint _subtractedValue) public returns (bool success) { - uint oldValue = allowed[msg.sender][_spender]; - if (_subtractedValue > oldValue) { - allowed[msg.sender][_spender] = 0; - } else { - allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); - } - Approval(msg.sender, _spender, allowed[msg.sender][_spender]); - return true; - } - -} diff --git a/apps/shared/test-helpers/contracts/test/TestACLInterpreter.sol b/apps/shared/test-helpers/contracts/test/TestACLInterpreter.sol deleted file mode 100644 index ca909e91e..000000000 --- a/apps/shared/test-helpers/contracts/test/TestACLInterpreter.sol +++ /dev/null @@ -1,268 +0,0 @@ -pragma solidity 0.4.24; - -import "../acl/ACL.sol"; -import "./helpers/Assert.sol"; -import "./helpers/ACLHelper.sol"; - - -contract TestACLInterpreter is ACL, ACLHelper { - function testEqualityUint() public { - // Assert param 0 is equal to 10, given that params are [10, 11] - assertEval(arr(uint256(10), 11), 0, Op.EQ, 10, true); - assertEval(arr(uint256(10), 11), 1, Op.EQ, 10, false); - assertEval(arr(uint256(10), 11), 1, Op.EQ, 11, true); - } - - function testEqualityAddr() public { - assertEval(arr(msg.sender), 0, Op.EQ, uint256(msg.sender), true); - assertEval(arr(msg.sender), 0, Op.EQ, uint256(this), false); - } - - function testEqualityBytes() public { - assertEval(arr(keccak256("hi")), 0, Op.EQ, uint256(keccak256("hi")), true); - assertEval(arr(keccak256("hi")), 0, Op.EQ, uint256(keccak256("bye")), false); - } - - function testInequalityUint() public { - assertEval(arr(uint256(10), 11), 0, Op.NEQ, 10, false); - assertEval(arr(uint256(10), 11), 1, Op.NEQ, 10, true); - assertEval(arr(uint256(10), 11), 1, Op.NEQ, 11, false); - } - - function testInequalityBytes() public { - assertEval(arr(keccak256("hi")), 0, Op.NEQ, uint256(keccak256("hi")), false); - assertEval(arr(keccak256("hi")), 0, Op.NEQ, uint256(keccak256("bye")), true); - } - - function testInequalityAddr() public { - assertEval(arr(msg.sender), 0, Op.NEQ, uint256(msg.sender), false); - assertEval(arr(msg.sender), 0, Op.NEQ, uint256(this), true); - } - - function testGreatherThan() public { - assertEval(arr(uint256(10), 11), 0, Op.GT, 9, true); - assertEval(arr(uint256(10), 11), 0, Op.GT, 10, false); - assertEval(arr(uint256(10), 11), 1, Op.GT, 10, true); - } - - function testLessThan() public { - assertEval(arr(uint256(10), 11), 0, Op.LT, 9, false); - assertEval(arr(uint256(9), 11), 0, Op.LT, 10, true); - assertEval(arr(uint256(10), 11), 1, Op.LT, 10, false); - } - - function testGreatherThanOrEqual() public { - assertEval(arr(uint256(10), 11), 0, Op.GTE, 9, true); - assertEval(arr(uint256(10), 11), 0, Op.GTE, 10, true); - assertEval(arr(uint256(10), 11), 1, Op.GTE, 12, false); - } - - function testLessThanOrEqual() public { - assertEval(arr(uint256(10), 11), 0, Op.LTE, 9, false); - assertEval(arr(uint256(9), 11), 0, Op.LTE, 10, true); - assertEval(arr(uint256(10), 11), 1, Op.LTE, 11, true); - } - - function testTimestamp() public { - assertEval(arr(), TIMESTAMP_PARAM_ID, Op.EQ, uint256(block.timestamp), true); - assertEval(arr(), TIMESTAMP_PARAM_ID, Op.EQ, uint256(1), false); - assertEval(arr(), TIMESTAMP_PARAM_ID, Op.GT, uint256(1), true); - } - - function testBlockNumber() public { - assertEval(arr(), BLOCK_NUMBER_PARAM_ID, Op.EQ, uint256(block.number), true); - assertEval(arr(), BLOCK_NUMBER_PARAM_ID, Op.EQ, uint256(1), false); - assertEval(arr(), BLOCK_NUMBER_PARAM_ID, Op.GT, uint256(block.number - 1), true); - } - - function testOracle() public { - assertEval(arr(), ORACLE_PARAM_ID, Op.EQ, uint256(new AcceptOracle()), true); - assertEval(arr(), ORACLE_PARAM_ID, Op.EQ, uint256(new RejectOracle()), false); - assertEval(arr(), ORACLE_PARAM_ID, Op.NEQ, uint256(new RejectOracle()), true); - - // doesn't revert even if oracle reverts - assertEval(arr(), ORACLE_PARAM_ID, Op.EQ, uint256(new RevertOracle()), false); - // the staticcall will error as the oracle tries to modify state, so a no is returned - assertEval(arr(), ORACLE_PARAM_ID, Op.EQ, uint256(new StateModifyingOracle()), false); - // if returned data size is not correct, returns false - assertEval(arr(), ORACLE_PARAM_ID, Op.EQ, uint256(new EmptyDataReturnOracle()), false); - - // conditional oracle returns true if first param > 0 - ConditionalOracle conditionalOracle = new ConditionalOracle(); - - assertEval(arr(uint256(1)), ORACLE_PARAM_ID, Op.EQ, uint256(conditionalOracle), true); - assertEval(arr(uint256(0), uint256(1)), ORACLE_PARAM_ID, Op.EQ, uint256(conditionalOracle), false); - } - - function testReturn() public { - assertEval(arr(), PARAM_VALUE_PARAM_ID, Op.RET, uint256(1), true); - assertEval(arr(), PARAM_VALUE_PARAM_ID, Op.RET, uint256(0), false); - assertEval(arr(), PARAM_VALUE_PARAM_ID, Op.RET, uint256(100), true); - assertEval(arr(), TIMESTAMP_PARAM_ID, Op.RET, uint256(0), true); - } - - function testNot() public { - Param memory retTrue = Param(PARAM_VALUE_PARAM_ID, uint8(Op.RET), 1); - Param memory retFalse = Param(PARAM_VALUE_PARAM_ID, uint8(Op.RET), 0); - - Param memory notOp = Param(LOGIC_OP_PARAM_ID, uint8(Op.NOT), encodeOperator(1, 0)); - Param[] memory params = new Param[](2); - - // !true == false - params[0] = notOp; - params[1] = retTrue; - assertEval(params, false); - - // !false == true - params[1] = retFalse; - assertEval(params, true); - } - - function testComplexCombination() public { - // if (oracle and block number > block number - 1) then arg 0 < 10 or oracle else false - Param[] memory params = new Param[](7); - params[0] = Param(LOGIC_OP_PARAM_ID, uint8(Op.IF_ELSE), encodeIfElse(1, 4, 6)); - params[1] = Param(LOGIC_OP_PARAM_ID, uint8(Op.AND), encodeOperator(2, 3)); - params[2] = Param(ORACLE_PARAM_ID, uint8(Op.EQ), uint240(new AcceptOracle())); - params[3] = Param(BLOCK_NUMBER_PARAM_ID, uint8(Op.GT), uint240(block.number - 1)); - params[4] = Param(LOGIC_OP_PARAM_ID, uint8(Op.OR), encodeOperator(5, 2)); - params[5] = Param(0, uint8(Op.LT), uint240(10)); - params[6] = Param(PARAM_VALUE_PARAM_ID, uint8(Op.RET), 0); - - assertEval(params, arr(uint256(10)), true); - - params[4] = Param(LOGIC_OP_PARAM_ID, uint8(Op.AND), encodeOperator(5, 2)); - assertEval(params, arr(uint256(10)), false); - } - - function testParamOutOfBoundsFail() public { - Param[] memory params = new Param[](2); - - params[1] = Param(PARAM_VALUE_PARAM_ID, uint8(Op.RET), 1); - assertEval(params, arr(uint256(10)), false); - - params[0] = Param(LOGIC_OP_PARAM_ID, uint8(Op.IF_ELSE), encodeIfElse(2, 2, 2)); - assertEval(params, arr(uint256(10)), false); - } - - function testArgOutOfBoundsFail() public { - assertEval(arr(uint256(10), 11), 3, Op.EQ, 10, false); - } - - function testIfElse() public { - Param memory retTrue = Param(PARAM_VALUE_PARAM_ID, uint8(Op.RET), 1); - Param memory retFalse = Param(PARAM_VALUE_PARAM_ID, uint8(Op.RET), 0); - - // If 1 then 2 else 3 - Param memory ifOp = Param(LOGIC_OP_PARAM_ID, uint8(Op.IF_ELSE), encodeIfElse(1, 2, 3)); - Param[] memory params = new Param[](4); - - // true ? true : false == true - params[0] = ifOp; - params[1] = retTrue; - params[2] = retTrue; - params[3] = retFalse; - assertEval(params, true); - - // false ? true : false == false - params[1] = retFalse; - assertEval(params, false); - } - - function testCombinators() public { - Param memory retTrue = Param(PARAM_VALUE_PARAM_ID, uint8(Op.RET), 1); - Param memory retFalse = Param(PARAM_VALUE_PARAM_ID, uint8(Op.RET), 0); - - // OR param at index 1 or param 2 - Param memory orOp = Param(LOGIC_OP_PARAM_ID, uint8(Op.OR), encodeOperator(1, 2)); - Param memory andOp = Param(LOGIC_OP_PARAM_ID, uint8(Op.AND), encodeOperator(1, 2)); - Param memory xorOp = Param(LOGIC_OP_PARAM_ID, uint8(Op.XOR), encodeOperator(1, 2)); - - Param[] memory params = new Param[](3); - - // or true true == true - params[0] = orOp; - params[1] = retTrue; - params[2] = retTrue; - assertEval(params, true); - - // or false true == true - params[1] = retFalse; - assertEval(params, true); - - // or true false == true - params[1] = retTrue; - params[2] = retFalse; - assertEval(params, true); - - // or false false == false - params[1] = retFalse; - assertEval(params, false); - - // and false false == false - params[0] = andOp; - assertEval(params, false); - - // and true false == false - params[1] = retTrue; - assertEval(params, false); - - // and false true == false - params[1] = retFalse; - params[2] = retTrue; - assertEval(params, false); - - // and true true == true - params[1] = retTrue; - params[2] = retTrue; - assertEval(params, true); - - // xor true true == false - params[0] = xorOp; - assertEval(params, false); - - // xor false true == true - params[1] = retFalse; - assertEval(params, true); - - // xor true false == true - params[1] = retTrue; - params[2] = retFalse; - assertEval(params, true); - - // xor false false == false - params[1] = retFalse; - assertEval(params, false); - } - - - function assertEval(uint256[] memory args, uint8 argId, Op op, uint256 value, bool expected) internal { - Param[] memory params = new Param[](1); - params[0] = Param(argId, uint8(op), uint240(value)); - assertEval(params, args, expected); - } - - function assertEval(Param[] memory params, bool expected) internal { - assertEval(params, new uint256[](0), expected); - } - - function assertEval(Param[] memory params, uint256[] memory args, bool expected) internal { - bytes32 paramHash = encodeAndSaveParams(params); - bool allow = _evalParam(paramHash, 0, address(0), address(0), bytes32(0), args); - - Assert.equal(allow, expected, "eval got unexpected result"); - } - - event LogParam(bytes32 param); - function encodeAndSaveParams(Param[] memory params) internal returns (bytes32) { - uint256[] memory encodedParams = new uint256[](params.length); - - for (uint256 i = 0; i < params.length; i++) { - Param memory param = params[i]; - encodedParams[i] = (uint256(param.id) << 248) + (uint256(param.op) << 240) + param.value; - emit LogParam(bytes32(encodedParams[i])); - } - - return _saveParams(encodedParams); - } -} diff --git a/apps/shared/test-helpers/contracts/test/TestDelegateProxy.sol b/apps/shared/test-helpers/contracts/test/TestDelegateProxy.sol deleted file mode 100644 index 3fdc83ab9..000000000 --- a/apps/shared/test-helpers/contracts/test/TestDelegateProxy.sol +++ /dev/null @@ -1,74 +0,0 @@ -pragma solidity 0.4.24; - -import "./helpers/Assert.sol"; -import "./helpers/ThrowProxy.sol"; - -import "../common/DelegateProxy.sol"; -import "../evmscript/ScriptHelpers.sol"; - - -contract Target { - function dontReturn() public pure {} - function fail() public pure { revert(); } - function die() public { selfdestruct(0); } -} - - -contract TestDelegateProxy is DelegateProxy { - using ScriptHelpers for *; - - Target target; - ThrowProxy throwProxy; - - // Mock ERCProxy implementation - function implementation() public view returns (address) { - return this; - } - - function proxyType() public pure returns (uint256) { - return FORWARDING; - } - - // Tests - function beforeAll() public { - target = new Target(); - } - - function beforeEach() public { - throwProxy = new ThrowProxy(address(this)); - } - - function testFailIfNoContract() public { - TestDelegateProxy(throwProxy).noContract(); - throwProxy.assertThrows("should have reverted if target is not a contract"); - } - - function noContract() public { - delegatedFwd(address(0x1234), target.dontReturn.selector.toBytes()); - } - - function testFailIfReverts() public { - TestDelegateProxy(throwProxy).revertCall(); - throwProxy.assertThrows("should have reverted if call reverted"); - } - - function revertCall() public { - delegatedFwd(target, target.fail.selector.toBytes()); - } - - function testIsContractZero() public { - bool result = isContract(address(0)); - Assert.isFalse(result, "should return false"); - } - - function testIsContractAddress() public { - address nonContract = 0x1234; - bool result = isContract(nonContract); - Assert.isFalse(result, "should return false"); - } - - // keep as last test as it will kill this contract - function testDieIfMinReturn0() public { - delegatedFwd(target, target.die.selector.toBytes()); - } -} diff --git a/apps/shared/test-helpers/contracts/test/helpers/ACLHelper.sol b/apps/shared/test-helpers/contracts/test/helpers/ACLHelper.sol deleted file mode 100644 index 404978572..000000000 --- a/apps/shared/test-helpers/contracts/test/helpers/ACLHelper.sol +++ /dev/null @@ -1,59 +0,0 @@ -pragma solidity 0.4.24; - -import "../../acl/IACLOracle.sol"; - - -contract ACLHelper { - function encodeOperator(uint256 param1, uint256 param2) internal pure returns (uint240) { - return encodeIfElse(param1, param2, 0); - } - - function encodeIfElse(uint256 condition, uint256 successParam, uint256 failureParam) internal pure returns (uint240) { - return uint240(condition + (successParam << 32) + (failureParam << 64)); - } -} - - -contract AcceptOracle is IACLOracle { - function canPerform(address, address, bytes32, uint256[]) external view returns (bool) { - return true; - } -} - - -contract RejectOracle is IACLOracle { - function canPerform(address, address, bytes32, uint256[]) external view returns (bool) { - return false; - } -} - - -contract RevertOracle is IACLOracle { - function canPerform(address, address, bytes32, uint256[]) external view returns (bool) { - revert(); - } -} - -// Can't implement from IACLOracle as its canPerform() is marked as view-only -contract StateModifyingOracle /* is IACLOracle */ { - bool modifyState; - - function canPerform(address, address, bytes32, uint256[]) external returns (bool) { - modifyState = true; - return true; - } -} - -contract EmptyDataReturnOracle is IACLOracle { - function canPerform(address, address, bytes32, uint256[]) external view returns (bool) { - assembly { - return(0, 0) - } - } -} - -contract ConditionalOracle is IACLOracle { - function canPerform(address, address, bytes32, uint256[] how) external view returns (bool) { - return how[0] > 0; - } -} diff --git a/apps/shared/test-helpers/contracts/test/helpers/Assert.sol b/apps/shared/test-helpers/contracts/test/helpers/Assert.sol deleted file mode 100644 index eed4edcd2..000000000 --- a/apps/shared/test-helpers/contracts/test/helpers/Assert.sol +++ /dev/null @@ -1,1405 +0,0 @@ -// Taken from https://github.com/trufflesuite/truffle/blob/ef03be9e35909e5e7c97a9ecb07ccae4872645ca/packages/truffle-core/lib/testing/Assert.sol - -pragma solidity ^0.4.24; - -/* - File: Assertions.slb - Author: Andreas Olofsson (androlo1980@gmail.com) - Library: Assertions - Assertions for unit testing contracts. Tests are run with the - - unit-testing framework. - (start code) - contract ModAdder { - function addMod(uint a, uint b, uint modulus) constant returns (uint sum) { - if (modulus == 0) - throw; - return addmod(a, b, modulus); - } - } - contract SomeTest { - using Assertions for uint; - function testAdd() { - var adder = new ModAdder(); - adder.addMod(50, 66, 30).equal(26, "addition returned the wrong sum"); - } - } - (end) - It is also possible to extend , to have all bindings (using) properly set up. - (start code) - contract SomeTest is Test { - function testAdd() { - var adder = new ModAdder(); - adder.addMod(50, 66, 30).equal(26, "addition returned the wrong sum"); - } - } - (end) -*/ - -library Assert { - - // Constant: ADDRESS_NULL - // The null address: 0 - address constant ADDRESS_NULL = 0x0000000000000000000000000000000000000000; - // Constant: BYTES32_NULL - // The null bytes32: 0 - bytes32 constant BYTES32_NULL = 0x0; - // Constant: STRING_NULL - // The null string: "" - string constant STRING_NULL = ""; - - uint8 constant ZERO = uint8(byte('0')); - uint8 constant A = uint8(byte('a')); - - byte constant MINUS = byte('-'); - - /* - Event: TestEvent - Fired when an assertion is made. - Params: - result (bool) - Whether or not the assertion holds. - message (string) - A message to display if the assertion does not hold. - */ - event TestEvent(bool indexed result, string message); - - // ************************************** general ************************************** - - /* - Function: fail() - Mark the test as failed. - Params: - message (string) - A message associated with the failure. - Returns: - result (bool) - false. - */ - function fail(string message) public returns (bool result) { - _report(false, message); - return false; - } - - // ************************************** strings ************************************** - - /* - Function: equal(string) - Assert that two strings are equal. - : _stringsEqual(A, B) == true - Params: - A (string) - The first string. - B (string) - The second string. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function equal(string a, string b, string message) public returns (bool result) { - result = _stringsEqual(a, b); - if (result) - _report(result, message); - else - _report(result, _appendTagged(_tag(a, "Tested"), _tag(b, "Against"), message)); - } - - /* - Function: notEqual(string) - Assert that two strings are not equal. - : _stringsEqual(A, B) == false - Params: - A (string) - The first string. - B (string) - The second string. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function notEqual(string a, string b, string message) public returns (bool result) { - result = !_stringsEqual(a, b); - if (result) - _report(result, message); - else - _report(result, _appendTagged(_tag(a, "Tested"), _tag(b, "Against"), message)); - } - - /* - Function: isEmpty(string) - Assert that a string is empty. - : _stringsEqual(str, STRING_NULL) == true - Params: - str (string) - The string. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function isEmpty(string str, string message) public returns (bool result) { - result = _stringsEqual(str, STRING_NULL); - if (result) - _report(result, message); - else - _report(result, _appendTagged(_tag(str, "Tested"), message)); - } - - /* - Function: isNotEmpty(string) - Assert that a string is not empty. - : _stringsEqual(str, STRING_NULL) == false - Params: - str (string) - The string. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function isNotEmpty(string str, string message) public returns (bool result) { - result = !_stringsEqual(str, STRING_NULL); - if (result) - _report(result, message); - else - _report(result, _appendTagged(_tag(str, "Tested"), message)); - } - - // ************************************** bytes32 ************************************** - - /* - Function: equal(bytes32) - Assert that two 'bytes32' are equal. - : A == B - Params: - A (bytes32) - The first 'bytes32'. - B (bytes32) - The second 'bytes32'. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function equal(bytes32 a, bytes32 b, string message) public returns (bool result) { - result = (a == b); - _report(result, message); - } - - /* - Function: notEqual(bytes32) - Assert that two 'bytes32' are not equal. - : A != B - Params: - A (bytes32) - The first 'bytes32'. - B (bytes32) - The second 'bytes32'. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function notEqual(bytes32 a, bytes32 b, string message) public returns (bool result) { - result = (a != b); - _report(result, message); - } - - /* - Function: isZero(bytes32) - Assert that a 'bytes32' is zero. - : bts == BYTES32_NULL - Params: - bts (bytes32) - The 'bytes32'. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function isZero(bytes32 bts, string message) public returns (bool result) { - result = (bts == BYTES32_NULL); - _report(result, message); - } - - /* - Function: isNotZero(bytes32) - Assert that a 'bytes32' is not zero. - : bts != BYTES32_NULL - Params: - bts (bytes32) - The 'bytes32'. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function isNotZero(bytes32 bts, string message) public returns (bool result) { - result = (bts != BYTES32_NULL); - _report(result, message); - } - - // ************************************** address ************************************** - - /* - Function: equal(address) - Assert that two addresses are equal. - : A == B - Params: - A (address) - The first address. - B (address) - The second address. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function equal(address a, address b, string message) public returns (bool result) { - result = (a == b); - _report(result, message); - } - /* - Function: notEqual(address) - Assert that two addresses are not equal. - : A != B - Params: - A (address) - The first address. - B (address) - The second address. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function notEqual(address a, address b, string message) public returns (bool result) { - result = (a != b); - _report(result, message); - } - - /* - Function: isZero(address) - Assert that an address is zero. - : addr == ADDRESS_NULL - Params: - addr (address) - The address. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function isZero(address addr, string message) public returns (bool result) { - result = (addr == ADDRESS_NULL); - _report(result, message); - } - - /* - Function: isNotZero(address) - Assert that an address is not zero. - : addr != ADDRESS_NULL - Params: - addr (address) - The address. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function isNotZero(address addr, string message) public returns (bool result) { - result = (addr != ADDRESS_NULL); - _report(result, message); - } - - // ************************************** bool ************************************** - - /* - Function: isTrue - Assert that a boolean is 'true'. - : b == true - Params: - b (bool) - The boolean. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function isTrue(bool b, string message) public returns (bool result) { - result = b; - _report(result, message); - } - - /* - Function: isFalse - Assert that a boolean is 'false'. - : b == false - Params: - b (bool) - The boolean. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function isFalse(bool b, string message) public returns (bool result) { - result = !b; - _report(result, message); - } - - /* - Function: equal(bool) - Assert that two booleans are equal. - : A == B - Params: - A (bool) - The first boolean. - B (bool) - The second boolean. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function equal(bool a, bool b, string message) public returns (bool result) { - result = (a == b); - if (result) - _report(result, message); - else - _report(result, _appendTagged(_tag(a, "Tested"), _tag(b, "Against"), message)); - } - - /* - Function: notEqual(bool) - Assert that two booleans are not equal. - : A != B - Params: - A (bool) - The first boolean. - B (bool) - The second boolean. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function notEqual(bool a, bool b, string message) public returns (bool result) { - result = (a != b); - if (result) - _report(result, message); - else - _report(result, _appendTagged(_tag(a, "Tested"), _tag(b, "Against"), message)); - } - - // ************************************** uint ************************************** - - /* - Function: equal(uint) - Assert that two (256 bit) unsigned integers are equal. - : A == B - Params: - A (uint) - The first uint. - B (uint) - The second uint. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function equal(uint a, uint b, string message) public returns (bool result) { - result = (a == b); - if (result) - _report(result, message); - else - _report(result, _appendTagged(_tag(a, "Tested"), _tag(b, "Against"), message)); - } - - /* - Function: notEqual(uint) - Assert that two (256 bit) unsigned integers are not equal. - : A != B - Params: - A (uint) - The first uint. - B (uint) - The second uint. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function notEqual(uint a, uint b, string message) public returns (bool result) { - result = (a != b); - if (result) - _report(result, message); - else - _report(result, _appendTagged(_tag(a, "Tested"), _tag(b, "Against"), message)); - } - - /* - Function: isAbove(uint) - Assert that the uint 'A' is greater than the uint 'B'. - : A > B - Params: - A (uint) - The first uint. - B (uint) - The second uint. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function isAbove(uint a, uint b, string message) public returns (bool result) { - result = (a > b); - if (result) - _report(result, message); - else - _report(result, _appendTagged(_tag(a, "Tested"), _tag(b, "Against"), message)); - } - - /* - Function: isAtLeast(uint) - Assert that the uint 'A' is greater than or equal to the uint 'B'. - : A >= B - Params: - A (uint) - The first uint. - B (uint) - The second uint. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function isAtLeast(uint a, uint b, string message) public returns (bool result) { - result = (a >= b); - if (result) - _report(result, message); - else - _report(result, _appendTagged(_tag(a, "Tested"), _tag(b, "Against"), message)); - } - - /* - Function: isBelow(uint) - Assert that the uint 'A' is lesser than the uint 'B'. - : A < B - Params: - A (uint) - The first uint. - B (uint) - The second uint. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function isBelow(uint a, uint b, string message) public returns (bool result) { - result = (a < b); - if (result) - _report(result, message); - else - _report(result, _appendTagged(_tag(a, "Tested"), _tag(b, "Against"), message)); - } - - /* - Function: isAtMost(uint) - Assert that the uint 'A' is lesser than or equal to the uint 'B'. - : A <= B - Params: - A (uint) - The first uint. - B (uint) - The second uint. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function isAtMost(uint a, uint b, string message) public returns (bool result) { - result = (a <= b); - if (result) - _report(result, message); - else - _report(result, _appendTagged(_tag(a, "Tested"), _tag(b, "Against"), message)); - } - - /* - Function: isZero(uint) - Assert that a (256 bit) unsigned integer is 0. - : number == 0 - Params: - number (uint) - The uint. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function isZero(uint number, string message) public returns (bool result) { - result = (number == 0); - if (result) - _report(result, message); - else - _report(result, _appendTagged(_tag(number, "Tested"), message)); - } - - /* - Function: isNotZero(uint) - Assert that a (256 bit) unsigned integer is not 0. - : number != 0 - Params: - number (uint) - The uint. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function isNotZero(uint number, string message) public returns (bool result) { - result = (number != 0); - if (result) - _report(result, message); - else - _report(result, _appendTagged(_tag(number, "Tested"), message)); - } - - // ************************************** int ************************************** - - /* - Function: equal(int) - Assert that two (256 bit) signed integers are equal. - : A == B - Params: - A (int) - The first int. - B (int) - The second int. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function equal(int a, int b, string message) public returns (bool result) { - result = (a == b); - if (result) - _report(result, message); - else - _report(result, _appendTagged(_tag(a, "Tested"), _tag(b, "Against"), message)); - } - - /* - Function: notEqual(int) - Assert that two (256 bit) signed integers are not equal. - : A != B - Params: - A (int) - The first int. - B (int) - The second int. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function notEqual(int a, int b, string message) public returns (bool result) { - result = (a != b); - if (result) - _report(result, message); - else - _report(result, _appendTagged(_tag(a, "Tested"), _tag(b, "Against"), message)); - } - - /* - Function: isAbove(int) - Assert that the int 'A' is greater than the int 'B'. - : A > B - Params: - A (int) - The first int. - B (int) - The second int. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function isAbove(int a, int b, string message) public returns (bool result) { - result = (a > b); - if (result) - _report(result, message); - else - _report(result, _appendTagged(_tag(a, "Tested"), _tag(b, "Against"), message)); - } - - /* - Function: isAtLeast(int) - Assert that the int 'A' is greater than or equal to the int 'B'. - : A >= B - Params: - A (int) - The first int. - B (int) - The second int. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function isAtLeast(int a, int b, string message) public returns (bool result) { - result = (a >= b); - if (result) - _report(result, message); - else - _report(result, _appendTagged(_tag(a, "Tested"), _tag(b, "Against"), message)); - } - - /* - Function: isBelow(int) - Assert that the int 'A' is lesser than the int 'B'. - : A < B - Params: - A (int) - The first int. - B (int) - The second int. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function isBelow(int a, int b, string message) public returns (bool result) { - result = (a < b); - if (result) - _report(result, message); - else - _report(result, _appendTagged(_tag(a, "Tested"), _tag(b, "Against"), message)); - } - - /* - Function: isAtMost(int) - Assert that the int 'A' is lesser than or equal to the int 'B'. - : A <= B - Params: - A (int) - The first int. - B (int) - The second int. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function isAtMost(int a, int b, string message) public returns (bool result) { - result = (a <= b); - if (result) - _report(result, message); - else - _report(result, _appendTagged(_tag(a, "Tested"), _tag(b, "Against"), message)); - } - - /* - Function: isZero(int) - Assert that a (256 bit) signed integer is 0. - : number == 0 - Params: - number (int) - The int. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function isZero(int number, string message) public returns (bool result) { - result = (number == 0); - if (result) - _report(result, message); - else - _report(result, _appendTagged(_tag(number, "Tested"), message)); - } - - /* - Function: isNotZero(int) - Assert that a (256 bit) signed integer is not 0. - : number != 0 - Params: - number (int) - The int. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function isNotZero(int number, string message) public returns (bool result) { - result = (number != 0); - if (result) - _report(result, message); - else - _report(result, _appendTagged(_tag(number, "Tested"), message)); - } - - // ************************************** uint[] ************************************** - - /* - Function: equal(uint[]) - Assert that two 'uint[ ]' are equal. - : arrA.length == arrB.length - and, for all valid indices 'i' - : arrA[i] == arrB[i] - Params: - A (uint[]) - The first array. - B (uint[]) - The second array. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function equal(uint[] arrA, uint[] arrB, string message) public returns (bool result) { - result = arrA.length == arrB.length; - if (result) { - for (uint i = 0; i < arrA.length; i++) { - if (arrA[i] != arrB[i]) { - result = false; - break; - } - } - } - _report(result, message); - } - - /* - Function: notEqual(uint[]) - Assert that two 'uint[]' are not equal. - : arrA.length != arrB.length - or, for some valid index 'i' - : arrA[i] != arrB[i] - Params: - A (uint[]) - The first string. - B (uint[]) - The second string. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function notEqual(uint[] arrA, uint[] arrB, string message) public returns (bool result) { - result = arrA.length == arrB.length; - if (result) { - for (uint i = 0; i < arrA.length; i++) { - if (arrA[i] != arrB[i]) { - result = false; - break; - } - } - } - result = !result; - _report(result, message); - } - - /* - Function: lengthEqual(uint[]) - Assert that the length of a 'uint[]' is equal to a given value. - : arr.length == length - Params: - arr (uint[]) - The array. - length (uint) - The length. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function lengthEqual(uint[] arr, uint length, string message) public returns (bool result) { - uint arrLength = arr.length; - if (arrLength == length) - _report(result, ""); - else - _report(result, _appendTagged(_tag(arrLength, "Tested"), _tag(length, "Against"), message)); - } - - /* - Function: lengthNotEqual(uint[]) - Assert that the length of a 'uint[]' is not equal to a given value. - : arr.length != length - Params: - arr (uint[]) - The array. - length (uint) - The length. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function lengthNotEqual(uint[] arr, uint length, string message) public returns (bool result) { - uint arrLength = arr.length; - if (arrLength != arr.length) - _report(result, ""); - else - _report(result, _appendTagged(_tag(arrLength, "Tested"), _tag(length, "Against"), message)); - } - - // ************************************** int[] ************************************** - - /* - Function: equal(int[]) - Assert that two 'int[]' are equal. - : arrA.length == arrB.length - and, for all valid indices 'i' - : arrA[i] == arrB[i] - Params: - A (int[]) - The first array. - B (int[]) - The second array. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function equal(int[] arrA, int[] arrB, string message) public returns (bool result) { - result = arrA.length == arrB.length; - if (result) { - for (uint i = 0; i < arrA.length; i++) { - if (arrA[i] != arrB[i]) { - result = false; - break; - } - } - } - _report(result, message); - } - - /* - Function: notEqual(int[]) - Assert that two 'int[]' are not equal. - : arrA.length != arrB.length - or, for some valid index 'i' - : arrA[i] != arrB[i] - Params: - A (int[]) - The first string. - B (int[]) - The second string. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function notEqual(int[] arrA, int[] arrB, string message) public returns (bool result) { - result = arrA.length == arrB.length; - if (result) { - for (uint i = 0; i < arrA.length; i++) { - if (arrA[i] != arrB[i]) { - result = false; - break; - } - } - } - result = !result; - _report(result, message); - } - - /* - Function: lengthEqual(int[]) - Assert that the length of an 'int[]' is equal to a given value. - : arr.length == length - Params: - arr (int[]) - The array. - length (uint) - The length. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function lengthEqual(int[] arr, uint length, string message) public returns (bool result) { - uint arrLength = arr.length; - if (arrLength == length) - _report(result, ""); - else - _report(result, _appendTagged(_tag(arrLength, "Tested"), _tag(length, "Against"), message)); - } - - /* - Function: lengthNotEqual(int[]) - Assert that the length of an 'int[]' is not equal to a given value. - : arr.length != length - Params: - arr (int[]) - The array. - length (uint) - The length. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function lengthNotEqual(int[] arr, uint length, string message) public returns (bool result) { - uint arrLength = arr.length; - if (arrLength != arr.length) - _report(result, ""); - else - _report(result, _appendTagged(_tag(arrLength, "Tested"), _tag(length, "Against"), message)); - } - - // ************************************** address[] ************************************** - - /* - Function: equal(address[]) - Assert that two 'address[]' are equal. - : arrA.length == arrB.length - and, for all valid indices 'i' - : arrA[i] == arrB[i] - Params: - A (address[]) - The first array. - B (address[]) - The second array. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function equal(address[] arrA, address[] arrB, string message) public returns (bool result) { - result = arrA.length == arrB.length; - if (result) { - for (uint i = 0; i < arrA.length; i++) { - if (arrA[i] != arrB[i]) { - result = false; - break; - } - } - } - _report(result, message); - } - - /* - Function: notEqual(address[]) - Assert that two 'address[]' are not equal. - : arrA.length != arrB.length - or, for some valid index 'i' - : arrA[i] != arrB[i] - Params: - A (address[]) - The first string. - B (address[]) - The second string. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function notEqual(address[] arrA, address[] arrB, string message) public returns (bool result) { - result = arrA.length == arrB.length; - if (result) { - for (uint i = 0; i < arrA.length; i++) { - if (arrA[i] != arrB[i]) { - result = false; - break; - } - } - } - result = !result; - _report(result, message); - } - - /* - Function: lengthEqual(address[]) - Assert that the length of an 'address[]' is equal to a given value. - : arr.length == length - Params: - arr (address[]) - The array. - length (uint) - The length. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function lengthEqual(address[] arr, uint length, string message) public returns (bool result) { - uint arrLength = arr.length; - if (arrLength == length) - _report(result, ""); - else - _report(result, _appendTagged(_tag(arrLength, "Tested"), _tag(length, "Against"), message)); - } - - /* - Function: lengthNotEqual(address[]) - Assert that the length of an 'address[]' is not equal to a given value. - : arr.length != length - Params: - arr (address[]) - The array. - length (uint) - The length. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function lengthNotEqual(address[] arr, uint length, string message) public returns (bool result) { - uint arrLength = arr.length; - if (arrLength != arr.length) - _report(result, ""); - else - _report(result, _appendTagged(_tag(arrLength, "Tested"), _tag(length, "Against"), message)); - } - - // ************************************** bytes32[] ************************************** - - /* - Function: equal(bytes32[]) - Assert that two 'bytes32[]' are equal. - : arrA.length == arrB.length - and, for all valid indices 'i' - : arrA[i] == arrB[i] - Params: - A (bytes32[]) - The first array. - B (bytes32[]) - The second array. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function equal(bytes32[] arrA, bytes32[] arrB, string message) public returns (bool result) { - result = arrA.length == arrB.length; - if (result) { - for (uint i = 0; i < arrA.length; i++) { - if (arrA[i] != arrB[i]) { - result = false; - break; - } - } - } - _report(result, message); - } - - /* - Function: notEqual(bytes32[]) - Assert that two 'bytes32[]' are not equal. - : arrA.length != arrB.length - or, for some valid index 'i' - : arrA[i] != arrB[i] - Params: - A (bytes32[]) - The first string. - B (bytes32[]) - The second string. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function notEqual(bytes32[] arrA, bytes32[] arrB, string message) public returns (bool result) { - result = arrA.length == arrB.length; - if (result) { - for (uint i = 0; i < arrA.length; i++) { - if (arrA[i] != arrB[i]) { - result = false; - break; - } - } - } - result = !result; - _report(result, message); - } - - /* - Function: lengthEqual(bytes32[]) - Assert that the length of an 'bytes32[]' is equal to a given value. - : arr.length == length - Params: - arr (bytes32[]) - The array. - length (uint) - The length. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function lengthEqual(bytes32[] arr, uint length, string message) public returns (bool result) { - uint arrLength = arr.length; - if (arrLength == length) - _report(result, ""); - else - _report(result, _appendTagged(_tag(arrLength, "Tested"), _tag(length, "Against"), message)); - } - - /* - Function: lengthNotEqual(bytes32[]) - Assert that the length of an 'bytes32[]' is not equal to a given value. - : arr.length != length - Params: - arr (bytes32[]) - The array. - length (uint) - The length. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function lengthNotEqual(bytes32[] arr, uint length, string message) public returns (bool result) { - uint arrLength = arr.length; - if (arrLength != arr.length) - _report(result, ""); - else - _report(result, _appendTagged(_tag(arrLength, "Tested"), _tag(length, "Against"), message)); - } - - // ************************************** balances ************************************** - - /* - Function: balanceEqual - Assert that the balance of an account 'A' is equal to a given number 'b'. - : A.balance = b - Params: - A (address) - The first address. - b (uint) - The balance. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function balanceEqual(address a, uint b, string message) public returns (bool result) { - result = (a.balance == b); - _report(result, message); - } - - /* - Function: balanceNotEqual - Assert that the balance of an account 'A' is not equal to a given number 'b'. - : A.balance != b - Params: - A (address) - The first address. - b (uint) - The balance. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function balanceNotEqual(address a, uint b, string message) public returns (bool result) { - result = (a.balance != b); - _report(result, message); - } - - /* - Function: balanceIsZero - Assert that the balance of an account 'A' is zero. - : A.balance == 0 - Params: - A (address) - The first address. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function balanceIsZero(address a, string message) public returns (bool result) { - result = (a.balance == 0); - _report(result, message); - } - - /* - Function: balanceIsNotZero - Assert that the balance of an account 'A' is not zero. - : A.balance != 0 - Params: - A (address) - The first address. - message (string) - A message that is sent if the assertion fails. - Returns: - result (bool) - The result. - */ - function balanceIsNotZero(address a, string message) public returns (bool result) { - result = (a.balance != 0); - _report(result, message); - } - - /******************************** internal ********************************/ - - /* - Function: _report - Internal function for triggering . - Params: - result (bool) - The test result (true or false). - message (string) - The message that is sent if the assertion fails. - */ - function _report(bool result, string message) internal { - if(result) - emit TestEvent(true, ""); - else - emit TestEvent(false, message); - } - - /* - Function: _stringsEqual - Compares two strings. Taken from the StringUtils contract in the Ethereum Dapp-bin - (https://github.com/ethereum/dapp-bin/blob/master/library/stringUtils.sol). - Params: - a (string) - The first string. - b (string) - The second string. - Returns: - result (bool) - 'true' if the strings are equal, otherwise 'false'. - */ - function _stringsEqual(string a, string b) internal pure returns (bool result) { - bytes memory ba = bytes(a); - bytes memory bb = bytes(b); - - if (ba.length != bb.length) - return false; - for (uint i = 0; i < ba.length; i ++) { - if (ba[i] != bb[i]) - return false; - } - return true; - } - - /* - Function: _itoa - Convert a signed integer to a string. Negative numbers gets a '-' in front, e.g. "-54". - Params: - n (int) - The integer. - radix (uint8) - A number between 2 and 16 (inclusive). Characters used are 0-9,a-f - Returns: - result (string) - The resulting string. - */ - function _itoa(int n, uint8 radix) internal pure returns (string) { - if (n == 0 || radix < 2 || radix > 16) - return '0'; - bytes memory bts = new bytes(256); - uint i; - bool neg = false; - if (n < 0) { - n = -n; - neg = true; - } - while (n > 0) { - bts[i++] = _utoa(uint8(n % radix)); // Turn it to ascii. - n /= radix; - } - // Reverse - uint size = i; - uint j = 0; - bytes memory rev; - if (neg) { - size++; - j = 1; - rev = new bytes(size); - rev[0] = MINUS; - } - else - rev = new bytes(size); - - for (; j < size; j++) { - rev[j] = bts[size - j - 1]; - } - return string(rev); - } - - /* - Function: _utoa(uint) - Convert an unsigned integer to a string. - Params: - n (uint) - The unsigned integer. - radix (uint8) - A number between 2 and 16 (inclusive). Characters used are 0-9,a-f - Returns: - result (string) - The resulting string. - */ - function _utoa(uint n, uint8 radix) internal pure returns (string) { - if (n == 0 || radix < 2 || radix > 16) - return '0'; - bytes memory bts = new bytes(256); - uint i; - while (n > 0) { - bts[i++] = _utoa(uint8(n % radix)); // Turn it to ascii. - n /= radix; - } - // Reverse - bytes memory rev = new bytes(i); - for (uint j = 0; j < i; j++) - rev[j] = bts[i - j - 1]; - return string(rev); - } - - /* - Function: _utoa(uint8) - Convert an unsigned 8-bit integer to its ASCII byte representation. Numbers 0-9 are converted to '0'-'9', - numbers 10-16 to 'a'-'f'. Numbers larger then 16 return the null byte. - Params: - u (uint8) - The unsigned 8-bit integer. - Returns: - result (string) - The ASCII byte. - */ - function _utoa(uint8 u) internal pure returns (byte) { - if (u < 10) - return byte(u + ZERO); - else if (u < 16) - return byte(u - 10 + A); - else - return 0; - } - - /* - Function: _ltoa - Convert an boolean to a string. - Params: - val (bool) - The boolean. - Returns: - result (string) - "true" if true, "false" if false. - */ - function _ltoa(bool val) internal pure returns (string) { - bytes memory b; - if (val) { - b = new bytes(4); - b[0] = 't'; - b[1] = 'r'; - b[2] = 'u'; - b[3] = 'e'; - return string(b); - } - else { - b = new bytes(5); - b[0] = 'f'; - b[1] = 'a'; - b[2] = 'l'; - b[3] = 's'; - b[4] = 'e'; - return string(b); - } - } - - /* - function htoa(address addr) constant returns (string) { - bytes memory bts = new bytes(40); - bytes20 addrBts = bytes20(addr); - for (uint i = 0; i < 20; i++) { - bts[2*i] = addrBts[i] % 16; - bts[2*i + 1] = (addrBts[i] / 16) % 16; - } - return string(bts); - } - */ - - /* - Function: _tag(string) - Add a tag to a string. The 'value' and 'tag' strings are returned on the form "tag: value". - Params: - value (string) - The value. - tag (string) - The tag. - Returns: - result (string) - "tag: value" - */ - function _tag(string value, string tag) internal pure returns (string) { - - bytes memory valueB = bytes(value); - bytes memory tagB = bytes(tag); - - uint vl = valueB.length; - uint tl = tagB.length; - - bytes memory newB = new bytes(vl + tl + 2); - - uint i; - uint j; - - for (i = 0; i < tl; i++) - newB[j++] = tagB[i]; - newB[j++] = ':'; - newB[j++] = ' '; - for (i = 0; i < vl; i++) - newB[j++] = valueB[i]; - - return string(newB); - } - - /* - Function: _tag(int) - Add a tag to an int. - Params: - value (int) - The value. - tag (string) - The tag. - Returns: - result (string) - "tag: _itoa(value)" - */ - function _tag(int value, string tag) internal pure returns (string) { - string memory nstr = _itoa(value, 10); - return _tag(nstr, tag); - } - - /* - Function: _tag(uint) - Add a tag to an uint. - Params: - value (uint) - The value. - tag (string) - The tag. - Returns: - result (string) - "tag: _utoa(value)" - */ - function _tag(uint value, string tag) internal pure returns (string) { - string memory nstr = _utoa(value, 10); - return _tag(nstr, tag); - } - - /* - Function: _tag(bool) - Add a tag to a boolean. - Params: - value (bool) - The value. - tag (string) - The tag. - Returns: - result (string) - "tag: _ltoa(value)" - */ - function _tag(bool value, string tag) internal pure returns (string) { - string memory nstr = _ltoa(value); - return _tag(nstr, tag); - } - - /* - Function: _appendTagged(string) - Append a tagged value to a string. - Params: - tagged (string) - The tagged value. - str (string) - The string. - Returns: - result (string) - "str (tagged)" - */ - function _appendTagged(string tagged, string str) internal pure returns (string) { - - bytes memory taggedB = bytes(tagged); - bytes memory strB = bytes(str); - - uint sl = strB.length; - uint tl = taggedB.length; - - bytes memory newB = new bytes(sl + tl + 3); - - uint i; - uint j; - - for (i = 0; i < sl; i++) - newB[j++] = strB[i]; - newB[j++] = ' '; - newB[j++] = '('; - for (i = 0; i < tl; i++) - newB[j++] = taggedB[i]; - newB[j++] = ')'; - - return string(newB); - } - - /* - Function: _appendTagged(string, string) - Append two tagged values to a string. - Params: - tagged0 (string) - The first tagged value. - tagged1 (string) - The second tagged value. - str (string) - The string. - Returns: - result (string) - "str (tagged0, tagged1)" - */ - function _appendTagged(string tagged0, string tagged1, string str) internal pure returns (string) { - - bytes memory tagged0B = bytes(tagged0); - bytes memory tagged1B = bytes(tagged1); - bytes memory strB = bytes(str); - - uint sl = strB.length; - uint t0l = tagged0B.length; - uint t1l = tagged1B.length; - - bytes memory newB = new bytes(sl + t0l + t1l + 5); - - uint i; - uint j; - - for (i = 0; i < sl; i++) - newB[j++] = strB[i]; - newB[j++] = ' '; - newB[j++] = '('; - for (i = 0; i < t0l; i++) - newB[j++] = tagged0B[i]; - newB[j++] = ','; - newB[j++] = ' '; - for (i = 0; i < t1l; i++) - newB[j++] = tagged1B[i]; - newB[j++] = ')'; - - return string(newB); - } - -} diff --git a/apps/shared/test-helpers/contracts/test/helpers/ThrowProxy.sol b/apps/shared/test-helpers/contracts/test/helpers/ThrowProxy.sol deleted file mode 100644 index f901046ba..000000000 --- a/apps/shared/test-helpers/contracts/test/helpers/ThrowProxy.sol +++ /dev/null @@ -1,33 +0,0 @@ -pragma solidity ^0.4.24; - -import "./Assert.sol"; - -// Based on Simon de la Rouviere method: http://truffleframework.com/tutorials/testing-for-throws-in-solidity-tests - - -// Proxy contract for testing throws -contract ThrowProxy { - address public target; - bytes data; - - constructor(address _target) public { - target = _target; - } - - //prime the data using the fallback function. - function() public { - data = msg.data; - } - - function assertThrows(string _msg) public { - Assert.isFalse(execute(), _msg); - } - - function assertItDoesntThrow(string _msg) public { - Assert.isTrue(execute(), _msg); - } - - function execute() public returns (bool) { - return target.call(data); - } -} diff --git a/apps/shared/test-helpers/contracts/test/mocks/APMNamehashWrapper.sol b/apps/shared/test-helpers/contracts/test/mocks/APMNamehashWrapper.sol deleted file mode 100644 index 3695dc2c7..000000000 --- a/apps/shared/test-helpers/contracts/test/mocks/APMNamehashWrapper.sol +++ /dev/null @@ -1,10 +0,0 @@ -pragma solidity 0.4.24; - -import "../../apm/APMNamehash.sol"; - - -contract APMNamehashWrapper is APMNamehash { - function getAPMNamehash(string name) external pure returns (bytes32) { - return apmNamehash(name); - } -} diff --git a/apps/shared/test-helpers/contracts/test/mocks/APMRegistryFactoryMock.sol b/apps/shared/test-helpers/contracts/test/mocks/APMRegistryFactoryMock.sol deleted file mode 100644 index cadd24c0a..000000000 --- a/apps/shared/test-helpers/contracts/test/mocks/APMRegistryFactoryMock.sol +++ /dev/null @@ -1,90 +0,0 @@ -pragma solidity 0.4.24; - -// Mock that doesn't grant enough permissions -// external ENS - -import "../../factory/APMRegistryFactory.sol"; - -contract APMRegistryFactoryMock is APMRegistryFactory { - constructor( - DAOFactory _daoFactory, - APMRegistry _registryBase, - Repo _repoBase, - ENSSubdomainRegistrar _ensSubBase, - ENS _ens, - ENSFactory _ensFactory - ) - APMRegistryFactory(_daoFactory, _registryBase, _repoBase, _ensSubBase, _ens, _ensFactory) public {} - - function newAPM(bytes32, bytes32, address) public returns (APMRegistry) {} - - function newBadAPM(bytes32 tld, bytes32 label, address _root, bool withoutACL) public returns (APMRegistry) { - bytes32 node = keccak256(abi.encodePacked(tld, label)); - - // Assume it is the test ENS - if (ens.owner(node) != address(this)) { - // If we weren't in test ens and factory doesn't have ownership, will fail - ens.setSubnodeOwner(tld, label, this); - } - - Kernel dao = daoFactory.newDAO(this); - ACL acl = ACL(dao.acl()); - - acl.createPermission(this, dao, dao.APP_MANAGER_ROLE(), this); - - // Deploy app proxies - bytes memory noInit = new bytes(0); - ENSSubdomainRegistrar ensSub = ENSSubdomainRegistrar( - dao.newAppInstance( - keccak256(abi.encodePacked(node, keccak256(abi.encodePacked(ENS_SUB_APP_NAME)))), - ensSubdomainRegistrarBase, - noInit, - false - ) - ); - APMRegistry apm = APMRegistry( - dao.newAppInstance( - keccak256(abi.encodePacked(node, keccak256(abi.encodePacked(APM_APP_NAME)))), - registryBase, - noInit, - false - ) - ); - - // APMRegistry controls Repos - bytes32 repoAppId = keccak256(abi.encodePacked(node, keccak256(abi.encodePacked(REPO_APP_NAME)))); - dao.setApp(dao.APP_BASES_NAMESPACE(), repoAppId, repoBase); - - emit DeployAPM(node, apm); - - // Grant permissions needed for APM on ENSSubdomainRegistrar - - if (withoutACL) { - acl.createPermission(apm, ensSub, ensSub.CREATE_NAME_ROLE(), _root); - } - - acl.createPermission(apm, ensSub, ensSub.POINT_ROOTNODE_ROLE(), _root); - - configureAPMPermissions(acl, apm, _root); - - // allow apm to create permissions for Repos in Kernel - bytes32 permRole = acl.CREATE_PERMISSIONS_ROLE(); - - if (!withoutACL) { - acl.grantPermission(apm, acl, permRole); - } - - // Permission transition to _root - acl.setPermissionManager(_root, dao, dao.APP_MANAGER_ROLE()); - acl.revokePermission(this, acl, permRole); - acl.grantPermission(_root, acl, permRole); - acl.setPermissionManager(_root, acl, permRole); - - // Initialize - ens.setOwner(node, ensSub); - ensSub.initialize(ens, node); - apm.initialize(ensSub); - - return apm; - } -} diff --git a/apps/shared/test-helpers/contracts/test/mocks/AppProxyPinnedStorageMock.sol b/apps/shared/test-helpers/contracts/test/mocks/AppProxyPinnedStorageMock.sol deleted file mode 100644 index 5de96a493..000000000 --- a/apps/shared/test-helpers/contracts/test/mocks/AppProxyPinnedStorageMock.sol +++ /dev/null @@ -1,41 +0,0 @@ -pragma solidity 0.4.24; - -import "../../apps/AppProxyPinned.sol"; -import "../../kernel/IKernel.sol"; -import "../../kernel/Kernel.sol"; - - -contract FakeAppConstants { - bytes32 constant FAKE_APP_ID = keccak256('FAKE_APP_ID'); -} - -contract KernelPinnedStorageMock is Kernel, FakeAppConstants { - bytes32 constant FAKE_APP_ID = keccak256('FAKE_APP_ID'); - constructor(address _fakeApp) Kernel(false) public { - _setApp(APP_BASES_NAMESPACE, FAKE_APP_ID, _fakeApp); - } -} - - -// Testing this contract is a bit of a pain... we can't overload anything to make the contract check -// pass in the constructor, so we're forced to initialize this with a mocked Kernel that already -// sets a contract for the fake app. -contract AppProxyPinnedStorageMock is AppProxyPinned, FakeAppConstants { - constructor(KernelPinnedStorageMock _mockKernel) - AppProxyPinned(IKernel(_mockKernel), FAKE_APP_ID, new bytes(0)) - public // solium-disable-line visibility-first - { - } - - function setPinnedCodeExt(address _pinnedCode) public { - setPinnedCode(_pinnedCode); - } - - function getPinnedCodePosition() public pure returns (bytes32) { - return PINNED_CODE_POSITION; - } - - function pinnedCodeExt() public view returns (address) { - return pinnedCode(); - } -} diff --git a/apps/shared/test-helpers/contracts/test/mocks/AppStorageMock.sol b/apps/shared/test-helpers/contracts/test/mocks/AppStorageMock.sol deleted file mode 100644 index 53d977e69..000000000 --- a/apps/shared/test-helpers/contracts/test/mocks/AppStorageMock.sol +++ /dev/null @@ -1,22 +0,0 @@ -pragma solidity 0.4.24; - -import "../../apps/AppStorage.sol"; - - -contract AppStorageMock is AppStorage { - function setKernelExt(IKernel _kernel) public { - setKernel(_kernel); - } - - function setAppIdExt(bytes32 _appId) public { - setAppId(_appId); - } - - function getKernelPosition() public pure returns (bytes32) { - return KERNEL_POSITION; - } - - function getAppIdPosition() public pure returns (bytes32) { - return APP_ID_POSITION; - } -} diff --git a/apps/shared/test-helpers/contracts/test/mocks/AppStub.sol b/apps/shared/test-helpers/contracts/test/mocks/AppStub.sol deleted file mode 100644 index 3225e4518..000000000 --- a/apps/shared/test-helpers/contracts/test/mocks/AppStub.sol +++ /dev/null @@ -1,48 +0,0 @@ -pragma solidity 0.4.24; - -import "../../apps/AragonApp.sol"; -import "../../apps/UnsafeAragonApp.sol"; -import "../../kernel/IKernel.sol"; - - -contract AppStubStorage { - uint a; - string public stringTest; -} - -contract AppStub is AragonApp, AppStubStorage { - bytes32 constant public ROLE = keccak256("ROLE"); - - function initialize() onlyInit public { - initialized(); - stringTest = "hola"; - } - - function requiresInitialization() isInitialized public constant returns (bool) { - return true; - } - - function setValue(uint i) auth(ROLE) public { - a = i; - } - - function setValueParam(uint i) authP(ROLE, arr(i)) public { - a = i; - } - - function getValue() public constant returns (uint) { - return a; - } -} - -contract AppStub2 is AragonApp, AppStubStorage { - function getValue() public constant returns (uint) { - return a * 2; - } -} - -contract UnsafeAppStub is AppStub, UnsafeAragonApp { - constructor(IKernel _kernel) public { - setKernel(_kernel); - } -} diff --git a/apps/shared/test-helpers/contracts/test/mocks/AppStubConditionalRecovery.sol b/apps/shared/test-helpers/contracts/test/mocks/AppStubConditionalRecovery.sol deleted file mode 100644 index 65298671d..000000000 --- a/apps/shared/test-helpers/contracts/test/mocks/AppStubConditionalRecovery.sol +++ /dev/null @@ -1,17 +0,0 @@ -pragma solidity 0.4.24; - -import "../../apps/AragonApp.sol"; -import "../../common/DepositableStorage.sol"; - - -contract AppStubConditionalRecovery is AragonApp, DepositableStorage { - function initialize() onlyInit public { - initialized(); - setDepositable(true); - } - - function allowRecoverability(address token) public view returns (bool) { - // Doesn't allow to recover ether - return token != address(0); - } -} diff --git a/apps/shared/test-helpers/contracts/test/mocks/AppStubDepositable.sol b/apps/shared/test-helpers/contracts/test/mocks/AppStubDepositable.sol deleted file mode 100644 index 095b89ee5..000000000 --- a/apps/shared/test-helpers/contracts/test/mocks/AppStubDepositable.sol +++ /dev/null @@ -1,26 +0,0 @@ -pragma solidity 0.4.24; - -import "../../apps/AragonApp.sol"; -import "../../apps/UnsafeAragonApp.sol"; -import "../../common/DepositableStorage.sol"; - - -contract AppStubDepositable is AragonApp, DepositableStorage { - function () external payable { - require(isDepositable()); - } - - function initialize() onlyInit public { - initialized(); - } - - function enableDeposits() external { - setDepositable(true); - } -} - -contract UnsafeAppStubDepositable is AppStubDepositable, UnsafeAragonApp { - constructor(IKernel _kernel) public { - setKernel(_kernel); - } -} diff --git a/apps/shared/test-helpers/contracts/test/mocks/DepositableStorageMock.sol b/apps/shared/test-helpers/contracts/test/mocks/DepositableStorageMock.sol deleted file mode 100644 index ede41cde5..000000000 --- a/apps/shared/test-helpers/contracts/test/mocks/DepositableStorageMock.sol +++ /dev/null @@ -1,14 +0,0 @@ -pragma solidity 0.4.24; - -import "../../common/DepositableStorage.sol"; - - -contract DepositableStorageMock is DepositableStorage { - function setDepositableExt(bool _depositable) public { - setDepositable(_depositable); - } - - function getDepositablePosition() public pure returns (bytes32) { - return DEPOSITABLE_POSITION; - } -} diff --git a/apps/shared/test-helpers/contracts/test/mocks/ERCProxyMock.sol b/apps/shared/test-helpers/contracts/test/mocks/ERCProxyMock.sol deleted file mode 100644 index ecce348ec..000000000 --- a/apps/shared/test-helpers/contracts/test/mocks/ERCProxyMock.sol +++ /dev/null @@ -1,17 +0,0 @@ -pragma solidity 0.4.24; - -import "../../lib/misc/ERCProxy.sol"; - - -contract ERCProxyMock is ERCProxy { - uint256 constant public FORWARDING = 1; - uint256 constant public UPGRADEABLE = 2; - - function proxyType() public pure returns (uint256 proxyTypeId) { - return 0; - } - - function implementation() public view returns (address codeAddr) { - return address(0); - } -} diff --git a/apps/shared/test-helpers/contracts/test/mocks/EVMScriptExecutorMock.sol b/apps/shared/test-helpers/contracts/test/mocks/EVMScriptExecutorMock.sol deleted file mode 100644 index fde68481d..000000000 --- a/apps/shared/test-helpers/contracts/test/mocks/EVMScriptExecutorMock.sol +++ /dev/null @@ -1,15 +0,0 @@ -pragma solidity 0.4.24; - - -import "../../evmscript/executors/BaseEVMScriptExecutor.sol"; - -contract EVMScriptExecutorMock is BaseEVMScriptExecutor { - bytes32 constant internal EXECUTOR_TYPE = keccak256("MOCK_SCRIPT"); - - function execScript(bytes, bytes, address[]) external isInitialized returns (bytes) { - } - - function executorType() external pure returns (bytes32) { - return EXECUTOR_TYPE; - } -} diff --git a/apps/shared/test-helpers/contracts/test/mocks/ExecutionTarget.sol b/apps/shared/test-helpers/contracts/test/mocks/ExecutionTarget.sol deleted file mode 100644 index c37930c17..000000000 --- a/apps/shared/test-helpers/contracts/test/mocks/ExecutionTarget.sol +++ /dev/null @@ -1,21 +0,0 @@ -pragma solidity 0.4.24; - - -contract ExecutionTarget { - uint public counter; - - function execute() public { - counter += 1; - emit Executed(counter); - } - - function failExecute() public pure { - revert(); - } - - function setCounter(uint x) public { - counter = x; - } - - event Executed(uint x); -} diff --git a/apps/shared/test-helpers/contracts/test/mocks/InitializableStorageMock.sol b/apps/shared/test-helpers/contracts/test/mocks/InitializableStorageMock.sol deleted file mode 100644 index 7dd93f1a2..000000000 --- a/apps/shared/test-helpers/contracts/test/mocks/InitializableStorageMock.sol +++ /dev/null @@ -1,14 +0,0 @@ -pragma solidity 0.4.24; - -import "../../common/Initializable.sol"; - - -contract InitializableStorageMock is Initializable { - function initialize() onlyInit public { - initialized(); - } - - function getInitializationBlockPosition() public pure returns (bytes32) { - return INITIALIZATION_BLOCK_POSITION; - } -} diff --git a/apps/shared/test-helpers/contracts/test/mocks/KeccakConstants.sol b/apps/shared/test-helpers/contracts/test/mocks/KeccakConstants.sol deleted file mode 100644 index 45e8103fc..000000000 --- a/apps/shared/test-helpers/contracts/test/mocks/KeccakConstants.sol +++ /dev/null @@ -1,57 +0,0 @@ -pragma solidity 0.4.24; - -import "../../apm/APMNamehash.sol"; - - -contract KeccakConstants is APMNamehash { - // Note: we can't use APMNamehash.apmNamehash() for constants, starting from pragma 0.5 :( - - // Kernel - bytes32 constant public CORE_NAMESPACE = keccak256(abi.encodePacked("core")); - bytes32 constant public APP_BASES_NAMESPACE = keccak256(abi.encodePacked("base")); - bytes32 constant public APP_ADDR_NAMESPACE = keccak256(abi.encodePacked("app")); - - bytes32 constant public KERNEL_APP_ID = keccak256(abi.encodePacked(APM_NODE, keccak256("kernel"))); - bytes32 constant public ACL_APP_ID = keccak256(abi.encodePacked(APM_NODE, keccak256("acl"))); - - bytes32 constant public APP_MANAGER_ROLE = keccak256(abi.encodePacked("APP_MANAGER_ROLE")); - - bytes32 constant public DEFAULT_VAULT_APP_ID = keccak256(abi.encodePacked(APM_NODE, keccak256("vault"))); - - // ENS - bytes32 constant public ENS_ROOT = bytes32(0); - bytes32 constant public ETH_TLD_LABEL = keccak256(abi.encodePacked("eth")); - bytes32 constant public ETH_TLD_NODE = keccak256(abi.encodePacked(ENS_ROOT, ETH_TLD_LABEL)); - bytes32 constant public PUBLIC_RESOLVER_LABEL = keccak256(abi.encodePacked("resolver")); - bytes32 constant public PUBLIC_RESOLVER_NODE = keccak256(abi.encodePacked(ETH_TLD_NODE, PUBLIC_RESOLVER_LABEL)); - - // ACL - bytes32 constant public CREATE_PERMISSIONS_ROLE = keccak256(abi.encodePacked("CREATE_PERMISSIONS_ROLE")); - bytes32 constant public EMPTY_PARAM_HASH = keccak256(abi.encodePacked(uint256(0))); - - // APMRegistry - bytes32 constant public CREATE_REPO_ROLE = keccak256(abi.encodePacked("CREATE_REPO_ROLE")); - - // ENSSubdomainRegistrar - bytes32 constant public CREATE_NAME_ROLE = keccak256(abi.encodePacked("CREATE_NAME_ROLE")); - bytes32 constant public DELETE_NAME_ROLE = keccak256(abi.encodePacked("DELETE_NAME_ROLE")); - bytes32 constant public POINT_ROOTNODE_ROLE = keccak256(abi.encodePacked("POINT_ROOTNODE_ROLE")); - - // EVMScriptRegistry - bytes32 constant public EVMSCRIPT_REGISTRY_APP_ID = keccak256(abi.encodePacked(APM_NODE, keccak256("evmreg"))); - bytes32 constant public REGISTRY_ADD_EXECUTOR_ROLE = keccak256("REGISTRY_ADD_EXECUTOR_ROLE"); - bytes32 constant public REGISTRY_MANAGER_ROLE = keccak256(abi.encodePacked("REGISTRY_MANAGER_ROLE")); - - // EVMScriptExecutor types - bytes32 constant public EVMSCRIPT_EXECUTOR_CALLS_SCRIPT = keccak256(abi.encodePacked("CALLS_SCRIPT")); - - // Repo - bytes32 constant public CREATE_VERSION_ROLE = keccak256(abi.encodePacked("CREATE_VERSION_ROLE")); - - // Unstructured storage - bytes32 public constant initializationBlockPosition = keccak256(abi.encodePacked("aragonOS.initializable.initializationBlock")); - bytes32 public constant depositablePosition = keccak256(abi.encodePacked("aragonOS.depositableStorage.depositable")); - bytes32 public constant kernelPosition = keccak256(abi.encodePacked("aragonOS.appStorage.kernel")); - bytes32 public constant appIdPosition = keccak256(abi.encodePacked("aragonOS.appStorage.appId")); - bytes32 public constant pinnedCodePosition = keccak256(abi.encodePacked("aragonOS.appStorage.pinnedCode")); -} diff --git a/apps/shared/test-helpers/contracts/test/mocks/KernelDepositableMock.sol b/apps/shared/test-helpers/contracts/test/mocks/KernelDepositableMock.sol deleted file mode 100644 index cf0e16f11..000000000 --- a/apps/shared/test-helpers/contracts/test/mocks/KernelDepositableMock.sol +++ /dev/null @@ -1,17 +0,0 @@ -pragma solidity 0.4.24; - -import "../../common/DepositableStorage.sol"; -import "../../kernel/Kernel.sol"; - -contract KernelDepositableMock is Kernel, DepositableStorage { - constructor(bool _shouldPetrify) Kernel(_shouldPetrify) public { - } - - function () external payable { - require(isDepositable()); - } - - function enableDeposits() external isInitialized { - setDepositable(true); - } -} diff --git a/apps/shared/test-helpers/contracts/test/mocks/KernelOverloadMock.sol b/apps/shared/test-helpers/contracts/test/mocks/KernelOverloadMock.sol deleted file mode 100644 index 6a9d36c39..000000000 --- a/apps/shared/test-helpers/contracts/test/mocks/KernelOverloadMock.sol +++ /dev/null @@ -1,31 +0,0 @@ -pragma solidity 0.4.24; - -import "../../kernel/Kernel.sol"; -import "../../lib/misc/ERCProxy.sol"; - - -/** Ugly hack to work around this issue: - * https://github.com/trufflesuite/truffle/issues/569 - * https://github.com/trufflesuite/truffle/issues/737 - */ -contract KernelOverloadMock { - Kernel kernel; - - event NewAppProxy(address proxy); - - constructor(address _kernel) public { - kernel = Kernel(_kernel); - } - - //function newAppInstance(bytes32 _name, address _appBase, bytes _initializePayload, bool _setDefault) auth(APP_MANAGER_ROLE, arr(APP_BASES_NAMESPACE, _name)) public returns (ERCProxy appProxy) { - function newAppInstance(bytes32 _name, address _appBase, bytes _initializePayload, bool _setDefault) public returns (ERCProxy appProxy) { - appProxy = kernel.newAppInstance(_name, _appBase, _initializePayload, _setDefault); - emit NewAppProxy(appProxy); - } - - // function newPinnedAppInstance(bytes32 _name, address _appBase, bytes _initializePayload, bool _setDefault) auth(APP_MANAGER_ROLE, arr(APP_BASES_NAMESPACE, _name)) public returns (ERCProxy appProxy) { - function newPinnedAppInstance(bytes32 _name, address _appBase, bytes _initializePayload, bool _setDefault) public returns (ERCProxy appProxy) { - appProxy = kernel.newPinnedAppInstance(_name, _appBase, _initializePayload, _setDefault); - emit NewAppProxy(appProxy); - } -} diff --git a/apps/shared/test-helpers/contracts/test/mocks/KernelSetAppMock.sol b/apps/shared/test-helpers/contracts/test/mocks/KernelSetAppMock.sol deleted file mode 100644 index df713cee4..000000000 --- a/apps/shared/test-helpers/contracts/test/mocks/KernelSetAppMock.sol +++ /dev/null @@ -1,13 +0,0 @@ -pragma solidity 0.4.24; - -import "../../kernel/Kernel.sol"; - -contract KernelSetAppMock is Kernel { - constructor() Kernel(false) public { - } - - // Overloaded mock to bypass the auth and isContract checks - function setApp(bytes32 _namespace, bytes32 _appId, address _app) public { - apps[_namespace][_appId] = _app; - } -} diff --git a/apps/shared/test-helpers/contracts/test/mocks/LifecycleMock.sol b/apps/shared/test-helpers/contracts/test/mocks/LifecycleMock.sol deleted file mode 100644 index bb52fcb85..000000000 --- a/apps/shared/test-helpers/contracts/test/mocks/LifecycleMock.sol +++ /dev/null @@ -1,15 +0,0 @@ -pragma solidity 0.4.24; - -import "../../common/Initializable.sol"; -import "../../common/Petrifiable.sol"; - - -contract LifecycleMock is Initializable, Petrifiable { - function initializeMock() public { - initialized(); - } - - function petrifyMock() public { - petrify(); - } -} diff --git a/apps/shared/test-helpers/contracts/test/mocks/MockScriptExecutorApp.sol b/apps/shared/test-helpers/contracts/test/mocks/MockScriptExecutorApp.sol deleted file mode 100644 index 291272390..000000000 --- a/apps/shared/test-helpers/contracts/test/mocks/MockScriptExecutorApp.sol +++ /dev/null @@ -1,33 +0,0 @@ -pragma solidity 0.4.24; - -import "../../apps/AragonApp.sol"; - - -contract MockScriptExecutorApp is AragonApp { - // Initialization is required to access any of the real executors - function initialize() public { - initialized(); - } - - function execute(bytes script) public { - runScript(script, new bytes(0), new address[](0)); - } - - function executeWithBan(bytes script, address[] memory blacklist) public { - runScript(script, new bytes(0), blacklist); - } - - function executeWithIO(bytes script, bytes input, address[] memory blacklist) public returns (bytes) { - return runScript(script, input, blacklist); - } - - /* - function getActionsCount(bytes script) public constant returns (uint256) { - return getScriptActionsCount(script); - } - - function getAction(bytes script, uint256 i) public constant returns (address, bytes) { - return getScriptAction(script, i); - } - */ -} diff --git a/apps/shared/test-helpers/contracts/test/mocks/SafeMath64Mock.sol b/apps/shared/test-helpers/contracts/test/mocks/SafeMath64Mock.sol deleted file mode 100644 index bd1fec780..000000000 --- a/apps/shared/test-helpers/contracts/test/mocks/SafeMath64Mock.sol +++ /dev/null @@ -1,28 +0,0 @@ -pragma solidity 0.4.24; - -import "../../lib/math/SafeMath64.sol"; - - -contract SafeMath64Mock { - using SafeMath64 for uint64; - - function mulExt(uint64 _a, uint64 _b) public pure returns (uint64) { - return _a.mul(_b); - } - - function divExt(uint64 _a, uint64 _b) public pure returns (uint64) { - return _a.div(_b); - } - - function subExt(uint64 _a, uint64 _b) public pure returns (uint64) { - return _a.sub(_b); - } - - function addExt(uint64 _a, uint64 _b) public pure returns (uint64) { - return _a.add(_b); - } - - function modExt(uint64 _a, uint64 _b) public pure returns (uint64) { - return _a.mod(_b); - } -} diff --git a/apps/shared/test-helpers/contracts/test/mocks/SafeMath8Mock.sol b/apps/shared/test-helpers/contracts/test/mocks/SafeMath8Mock.sol deleted file mode 100644 index 7105f0ee9..000000000 --- a/apps/shared/test-helpers/contracts/test/mocks/SafeMath8Mock.sol +++ /dev/null @@ -1,28 +0,0 @@ -pragma solidity 0.4.24; - -import "../../lib/math/SafeMath8.sol"; - - -contract SafeMath8Mock { - using SafeMath8 for uint8; - - function mulExt(uint8 _a, uint8 _b) public pure returns (uint8) { - return _a.mul(_b); - } - - function divExt(uint8 _a, uint8 _b) public pure returns (uint8) { - return _a.div(_b); - } - - function subExt(uint8 _a, uint8 _b) public pure returns (uint8) { - return _a.sub(_b); - } - - function addExt(uint8 _a, uint8 _b) public pure returns (uint8) { - return _a.add(_b); - } - - function modExt(uint8 _a, uint8 _b) public pure returns (uint8) { - return _a.mod(_b); - } -} diff --git a/apps/shared/test-helpers/contracts/test/mocks/TimeHelpersMock.sol b/apps/shared/test-helpers/contracts/test/mocks/TimeHelpersMock.sol deleted file mode 100644 index d8bf3234b..000000000 --- a/apps/shared/test-helpers/contracts/test/mocks/TimeHelpersMock.sol +++ /dev/null @@ -1,30 +0,0 @@ -pragma solidity 0.4.24; - -import "../../common/TimeHelpers.sol"; - - -contract TimeHelpersMock is TimeHelpers { - function getBlockNumberDirect() public view returns (uint256) { - return block.number; - } - - function getBlockNumberExt() public view returns (uint256) { - return getBlockNumber(); - } - - function getBlockNumber64Ext() public view returns (uint64) { - return getBlockNumber64(); - } - - function getTimestampDirect() public view returns (uint256) { - return now; - } - - function getTimestampExt() public view returns (uint256) { - return getTimestamp(); - } - - function getTimestamp64Ext() public view returns (uint64) { - return getTimestamp64(); - } -} diff --git a/apps/shared/test-helpers/contracts/test/mocks/TokenMock.sol b/apps/shared/test-helpers/contracts/test/mocks/TokenMock.sol deleted file mode 100644 index 7442d80be..000000000 --- a/apps/shared/test-helpers/contracts/test/mocks/TokenMock.sol +++ /dev/null @@ -1,46 +0,0 @@ -// Stripped from https://github.com/OpenZeppelin/openzeppelin-solidity/blob/a9f910d34f0ab33a1ae5e714f69f9596a02b4d91/contracts/token/ERC20/StandardToken.sol - -pragma solidity 0.4.24; - -import "../../lib/math/SafeMath.sol"; - - -contract TokenMock { - using SafeMath for uint256; - mapping (address => uint256) private balances; - uint256 private totalSupply_; - - event Transfer(address indexed from, address indexed to, uint256 value); - - // Allow us to set the inital balance for an account on construction - constructor(address initialAccount, uint256 initialBalance) public { - balances[initialAccount] = initialBalance; - totalSupply_ = initialBalance; - } - - function totalSupply() public view returns (uint256) { return totalSupply_; } - - /** - * @dev Gets the balance of the specified address. - * @param _owner The address to query the the balance of. - * @return An uint256 representing the amount owned by the passed address. - */ - function balanceOf(address _owner) public view returns (uint256) { - return balances[_owner]; - } - - /** - * @dev Transfer token for a specified address - * @param _to The address to transfer to. - * @param _value The amount to be transferred. - */ - function transfer(address _to, uint256 _value) public returns (bool) { - require(_value <= balances[msg.sender]); - require(_to != address(0)); - - balances[msg.sender] = balances[msg.sender].sub(_value); - balances[_to] = balances[_to].add(_value); - emit Transfer(msg.sender, _to, _value); - return true; - } -} diff --git a/apps/shared/test-helpers/contracts/test/mocks/Uint256Mock.sol b/apps/shared/test-helpers/contracts/test/mocks/Uint256Mock.sol deleted file mode 100644 index 9616376d7..000000000 --- a/apps/shared/test-helpers/contracts/test/mocks/Uint256Mock.sol +++ /dev/null @@ -1,12 +0,0 @@ -pragma solidity 0.4.24; - -import "../../common/Uint256Helpers.sol"; - - -contract Uint256Mock { - using Uint256Helpers for uint256; - - function convert(uint256 a) public pure returns (uint64) { - return a.toUint64(); - } -} diff --git a/apps/shared/test-helpers/contracts/test/mocks/UnsafeAragonAppMock.sol b/apps/shared/test-helpers/contracts/test/mocks/UnsafeAragonAppMock.sol deleted file mode 100644 index 61551949c..000000000 --- a/apps/shared/test-helpers/contracts/test/mocks/UnsafeAragonAppMock.sol +++ /dev/null @@ -1,19 +0,0 @@ -pragma solidity 0.4.24; - -import "../../apps/UnsafeAragonApp.sol"; -import "../../kernel/IKernel.sol"; - - -contract UnsafeAragonAppMock is UnsafeAragonApp { - function initialize() public { - initialized(); - } - - function getKernel() public view returns (IKernel) { - return kernel(); - } - - function setKernelOnMock(IKernel _kernel) public { - setKernel(_kernel); - } -} diff --git a/apps/shared/test-helpers/contracts/test/mocks/UnsafeRepo.sol b/apps/shared/test-helpers/contracts/test/mocks/UnsafeRepo.sol deleted file mode 100644 index ce121b9c0..000000000 --- a/apps/shared/test-helpers/contracts/test/mocks/UnsafeRepo.sol +++ /dev/null @@ -1,13 +0,0 @@ -pragma solidity 0.4.24; - -import "../../apm/Repo.sol"; -import "../../apps/UnsafeAragonApp.sol"; - - -// Allows Repo to be used without a proxy or access controls -contract UnsafeRepo is Repo, UnsafeAragonApp { - // Protected actions are always performable - function canPerform(address, bytes32, uint256[]) public view returns (bool) { - return true; - } -} diff --git a/apps/shared/test-helpers/contracts/test/mocks/UpgradedKernel.sol b/apps/shared/test-helpers/contracts/test/mocks/UpgradedKernel.sol deleted file mode 100644 index 5a00fd2a5..000000000 --- a/apps/shared/test-helpers/contracts/test/mocks/UpgradedKernel.sol +++ /dev/null @@ -1,14 +0,0 @@ -pragma solidity 0.4.24; - -import "../../kernel/Kernel.sol"; - - -contract UpgradedKernel is Kernel { - constructor(bool _shouldPetrify) Kernel(_shouldPetrify) public {} - - // just adds one more function to the kernel implementation. - // calling this function on the previous instance will fail - function isUpgraded() public pure returns (bool) { - return true; - } -} diff --git a/apps/shared/test-helpers/contracts/test/mocks/VaultMock.sol b/apps/shared/test-helpers/contracts/test/mocks/VaultMock.sol deleted file mode 100644 index 452f8ea25..000000000 --- a/apps/shared/test-helpers/contracts/test/mocks/VaultMock.sol +++ /dev/null @@ -1,18 +0,0 @@ -pragma solidity 0.4.24; - -import "../../apps/UnsafeAragonApp.sol"; -import "../../common/DepositableStorage.sol"; - - -contract VaultMock is UnsafeAragonApp, DepositableStorage { - event LogFund(address sender, uint256 amount); - - function initialize() external { - initialized(); - setDepositable(true); - } - - function () external payable { - emit LogFund(msg.sender, msg.value); - } -} diff --git a/kits/planning-suite/contracts/PlanningSuite.sol b/kits/planning-suite/contracts/PlanningSuite.sol index 3244349f8..32285a120 100644 --- a/kits/planning-suite/contracts/PlanningSuite.sol +++ b/kits/planning-suite/contracts/PlanningSuite.sol @@ -2,18 +2,18 @@ pragma solidity 0.4.24; import "@aragon/kits-beta-base/contracts/BetaKitBase.sol"; -import "@tps/test-helpers/contracts/lib/bounties/StandardBounties.sol"; +import "@tps/apps-projects/contracts/bounties/StandardBounties.sol"; import "@tps/apps-address-book/contracts/AddressBook.sol"; import "@tps/apps-allocations/contracts/Allocations.sol"; import "@tps/apps-projects/contracts/Projects.sol"; -import { DotVoting } from "@tps/apps-dot-voting/contracts/DotVoting.sol"; -import { Rewards as Rewards } from "@tps/apps-rewards/contracts/Rewards.sol"; +import "@tps/apps-dot-voting/contracts/DotVoting.sol"; +import "@tps/apps-rewards/contracts/Rewards.sol"; contract PlanningSuite is BetaKitBase { StandardBounties public registry; - bytes32[5] public planningAppIds; + bytes32[5] public planningAppIds; uint256 constant PCT256 = 10 ** 16; uint64 constant PCT64 = 10 ** 16; address constant ANY_ENTITY = address(-1); @@ -21,7 +21,7 @@ contract PlanningSuite is BetaKitBase { mapping (address => address) tokenCache; // ensure alphabetic order - enum PlanningApps { AddressBook, Allocations, DotVoting, Projects, Rewards } + enum PlanningApps { AddressBook, Allocations, DotVoting, Projects, Rewards } // Overload the DeployInstance event for easy grabing of all the things event DeployInstance(address dao, address indexed token, address vault, address voting); @@ -95,7 +95,7 @@ contract PlanningSuite is BetaKitBase { public returns (Kernel dao, Vault vault, Voting voting) { require(voteDuration > 0, "VOTE_DURATION_IS_ZERO"); // TODO: remove it once we add it to Voting app - MiniMeToken token = popTokenCache(msg.sender); + MiniMeToken token = popTokenCache(msg.sender); (dao, vault, voting) = createPlanningDAO( token, holders, @@ -234,8 +234,8 @@ contract PlanningSuite is BetaKitBase { initializeA1Apps( tokenManager, vault, - finance, - voting, + finance, + voting, voteParams, token ); @@ -310,7 +310,7 @@ contract PlanningSuite is BetaKitBase { uint256 candidateSupportPct, uint256 minParticipationPct, uint64 voteDuration - ) internal returns (AddressBook addressBook, DotVoting dotVoting) + ) internal returns (AddressBook addressBook, DotVoting dotVoting) { addressBook = AddressBook( dao.newAppInstance( @@ -328,7 +328,7 @@ contract PlanningSuite is BetaKitBase { addressBook.initialize(); dotVoting.initialize(addressBook, token, minParticipationPct, candidateSupportPct, voteDuration); } - + function createOtherTPSApps ( Kernel dao, Vault vault, @@ -451,7 +451,6 @@ contract PlanningSuite is BetaKitBase { ////////////////////////////////////////////////////////////// // Additional Internal Helpers ////////////////////////////////////////////////////////////// - function handleVaultPermissions( Kernel dao, Allocations allocations, @@ -463,8 +462,8 @@ contract PlanningSuite is BetaKitBase { { ACL acl = ACL(dao.acl()); bytes32 vaultTransferRole = vault.TRANSFER_ROLE(); + // Vault permissions - acl.grantPermission(projects, vault, vaultTransferRole); acl.grantPermission(allocations, vault, vaultTransferRole); acl.grantPermission(rewards, vault, vaultTransferRole); @@ -475,7 +474,6 @@ contract PlanningSuite is BetaKitBase { function handleCleanupPermissions(Kernel dao, Voting voting) internal { ACL acl = ACL(dao.acl()); - // Clean up template permissions cleanupPermission(acl, voting, dao, dao.APP_MANAGER_ROLE()); cleanupPermission(acl, voting, acl, acl.CREATE_PERMISSIONS_ROLE()); diff --git a/package.json b/package.json index 002402297..d079a2982 100644 --- a/package.json +++ b/package.json @@ -17,9 +17,9 @@ "build:script:projects": "lerna run build:script --scope=@tps/apps-projects", "build:script:rewards": "lerna run build:script --scope=@tps/apps-rewards", "clean:aragon": "rm -rf ~/.aragon && rm -rf ~/.ipfs", - "clean:build": "git clean -ffdx --exclude=node_modules/", + "clean:build": "npm run clean -- --exclude=node_modules/", "clean:commit": "rm -f package-lock.json && npm run bootstrap", - "clean": "git clean -ffdx", + "clean": "git clean -fXd", "coverage": "npx lerna run coverage --no-bail", "coveralls": "cat apps/*/coverage/lcov.info | npx coveralls", "cypress:open": "cypress open",