Commit 2818541b authored by Chuck LeDuc Díaz's avatar Chuck LeDuc Díaz
Browse files

use truffle build and solidity-coverage

parent 028c4403
Pipeline #68769365 canceled with stage
......@@ -6,6 +6,9 @@ yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# solidity-coverage
coverage.json
# Vim
**/*.swp
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -4,10 +4,9 @@
"description": "Caelum Identity library",
"main": "index.js",
"scripts": {
"build": "node src/build",
"build": "truffle build",
"codecov": "nyc report --report=text-lcov > coverage.lcov ; codecov",
"coverage": "nyc npm test",
"coverage:report": "nyc report --reporter=html",
"coverage": "npx solidity-coverage",
"eslint": "npx eslint .",
"lint": "npm run eslint; npm run solium",
"mocha": "mocha --timeout 30000 test",
......@@ -15,7 +14,7 @@
"solium": "solium --dir contracts",
"start": "./node_modules/@caelum-tech/parity/scripts/startParity.sh",
"stop": "./node_modules/@caelum-tech/parity/scripts/stopParity.sh",
"test": "npm run start; npm run mocha; npm run stop"
"test": "npm run start; truffle test; npm run stop"
},
"repository": {
"type": "git",
......@@ -37,7 +36,7 @@
"keythereum": "^1.0.4"
},
"devDependencies": {
"@caelum-tech/parity": "^0.1.2",
"@caelum-tech/parity": "^1.1.1",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"chai-bignumber": "^3.0.0",
......@@ -49,12 +48,11 @@
"eslint-plugin-promise": "^4.1.1",
"eslint-plugin-standard": "^4.0.0",
"fs-extra": "^8.0.1",
"openzeppelin-solidity": "^2.3.0",
"mocha": "^6.1.4",
"nyc": "^14.1.1",
"path": "^0.12.7",
"solc": "^0.5.9",
"solidity-coverage": "github:sc-forks/solidity-coverage#leapdao",
"solium": "^1.2.4"
"solium": "^1.2.4",
"truffle": "^5.0.25"
},
"directories": {
"test": "test"
......
// imports & defines
const path = require('path')
const solc = require('solc')
const fs = require('fs-extra')
// Functions
/**
* Makes sure that the build folder is deleted, before every compilation
* @returns {*} - Path where the compiled sources should be saved.
*/
function compilingPreperations () {
const buildPath = path.resolve(__dirname, '../build/contracts')
fs.removeSync(buildPath)
return buildPath
}
/**
* Returns and Object describing what to compile and what need to be returned.
*/
function createConfiguration () {
return {
language: 'Solidity',
sources: {
'Identity.sol': {
content: fs.readFileSync(path.resolve(__dirname, '../contracts', 'Identity.sol'), 'utf8')
}
},
settings: {
outputSelection: { // return everything
'*': {
'*': ['*']
}
}
}
}
}
/**
* Compiles the sources, defined in the config object with solc-js.
* @param config - Configuration object.
* @returns {any} - Object with compiled sources and errors object.
*/
function compileSources (config) {
try {
return JSON.parse(solc.compile(JSON.stringify(config), getImports))
} catch (e) {
console.log(e)
}
}
/**
* Searches for dependencies in the Solidity files (import statements). All import Solidity files
* need to be declared here.
* @param dependency
* @returns {*}
*/
function getImports (dependency) {
switch (dependency) {
case 'ERC725.sol':
return { contents: fs.readFileSync(path.resolve(__dirname, '../contracts', 'ERC725.sol'), 'utf8') }
default:
return { error: 'File not found' }
}
}
/**
* Shows when there were errors during compilation.
* @param compiledSources
*/
function errorHandling (compiledSources) {
if (!compiledSources) {
return 'No output'
} else if (compiledSources.errors) { // something went wrong.
return 'Something went wrong'
// compiledSources.errors.map(error => console.log(error.formattedMessage));
} else return false
}
/**
* Writes the contracts from the compiled sources into JSON files, which you will later be able to
* use in combination with web3.
* @param compiled - Object containing the compiled contracts.
* @param buildPath - Path of the build folder.
*/
function writeOutput (compiled, buildPath) {
fs.ensureDirSync(buildPath)
for (let contractFileName in compiled.contracts) {
const contractName = contractFileName.replace('.sol', '')
let contractJson = {
abi: compiled.contracts[contractFileName][contractName].abi,
bytecode: '0x' + compiled.contracts[contractFileName][contractName].evm.bytecode.object
}
fs.outputJsonSync(
path.resolve(buildPath, contractName + '.json'),
contractJson
)
}
}
// Workflow
function buildId () {
const buildPath = compilingPreperations()
const config = createConfiguration()
const compiled = compileSources(config)
const error = errorHandling(compiled)
if (error === false) {
writeOutput(compiled, buildPath)
return true
} else {
return error
}
}
module.exports = buildId
const path = require('path')
const fs = require('fs-extra')
let buildId = require('../src/build')
let expect = require('chai').expect
let Parity = require('@caelum-tech/parity')
const ethers = require('ethers')
let parity, wallet, identityAddr, identityContract, IdentityContract
// const KEY_OWNER = '0x0000000000000000000000000000000000000000000000000000000000000000'
const OPERATION_CALL = 0
// const key0 = ethers.utils.formatBytes32String(0)
const key = ethers.utils.formatBytes32String('test')
const value = ethers.utils.formatBytes32String('Hello World')
describe('1.1. Identity', function () {
const walletAddress = '0x8ad0ba67f8088d1f990f878815173f1dafda0a55'
contract('1.1. Identity', (accounts) => {
before(async () => {
parity = new Parity()
wallet = await parity.loadWallet('0x8ad0ba67f8088d1f990f878815173f1dafda0a55', '59Ta_ad6_]k<PWPp')
parity = new Parity('http://localhost:8545')
wallet = await parity.loadWallet(walletAddress, '59Ta_ad6_]k<PWPp')
})
it('Blockchain should be running', () => {
expect(parity.isBlockchainRunning()).to.not.be.equal(null)
})
it('Should Build the Identity Contract', done => {
buildId()
let content = fs.readFileSync(path.resolve(__dirname, '../build/contracts', 'Identity.json'), 'utf8')
expect(content).to.not.be.equal(null)
done()
it('Should send gas to the wallet', () => {
expect(parity.isBlockchainRunning()).to.not.be.equal(null)
web3.eth.sendTransaction({ from: accounts[0], to: walletAddress, value: web3.utils.toWei('10', 'ether') })
})
it('Should Deploy the Identity Contract', (done) => {
......
......@@ -42,11 +42,11 @@ module.exports = {
// tab if you use this network and you must also set the `host`, `port` and `network_id`
// options below to some value.
//
// development: {
// host: "127.0.0.1", // Localhost (default: none)
// port: 8545, // Standard Ethereum port (default: none)
// network_id: "*", // Any network (default: none)
// },
coverage: {
host: '127.0.0.1', // Localhost (default: none)
port: 8545, // Standard Ethereum port (default: none)
network_id: '*' // Any network (default: none)
}
// Another network with more advanced options...
// advanced: {
......@@ -79,7 +79,7 @@ module.exports = {
// Set default mocha options here, use special reporters etc.
mocha: {
// timeout: 100000
timeout: 100000
},
// Configure your compilers
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment