How to use TestSpecs method in tracetest

Best JavaScript code snippet using tracetest

suite-tooth.js

Source:suite-tooth.js Github

copy

Full Screen

1const _ = require('lodash')2const stringifyObject = require('stringify-object')3//const SuiteTap = require('./tap')4const tap = require('tap')5const BEFORE_EACH = '__beforeEach'6const BEFORE_ALL = '__beforeAll'7const AFTER_EACH = '__afterEach'8const AFTER_ALL = '__afterAll'9const SKIP = '__skip'10const ONLY = '__only'11const TEST_PREFIX_ONLY = 'ONLY'12const TEST_PREFIX_SKIP = 'SKIP'13const isMagicKey = k => [BEFORE_EACH, BEFORE_ALL, AFTER_EACH, AFTER_ALL, SKIP, ONLY].find(x => x === k)14const mergeCopy = (ctx, newCtx) => Object.assign({}, ctx, newCtx)15async function executeTestSuite(testSpecs, _options={}, _ctx={}, ) {16 ctx = await executeWithTap(testSpecs, _ctx, [], _options)17 return ctx18}19async function executeWithTap(testSpecs, ctx, path=[], options={}) {20 try {21 const res = await _executeWithTap(testSpecs, path, test, ctx)22 test.end()23 return res24 } catch (e) {25 console.error('Test suite failed: ', e)26 }27}28function hasDescFlaggedAsOnly(testSpecs, isRoot=true) {29 if (!isRoot && isOnlyNode(testSpecs)) {30 return true31 }32 // figure out if any tests are marked as "only" so that "only mode" can be enabled in node-tap33 if (_.isFunction(testSpecs)) {34 return false35 } else if (_.isArray(testSpecs)) {36 return false37 } else if (_.isObject(testSpecs)) {38 const tests = _.chain(testSpecs)39 .toPairs()40 .filter(([k, v]) => !isMagicKey(k))41 .value()42 if (testSpecs[SKIP]) {43 return false44 }45 return !!tests.find(function([pathKey, test]) {46 return pathKey.startsWith(TEST_PREFIX_ONLY) || hasDescFlaggedAsOnly(test, false)47 })48 } else {49 throw new Error('Invalid test spec format' + testSpecs.toString())50 }51}52function withoutMagicKeys(obj) {53 return _.chain(testSpecs)54 .toPairs()55 .filter(([k, test]) => !isMagicKey(k))56 //.filter(([k, test]) => !test[SKIP])57 .value()58}59function isTestObject(obj) {60 return _.isObject(obj) && !_.isArray(obj) && !_.isFunction(obj);61}62function isOnlyNode(obj, description) {63 return obj[ONLY] || description.startsWith(TEST_PREFIX_ONLY);64}65/*66 * a test plan is a data structure specifying the exact list of tests to be67 * run, as well as information how to run them.68 * eg.69 *70 *71 * [72 * {73 * description,74 * fn,75 * type, //eg. TEST, BEFORE, AFTER, etc76 * }77 * ]78 */79async function generateTestPlan(testSpecs, path) {80 const pathStr = _pathToName(path)81 const toExecute = []82 if (testSpecs[SKIP]) {83 return []84 }85 const tests = _.chain(testSpecs)86 .toPairs()87 .filter(([k, test]) => !isMagicKey(k))88 .filter(([k, test]) => !test[SKIP])89 .value()90 const requireOnly = hasDescFlaggedAsOnly(testSpecs)91 const beforeAll = testSpecs[BEFORE_ALL] && tests.length ? _arrayWrap(testSpecs[BEFORE_ALL]) : []92 const afterAll = testSpecs[AFTER_ALL] && tests.length ? _arrayWrap(testSpecs[AFTER_ALL]) : []93 //AOEU: you were in the middle of modifying the code below94 // to return a test plan rather than to execute the tests95 // directly.96 //97 // if (beforeAll) {98 // await chainPromises(beforeAll.map(async function(hook) {99 // const newCtx = await hook(ctx)100 // ctx = mergeCopy(ctx, newCtx)101 // }))102 // }103 // if (testSpecs[BEFORE_EACH]) {104 // const beforeEachHooks = _arrayWrap(testSpecs[BEFORE_EACH])105 // beforeEachHooks.forEach(hook => {106 // tapTest.beforeEach(function(done) {107 // _withPromise(hook(ctx)).then((newCtx) => {108 // ctx = mergeCopy(ctx, newCtx)109 // done()110 // })111 // })112 // })113 // }114 // if (testSpecs[AFTER_EACH]) {115 // const afterEachHooks = _arrayWrap(testSpecs[AFTER_EACH])116 // afterEachHooks.forEach(hook => {117 // tapTest.afterEach(function(done) {118 // _withPromise(hook(ctx)).then((newCtx) => {119 // ctx = mergeCopy(ctx, newCtx)120 // done()121 // })122 // })123 // })124 // }125 // try {126 // const testThenables = tests.filter(([pathKey, test]) => {127 // return !(test.__skip || pathKey.startsWith(TEST_PREFIX_SKIP))128 // }).map(async function([pathKey, test]) {129 // if (pathKey.startsWith(TEST_PREFIX_ONLY)) {130 // test = only(test)131 // }132 // const newPath = path.concat([pathKey])133 // const pathStr = pathKey134 // await tapTest.test(pathStr, async (subTest) => {135 // try {136 // const newCtx = await _executeWithTap(test, newPath, subTest, ctx)137 // ctx = mergeCopy(ctx, newCtx)138 // subTest.end()139 // } catch (e) {140 // console.error('error: ', e)141 // subTest.end()142 // }143 // })144 // })145 // await chainPromises(testThenables)146 // } catch (e) {147 // console.log('error:', e)148 // }149 // if (afterAll) {150 // await chainPromises(afterAll.map(async function(hook) {151 // const newCtx = await hook(ctx)152 // ctx = mergeCopy(ctx, newCtx)153 // }))154 // }155 // } else {156 // const msg = 'test plan cant be nil'157 // console.error(msg)158 // throw new Error(msg)159 // }160 // } catch (e) {161 // console.error('Test execution failure: ', e)162 // throw e163 // }164 // return ctx165}166async function _executeWithTap(testSpecs, path, parentTapTest, _ctx={}) {167 const pathStr = _pathToName(path)168 let ctx = _ctx169 let tapTest = parentTapTest170 try {171 if (_.isFunction(testSpecs) || testSpecs.__testFn) {172 const fn = testSpecs.__testFn || testSpecs173 try {174 const newCtx = await fn(ctx, tapTest)175 ctx = mergeCopy(ctx, newCtx)176 } catch (e) {177 //console.log('Error while individual test run:', e)178 tapTest.error(e)179 }180 } else if (_.isArray(testSpecs) || testSpecs.__testArray) {181 const testArray = testSpecs.__testArray || testSpecs182 const onlyRequired = !!testArray.find((testFn) => testFn[ONLY])183 const testProms = testArray.filter((_testFn) => {184 return !onlyRequired || _testFn[ONLY]185 }).map((_testFn, i) => {186 const testFn = _testFn.__testFn || _testFn187 return tapTest.test(`${pathStr}-${i}`, async function(tapSubTest) {188 try {189 const newCtx = await testFn(ctx, tapSubTest)190 ctx = mergeCopy(ctx, newCtx)191 tapSubTest.end()192 } catch (e) {193 console.log('error while running test in series:', e)194 tapSubTest.fail(e.message)195 tapSubTest.end()196 throw e197 }198 })199 })200 return chainPromises(testProms).then(() => {201 return ctx202 })203 } else if (testSpecs) {204 if (testSpecs[SKIP]) {205 tap.skip(pathStr)206 return ctx207 }208 let tests = _.chain(testSpecs)209 .toPairs()210 .filter(([k, test]) => !isMagicKey(k))211 .filter(([k, test]) => !test[SKIP])212 .value()213 const requireOnly = hasDescFlaggedAsOnly(testSpecs)214 if (requireOnly) {215 tests = tests.filter(([_k, test]) => (test[ONLY] || _k.startsWith(TEST_PREFIX_ONLY)) || hasDescFlaggedAsOnly(test))216 }217 if (!tests.length) {218 return ctx219 }220 const beforeAll = testSpecs[BEFORE_ALL] && tests.length ? _arrayWrap(testSpecs[BEFORE_ALL]) : []221 const afterAll = testSpecs[AFTER_ALL] && tests.length ? _arrayWrap(testSpecs[AFTER_ALL]) : []222 if (beforeAll) {223 await chainPromises(beforeAll.map(async function(hook) {224 const newCtx = await hook(ctx)225 ctx = mergeCopy(ctx, newCtx)226 }))227 }228 if (testSpecs[BEFORE_EACH]) {229 const beforeEachHooks = _arrayWrap(testSpecs[BEFORE_EACH])230 beforeEachHooks.forEach(hook => {231 tapTest.beforeEach(function(done) {232 _withPromise(hook(ctx)).then((newCtx) => {233 ctx = mergeCopy(ctx, newCtx)234 done()235 })236 })237 })238 }239 if (testSpecs[AFTER_EACH]) {240 const afterEachHooks = _arrayWrap(testSpecs[AFTER_EACH])241 afterEachHooks.forEach(hook => {242 tapTest.afterEach(function(done) {243 _withPromise(hook(ctx)).then((newCtx) => {244 ctx = mergeCopy(ctx, newCtx)245 done()246 })247 })248 })249 }250 try {251 const testThenables = tests.filter(([pathKey, test]) => {252 return !(test.__skip || pathKey.startsWith(TEST_PREFIX_SKIP))253 }).map(async function([pathKey, test]) {254 if (pathKey.startsWith(TEST_PREFIX_ONLY)) {255 test = only(test)256 }257 const newPath = path.concat([pathKey])258 const pathStr = pathKey259 await tapTest.test(pathStr, async (subTest) => {260 try {261 const newCtx = await _executeWithTap(test, newPath, subTest, ctx)262 ctx = mergeCopy(ctx, newCtx)263 subTest.end()264 } catch (e) {265 console.error('error: ', e)266 subTest.end()267 }268 })269 })270 await chainPromises(testThenables)271 } catch (e) {272 console.log('error:', e)273 }274 if (afterAll) {275 await chainPromises(afterAll.map(async function(hook) {276 const newCtx = await hook(ctx)277 ctx = mergeCopy(ctx, newCtx)278 }))279 }280 } else {281 const msg = 'test plan cant be nil'282 console.error(msg)283 throw new Error(msg)284 }285 } catch (e) {286 console.error('Test execution failure: ', e)287 throw e288 }289 return ctx290}291async function executeRootSuite(suiteSpecs, options={}) {292 const tapSpec = require('tap-spec')293 const tapTest = new tap.Test()294 options.nodeTapTest = tapTest295 tapTest.pipe(tapSpec()).pipe(process.stdout)296 const ctx = await executeTestSuite(suiteSpecs, options)297}298function skip(testSpec) {299 if (_.isFunction(testSpec)) {300 return {301 __testFn: testSpec,302 [SKIP]: true,303 }304 } else if (testSpec) {305 return Object.assign({}, testSpec, {306 [SKIP]: true,307 })308 }309}310function only(testSpec) {311 if (_.isFunction(testSpec)) {312 return {313 __testFn: testSpec,314 [ONLY]: true,315 }316 } else if (testSpec) {317 return Object.assign({}, testSpec, {318 [ONLY]: true,319 })320 }321}322module.exports = {323 executeTestSuite,324 suite: executeTestSuite,325 executeRootSuite,326 only,327 skip,328}329// testing "middleware"330// The test plan is a tree structure that defines a plan of testing.331//332// Middleware:333// where at each level there can be one or more test middleware. the middleware could work by calling a callback, which would allow them to get access to the result of that test.334// this would allow a very extendable testing scenario.335//336// One middleware pattern: each middleware runs and can influence the "context" (eg. ctx) for inbound tests and the "result" of running the test. However, to make337// it behave more intuitively, both the result and context must be objects (ie. not arrays). The context at i+1 is just the result a key-by-key merge of the i into i-1.338//339// Most of the time the middleware will just be creating some data and merging it into a key340//341// Maybe every test would be a middleware. Libraries and functionality would have the same structure.342//343// possible not to use exception throwing?344//345// every async must be called out346//347function _arrayWrap(inp) {348 return _.isArray(inp) ? inp : [inp]349}350function _pathToName(path) {351 if (_.isArray(path)) {352 return path.join(' > ')353 } else {354 return path355 }356}357function _withPromise(x) {358 x = x || {}359 return !!x.then ? x : Promise.resolve(x)360}361function chainPromises(promises) {362 let p = Promise.resolve()363 promises.forEach(_p => {364 p = p.then(() => _p)365 })366 return p367}368// taken from previous version of code. it pregenerates a test plan369// rather than executing everything inline.370// function _testPlan(testSpecs, path, isTest) {371// const withIndent = str => _.times(path.length * 4, () => ' ').join('') + str372//373// //console.log(withIndent(`----------------------------------`))374// //console.log(withIndent(`PATH: ${path}`))375// const pathStr = path.join(' | ')376// if (_.isFunction(testSpecs)) {377// return {378// path,379// thunk: testSpecs,380// isTest,381// }382// } else if (_.isArray(testSpecs)){383// if (testSpecs.find(x => !_.isFunction(x))) {384// throw new Error('Cant have object test plans inside of an array')385// }386//387// return testSpecs.map((plan, i) => _testPlan(plan, path.concat([`${i}`]), isTest))388// } else if (testSpecs) {389// const tests = _.chain(testSpecs)390// .toPairs()391// .filter(([k, v]) => !isMagicKey(k))392// //.tap((x) => console.log('x: ', x))393// .value()394//395//396// if (testSpecs[SKIP]) return []397// const beforeAll = testSpecs[BEFORE_ALL] && tests.length ? [_testPlan(testSpecs[BEFORE_ALL], path.concat([BEFORE_ALL]), false)] : []398// const afterAll = testSpecs[AFTER_ALL] && tests.length ? [_testPlan(testSpecs[AFTER_ALL], path.concat([AFTER_ALL]), false)] : []399//400// let r = [401// ...beforeAll,402// ...tests.map(([k, v]) => {403// const beforeEach = testSpecs[BEFORE_EACH] ? _testPlan(testSpecs[BEFORE_EACH], path.concat([BEFORE_EACH]), false) : []404// const afterEach = testSpecs[AFTER_EACH] ? _testPlan(testSpecs[AFTER_EACH], path.concat([AFTER_EACH]), false) : []405// const tests = _testPlan(v, path.concat([k]), isTest)406//407// const objectRes = [408// ...beforeEach,409// tests,410// ...afterEach,411// ]412//413// //console.log('objectRes:', objectRes)414// return objectRes415// }),416// ...afterAll,417// ]418//419// return r420// } else {421// throw new Error('test plan cant be nil')422// }...

Full Screen

Full Screen

test.js

Source:test.js Github

copy

Full Screen

1const bre = require("@nomiclabs/buidler");2const { expect } = require("chai");3const child_process = require('child_process');4const fs = require('fs');5const quadb = '../quadb';6if (!fs.existsSync(quadb)) {7 console.error();8 console.error(`The quadb binary does not exist: ${quadb}`);9 console.error(`Please compile it, and then try running tests again`);10 console.error(` https://github.com/hoytech/quadrable#building`);11 console.error();12 process.exit(1);13}14let testSpecs = [];15testSpecs.push({16 desc: 'single branch inclusion',17 data: {18 a: 'b',19 b: 'c',20 },21 inc: ['a'],22 non: [],23 err: ['b'],24});25testSpecs.push({26 desc: '1000 records, both types of non-inclusion',27 data: makeData(1000, i => [i+1, i+1]),28 inc: ['3', '4'],29 non: [30 '5000', // WitnessEmpty31 '5001', // WitnessLeaf32 ],33 err: ['b'],34});35testSpecs.push({36 desc: 'larger number of strands',37 data: makeData(1000, i => [i+1, i+1]),38 inc: Array.from(Array(50).keys()).map(i => `${i+1}`),39});40testSpecs.push({41 desc: 'long key/value',42 data: {43 ['key'.repeat(100)]: 'value'.repeat(1000),44 ['key'.repeat(101)]: 'value'.repeat(1004),45 },46 inc: [47 'key'.repeat(100),48 'key'.repeat(101),49 ],50});51testSpecs.push({52 desc: 'put update left side',53 data: {54 a: 'b',55 b: 'c',56 },57 inc: ['a'],58 put: [59 ['a', 'hello'],60 ],61});62testSpecs.push({63 desc: 'put update right side',64 data: {65 a: 'b',66 b: 'c',67 },68 inc: ['b'],69 put: [70 ['b', 'hello'],71 ],72});73testSpecs.push({74 desc: 'put both sides',75 data: {76 a: 'b',77 b: 'c',78 },79 inc: ['a', 'b'],80 put: [81 ['a', 'hello'],82 ['b', 'hello'],83 ],84});85testSpecs.push({86 desc: 'put both sides, other order',87 data: {88 a: 'b',89 b: 'c',90 },91 inc: ['a', 'b'],92 put: [93 ['b', 'hello'],94 ['a', 'hello'],95 ],96});97testSpecs.push({98 desc: '1000 records, update a few of them',99 data: makeData(1000, i => [i+1, i+1]),100 inc: ['200', '201', '202'],101 put: [102 ['200', 'new value for 200'],103 ['201', 'new value for 201'],104 ['202', 'new value for 202'],105 ],106});107testSpecs.push({108 desc: 'add record to WitnessEmpty',109 data: makeData(1000, i => [i+1, i+1]),110 non: ['5000'],111 put: [112 ['5000', 'new value for 5000'],113 ],114});115testSpecs.push({116 desc: 'add record, split WitnessLeaf',117 data: {118 a: 'b',119 b: 'c',120 },121 non: ['x'],122 put: [123 ['x', 'new value for x'],124 ],125});126testSpecs.push({127 desc: 'add record, split WitnessLeaf, with extra branch',128 data: {129 a: 'b',130 b: 'c',131 },132 non: ['y'],133 put: [134 ['y', 'new value for y'],135 ],136});137testSpecs.push({138 desc: '1000 records, add record, split WitnessLeaf',139 data: makeData(1000, i => [i+1, i+1]),140 non: ['5001'],141 put: [142 ['5001', 'new value for 5001'],143 ],144});145testSpecs.push({146 desc: 'basic push test',147 intData: ['a', 'b', 'c'],148 intInc: [1],149 push: ['d'],150});151testSpecs.push({152 desc: 'push from empty',153 intData: [],154 intInc: [],155 push: ['a', 'b', 'c', 'd', 'e', 'f', 'g'],156});157testSpecs.push({158 desc: 'bigger push test',159 intData: [...Array(1000).keys()].map(i => `item${i}`),160 intInc: [500, 501, 502],161 push: ['another item', 'another'],162});163if (process.env.GAS_USAGE) {164 let firstRow = true;165 for (let n of [1, 10, 100, 1000, 10000, 100000, 1000000]) {166 testSpecs.push({167 desc: `GAS_USAGE: ${n} records in db`,168 gasUsageTest: true,169 data: makeData(n, i => [i+1, i+1]),170 inc: ['1'],171 put: [['1', '2']],172 preAction: () => {173 if (!firstRow) return;174 firstRow = false;175 console.error("\n\n\n");176 console.error(`| DB Size | Average Depth | Calldata (gas) | Import (gas) | Query (gas) | Update (gas) | Total (gas) |`);177 console.error(`| --- | --- | --- | --- | --- | --- | --- |`);178 },179 logGas: (r, proofSize) => {180 let calldata = proofSize * 16;181 let total = calldata + parseInt(r[0]) + parseInt(r[1]) + parseInt(r[2]);182 console.error(`| ${n} | ${Math.round(Math.log2(n) * 10) / 10} | ${calldata} | ${r[0]} | ${r[1]} | ${r[2]} | ${total} |`);183 },184 });185 }186}187if (process.env.GAS_USAGE) {188 let dbSize = 1000000;189 let avgDepth = Math.log2(dbSize);190 let firstRow = true;191 for (let n of [1, 2, 4, 8, 16, 32, 64, 128]) {192 let keys = Array.from(Array(n).keys()).map(i => `${i+1}`);193 testSpecs.push({194 desc: `GAS_USAGE: ${n} strands`,195 gasUsageTest: true,196 data: makeData(dbSize, i => [i+1, i+1]),197 inc: keys,198 put: keys.map(k => [k, `${k} ${n}`]),199 manualDbInit: true,200 preAction: (quadb) => {201 if (!firstRow) {202 quadb('fork --from gas-usage-strand-test');203 return;204 }205 firstRow = false;206 quadb('checkout gas-usage-strand-test');207 {208 let input = '';209 for (let i = 0; i < dbSize; i++) {210 input += `${i+1},${i+1}\n`;211 }212 quadb('import', { input, });213 }214 quadb('fork');215 console.error("\n\n\n");216 console.error(`| Num Strands | Approx Witnesses | Calldata (gas) | Import (gas) | Query (gas) | Update (gas) | Total (gas) |`);217 console.error(`| --- | --- | --- | --- | --- | --- | --- |`);218 },219 logGas: (r, proofSize) => {220 let calldata = proofSize * 16;221 let total = calldata + parseInt(r[0]) + parseInt(r[1]) + parseInt(r[2]);222 console.error(`| ${n} | ${Math.round(n * avgDepth * 10) / 10} | ${calldata} | ${r[0]} | ${r[1]} | ${r[2]} | ${total} |`);223 },224 });225 }226}227describe("Quadrable Test Suite", function() {228 let quadb_dir = './quadb-test-dir';229 let quadb_cmd = `${quadb} --db ${quadb_dir}`;230 child_process.execSync(`mkdir -p ${quadb_dir}`);231 child_process.execSync(`rm -f ${quadb_dir}/*.mdb`);232 let specsDevMode = testSpecs.filter(s => s.dev);233 if (specsDevMode.length) {234 testSpecs = specsDevMode;235 console.log("RUNNING IN DEV MODE");236 }237 let origSpecsLen = testSpecs.length;238 testSpecs = testSpecs.filter(s => !s.skip);239 if (origSpecsLen !== testSpecs.length) console.log("SKIPPING ONE OR MORE TESTS");240 if (process.env.GAS_USAGE) testSpecs = testSpecs.filter(s => s.gasUsageTest);241 for (let spec of testSpecs) {242 it(spec.desc, async function() {243 const TestHarness = await ethers.getContractFactory("TestHarness");244 const testHarness = await TestHarness.deploy();245 await testHarness.deployed();246 let quadb = (cmd, opts) => {247 if (!opts) opts = {};248 return child_process.execSync(`${quadb_cmd} ${cmd}`, { ...opts, });249 };250 if (!spec.manualDbInit) quadb(`checkout`);251 if (spec.preAction) spec.preAction(quadb);252 let rootHex, proofHex;253 let logGas = (res) => {254 if (process.env.GAS_USAGE) console.log(" GAS:", res[3].map(g => g.toNumber()));255 if (spec.logGas) spec.logGas(res[3], proofHex.length - 2);256 };257 {258 if (!spec.manualDbInit) {259 if (spec.intData) {260 let input = '';261 for (let item of spec.intData) {262 input += `${item}\n`;263 }264 quadb(`push --stdin`, { input, });265 } else {266 let input = '';267 for (let key of Object.keys(spec.data)) {268 input += `${key},${spec.data[key]}\n`;269 }270 quadb(`import`, { input, });271 }272 }273 rootHex = quadb(`root`).toString().trim();274 let proofKeys;275 if (spec.intData) proofKeys = spec.intInc.join(' ');276 else proofKeys = (spec.inc || []).concat(spec.non || []).join(' ');277 proofHex = quadb(`exportProof --hex ${spec.intData ? '--int --pushable' : ''} -- ${proofKeys}`).toString().trim();278 }279 let updateKeys = [];280 let updateVals = [];281 for (let p of (spec.put || [])) {282 updateKeys.push(Buffer.from(p[0]));283 updateVals.push(Buffer.from(p[1]));284 }285 for (let p of (spec.push || [])) {286 updateVals.push(Buffer.from(p));287 }288 let res = await testHarness.testProof(proofHex, (spec.inc || []).map(i => Buffer.from(i)), spec.intInc || [], updateKeys, updateVals);289 expect(res[0]).to.equal(rootHex);290 logGas(res);291 for (let i = 0; i < (spec.inc || []).length; i++) {292 let valHex = res[1][i];293 valHex = valHex.substr(2); // remove 0x prefix294 expect(Buffer.from(valHex, 'hex').toString()).to.equal(spec.data[spec.inc[i]]);295 }296 for (let i = 0; i < (spec.intInc || []).length; i++) {297 let valHex = res[1][i];298 valHex = valHex.substr(2); // remove 0x prefix299 expect(Buffer.from(valHex, 'hex').toString()).to.equal(spec.intData[spec.intInc[i]]);300 }301 if (spec.non && spec.non.length) {302 let res = await testHarness.testProof(proofHex, spec.non.map(i => Buffer.from(i)), spec.intNon || [], [], []);303 logGas(res);304 for (let i = 0; i < spec.non.length; i++) {305 expect(res[1][i]).to.equal('0x');306 }307 }308 for (let e of (spec.err || [])) {309 let threw;310 try {311 await testHarness.testProof(proofHex, [Buffer.from(e)], [], [], []);312 } catch (e) {313 threw = '' + e;314 }315 expect(threw).to.not.be.undefined;316 expect(threw).to.contain("incomplete tree");317 }318 if (spec.push && spec.push.length) {319 let input = '';320 for (let p of (spec.push || [])) {321 input += `${p}\n`;322 }323 quadb(`push --stdin`, { input, });324 } else if (spec.put && spec.put.length) {325 let input = '';326 for (let p of (spec.put || [])) {327 input += `${p[0]},${p[1]}\n`;328 }329 quadb(`import`, { input, });330 }331 let newRootHex = quadb(`root`).toString().trim();332 expect(res[2]).to.equal(newRootHex);333 });334 }335});336function makeData(n, cb) {337 let output = {};338 for (let i of Array.from(Array(n).keys())) {339 let [k, v] = cb(i);340 output[k] = '' + v;341 }342 return output;...

Full Screen

Full Screen

main.js

Source:main.js Github

copy

Full Screen

1mocha.setup('bdd');2const resetMocha = () => {3 mocha.suite.suites = [];4 let testSpecs = document.getElementById('testSpecs');5 if (testSpecs) { testSpecs.remove() };6 testSpecs = document.createElement('script');7 testSpecs.src = './pow.spec.js';8 testSpecs.async = true;9 testSpecs.id = 'testSpecs';10 document.body.appendChild(testSpecs);11}12const startMocha = () => {13 document.getElementById('mocha').textContent = '';14 window.eval(CodeMirror1.getValue());15 window.eval(CodeMirror2.getValue());16 window.eval(CodeMirror3.getValue());17 mocha.checkLeaks();18 mocha.run();19 setTimeout(resetMocha, 1000);20};21const startBenchmark = () => {22 document.getElementById('benchmark-result').textContent = '';23 document.getElementById('benchmark-loading').textContent = 'Выполняется тест скорости...';24 document.getElementById('test').disabled = true;25 document.getElementById('test').textContent = 'Идёт тетирование...';26 let suite = new Benchmark.Suite;27 suite.add('pow1', new Function("return " + CodeMirror1.getValue())())28 .add('pow2', new Function("return " + CodeMirror2.getValue())())29 .add('pow3', new Function("return " + CodeMirror3.getValue())())30 .on('cycle', (event) => {31 let result = document.createElement("p");32 result.textContent = String(event.target);33 document.getElementById('benchmark-result').appendChild(result);34 })35 .on('complete', function () {36 let final = document.createElement("p");37 final.classList.add('fastest');38 final.textContent = 'Самое быстрое: ' + this.filter('fastest').map('name');39 document.getElementById('benchmark-result').appendChild(final);40 document.getElementById('benchmark-loading').textContent = '';41 document.getElementById('test').textContent = 'Начать тестирование';42 document.getElementById('test').disabled = false;43 })44 .run({45 'async': true46 });47}48const runTests = () => {49 try {50 startMocha();51 startBenchmark();52 } catch (err) {53 alert('Syntax error. Try again!');54 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var tracetest = require('tracetest');2tracetest.TestSpecs();3exports.TestSpecs = function() {4 console.log("TestSpecs");5}6exports.TestSpecs = function() {7 console.log("TestSpecs");8}9var tracetest = require('tracetest');10tracetest.TestSpecs();

Full Screen

Using AI Code Generation

copy

Full Screen

1var tracetest = require('tracetest');2var test = tracetest.TestSpecs();3test.addTest(1, 2, 3);4test.addTest(2, 3, 5);5test.addTest(3, 4, 7);6var result = test.runTest();7console.log(result);8var tracetest = require('tracetest');9var test = tracetest.TestSpecs();10test.addTest(1, 2, 3);11test.addTest(2, 3, 5);12test.addTest(3, 4, 7);13var result = test.runTest();14console.log(result);15var tracetest = require('tracetest');16var test = tracetest.TestSpecs();17test.addTest(1, 2, 3);18test.addTest(2, 3, 5);19test.addTest(3, 4, 7);20var result = test.runTest();21console.log(result);22var tracetest = require('tracetest');23var test = tracetest.TestSpecs();24test.addTest(1, 2, 3);25test.addTest(2, 3, 5);26test.addTest(3, 4, 7);27var result = test.runTest();28console.log(result);29var tracetest = require('tracetest');30var test = tracetest.TestSpecs();31test.addTest(1, 2, 3);32test.addTest(2, 3, 5);33test.addTest(3, 4, 7);34var result = test.runTest();35console.log(result);

Full Screen

Using AI Code Generation

copy

Full Screen

1var tracetest = require('tracetest');2tracetest.TestSpecs('testspecs.json');3{4 {5 }6}7var tracetest = require('tracetest');8tracetest.Test('Test 1', function () {9 tracetest.Assert(true);10});11var tracetest = require('tracetest');12tracetest.Test('Test 2', function () {13 tracetest.Assert(true);14});15{16 {17 },18 {19 }20}21var tracetest = require('tracetest');22tracetest.TestSpecs('testspecs.json');23tracetest.TestSpecs('testspecs2.json');24var tracetest = require('tracetest');25tracetest.TestSpecs('testspecs.json', function () {26 tracetest.TestSpecs('testspecs2.json');27});28tracetest.TestSpecs('testspecs.json', function () {29 tracetest.TestSpecs('testspecs2.json', function () {30 tracetest.TestSpecs('testspecs3.json');31 });32});33var tracetest = require('tracetest');34tracetest.TestSpecs('testspecs.json', function () {35 tracetest.TestSpecs('testspecs2.json', function () {36 tracetest.TestSpecs('testspecs3.json', function () {37 tracetest.TestSpecs('testspecs4.json');38 });39 });40});

Full Screen

Using AI Code Generation

copy

Full Screen

1var tracetest = require('tracetest');2var test = new tracetest.TestSpecs();3test.test('Test 1', function() {4 test.assert(true, 'This should pass');5 test.assert(false, 'This should fail');6});7test.test('Test 2', function() {8 test.assert(true, 'This should pass');9 test.assert(false, 'This should fail');10});11var tracetest = require('tracetest');12var test = new tracetest.TestSpecs();13test.test('Test 1', function() {14 test.assert(true, 'This should pass');15 test.assert(false, 'This should fail');16});17test.test('Test 2', function() {18 test.assert(true, 'This should pass');19 test.assert(false, 'This should fail');20});21var tracetest = require('tracetest');22var test = new tracetest.TestSpecs();23test.test('Test 1', function() {24 test.assert(true, 'This should pass');25 test.assert(false, 'This should fail');26});27test.test('Test 2', function() {28 test.assert(true, 'This should pass');29 test.assert(false, 'This should fail');30});31var tracetest = require('tracetest');32var test = new tracetest.TestSpecs();33test.test('Test 1', function() {34 test.assert(true, 'This should pass');35 test.assert(false, 'This should fail');36});37test.test('Test 2', function() {38 test.assert(true, 'This should pass');39 test.assert(false, 'This should fail');40});41var tracetest = require('tracetest');42var test = new tracetest.TestSpecs();43test.test('Test 1', function() {44 test.assert(true, 'This should pass');45 test.assert(false, 'This should fail');46});47test.test('Test 2', function() {48 test.assert(true, 'This should pass');49 test.assert(false, 'This should fail');

Full Screen

Using AI Code Generation

copy

Full Screen

1var tracetest = require('tracetest');2var testSpecs = tracetest.TestSpecs;3var specs = {4 'test1' : function (test) {5 test.ok(true, 'this assertion should pass');6 test.done();7 },8 'test2' : function (test) {9 test.ok(false, 'this assertion should fail');10 test.done();11 }12};13testSpecs(specs, function (results) {14 console.log(results);15});16var util = require('util');17var TestRunner = require('nodeunit').TestRunner;18var TestSpecs = function (specs, callback) {19 var testRunner = new TestRunner();20 var test = {};21 var testCases = {};22 var testCount = 0;23 var results = {};24 for (var spec in specs) {25 if (specs.hasOwnProperty(spec)) {26 test[spec] = function (test) {27 var spec = this.spec;28 test.expect(1);29 specs[spec](test);30 };31 testCases[spec] = test;32 testCount++;33 }34 }35 testRunner.run(testCases, {36 testDone: function (name, assertions) {37 results[name] = assertions;38 testCount--;39 if (testCount === 0) {40 callback(results);41 }42 }43 });44};45exports.TestSpecs = TestSpecs;

Full Screen

Using AI Code Generation

copy

Full Screen

1var tracetest = require("tracetest");2tracetest.TestSpecs([{3 "test": function() {4 var a = 1;5 var b = 2;6 tracetest.Assert(a + b === 3, "1 + 2 should be 3");7 }8}, {9 "test": function() {10 var a = 1;11 var b = 2;12 tracetest.Assert(a + b === 4, "1 + 2 should be 4");13 }14}]);15var tracetest = require("tracetest");16tracetest.TestSpecs([{17 "test": function() {18 var a = 1;19 var b = 2;20 tracetest.Assert(a + b === 3, "1 + 2 should be 3");21 }22}, {23 "test": function() {24 var a = 1;25 var b = 2;26 tracetest.Assert(a + b === 4, "1 + 2 should be 4");27 }28}]);29var tracetest = require("tracetest");30tracetest.TestSpecs([{31 "test": function() {32 var a = 1;33 var b = 2;34 tracetest.Assert(a + b === 3, "1 + 2 should be 3");35 }36}, {37 "test": function() {38 var a = 1;39 var b = 2;40 tracetest.Assert(a + b === 4, "1 + 2 should be 4");41 }42}]);

Full Screen

Using AI Code Generation

copy

Full Screen

1var tracetest = require('./tracetest.js');2tracetest.TestSpecs("Test 1", function() {3 var test1 = 1;4 var test2 = 2;5 var test3 = test1 + test2;6 tracetest.AssertTrue("Test 1", test3 == 3);7});8tracetest.TestSpecs("Test 2", function() {9 var test1 = 1;10 var test2 = 2;11 var test3 = test1 + test2;12 tracetest.AssertTrue("Test 2", test3 == 4);13});14tracetest.RunTests();15var tracetest = function() {16 var tests = [];17 var testResults = [];18 var testCount = 0;19 var TestSpecs = function(testName, testFunction) {20 tests.push({name: testName, test: testFunction});21 }22 var RunTests = function() {23 for (var i = 0; i < tests.length; i++) {24 var test = tests[i];25 test.test();26 }27 for (var i = 0; i < testResults.length; i++) {28 var testResult = testResults[i];29 if (testResult.passed) {30 console.log(testResult.name + ": PASSED");31 } else {32 console.log(testResult.name + ": FAILED");33 }34 }35 }36 var AssertTrue = function(testName, testResult) {37 testResults.push({name: testName, passed: testResult});38 }39 return {40 }41}();42module.exports = tracetest;

Full Screen

Using AI Code Generation

copy

Full Screen

1var tracetest = require('../index');2var path = require('path');3var fs = require('fs');4function TestSpecs() {5 var files = fs.readdirSync(path.join(__dirname, 'testspecs'));6 files.forEach(function (file) {7 var test = require('./testspecs/' + file);8 tracetest.test(test.name, test.test);9 });10}11module.exports = TestSpecs;12var test1 = {13 test: function (test) {14 test.ok(true);15 test.done();16 }17};18module.exports = test1;19var test2 = {20 test: function (test) {21 test.ok(true);22 test.done();23 }24};25module.exports = test2;26var test3 = {27 test: function (test) {28 test.ok(true);29 test.done();30 }31};32module.exports = test3;33var test4 = {34 test: function (test) {35 test.ok(true);36 test.done();37 }38};39module.exports = test4;40var test5 = {41 test: function (test) {42 test.ok(true);43 test.done();44 }45};46module.exports = test5;47var test6 = {48 test: function (test) {49 test.ok(true);50 test.done();51 }52};53module.exports = test6;54var test7 = {55 test: function (test) {56 test.ok(true);57 test.done();58 }59};60module.exports = test7;

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tracetest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful