Commit 28773548 authored by aniket-engg's avatar aniket-engg

linting for remix-tests fixed

parent 84d0bac2
{
"extends": "../../.eslintrc",
"rules": {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/ban-ts-comment": "off"
"dot-notation": "off",
"no-unused-vars": "off"
},
"env": {
"browser": true,
......
const assertionEvents = [
{
name: 'AssertionEvent',
params: ['bool', 'string', 'string']
},
{
name: 'AssertionEventUint',
params: ['bool', 'string', 'string', 'uint256', 'uint256']
},
{
name: 'AssertionEventInt',
params: ['bool', 'string', 'string', 'int256', 'int256']
},
{
name: 'AssertionEventBool',
params: ['bool', 'string', 'string', 'bool', 'bool']
},
{
name: 'AssertionEventAddress',
params: ['bool', 'string', 'string', 'address', 'address']
},
{
name: 'AssertionEventBytes32',
params: ['bool', 'string', 'string', 'bytes32', 'bytes32']
},
{
name: 'AssertionEventString',
params: ['bool', 'string', 'string', 'string', 'string']
},
{
name: 'AssertionEventUintInt',
params: ['bool', 'string', 'string', 'uint256', 'int256']
},
{
name: 'AssertionEventIntUint',
params: ['bool', 'string', 'string', 'int256', 'uint256']
}
{
name: 'AssertionEvent',
params: ['bool', 'string', 'string']
},
{
name: 'AssertionEventUint',
params: ['bool', 'string', 'string', 'uint256', 'uint256']
},
{
name: 'AssertionEventInt',
params: ['bool', 'string', 'string', 'int256', 'int256']
},
{
name: 'AssertionEventBool',
params: ['bool', 'string', 'string', 'bool', 'bool']
},
{
name: 'AssertionEventAddress',
params: ['bool', 'string', 'string', 'address', 'address']
},
{
name: 'AssertionEventBytes32',
params: ['bool', 'string', 'string', 'bytes32', 'bytes32']
},
{
name: 'AssertionEventString',
params: ['bool', 'string', 'string', 'string', 'string']
},
{
name: 'AssertionEventUintInt',
params: ['bool', 'string', 'string', 'uint256', 'int256']
},
{
name: 'AssertionEventIntUint',
params: ['bool', 'string', 'string', 'int256', 'uint256']
}
]
export default assertionEvents
\ No newline at end of file
export default assertionEvents
This diff is collapsed.
......@@ -11,108 +11,108 @@ import { compilationInterface } from './types'
* @param callback Callback
*/
export function deployAll(compileResult: compilationInterface, web3: Web3, withDoubleGas: boolean, callback) {
const compiledObject = {}
const contracts = {}
let accounts: string[] = []
export function deployAll (compileResult: compilationInterface, web3: Web3, withDoubleGas: boolean, callback) {
const compiledObject = {}
const contracts = {}
let accounts: string[] = []
async.waterfall([
function getAccountList(next) {
web3.eth.getAccounts((_err, _accounts) => {
accounts = _accounts
next()
})
},
function getContractData(next) {
for (const contractFile in compileResult) {
for (const contractName in compileResult[contractFile]) {
const contract = compileResult[contractFile][contractName]
async.waterfall([
function getAccountList (next) {
web3.eth.getAccounts((_err, _accounts) => {
accounts = _accounts
next()
})
},
function getContractData (next) {
for (const contractFile in compileResult) {
for (const contractName in compileResult[contractFile]) {
const contract = compileResult[contractFile][contractName]
const className = contractName
const filename = contractFile
const className = contractName
const filename = contractFile
const abi = contract.abi
const code = contract.evm.bytecode.object
const abi = contract.abi
const code = contract.evm.bytecode.object
compiledObject[className] = {}
compiledObject[className].abi = abi
compiledObject[className].code = code
compiledObject[className].filename = filename
compiledObject[className].className = className
compiledObject[className].raw = contract
compiledObject[className] = {}
compiledObject[className].abi = abi
compiledObject[className].code = code
compiledObject[className].filename = filename
compiledObject[className].className = className
compiledObject[className].raw = contract
if (contractFile.endsWith('_test.sol')) {
compiledObject[className].isTest = true
}
}
}
next()
},
function determineContractsToDeploy(next) {
const contractsToDeploy: string[] = ['Assert']
const allContracts = Object.keys(compiledObject)
for (const contractName of allContracts) {
if (contractName === 'Assert') {
continue
}
if (compiledObject[contractName].isTest) {
contractsToDeploy.push(contractName)
}
}
next(null, contractsToDeploy)
},
function deployContracts(contractsToDeploy: string[], next) {
const deployRunner = (deployObject, contractObject, contractName, filename, callback) => {
deployObject.estimateGas().then((gasValue) => {
const gasBase = Math.ceil(gasValue * 1.2)
const gas = withDoubleGas ? gasBase * 2 : gasBase
deployObject.send({
from: accounts[0],
gas: gas
}).on('receipt', function (receipt) {
contractObject.options.address = receipt.contractAddress
contractObject.options.from = accounts[0]
contractObject.options.gas = 5000 * 1000
compiledObject[contractName].deployedAddress = receipt.contractAddress
if (contractFile.endsWith('_test.sol')) {
compiledObject[className].isTest = true
}
}
}
next()
},
function determineContractsToDeploy (next) {
const contractsToDeploy: string[] = ['Assert']
const allContracts = Object.keys(compiledObject)
contracts[contractName] = contractObject
contracts[contractName].filename = filename
for (const contractName of allContracts) {
if (contractName === 'Assert') {
continue
}
if (compiledObject[contractName].isTest) {
contractsToDeploy.push(contractName)
}
}
next(null, contractsToDeploy)
},
function deployContracts (contractsToDeploy: string[], next) {
const deployRunner = (deployObject, contractObject, contractName, filename, callback) => {
deployObject.estimateGas().then((gasValue) => {
const gasBase = Math.ceil(gasValue * 1.2)
const gas = withDoubleGas ? gasBase * 2 : gasBase
deployObject.send({
from: accounts[0],
gas: gas
}).on('receipt', function (receipt) {
contractObject.options.address = receipt.contractAddress
contractObject.options.from = accounts[0]
contractObject.options.gas = 5000 * 1000
compiledObject[contractName].deployedAddress = receipt.contractAddress
callback(null, { result: { createdAddress: receipt.contractAddress } }) // TODO this will only work with JavaScriptV VM
}).on('error', function (err) {
console.error(err)
callback(err)
})
})
}
contracts[contractName] = contractObject
contracts[contractName].filename = filename
async.eachOfLimit(contractsToDeploy, 1, function (contractName, index, nextEach) {
const contract = compiledObject[contractName]
const encodeDataFinalCallback = (error, contractDeployData) => {
if (error) return nextEach(error)
const contractObject = new web3.eth.Contract(contract.abi)
const deployObject = contractObject.deploy({arguments: [], data: '0x' + contractDeployData.dataHex})
deployRunner(deployObject, contractObject, contractName, contract.filename, (error) => { nextEach(error) })
}
callback(null, { result: { createdAddress: receipt.contractAddress } }) // TODO this will only work with JavaScriptV VM
}).on('error', function (err) {
console.error(err)
callback(err)
})
})
}
const encodeDataStepCallback = (msg) => { console.dir(msg) }
async.eachOfLimit(contractsToDeploy, 1, function (contractName, index, nextEach) {
const contract = compiledObject[contractName]
const encodeDataFinalCallback = (error, contractDeployData) => {
if (error) return nextEach(error)
const contractObject = new web3.eth.Contract(contract.abi)
const deployObject = contractObject.deploy({ arguments: [], data: '0x' + contractDeployData.dataHex })
deployRunner(deployObject, contractObject, contractName, contract.filename, (error) => { nextEach(error) })
}
const encodeDataDeployLibraryCallback = (libData, callback) => {
const abi = compiledObject[libData.data.contractName].abi
const code = compiledObject[libData.data.contractName].code
const libraryObject = new web3.eth.Contract(abi)
const deployObject = libraryObject.deploy({arguments: [], data: '0x' + code})
deployRunner(deployObject, libraryObject, libData.data.contractName, contract.filename, callback)
}
const encodeDataStepCallback = (msg) => { console.dir(msg) }
const funAbi = null // no need to set the abi for encoding the constructor
const params = '' // we suppose that the test contract does not have any param in the constructor
execution.txFormat.encodeConstructorCallAndDeployLibraries(contractName, contract.raw, compileResult, params, funAbi, encodeDataFinalCallback, encodeDataStepCallback, encodeDataDeployLibraryCallback)
}, function (err) {
if(err) next(err)
next(null, contracts)
})
const encodeDataDeployLibraryCallback = (libData, callback) => {
const abi = compiledObject[libData.data.contractName].abi
const code = compiledObject[libData.data.contractName].code
const libraryObject = new web3.eth.Contract(abi)
const deployObject = libraryObject.deploy({ arguments: [], data: '0x' + code })
deployRunner(deployObject, libraryObject, libData.data.contractName, contract.filename, callback)
}
], callback)
const funAbi = null // no need to set the abi for encoding the constructor
const params = '' // we suppose that the test contract does not have any param in the constructor
execution.txFormat.encodeConstructorCallAndDeployLibraries(contractName, contract.raw, compileResult, params, funAbi, encodeDataFinalCallback, encodeDataStepCallback, encodeDataDeployLibraryCallback)
}, function (err) {
if (err) next(err)
next(null, contracts)
})
}
], callback)
}
// Extend fs
const fs: any = require('fs')
import path from 'path'
const fs: any = require('fs')
// https://github.com/mikeal/node-utils/blob/master/file/lib/main.js
fs.walkSync = function (start: string, callback) {
fs.readdirSync(start).forEach((name: string) => {
if (name === 'node_modules') {
return // hack
}
const abspath = path.join(start, name)
if (fs.statSync(abspath).isDirectory()) {
fs.walkSync(abspath, callback)
} else {
callback(abspath)
}
})
fs.readdirSync(start).forEach((name: string) => {
if (name === 'node_modules') {
return // hack
}
const abspath = path.join(start, name)
if (fs.statSync(abspath).isDirectory()) {
fs.walkSync(abspath, callback)
} else {
callback(abspath)
}
})
}
export = fs
import colors from 'colors'
import winston, { Logger, LoggerOptions } from 'winston'
import timestamp from 'time-stamp';
import timestamp from 'time-stamp'
import supportsColor from 'color-support'
function hasFlag (flag: string) {
return ((typeof (process) !== 'undefined') && (process.argv.indexOf('--' + flag) !== -1))
return ((typeof (process) !== 'undefined') && (process.argv.indexOf('--' + flag) !== -1))
}
function addColor (str: string) {
if (hasFlag('no-color')) {
return str
}
if (hasFlag('no-color')) {
return str
}
if (hasFlag('color')) {
return colors.gray(str)
}
if (hasFlag('color')) {
return colors.gray(str)
}
if (supportsColor()) {
return colors.gray(str)
}
if (supportsColor()) {
return colors.gray(str)
}
return str
return str
}
function getTimestamp () {
return '[' + addColor(timestamp('HH:mm:ss')) + ']'
return '[' + addColor(timestamp('HH:mm:ss')) + ']'
}
// create winston logger format
const logFmt = winston.format.printf((info) => {
return `${getTimestamp()} ${info.level}: ${info.message}`
return `${getTimestamp()} ${info.level}: ${info.message}`
})
class Log {
logger: Logger;
constructor () {
this.logger = winston.createLogger({
level: 'info',
transports: [new winston.transports.Console()],
format: winston.format.combine(
winston.format.colorize({ all: true }),
logFmt
)
})
this.logger = winston.createLogger({
level: 'info',
transports: [new winston.transports.Console()],
format: winston.format.combine(
winston.format.colorize({ all: true }),
logFmt
)
})
}
setVerbosity (v: LoggerOptions["level"]): void {
this.logger.configure({
level: v,
transports: [new winston.transports.Console()],
format: winston.format.combine(
winston.format.colorize({ all: true }),
logFmt
)
})
setVerbosity (v: LoggerOptions['level']): void {
this.logger.configure({
level: v,
transports: [new winston.transports.Console()],
format: winston.format.combine(
winston.format.colorize({ all: true }),
logFmt
)
})
}
}
......
......@@ -7,29 +7,29 @@ import fs from './fileSystem'
import { Provider } from '@remix-project/remix-simulator'
import { CompilerConfiguration } from './types'
import Log from './logger'
import colors from 'colors'
const logger = new Log()
const log = logger.logger
import colors from 'colors'
// parse verbosity
function mapVerbosity (v: number) {
const levels = {
0: 'error',
1: 'warn',
2: 'info',
3: 'verbose',
4: 'debug',
5: 'silly'
}
return levels[v]
const levels = {
0: 'error',
1: 'warn',
2: 'info',
3: 'verbose',
4: 'debug',
5: 'silly'
}
return levels[v]
}
function mapOptimize (v: string) {
const optimize = {
'true': true,
'false': false
}
return optimize[v];
const optimize = {
true: true,
false: false
}
return optimize[v]
}
const version = require('../package.json').version
......@@ -37,92 +37,91 @@ const version = require('../package.json').version
commander.version(version)
commander.command('version').description('output the version number').action(function () {
console.log(version)
console.log(version)
})
commander.command('help').description('output usage information').action(function () {
commander.help()
commander.help()
})
// get current version
commander
.option('-c, --compiler <string>', 'set compiler version (e.g: 0.6.1, 0.7.1 etc)')
.option('-e, --evm <string>', 'set EVM version (e.g: petersburg, istanbul etc)')
.option('-o, --optimize <bool>', 'enable/disable optimization', mapOptimize)
.option('-r, --runs <number>', 'set runs (e.g: 150, 250 etc)')
.option('-v, --verbose <level>', 'set verbosity level (0 to 5)', mapVerbosity)
.action(async (testsPath) => {
// Check if path exists
if (!fs.existsSync(testsPath)) {
log.error(testsPath + ' not found')
process.exit(1)
}
// Check if path is for a directory
const isDirectory = fs.lstatSync(testsPath).isDirectory()
// If path is for a file, file name must have `_test.sol` suffix
if(!isDirectory && !testsPath.endsWith('_test.sol')) {
log.error('Test filename should end with "_test.sol"')
process.exit()
}
// Console message
console.log(colors.white('\n\t👁\t:: Running remix-tests - Unit testing for solidity ::\t👁\n'))
// Set logger verbosity
if (commander.verbose) {
logger.setVerbosity(commander.verbose)
log.info('verbosity level set to ' + commander.verbose.blue)
}
let compilerConfig = {} as CompilerConfiguration
if (commander.compiler) {
const compVersion = commander.compiler
const baseURL = 'https://binaries.soliditylang.org/wasm/'
const response: AxiosResponse = await axios.get(baseURL + 'list.json')
const { releases, latestRelease } = response.data
const compString = releases[compVersion]
if(!compString) {
log.error(`No compiler found in releases with version ${compVersion}`)
process.exit()
} else {
compilerConfig.currentCompilerUrl = compString.replace('soljson-', '').replace('.js', '')
log.info(`Compiler version set to ${compVersion}. Latest version is ${latestRelease}`)
}
}
if (commander.evm) {
compilerConfig.evmVersion = commander.evm
log.info(`EVM set to ${compilerConfig.evmVersion}`)
}
if (commander.optimize) {
compilerConfig.optimize = commander.optimize
log.info(`Optimization is ${compilerConfig.optimize ? 'enabled' : 'disabled'}`)
}
if (commander.runs) {
if(!commander.optimize) {
log.error(`Optimization should be enabled for runs`)
process.exit()
}
compilerConfig.runs = commander.runs
log.info(`Runs set to ${compilerConfig.runs}`)
}
const web3 = new Web3()
const provider: any = new Provider()
await provider.init()
web3.setProvider(provider)
runTestFiles(path.resolve(testsPath), isDirectory, web3, compilerConfig)
})
.option('-c, --compiler <string>', 'set compiler version (e.g: 0.6.1, 0.7.1 etc)')
.option('-e, --evm <string>', 'set EVM version (e.g: petersburg, istanbul etc)')
.option('-o, --optimize <bool>', 'enable/disable optimization', mapOptimize)
.option('-r, --runs <number>', 'set runs (e.g: 150, 250 etc)')
.option('-v, --verbose <level>', 'set verbosity level (0 to 5)', mapVerbosity)
.action(async (testsPath) => {
// Check if path exists
if (!fs.existsSync(testsPath)) {
log.error(testsPath + ' not found')
process.exit(1)
}
// Check if path is for a directory
const isDirectory = fs.lstatSync(testsPath).isDirectory()
// If path is for a file, file name must have `_test.sol` suffix
if (!isDirectory && !testsPath.endsWith('_test.sol')) {
log.error('Test filename should end with "_test.sol"')
process.exit()
}
// Console message
console.log(colors.white('\n\t👁\t:: Running remix-tests - Unit testing for solidity ::\t👁\n'))
// Set logger verbosity
if (commander.verbose) {
logger.setVerbosity(commander.verbose)
log.info('verbosity level set to ' + commander.verbose.blue)
}
const compilerConfig = {} as CompilerConfiguration
if (commander.compiler) {
const compVersion = commander.compiler
const baseURL = 'https://binaries.soliditylang.org/wasm/'
const response: AxiosResponse = await axios.get(baseURL + 'list.json')
const { releases, latestRelease } = response.data
const compString = releases[compVersion]
if (!compString) {
log.error(`No compiler found in releases with version ${compVersion}`)
process.exit()
} else {
compilerConfig.currentCompilerUrl = compString.replace('soljson-', '').replace('.js', '')
log.info(`Compiler version set to ${compVersion}. Latest version is ${latestRelease}`)
}
}
if (commander.evm) {
compilerConfig.evmVersion = commander.evm
log.info(`EVM set to ${compilerConfig.evmVersion}`)
}
if (commander.optimize) {
compilerConfig.optimize = commander.optimize
log.info(`Optimization is ${compilerConfig.optimize ? 'enabled' : 'disabled'}`)
}
if (commander.runs) {
if (!commander.optimize) {
log.error('Optimization should be enabled for runs')
process.exit()
}
compilerConfig.runs = commander.runs
log.info(`Runs set to ${compilerConfig.runs}`)
}
const web3 = new Web3()
const provider: any = new Provider()
await provider.init()
web3.setProvider(provider)
runTestFiles(path.resolve(testsPath), isDirectory, web3, compilerConfig)
})
if (!process.argv.slice(2).length) {
log.error('Please specify a file or directory path')
process.exit()
log.error('Please specify a file or directory path')
process.exit()
}
commander.parse(process.argv)
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -51,8 +51,8 @@ export interface Options {
export interface CompilerConfiguration {
currentCompilerUrl: string,
evmVersion: string,
optimize: boolean,
evmVersion: string,
optimize: boolean,
usingWorker?: boolean,
runs: number
}
......@@ -64,7 +64,7 @@ export interface CompilationErrors {
}
export class CompilationErrors extends Error {
constructor(errors: Array<any>) {
constructor (errors: Array<any>) {
const mapError = errors.map((e) => { return e.formattedMessage || e.message })
super(mapError.join('\n'))
this.errors = errors
......@@ -74,9 +74,9 @@ export class CompilationErrors extends Error {
/** sources object with name of the file and content **/
////////////
/// /////////
// SOURCE //
////////////
/// /////////
export interface CompilationSource {
/** Identifier of the source (used in source maps) */
id: number
......@@ -162,9 +162,9 @@ export interface CompiledContract {
}
}
/////////
/// //////
// ABI //
/////////
/// //////
export type ABIDescription = FunctionDescription | EventDescription
export interface FunctionDescription {
......@@ -227,9 +227,9 @@ export type ABITypeParameter =
| 'tuple[]'
| string // Fallback
///////////////////////////
/// ////////////////////////
// NATURAL SPECIFICATION //
///////////////////////////
/// ////////////////////////
// Userdoc
export interface UserDocumentation {
......@@ -267,9 +267,9 @@ export interface DevMethodDoc {
}
}
//////////////
/// ///////////
// BYTECODE //
//////////////
/// ///////////
export interface BytecodeObject {
/** The bytecode as a hex string. */
object: string
......
......@@ -41,7 +41,7 @@
"workspace-schematic": "nx workspace-schematic",
"dep-graph": "nx dep-graph",
"help": "nx help",
"lint:libs": "nx run-many --target=lint --projects=remix-analyzer,remix-astwalker,remix-debug,remix-lib,remix-simulator,remix-solidity,remixd,remix-ui-tree-view,remix-ui-modal-dialog,remix-ui-toaster,remix-ui-file-explorer,remix-ui-debugger-ui",
"lint:libs": "nx run-many --target=lint --projects=remix-analyzer,remix-astwalker,remix-debug,remix-lib,remix-simulator,remix-solidity,remix-tests,remixd,remix-ui-tree-view,remix-ui-modal-dialog,remix-ui-toaster,remix-ui-file-explorer,remix-ui-debugger-ui",
"build:libs": "nx run-many --target=build --parallel=false --with-deps=true --projects=remix-analyzer,remix-astwalker,remix-debug,remix-lib,remix-simulator,remix-solidity,remix-tests,remix-url-resolver,remixd",
"test:libs": "nx run-many --target=test --projects=remix-analyzer,remix-astwalker,remix-debug,remix-lib,remix-simulator,remix-solidity,remix-tests,remix-url-resolver,remixd",
"publish:libs": "npm run build:libs & lerna publish --skip-git & npm run bumpVersion:libs",
......
......@@ -347,7 +347,7 @@
"linter": "eslint",
"config": "libs/remix-tests/.eslintrc",
"tsConfig": ["libs/remix-tests/tsconfig.lib.json"],
"exclude": ["**/node_modules/**", "libs/remix-tests/tests/**/*"]
"exclude": ["**/node_modules/**", "libs/remix-tests/tests/**/*", "**/dist/**"]
}
},
"test": {
......
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