parent
dc3edfa527
commit
e52a3ab59f
@ -0,0 +1 @@ |
||||
module.exports = { value: true }; |
@ -0,0 +1,25 @@ |
||||
pragma solidity ^0.5.0; |
||||
|
||||
|
||||
contract Migrations { |
||||
address public owner; |
||||
|
||||
uint public last_completed_migration; |
||||
|
||||
modifier restricted() { |
||||
if (msg.sender == owner) { _; } |
||||
} |
||||
|
||||
constructor() public { |
||||
owner = msg.sender; |
||||
} |
||||
|
||||
function setCompleted(uint completed) public restricted { |
||||
last_completed_migration = completed; |
||||
} |
||||
|
||||
function upgrade(address new_address) public restricted { |
||||
Migrations upgraded = Migrations(new_address); |
||||
upgraded.setCompleted(last_completed_migration); |
||||
} |
||||
} |
@ -0,0 +1,121 @@ |
||||
|
||||
/* |
||||
Utilities for generating a mock truffle project to test plugin. |
||||
*/ |
||||
|
||||
const fs = require('fs'); |
||||
const shell = require('shelljs'); |
||||
|
||||
const configPath = './mock/.solcover.js'; |
||||
const testPath = './test/sources/js/'; |
||||
const sourcesPath = './test/sources/solidity/contracts/app/'; |
||||
const migrationPath = './mock/migrations/2_deploy.js'; |
||||
|
||||
const defaultTruffleConfig = ` |
||||
module.exports = { |
||||
networks: { |
||||
development: { |
||||
host: "localhost", |
||||
port: 8545, |
||||
network_id: "*" |
||||
} |
||||
}, |
||||
compilers: { |
||||
solc: { |
||||
version: "0.5.3", |
||||
} |
||||
} |
||||
}; |
||||
` |
||||
|
||||
/** |
||||
* Installs mock truffle project at ./mock with a single contract |
||||
* and test specified by the params. |
||||
* @param {String} contract <contractName.sol> located in /test/sources/cli/ |
||||
* @param {[type]} test <testName.js> located in /test/cli/ |
||||
*/ |
||||
function install( |
||||
contract, |
||||
test, |
||||
config, |
||||
_truffleConfig, |
||||
_trufflejsName, |
||||
noMigrations |
||||
) { |
||||
|
||||
const configjs = `module.exports = ${JSON.stringify(config)}`; |
||||
|
||||
const migration = ` |
||||
const A = artifacts.require('${contract}'); |
||||
module.exports = function(deployer) { deployer.deploy(A) }; |
||||
`;
|
||||
|
||||
// Mock truffle-config.js
|
||||
const trufflejsName = _trufflejsName || 'truffle-config.js'; |
||||
const trufflejs = _truffleConfig || defaultTruffleConfig; |
||||
|
||||
// Generate mock
|
||||
shell.mkdir('./mock'); |
||||
shell.cp('-Rf', './test/integration/truffle', './mock'); |
||||
shell.cp(`${sourcesPath}${contract}.sol`, `./mock/contracts/${contract}.sol`); |
||||
|
||||
if (!noMigrations){ |
||||
fs.writeFileSync(migrationPath, migration); |
||||
} |
||||
|
||||
fs.writeFileSync(`./mock/${trufflejsName}`, trufflejs); |
||||
fs.writeFileSync(`${configPath}`, configjs); |
||||
|
||||
shell.cp(`${testPath}${test}`, `./mock/test/${test}`); |
||||
}; |
||||
|
||||
/** |
||||
* Installs mock truffle project with two contracts (for inheritance, libraries, etc) |
||||
* @param {config} .solcover.js configuration |
||||
*/ |
||||
function installMultiple(contracts, test, config) { |
||||
const configjs = `module.exports = ${JSON.stringify(config)}`; |
||||
|
||||
const deployContracts = ` |
||||
var A = artifacts.require(`${contracts[0]}`); |
||||
var B = artifacts.require(`${contracts[1]}`); |
||||
module.exports = function(deployer) { |
||||
deployer.deploy(A); |
||||
deployer.link(A, B); |
||||
deployer.deploy(B); |
||||
}; |
||||
`;
|
||||
|
||||
shell.mkdir('./mock'); |
||||
shell.cp('-Rf', './test/integration/truffle', './mock'); |
||||
|
||||
contracts.forEach(item => { |
||||
shell.cp(`${sourcesPath}${item}.sol`, `./mock/contracts/${item}.sol`) |
||||
}); |
||||
|
||||
shell.cp(`${testPath}${test}`, `./mock/test/${test}`); |
||||
fs.writeFileSync('./mock/truffle-config.js', defaultTruffleJs); |
||||
fs.writeFileSync('./.solcover.js', configjs); |
||||
fs.writeFileSync(migrationPath, migration) |
||||
}; |
||||
|
||||
|
||||
/** |
||||
* Removes mock truffle project and coverage reports generated by exec.js |
||||
*/ |
||||
function remove() { |
||||
shell.config.silent = true; |
||||
shell.rm('./.solcover.js'); |
||||
shell.rm('-Rf', 'mock'); |
||||
shell.rm('-Rf', 'coverage'); |
||||
shell.rm('coverage.json'); |
||||
shell.config.silent = false; |
||||
}; |
||||
|
||||
|
||||
module.exports = { |
||||
install: install, |
||||
installMultiple: installMultiple, |
||||
remove: remove |
||||
} |
||||
|
@ -1,199 +0,0 @@ |
||||
|
||||
/* |
||||
This file contains utilities for generating a mock truffle project to test solcover's |
||||
run script against. |
||||
*/ |
||||
const fs = require('fs'); |
||||
const shell = require('shelljs'); |
||||
|
||||
const defaultTruffleJs = `module.exports = {
|
||||
networks: { |
||||
development: { |
||||
host: "localhost", |
||||
port: 8545, |
||||
network_id: "*" |
||||
} |
||||
}, |
||||
compilers: { |
||||
solc: { |
||||
version: "0.5.3", |
||||
} |
||||
} |
||||
};` |
||||
|
||||
/** |
||||
* Installs mock truffle project at ./mock with a single contract |
||||
* and test specified by the params. |
||||
* @param {String} contract <contractName.sol> located in /test/sources/cli/ |
||||
* @param {[type]} test <testName.js> located in /test/cli/ |
||||
*/ |
||||
module.exports.install = function install( |
||||
contract, |
||||
test, |
||||
config, |
||||
_trufflejs, |
||||
_trufflejsName, |
||||
noMigrations |
||||
) { |
||||
const configjs = `module.exports = ${JSON.stringify(config)}`; |
||||
const contractLocation = `./${contract}`; |
||||
const trufflejsName = _trufflejsName || 'truffle-config.js'; |
||||
|
||||
// Mock migrations
|
||||
const initialMigration = ` |
||||
let Migrations = artifacts.require('Migrations.sol'); |
||||
module.exports = function(deployer) { |
||||
deployer.deploy(Migrations); |
||||
};`;
|
||||
|
||||
const deployContracts = ` |
||||
var contract = artifacts.require('${contractLocation}'); |
||||
module.exports = function(deployer) { |
||||
deployer.deploy(contract); |
||||
};`;
|
||||
|
||||
// Mock external asset
|
||||
const asset = 'module.exports = { value: true };'; |
||||
|
||||
// Mock truffle-config.js
|
||||
const trufflejs = _trufflejs || defaultTruffleJs; |
||||
|
||||
// Generate mock
|
||||
shell.mkdir('./mock'); |
||||
shell.mkdir('./mock/contracts'); |
||||
shell.mkdir('./mock/migrations'); |
||||
shell.mkdir('./mock/assets'); |
||||
shell.cp('./test/sources/cli/SimpleError.sol', './mock/assets/SimpleError.sol'); |
||||
shell.mkdir('./mock/node_modules'); |
||||
shell.mkdir('./mock/test'); |
||||
|
||||
if (Array.isArray(contract)) { |
||||
contract.forEach(item => { |
||||
shell.cp(`./test/sources/cli/${item}`, `./mock/contracts/${item}`); |
||||
}); |
||||
} else { |
||||
shell.cp(`./test/sources/cli/${contract}`, `./mock/contracts/${contract}`); |
||||
} |
||||
|
||||
if (!noMigrations){ |
||||
shell.cp('./test/sources/cli/Migrations.sol', './mock/contracts/Migrations.sol'); |
||||
fs.writeFileSync('./mock/migrations/1_initial_migration.js', initialMigration); |
||||
fs.writeFileSync('./mock/migrations/2_deploy_contracts.js', deployContracts); |
||||
} |
||||
|
||||
fs.writeFileSync(`./mock/${trufflejsName}`, trufflejs); |
||||
fs.writeFileSync('./mock/assets/asset.js', asset); |
||||
fs.writeFileSync('./.solcover.js', configjs); |
||||
|
||||
shell.cp(`./test/cli/${test}`, `./mock/test/${test}`); |
||||
}; |
||||
|
||||
/** |
||||
* Installs mock truffle project at ./mock with two contracts - one inherits from the other |
||||
* and test specified by the params. |
||||
* @param {config} .solcover.js configuration |
||||
*/ |
||||
module.exports.installInheritanceTest = function installInheritanceTest(config) { |
||||
shell.mkdir('./mock'); |
||||
shell.mkdir('./mock/contracts'); |
||||
shell.mkdir('./mock/migrations'); |
||||
shell.mkdir('./mock/test'); |
||||
|
||||
// Mock contracts
|
||||
shell.cp('./test/sources/cli/Proxy.sol', './mock/contracts/Proxy.sol'); |
||||
shell.cp('./test/sources/cli/Owned.sol', './mock/contracts/Owned.sol'); |
||||
shell.cp('./test/sources/cli/Migrations.sol', './mock/contracts/Migrations.sol'); |
||||
|
||||
// Mock migrations
|
||||
const initialMigration = ` |
||||
let Migrations = artifacts.require('Migrations.sol'); |
||||
module.exports = function(deployer) { |
||||
deployer.deploy(Migrations); |
||||
};`;
|
||||
|
||||
const deployContracts = ` |
||||
var Owned = artifacts.require('./Owned.sol'); |
||||
var Proxy = artifacts.require('./Proxy.sol'); |
||||
module.exports = function(deployer) { |
||||
deployer.deploy(Owned); |
||||
deployer.link(Owned, Proxy); |
||||
deployer.deploy(Proxy); |
||||
};`;
|
||||
|
||||
fs.writeFileSync('./mock/migrations/1_initial_migration.js', initialMigration); |
||||
fs.writeFileSync('./mock/migrations/2_deploy_contracts.js', deployContracts); |
||||
|
||||
// Mock test
|
||||
shell.cp('./test/cli/inheritance.js', './mock/test/inheritance.js'); |
||||
|
||||
// Mock truffle-config.js
|
||||
const trufflejs = defaultTruffleJs; |
||||
|
||||
const configjs = `module.exports = ${JSON.stringify(config)}`; |
||||
|
||||
fs.writeFileSync('./mock/truffle-config.js', trufflejs); |
||||
fs.writeFileSync('./.solcover.js', configjs); |
||||
}; |
||||
|
||||
|
||||
/** |
||||
* Installs mock truffle project at ./mock with two contracts - one is a library the other |
||||
* uses, and test specified by the params. |
||||
* @param {config} .solcover.js configuration |
||||
*/ |
||||
module.exports.installLibraryTest = function installInheritanceTest(config) { |
||||
shell.mkdir('./mock'); |
||||
shell.mkdir('./mock/contracts'); |
||||
shell.mkdir('./mock/migrations'); |
||||
shell.mkdir('./mock/test'); |
||||
shell.mkdir('./mock/assets'); |
||||
|
||||
// Mock contracts
|
||||
shell.cp('./test/sources/cli/TotallyPure.sol', './mock/contracts/TotallyPure.sol'); |
||||
shell.cp('./test/sources/cli/Migrations.sol', './mock/contracts/Migrations.sol'); |
||||
|
||||
// Mock migrations
|
||||
const initialMigration = ` |
||||
let Migrations = artifacts.require('Migrations.sol'); |
||||
module.exports = function(deployer) { |
||||
deployer.deploy(Migrations); |
||||
};`;
|
||||
|
||||
const deployContracts = ` |
||||
var CLibrary = artifacts.require('CLibrary.sol'); |
||||
var TotallyPure = artifacts.require('./TotallyPure.sol'); |
||||
module.exports = function(deployer) { |
||||
deployer.deploy(CLibrary); |
||||
deployer.link(CLibrary, TotallyPure); |
||||
deployer.deploy(TotallyPure); |
||||
};`;
|
||||
|
||||
fs.writeFileSync('./mock/migrations/1_initial_migration.js', initialMigration); |
||||
fs.writeFileSync('./mock/migrations/2_deploy_contracts.js', deployContracts); |
||||
|
||||
// Mock test
|
||||
shell.cp('./test/cli/totallyPure.js', './mock/test/totallyPure.js'); |
||||
shell.cp('./test/sources/cli/PureView.sol', './mock/assets/PureView.sol'); |
||||
shell.cp('./test/sources/cli/CLibrary.sol', './mock/assets/CLibrary.sol'); |
||||
shell.cp('./test/sources/cli/Face.sol', './mock/assets/Face.sol'); |
||||
|
||||
// Mock truffle-config.js
|
||||
const trufflejs = defaultTruffleJs; |
||||
|
||||
const configjs = `module.exports = ${JSON.stringify(config)}`; |
||||
|
||||
fs.writeFileSync('./mock/truffle-config.js', trufflejs); |
||||
fs.writeFileSync('./.solcover.js', configjs); |
||||
}; |
||||
|
||||
/** |
||||
* Removes mock truffle project and coverage reports generated by exec.js |
||||
*/ |
||||
module.exports.remove = function remove() { |
||||
shell.config.silent = true; |
||||
shell.rm('./.solcover.js'); |
||||
shell.rm('-Rf', 'mock'); |
||||
shell.rm('-Rf', 'coverage'); |
||||
shell.rm('coverage.json'); |
||||
shell.config.silent = false; |
||||
}; |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue