parent
2c2d01f639
commit
4bbc71694c
@ -1 +0,0 @@ |
||||
export {}; |
@ -1,15 +0,0 @@ |
||||
"use strict"; |
||||
var __importDefault = (this && this.__importDefault) || function (mod) { |
||||
return (mod && mod.__esModule) ? mod : { "default": mod }; |
||||
}; |
||||
Object.defineProperty(exports, "__esModule", { value: true }); |
||||
var runTestFiles_1 = __importDefault(require("./runTestFiles")); |
||||
var runTestSources_1 = __importDefault(require("./runTestSources")); |
||||
var testRunner_1 = __importDefault(require("./testRunner")); |
||||
module.exports = { |
||||
runTestFiles: runTestFiles_1.default, |
||||
runTestSources: runTestSources_1.default, |
||||
runTest: testRunner_1.default, |
||||
assertLibCode: require('../sol/tests.sol.js') |
||||
}; |
||||
//# sourceMappingURL=index.js.map
|
@ -1 +0,0 @@ |
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,gEAAyC;AACzC,oEAA6C;AAC7C,4DAAkC;AAElC,MAAM,CAAC,OAAO,GAAG;IACf,YAAY,EAAE,sBAAY;IAC1B,cAAc,EAAE,wBAAc;IAC9B,OAAO,EAAE,oBAAO;IAChB,aAAa,EAAE,OAAO,CAAC,qBAAqB,CAAC;CAC9C,CAAA"} |
@ -1,2 +0,0 @@ |
||||
declare function runTestFiles(filepath: any, isDirectory: any, web3: any, opts: any): void; |
||||
export = runTestFiles; |
@ -1,134 +0,0 @@ |
||||
"use strict"; |
||||
var __importDefault = (this && this.__importDefault) || function (mod) { |
||||
return (mod && mod.__esModule) ? mod : { "default": mod }; |
||||
}; |
||||
var async = require("async"); |
||||
var path = require("path"); |
||||
var fs = require("./fs"); |
||||
var testRunner_1 = __importDefault(require("./testRunner")); |
||||
require('colors'); |
||||
var Compiler = require("./compiler.js"); |
||||
var Deployer = require("./deployer.js"); |
||||
function runTestFiles(filepath, isDirectory, web3, opts) { |
||||
opts = opts || {}; |
||||
var Signale = require('signale').Signale; |
||||
// signale configuration
|
||||
var options = { |
||||
types: { |
||||
result: { |
||||
badge: '\t✓', |
||||
label: '', |
||||
color: 'greenBright' |
||||
}, |
||||
name: { |
||||
badge: '\n\t◼', |
||||
label: '', |
||||
color: 'white' |
||||
}, |
||||
error: { |
||||
badge: '\t✘', |
||||
label: '', |
||||
color: 'redBright' |
||||
} |
||||
} |
||||
}; |
||||
var signale = new Signale(options); |
||||
var accounts = opts.accounts || null; |
||||
async.waterfall([ |
||||
function getAccountList(next) { |
||||
if (accounts) |
||||
return next(null); |
||||
web3.eth.getAccounts(function (_err, _accounts) { |
||||
accounts = _accounts; |
||||
next(null); |
||||
}); |
||||
}, |
||||
function compile(next) { |
||||
Compiler.compileFileOrFiles(filepath, isDirectory, { accounts: accounts }, next); |
||||
}, |
||||
function deployAllContracts(compilationResult, next) { |
||||
Deployer.deployAll(compilationResult, web3, function (err, contracts) { |
||||
if (err) { |
||||
next(err); |
||||
} |
||||
next(null, compilationResult, contracts); |
||||
}); |
||||
}, |
||||
function determineTestContractsToRun(compilationResult, contracts, next) { |
||||
var contractsToTest = []; |
||||
var contractsToTestDetails = []; |
||||
var gatherContractsFrom = function (filename) { |
||||
if (filename.indexOf('_test.sol') < 0) { |
||||
return; |
||||
} |
||||
Object.keys(compilationResult[path.basename(filename)]).forEach(function (contractName) { |
||||
contractsToTest.push(contractName); |
||||
contractsToTestDetails.push(compilationResult[path.basename(filename)][contractName]); |
||||
}); |
||||
}; |
||||
if (isDirectory) { |
||||
fs.walkSync(filepath, function (foundpath) { |
||||
gatherContractsFrom(foundpath); |
||||
}); |
||||
} |
||||
else { |
||||
gatherContractsFrom(filepath); |
||||
} |
||||
next(null, contractsToTest, contractsToTestDetails, contracts); |
||||
}, |
||||
function runTests(contractsToTest, contractsToTestDetails, contracts, next) { |
||||
var totalPassing = 0; |
||||
var totalFailing = 0; |
||||
var totalTime = 0; |
||||
var errors = []; |
||||
var testCallback = function (result) { |
||||
if (result.type === 'contract') { |
||||
signale.name(result.value.white); |
||||
} |
||||
else if (result.type === 'testPass') { |
||||
signale.result(result.value); |
||||
} |
||||
else if (result.type === 'testFailure') { |
||||
signale.result(result.value.red); |
||||
errors.push(result); |
||||
} |
||||
}; |
||||
var resultsCallback = function (_err, result, cb) { |
||||
totalPassing += result.passingNum; |
||||
totalFailing += result.failureNum; |
||||
totalTime += result.timePassed; |
||||
cb(); |
||||
}; |
||||
async.eachOfLimit(contractsToTest, 1, function (contractName, index, cb) { |
||||
testRunner_1.default(contractName, contracts(contractName), contractsToTestDetails[index], { accounts: accounts }, testCallback, function (err, result) { |
||||
if (err) { |
||||
return cb(err); |
||||
} |
||||
resultsCallback(null, result, cb); |
||||
}); |
||||
}, function (err) { |
||||
if (err) { |
||||
return next(err); |
||||
} |
||||
console.log('\n'); |
||||
if (totalPassing > 0) { |
||||
console.log(('%c ' + totalPassing + ' passing ') + ('%c(' + totalTime + 's)'), 'color: green', 'color: grey'); |
||||
} |
||||
if (totalFailing > 0) { |
||||
console.log(('%c ' + totalFailing + ' failing'), 'color: red'); |
||||
} |
||||
console.log(''); |
||||
errors.forEach(function (error, index) { |
||||
console.log(' ' + (index + 1) + ') ' + error.context + ' ' + error.value); |
||||
console.log(''); |
||||
console.log(('%c\t error: ' + error.errMsg), 'color: red'); |
||||
}); |
||||
console.log(''); |
||||
next(); |
||||
}); |
||||
} |
||||
], function () { |
||||
}); |
||||
} |
||||
module.exports = runTestFiles; |
||||
//# sourceMappingURL=runTestFiles.js.map
|
@ -1 +0,0 @@ |
||||
{"version":3,"file":"runTestFiles.js","sourceRoot":"","sources":["../src/runTestFiles.ts"],"names":[],"mappings":";;;;AAAA,6BAA+B;AAC/B,2BAA6B;AAC7B,yBAA2B;AAC3B,4DAAkC;AAClC,OAAO,CAAC,QAAQ,CAAC,CAAA;AAEjB,wCAA0C;AAC1C,wCAA0C;AAE1C,SAAS,YAAY,CAAC,QAAQ,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI;IACnD,IAAI,GAAG,IAAI,IAAI,EAAE,CAAA;IACT,IAAA,oCAAO,C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AAG,YAAY,GAAG,WAAW,CAAC,GAAG,CAAC,KAAK,GAAG,SAAS,GAAG,IAAI,CAAC,EAAC,cAAc,EAAC,aAAa,CAAC,CAAA;iBAC/G;gBACD,IAAI,YAAY,GAAG,CAAC,EAAE;oBAClB,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,GAAG,YAAY,GAAG,UAAU,CAAC,EAAC,YAAY,CAAC,CAAA;iBACjE;gBACD,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;gBAEf,MAAM,CAAC,OAAO,CAAC,UAAC,KAAK,EAAE,KAAK;oBACxB,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC,OAAO,GAAG,GAAG,GAAG,KAAK,CAAC,KAAK,CAAC,CAAA;oBAC1E,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;oBACf,OAAO,CAAC,GAAG,CAAC,CAAC,cAAc,GAAG,KAAK,CAAC,MAAM,CAAC,EAAC,YAAY,CAAC,CAAA;gBAC7D,CAAC,CAAC,CAAA;gBACF,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;gBAEf,IAAI,EAAE,CAAA;YACV,CAAC,CAAC,CAAA;QACN,CAAC;KACJ,EAAE;IACH,CAAC,CAAC,CAAA;AACN,CAAC;AAED,iBAAS,YAAY,CAAC"} |
@ -1,2 +0,0 @@ |
||||
declare function runTestSources(contractSources: any, testCallback: any, resultCallback: any, finalCallback: any, importFileCb: any, opts: any): void; |
||||
export = runTestSources; |
@ -1,106 +0,0 @@ |
||||
"use strict"; |
||||
var __importDefault = (this && this.__importDefault) || function (mod) { |
||||
return (mod && mod.__esModule) ? mod : { "default": mod }; |
||||
}; |
||||
var async_1 = __importDefault(require("async")); |
||||
require('colors'); |
||||
var Compiler = require("./compiler.js"); |
||||
var Deployer = require("./deployer.js"); |
||||
var testRunner_1 = __importDefault(require("./testRunner")); |
||||
var Web3 = require("web3"); |
||||
var remix_simulator_1 = __importDefault(require("remix-simulator")); |
||||
var createWeb3Provider = function () { |
||||
var web3 = new Web3(); |
||||
web3.setProvider(new remix_simulator_1.default()); |
||||
return web3; |
||||
}; |
||||
function runTestSources(contractSources, testCallback, resultCallback, finalCallback, importFileCb, opts) { |
||||
opts = opts || {}; |
||||
var web3 = opts.web3 || createWeb3Provider(); |
||||
var accounts = opts.accounts || null; |
||||
async_1.default.waterfall([ |
||||
function getAccountList(next) { |
||||
if (accounts) |
||||
return next(); |
||||
web3.eth.getAccounts(function (_err, _accounts) { |
||||
accounts = _accounts; |
||||
next(); |
||||
}); |
||||
}, |
||||
function compile(next) { |
||||
Compiler.compileContractSources(contractSources, importFileCb, next); |
||||
}, |
||||
function deployAllContracts(compilationResult, next) { |
||||
Deployer.deployAll(compilationResult, web3, function (err, contracts) { |
||||
if (err) { |
||||
next(err); |
||||
} |
||||
next(null, compilationResult, contracts); |
||||
}); |
||||
}, |
||||
function determineTestContractsToRun(compilationResult, contracts, next) { |
||||
var contractsToTest = []; |
||||
var contractsToTestDetails = []; |
||||
var _loop_1 = function (filename) { |
||||
if (filename.indexOf('_test.sol') < 0) { |
||||
return "continue"; |
||||
} |
||||
Object.keys(compilationResult[filename]).forEach(function (contractName) { |
||||
contractsToTestDetails.push(compilationResult[filename][contractName]); |
||||
contractsToTest.push(contractName); |
||||
}); |
||||
}; |
||||
for (var filename in compilationResult) { |
||||
_loop_1(filename); |
||||
} |
||||
next(null, contractsToTest, contractsToTestDetails, contracts); |
||||
}, |
||||
function runTests(contractsToTest, contractsToTestDetails, contracts, next) { |
||||
var totalPassing = 0; |
||||
var totalFailing = 0; |
||||
var totalTime = 0; |
||||
var errors = []; |
||||
var _testCallback = function (result) { |
||||
if (result.type === 'testFailure') { |
||||
errors.push(result); |
||||
} |
||||
testCallback(result); |
||||
}; |
||||
var _resultsCallback = function (_err, result, cb) { |
||||
resultCallback(_err, result, function () { }); |
||||
totalPassing += result.passingNum; |
||||
totalFailing += result.failureNum; |
||||
totalTime += result.timePassed; |
||||
cb(); |
||||
}; |
||||
async_1.default.eachOfLimit(contractsToTest, 1, function (contractName, index, cb) { |
||||
testRunner_1.default(contractName, contracts(contractName), contractsToTestDetails[index], { accounts: accounts }, _testCallback, function (err, result) { |
||||
if (err) { |
||||
return cb(err); |
||||
} |
||||
_resultsCallback(null, result, cb); |
||||
}); |
||||
}, function (err) { |
||||
if (err) { |
||||
return next(err); |
||||
} |
||||
var finalResults = { |
||||
totalPassing: 0, |
||||
totalFailing: 0, |
||||
totalTime: 0, |
||||
errors: [], |
||||
}; |
||||
finalResults.totalPassing = totalPassing || 0; |
||||
finalResults.totalFailing = totalFailing || 0; |
||||
finalResults.totalTime = totalTime || 0; |
||||
finalResults.errors = []; |
||||
errors.forEach(function (error, _index) { |
||||
finalResults.errors.push({ context: error.context, value: error.value, message: error.errMsg }); |
||||
}); |
||||
next(null, finalResults); |
||||
}); |
||||
} |
||||
], finalCallback); |
||||
} |
||||
module.exports = runTestSources; |
||||
//# sourceMappingURL=runTestSources.js.map
|
@ -1 +0,0 @@ |
||||
{"version":3,"file":"runTestSources.js","sourceRoot":"","sources":["../src/runTestSources.ts"],"names":[],"mappings":";;;;AAAA,gDAAyB;AACzB,OAAO,CAAC,QAAQ,CAAC,CAAA;AAEjB,wCAA0C;AAC1C,wCAA0C;AAC1C,4DAAkC;AAElC,2BAA6B;AAC7B,oEAAsC;AAStC,IAAI,kBAAkB,GAAG;IACrB,IAAI,IAAI,GAAG,IAAI,IAAI,EAAE,CAAA;IACrB,IAAI,CAAC,WAAW,CAAC,IAAI,yBAAQ,EAAE,CAAC,CAAA;IAChC,OAAO,IAAI,CAAA;AACf,CAAC,CAAA;AAED,SAAS,cAAc,CAAC,eAAe,EAAE,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,YAAY,EAAE,IAAI;IACpG,IAAI,GAAG,IAAI,IAAI,EAAE,CAAA;IACjB,IAAI,IAAI,GAAG,IAAI,CAAC,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AgB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,CAAA;gBACtC,CAAC,CAAC,CAAA;YACN,CAAC,EAAE,UAAU,GAAG;gBACZ,IAAI,GAAG,EAAE;oBACL,OAAO,IAAI,CAAC,GAAG,CAAC,CAAA;iBACnB;gBAED,IAAI,YAAY,GAAgB;oBAC5B,YAAY,EAAE,CAAC;oBACf,YAAY,EAAE,CAAC;oBACf,SAAS,EAAE,CAAC;oBACZ,MAAM,EAAE,EAAE;iBACb,CAAA;gBAED,YAAY,CAAC,YAAY,GAAG,YAAY,IAAI,CAAC,CAAA;gBAC7C,YAAY,CAAC,YAAY,GAAG,YAAY,IAAI,CAAC,CAAA;gBAC7C,YAAY,CAAC,SAAS,GAAG,SAAS,IAAI,CAAC,CAAA;gBACvC,YAAY,CAAC,MAAM,GAAG,EAAE,CAAA;gBAExB,MAAM,CAAC,OAAO,CAAC,UAAC,KAAK,EAAE,MAAM;oBACzB,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,EAAC,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,MAAM,EAAC,CAAC,CAAA;gBACjG,CAAC,CAAC,CAAA;gBAEF,IAAI,CAAC,IAAI,EAAE,YAAY,CAAC,CAAA;YAC5B,CAAC,CAAC,CAAA;QACN,CAAC;KACJ,EAAE,aAAa,CAAC,CAAA;AACrB,CAAC;AACD,iBAAS,cAAc,CAAC"} |
@ -1 +0,0 @@ |
||||
export default function runTest(testName: any, testObject: any, contractDetails: any, opts: any, testCallback: Function, resultsCallback: Function): void; |
@ -1,146 +0,0 @@ |
||||
"use strict"; |
||||
var __importDefault = (this && this.__importDefault) || function (mod) { |
||||
return (mod && mod.__esModule) ? mod : { "default": mod }; |
||||
}; |
||||
var __importStar = (this && this.__importStar) || function (mod) { |
||||
if (mod && mod.__esModule) return mod; |
||||
var result = {}; |
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; |
||||
result["default"] = mod; |
||||
return result; |
||||
}; |
||||
Object.defineProperty(exports, "__esModule", { value: true }); |
||||
var async_1 = __importDefault(require("async")); |
||||
var changeCase = __importStar(require("change-case")); |
||||
var web3_1 = __importDefault(require("web3")); |
||||
function getFunctionFullName(signature, methodIdentifiers) { |
||||
for (var method in methodIdentifiers) { |
||||
if (signature.replace('0x', '') === methodIdentifiers[method].replace('0x', '')) { |
||||
return method; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
function getOverridedSender(userdoc, signature, methodIdentifiers) { |
||||
var fullName = getFunctionFullName(signature, methodIdentifiers); |
||||
var match = /sender: account-+(\d)/g; |
||||
var accountIndex = userdoc.methods[fullName] ? match.exec(userdoc.methods[fullName].notice) : null; |
||||
return fullName && accountIndex ? accountIndex[1] : null; |
||||
} |
||||
function getAvailableFunctions(jsonInterface) { |
||||
return jsonInterface.reverse().filter(function (x) { return x.type === 'function'; }).map(function (x) { return x.name; }); |
||||
} |
||||
function getTestFunctions(jsonInterface) { |
||||
var specialFunctions = ['beforeAll', 'beforeEach', 'afterAll', 'afterEach']; |
||||
return jsonInterface.filter(function (x) { return specialFunctions.indexOf(x.name) < 0 && x.type === 'function'; }); |
||||
} |
||||
function createRunList(jsonInterface) { |
||||
var availableFunctions = getAvailableFunctions(jsonInterface); |
||||
var testFunctions = getTestFunctions(jsonInterface); |
||||
var runList = []; |
||||
if (availableFunctions.indexOf('beforeAll') >= 0) { |
||||
runList.push({ name: 'beforeAll', type: 'internal', constant: false }); |
||||
} |
||||
for (var _i = 0, testFunctions_1 = testFunctions; _i < testFunctions_1.length; _i++) { |
||||
var func = testFunctions_1[_i]; |
||||
if (availableFunctions.indexOf('beforeEach') >= 0) { |
||||
runList.push({ name: 'beforeEach', type: 'internal', constant: false }); |
||||
} |
||||
runList.push({ name: func.name, signature: func.signature, type: 'test', constant: func.constant }); |
||||
if (availableFunctions.indexOf('afterEach') >= 0) { |
||||
runList.push({ name: 'afterEach', type: 'internal', constant: false }); |
||||
} |
||||
} |
||||
if (availableFunctions.indexOf('afterAll') >= 0) { |
||||
runList.push({ name: 'afterAll', type: 'internal', constant: false }); |
||||
} |
||||
return runList; |
||||
} |
||||
function runTest(testName, testObject, contractDetails, opts, testCallback, resultsCallback) { |
||||
var runList = createRunList(testObject._jsonInterface); |
||||
var passingNum = 0; |
||||
var failureNum = 0; |
||||
var timePassed = 0; |
||||
var web3 = new web3_1.default(); |
||||
var userAgent = (typeof (navigator) !== 'undefined') && navigator.userAgent ? navigator.userAgent.toLowerCase() : '-'; |
||||
var isBrowser = !(typeof (window) === 'undefined' || userAgent.indexOf(' electron/') > -1); |
||||
if (!isBrowser) { |
||||
var signale = require('signale'); |
||||
signale.warn('DO NOT TRY TO ACCESS (IN YOUR SOLIDITY TEST) AN ACCOUNT GREATER THAN THE LENGTH OF THE FOLLOWING ARRAY (' + opts.accounts.length + ') :'); |
||||
signale.warn(opts.accounts); |
||||
signale.warn('e.g: the following code won\'t work in the current context:'); |
||||
signale.warn('TestsAccounts.getAccount(' + opts.accounts.length + ')'); |
||||
} |
||||
testCallback({ type: 'contract', value: testName, filename: testObject.filename }); |
||||
async_1.default.eachOfLimit(runList, 1, function (func, index, next) { |
||||
var sender; |
||||
if (func.signature) { |
||||
sender = getOverridedSender(contractDetails.userdoc, func.signature, contractDetails.evm.methodIdentifiers); |
||||
if (opts.accounts) { |
||||
sender = opts.accounts[sender]; |
||||
} |
||||
} |
||||
var sendParams; |
||||
if (sender) |
||||
sendParams = { from: sender }; |
||||
var method = testObject.methods[func.name].apply(testObject.methods[func.name], []); |
||||
var startTime = Date.now(); |
||||
if (func.constant) { |
||||
method.call(sendParams).then(function (result) { |
||||
var time = Math.ceil((Date.now() - startTime) / 1000.0); |
||||
if (result) { |
||||
testCallback({ type: 'testPass', value: changeCase.sentenceCase(func.name), time: time, context: testName }); |
||||
passingNum += 1; |
||||
timePassed += time; |
||||
} |
||||
else { |
||||
testCallback({ type: 'testFailure', value: changeCase.sentenceCase(func.name), time: time, errMsg: 'function returned false', context: testName }); |
||||
failureNum += 1; |
||||
} |
||||
next(); |
||||
}); |
||||
} |
||||
else { |
||||
method.send(sendParams).on('receipt', function (receipt) { |
||||
try { |
||||
var time = Math.ceil((Date.now() - startTime) / 1000.0); |
||||
var topic = web3_1.default.utils.sha3('AssertionEvent(bool,string)'); |
||||
var testPassed = false; |
||||
for (var i in receipt.events) { |
||||
var event_1 = receipt.events[i]; |
||||
if (event_1.raw.topics.indexOf(topic) >= 0) { |
||||
var testEvent = web3.eth.abi.decodeParameters(['bool', 'string'], event_1.raw.data); |
||||
if (!testEvent[0]) { |
||||
testCallback({ type: 'testFailure', value: changeCase.sentenceCase(func.name), time: time, errMsg: testEvent[1], context: testName }); |
||||
failureNum += 1; |
||||
return next(); |
||||
} |
||||
testPassed = true; |
||||
} |
||||
} |
||||
if (testPassed) { |
||||
testCallback({ type: 'testPass', value: changeCase.sentenceCase(func.name), time: time, context: testName }); |
||||
passingNum += 1; |
||||
} |
||||
return next(); |
||||
} |
||||
catch (err) { |
||||
console.log('error!'); |
||||
console.dir(err); |
||||
return next(err); |
||||
} |
||||
}).on('error', function (err) { |
||||
console.error(err); |
||||
next(err); |
||||
}); |
||||
} |
||||
}, function (error) { |
||||
resultsCallback(error, { |
||||
passingNum: passingNum, |
||||
failureNum: failureNum, |
||||
timePassed: timePassed |
||||
}); |
||||
}); |
||||
} |
||||
exports.default = runTest; |
||||
//# sourceMappingURL=testRunner.js.map
|
File diff suppressed because one or more lines are too long
Loading…
Reference in new issue