How to use invalidPath method in wpt

Best JavaScript code snippet using wpt

state-util.test.js

Source:state-util.test.js Github

copy

Full Screen

1const {2 hasEnabledShardConfig,3 isWritablePathWithSharding,4 hasReservedChar,5 hasAllowedPattern,6 isValidStateLabel,7 isValidPathForStates,8 isValidJsObjectForStates,9 jsObjectToStateTree,10 stateTreeToJsObject,11 deleteStateTree,12 makeCopyOfStateTree,13 buildProofHashOfStateNode,14 setProofHashForStateTree,15 updateProofHashForPath,16} = require('../db/state-util');17const { HASH_DELIMITER } = require('../constants');18const ChainUtil = require('../chain-util');19const chai = require('chai');20const expect = chai.expect;21const assert = chai.assert;22describe("state-util", () => {23 describe("hasEnabledShardConfig", () => {24 it("when input without matched shard config returning false", () => {25 expect(hasEnabledShardConfig(jsObjectToStateTree(null))).to.equal(false);26 expect(hasEnabledShardConfig(jsObjectToStateTree({}))).to.equal(false);27 expect(hasEnabledShardConfig(jsObjectToStateTree({28 subtree: {29 path: "some value"30 },31 str: "string value"32 }33 ))).to.equal(false);34 expect(hasEnabledShardConfig(jsObjectToStateTree({35 subtree: {36 path: "some value",37 ".shard": {38 sharding_enabled: true39 }40 },41 str: "string value"42 }43 ))).to.equal(false);44 })45 it("when input with matched shard config returning false", () => {46 expect(hasEnabledShardConfig(jsObjectToStateTree({47 subtree: {48 path: "some value",49 },50 str: "string value",51 ".shard": {52 sharding_enabled: false53 }54 }55 ))).to.equal(false);56 })57 it("when input with shard config returning true", () => {58 expect(hasEnabledShardConfig(jsObjectToStateTree({59 subtree: {60 path: "some value",61 },62 str: "string value",63 ".shard": {64 sharding_enabled: true65 }66 }67 ))).to.equal(true);68 })69 })70 describe("isWritablePathWithSharding", () => {71 it("when non-writable path with shard config", () => {72 assert.deepEqual(isWritablePathWithSharding(73 ['some', 'path'],74 jsObjectToStateTree({75 some: {76 path: {77 ".shard": {78 sharding_enabled: true79 }80 }81 }82 })), {isValid: false, invalidPath: '/some/path'});83 assert.deepEqual(isWritablePathWithSharding(84 ['some', 'path'],85 jsObjectToStateTree({86 some: {87 other_path: true,88 ".shard": {89 sharding_enabled: true90 }91 }92 })), {isValid: false, invalidPath: '/some'});93 })94 it("when writable path w/o shard config", () => {95 assert.deepEqual(isWritablePathWithSharding(96 ['some', 'path'],97 jsObjectToStateTree({98 some: {99 path: true100 }101 })), {isValid: true, invalidPath: ''});102 assert.deepEqual(isWritablePathWithSharding(103 ['some', 'path'],104 jsObjectToStateTree({105 some: {106 other_path: true107 }108 })), {isValid: true, invalidPath: ''});109 })110 it("when writable path with shard config", () => {111 assert.deepEqual(isWritablePathWithSharding(112 ['some', 'path'],113 jsObjectToStateTree({114 some: {115 path: {116 ".shard": {117 sharding_enabled: false118 }119 }120 }121 })), {isValid: true, invalidPath: ''});122 assert.deepEqual(isWritablePathWithSharding(123 ['some', 'path'],124 jsObjectToStateTree({125 some: {126 other_path: true,127 ".shard": {128 sharding_enabled: false129 }130 }131 })), {isValid: true, invalidPath: ''});132 })133 it("when writable path through shard config", () => {134 assert.deepEqual(isWritablePathWithSharding(135 ['some', 'path', '.shard', 'sharding_enabled'],136 jsObjectToStateTree({137 some: {138 path: {139 ".shard": {140 sharding_enabled: true141 }142 }143 }144 })), {isValid: true, invalidPath: ''});145 assert.deepEqual(isWritablePathWithSharding(146 ['some', 'path', '.shard', 'proof_hash_map'],147 jsObjectToStateTree({148 some: {149 path: {150 ".shard": {151 sharding_enabled: true152 }153 }154 }155 })), {isValid: true, invalidPath: ''});156 })157 })158 describe("hasReservedChar", () => {159 it("when non-string input", () => {160 expect(hasReservedChar(null)).to.equal(false);161 expect(hasReservedChar(undefined)).to.equal(false);162 expect(hasReservedChar(true)).to.equal(false);163 expect(hasReservedChar(false)).to.equal(false);164 expect(hasReservedChar(0)).to.equal(false);165 expect(hasReservedChar([])).to.equal(false);166 expect(hasReservedChar({})).to.equal(false);167 })168 it("when string input returning false", () => {169 expect(hasReservedChar('')).to.equal(false);170 expect(hasReservedChar('abc')).to.equal(false);171 expect(hasReservedChar('ABC')).to.equal(false);172 expect(hasReservedChar('0')).to.equal(false);173 expect(hasReservedChar('true')).to.equal(false);174 expect(hasReservedChar('\u2000\u2E00')).to.equal(false);175 })176 it("when string input returning true", () => {177 expect(hasReservedChar('/')).to.equal(true);178 expect(hasReservedChar('/abc')).to.equal(true);179 expect(hasReservedChar('a/bc')).to.equal(true);180 expect(hasReservedChar('abc/')).to.equal(true);181 expect(hasReservedChar('\u2000/\u2E00')).to.equal(true);182 expect(hasReservedChar('.')).to.equal(true);183 expect(hasReservedChar('*')).to.equal(true);184 expect(hasReservedChar('$')).to.equal(true);185 expect(hasReservedChar('#')).to.equal(true);186 expect(hasReservedChar('{')).to.equal(true);187 expect(hasReservedChar('}')).to.equal(true);188 expect(hasReservedChar('[')).to.equal(true);189 expect(hasReservedChar(']')).to.equal(true);190 expect(hasReservedChar('\x00')).to.equal(true);191 expect(hasReservedChar('\x01')).to.equal(true);192 expect(hasReservedChar('\x02')).to.equal(true);193 expect(hasReservedChar('\x03')).to.equal(true);194 expect(hasReservedChar('\x04')).to.equal(true);195 expect(hasReservedChar('\x05')).to.equal(true);196 expect(hasReservedChar('\x06')).to.equal(true);197 expect(hasReservedChar('\x07')).to.equal(true);198 expect(hasReservedChar('\x08')).to.equal(true);199 expect(hasReservedChar('\x09')).to.equal(true);200 expect(hasReservedChar('\x0A')).to.equal(true);201 expect(hasReservedChar('\x0B')).to.equal(true);202 expect(hasReservedChar('\x0C')).to.equal(true);203 expect(hasReservedChar('\x0D')).to.equal(true);204 expect(hasReservedChar('\x0E')).to.equal(true);205 expect(hasReservedChar('\x0F')).to.equal(true);206 expect(hasReservedChar('\x10')).to.equal(true);207 expect(hasReservedChar('\x11')).to.equal(true);208 expect(hasReservedChar('\x12')).to.equal(true);209 expect(hasReservedChar('\x13')).to.equal(true);210 expect(hasReservedChar('\x14')).to.equal(true);211 expect(hasReservedChar('\x15')).to.equal(true);212 expect(hasReservedChar('\x16')).to.equal(true);213 expect(hasReservedChar('\x17')).to.equal(true);214 expect(hasReservedChar('\x18')).to.equal(true);215 expect(hasReservedChar('\x19')).to.equal(true);216 expect(hasReservedChar('\x1A')).to.equal(true);217 expect(hasReservedChar('\x1B')).to.equal(true);218 expect(hasReservedChar('\x1C')).to.equal(true);219 expect(hasReservedChar('\x1D')).to.equal(true);220 expect(hasReservedChar('\x1E')).to.equal(true);221 expect(hasReservedChar('\x1F')).to.equal(true);222 expect(hasReservedChar('\x7F')).to.equal(true);223 })224 })225 describe("hasAllowedPattern", () => {226 it("when non-string input", () => {227 expect(hasAllowedPattern(null)).to.equal(false);228 expect(hasAllowedPattern(undefined)).to.equal(false);229 expect(hasAllowedPattern(true)).to.equal(false);230 expect(hasAllowedPattern(false)).to.equal(false);231 expect(hasAllowedPattern(0)).to.equal(false);232 expect(hasAllowedPattern([])).to.equal(false);233 expect(hasAllowedPattern({})).to.equal(false);234 })235 it("when string input returning false", () => {236 expect(hasAllowedPattern('.')).to.equal(false);237 expect(hasAllowedPattern('$')).to.equal(false);238 expect(hasAllowedPattern('./')).to.equal(false);239 expect(hasAllowedPattern('$/')).to.equal(false);240 expect(hasAllowedPattern('a.')).to.equal(false);241 expect(hasAllowedPattern('a$')).to.equal(false);242 expect(hasAllowedPattern('a.b')).to.equal(false);243 expect(hasAllowedPattern('a$b')).to.equal(false);244 expect(hasAllowedPattern('..')).to.equal(false);245 expect(hasAllowedPattern('$$')).to.equal(false);246 expect(hasAllowedPattern('.$')).to.equal(false);247 expect(hasAllowedPattern('$.')).to.equal(false);248 expect(hasAllowedPattern('*a')).to.equal(false);249 expect(hasAllowedPattern('a*')).to.equal(false);250 })251 it("when string input returning true", () => {252 expect(hasAllowedPattern('.a')).to.equal(true);253 expect(hasAllowedPattern('$a')).to.equal(true);254 expect(hasAllowedPattern('*')).to.equal(true);255 })256 })257 describe("isValidStateLabel", () => {258 it("when non-string input", () => {259 expect(isValidStateLabel(null)).to.equal(false);260 expect(isValidStateLabel(undefined)).to.equal(false);261 expect(isValidStateLabel(true)).to.equal(false);262 expect(isValidStateLabel(false)).to.equal(false);263 expect(isValidStateLabel(0)).to.equal(false);264 expect(isValidStateLabel([])).to.equal(false);265 expect(isValidStateLabel({})).to.equal(false);266 })267 it("when string input returning false", () => {268 expect(isValidStateLabel('')).to.equal(false);269 expect(isValidStateLabel('.')).to.equal(false);270 expect(isValidStateLabel('$')).to.equal(false);271 expect(isValidStateLabel('/')).to.equal(false);272 })273 it("when string input returning true", () => {274 expect(isValidStateLabel('a')).to.equal(true);275 expect(isValidStateLabel('.a')).to.equal(true);276 expect(isValidStateLabel('$a')).to.equal(true);277 expect(isValidStateLabel('*')).to.equal(true);278 })279 })280 describe("isValidPathForStates", () => {281 it("when invalid input", () => {282 assert.deepEqual(isValidPathForStates([null]), {isValid: false, invalidPath: '/null'});283 assert.deepEqual(284 isValidPathForStates([undefined]), {isValid: false, invalidPath: '/undefined'});285 assert.deepEqual(isValidPathForStates([Infinity]), {isValid: false, invalidPath: '/null'});286 assert.deepEqual(isValidPathForStates([NaN]), {isValid: false, invalidPath: '/null'});287 assert.deepEqual(isValidPathForStates([true]), {isValid: false, invalidPath: '/true'});288 assert.deepEqual(isValidPathForStates([false]), {isValid: false, invalidPath: '/false'});289 assert.deepEqual(isValidPathForStates([0]), {isValid: false, invalidPath: '/0'});290 assert.deepEqual(isValidPathForStates(['']), {isValid: false, invalidPath: '/'});291 assert.deepEqual(isValidPathForStates(['', '', '']), {isValid: false, invalidPath: '/'});292 assert.deepEqual(isValidPathForStates([{}]), {isValid: false, invalidPath: '/{}'});293 assert.deepEqual(294 isValidPathForStates([{a: 'A'}]), {isValid: false, invalidPath: '/{"a":"A"}'});295 assert.deepEqual(isValidPathForStates([[]]), {isValid: false, invalidPath: '/[]'});296 assert.deepEqual(isValidPathForStates([['a']]), {isValid: false, invalidPath: '/["a"]'});297 assert.deepEqual(isValidPathForStates(['a', '/']), {isValid: false, invalidPath: '/a//'});298 assert.deepEqual(isValidPathForStates(['a', '.']), {isValid: false, invalidPath: '/a/.'});299 assert.deepEqual(isValidPathForStates(['a', '$']), {isValid: false, invalidPath: '/a/$'});300 assert.deepEqual(isValidPathForStates(['a', '*b']), {isValid: false, invalidPath: '/a/*b'});301 assert.deepEqual(isValidPathForStates(['a', 'b*']), {isValid: false, invalidPath: '/a/b*'});302 assert.deepEqual(isValidPathForStates(['a', '#']), {isValid: false, invalidPath: '/a/#'});303 assert.deepEqual(isValidPathForStates(['a', '{']), {isValid: false, invalidPath: '/a/{'});304 assert.deepEqual(isValidPathForStates(['a', '}']), {isValid: false, invalidPath: '/a/}'});305 assert.deepEqual(isValidPathForStates(['a', '[']), {isValid: false, invalidPath: '/a/['});306 assert.deepEqual(isValidPathForStates(['a', ']']), {isValid: false, invalidPath: '/a/]'});307 assert.deepEqual(308 isValidPathForStates(['a', '\x00']), {isValid: false, invalidPath: '/a/\x00'});309 assert.deepEqual(310 isValidPathForStates(['a', '\x1F']), {isValid: false, invalidPath: '/a/\x1F'});311 assert.deepEqual(312 isValidPathForStates(['a', '\x7F']), {isValid: false, invalidPath: '/a/\x7F'});313 })314 it("when valid input", () => {315 assert.deepEqual(isValidPathForStates(['a', 'b', 'c']), {isValid: true, invalidPath: ''});316 assert.deepEqual(317 isValidPathForStates(['0', 'true', 'false']), {isValid: true, invalidPath: ''});318 assert.deepEqual(isValidPathForStates(['a', '.b']), {isValid: true, invalidPath: ''});319 assert.deepEqual(isValidPathForStates(['a', '$b']), {isValid: true, invalidPath: ''});320 assert.deepEqual(isValidPathForStates(['a', '*']), {isValid: true, invalidPath: ''});321 })322 })323 describe("isValidJsObjectForStates", () => {324 it("when invalid input", () => {325 assert.deepEqual(isValidJsObjectForStates(undefined), {isValid: false, invalidPath: '/'});326 assert.deepEqual(isValidJsObjectForStates({}), {isValid: false, invalidPath: '/'});327 assert.deepEqual(isValidJsObjectForStates([]), {isValid: false, invalidPath: '/'});328 assert.deepEqual(isValidJsObjectForStates([1, 2, 3]), {isValid: false, invalidPath: '/'});329 assert.deepEqual(330 isValidJsObjectForStates(['a', 'b', 'c']), {isValid: false, invalidPath: '/'});331 assert.deepEqual(isValidJsObjectForStates({332 undef: undefined 333 }), {isValid: false, invalidPath: '/undef'});334 assert.deepEqual(335 isValidJsObjectForStates({336 empty_obj: {}337 }), {isValid: false, invalidPath: '/empty_obj'});338 assert.deepEqual(339 isValidJsObjectForStates({340 array: []341 }), {isValid: false, invalidPath: '/array'});342 assert.deepEqual(343 isValidJsObjectForStates({344 array: [1, 2, 3]345 }), {isValid: false, invalidPath: '/array'});346 assert.deepEqual(347 isValidJsObjectForStates({348 array: ['a', 'b', 'c']349 }), {isValid: false, invalidPath: '/array'});350 assert.deepEqual(351 isValidJsObjectForStates({352 'a': {353 '.': 'x'354 }355 }), {isValid: false, invalidPath: '/a/.'});356 assert.deepEqual(357 isValidJsObjectForStates({358 'a': {359 '$': 'x'360 }361 }), {isValid: false, invalidPath: '/a/$'});362 assert.deepEqual(363 isValidJsObjectForStates({364 'a': {365 '*b': 'x'366 }367 }), {isValid: false, invalidPath: '/a/*b'});368 assert.deepEqual(369 isValidJsObjectForStates({370 'a': {371 'b*': 'x'372 }373 }), {isValid: false, invalidPath: '/a/b*'});374 })375 it("when invalid input with deeper path", () => {376 assert.deepEqual(isValidJsObjectForStates({377 internal1: {378 internal2a: {379 internal3a: {380 str: 'str'381 }382 },383 internal2b: {384 internal3b: {385 undef: undefined 386 }387 },388 internal2c: {389 internal3c: {390 empty_obj: {}391 }392 },393 internal2d: {394 internal3d: {395 array: []396 }397 },398 }399 }), {isValid: false, invalidPath: '/internal1/internal2b/internal3b/undef'});400 })401 it("when valid input", () => {402 assert.deepEqual(isValidJsObjectForStates(10), {isValid: true, invalidPath: ''});403 assert.deepEqual(isValidJsObjectForStates("str"), {isValid: true, invalidPath: ''});404 assert.deepEqual(isValidJsObjectForStates(null), {isValid: true, invalidPath: ''});405 assert.deepEqual(isValidJsObjectForStates({406 bool: false,407 number: 10,408 str: 'str',409 empty_str: '',410 null: null,411 subobj1: {412 bool: true,413 number: 20,414 str: 'str2',415 empty_str: '',416 null: null,417 },418 subobj2: {419 bool: true,420 number: -10,421 str: 'str3',422 empty_str: '',423 null: null,424 }425 }), {isValid: true, invalidPath: ''});426 assert.deepEqual(isValidJsObjectForStates({427 "owners": {428 ".owner": {429 "owners": {430 "*": {431 "branch_owner": true,432 "write_function": true,433 "write_owner": true,434 "write_rule": true435 }436 }437 }438 },439 "rules": {440 ".write": true441 }442 }), {isValid: true, invalidPath: ''});443 assert.deepEqual(444 isValidJsObjectForStates({445 'a': {446 '.b': 'x'447 }448 }), {isValid: true, invalidPath: ''});449 assert.deepEqual(450 isValidJsObjectForStates({451 'a': {452 '$b': 'x'453 }454 }), {isValid: true, invalidPath: ''});455 assert.deepEqual(456 isValidJsObjectForStates({457 'a': {458 '*': 'x'459 }460 }), {isValid: true, invalidPath: ''});461 })462 })463 describe("jsObjectToStateTree / stateTreeToJsObject", () => {464 it("when valid input", () => {465 expect(stateTreeToJsObject(jsObjectToStateTree(true))).to.equal(true);466 expect(stateTreeToJsObject(jsObjectToStateTree(false))).to.equal(false);467 expect(stateTreeToJsObject(jsObjectToStateTree(10))).to.equal(10);468 expect(stateTreeToJsObject(jsObjectToStateTree('str'))).to.equal('str');469 expect(stateTreeToJsObject(jsObjectToStateTree(null))).to.equal(null);470 const stateObj = {471 bool: false,472 number: 10,473 str: 'str',474 empty_str: '',475 null: null,476 undef: undefined,477 empty_obj: {},478 subobj1: {479 bool: true,480 number: 20,481 str: 'str2',482 empty_str: '',483 null: null,484 undef: undefined,485 empty_obj: {},486 },487 subobj2: {488 bool: true,489 number: -10,490 str: 'str3',491 empty_str: '',492 null: null,493 undef: undefined,494 empty_obj: {},495 }496 };497 assert.deepEqual(stateTreeToJsObject(jsObjectToStateTree(stateObj)), {498 bool: false,499 number: 10,500 str: 'str',501 empty_str: '',502 null: null,503 undef: undefined,504 empty_obj: null,505 subobj1: {506 bool: true,507 number: 20,508 str: 'str2',509 empty_str: '',510 null: null,511 undef: undefined,512 empty_obj: null,513 },514 subobj2: {515 bool: true,516 number: -10,517 str: 'str3',518 empty_str: '',519 null: null,520 undef: undefined,521 empty_obj: null,522 }523 });524 })525 })526 describe("makeCopyOfStateTree", () => {527 it("when valid input", () => {528 const stateObj = {529 bool: false,530 number: 10,531 str: 'str',532 empty_str: '',533 null: null,534 undef: undefined,535 empty_obj: {},536 subobj1: {537 bool: true,538 number: 20,539 str: 'str2',540 empty_str: '',541 null: null,542 undef: undefined,543 empty_obj: {},544 },545 subobj2: {546 bool: true,547 number: -10,548 str: 'str3',549 empty_str: '',550 null: null,551 undef: undefined,552 empty_obj: {},553 }554 };555 const root = jsObjectToStateTree(stateObj);556 const copy = makeCopyOfStateTree(root);557 deleteStateTree(root);558 assert.deepEqual(stateTreeToJsObject(copy), {559 bool: false,560 number: 10,561 str: 'str',562 empty_str: '',563 null: null,564 undef: undefined,565 empty_obj: null,566 subobj1: {567 bool: true,568 number: 20,569 str: 'str2',570 empty_str: '',571 null: null,572 undef: undefined,573 empty_obj: null,574 },575 subobj2: {576 bool: true,577 number: -10,578 str: 'str3',579 empty_str: '',580 null: null,581 undef: undefined,582 empty_obj: null,583 }584 });585 })586 })587})588describe("state-util: a part of state Proof", () => {589 describe("buildProofHashOfStateNode", () => {590 it("tests a leaf node case", () => {591 expect(buildProofHashOfStateNode(jsObjectToStateTree(true)))592 .to.equal(ChainUtil.hashString(ChainUtil.toString(true)));593 expect(buildProofHashOfStateNode(jsObjectToStateTree(10)))594 .to.equal(ChainUtil.hashString(ChainUtil.toString(10)));595 expect(buildProofHashOfStateNode(jsObjectToStateTree(-200)))596 .to.equal(ChainUtil.hashString(ChainUtil.toString(-200)));597 expect(buildProofHashOfStateNode(jsObjectToStateTree('')))598 .to.equal(ChainUtil.hashString(ChainUtil.toString('')));599 expect(buildProofHashOfStateNode(jsObjectToStateTree('unittest')))600 .to.equal(ChainUtil.hashString(ChainUtil.toString('unittest')));601 expect(buildProofHashOfStateNode(jsObjectToStateTree(null)))602 .to.equal(ChainUtil.hashString(ChainUtil.toString(null)));603 expect(buildProofHashOfStateNode(jsObjectToStateTree(undefined)))604 .to.equal(ChainUtil.hashString(ChainUtil.toString(undefined)));605 });606 it("tests a NON-leaf node case", () => {607 const jsObject = {608 level0: {609 child1: 'value1',610 child2: 'value2',611 child3: 'value3'612 }613 };614 const level0Node = jsObjectToStateTree(jsObject).getChild('level0');615 const childLabels = level0Node.getChildLabels();616 const child1Node = level0Node.getChild(childLabels[0]);617 const child2Node = level0Node.getChild(childLabels[1]);618 const child3Node = level0Node.getChild(childLabels[2]);619 child1Node.setProofHash('proofHash1');620 child2Node.setProofHash('proofHash2');621 child3Node.setProofHash('proofHash3');622 const preimage = `${childLabels[0]}${HASH_DELIMITER}`623 + `${child1Node.getProofHash()}${HASH_DELIMITER}`624 + `${childLabels[1]}${HASH_DELIMITER}`625 + `${child2Node.getProofHash()}${HASH_DELIMITER}`626 + `${childLabels[2]}${HASH_DELIMITER}`627 + `${child3Node.getProofHash()}`;628 expect(buildProofHashOfStateNode(level0Node))629 .to.equal(ChainUtil.hashString(ChainUtil.toString(preimage)));630 });631 });632 describe("setProofHashForStateTree", () => {633 it("generates a proof hash along with the given stateTree", () => {634 const jsObject = {635 level0: {636 level1: {637 foo: 'bar',638 baz: 'caz'639 }640 },641 another_route: {642 test: 10643 }644 };645 const stateTree = jsObjectToStateTree(jsObject);646 const level0Node = stateTree.getChild('level0');647 const level1Node = level0Node.getChild('level1');648 const fooNode = level1Node.getChild('foo');649 const bazNode = level1Node.getChild('baz');650 setProofHashForStateTree(level0Node);651 expect(level0Node.getProofHash()).to.equal(buildProofHashOfStateNode(level0Node));652 expect(level1Node.getProofHash()).to.equal(buildProofHashOfStateNode(level1Node));653 expect(fooNode.getProofHash()).to.equal(buildProofHashOfStateNode(fooNode));654 expect(bazNode.getProofHash()).to.equal(buildProofHashOfStateNode(bazNode));655 expect(stateTree.getChild('another_route').getChild('test').getProofHash()).to.equal(null);656 expect(stateTree.getChild('another_route').getProofHash()).to.equal(null);657 expect(stateTree.getProofHash()).to.equal(null);658 });659 });660 describe("updateProofHashForPath", () => {661 it("updates proof hashes to the root", () => {662 const jsObject = {663 level0: {664 level1: {665 level2: {666 foo: 'bar',667 baz: 'caz'668 }669 },670 another_route: {671 test: -1000672 }673 }674 };675 const stateTree = jsObjectToStateTree(jsObject);676 const level0Node = stateTree.getChild('level0');677 const level1Node = level0Node.getChild('level1');678 const level2Node = level1Node.getChild('level2');679 const anotherNode = level0Node.getChild('another_route');680 updateProofHashForPath(['level0', 'level1'], stateTree);681 expect(level2Node.getChild('foo').getProofHash()).to.equal(null);682 expect(level2Node.getChild('baz').getProofHash()).to.equal(null);683 expect(level2Node.getProofHash()).to.equal(null);684 expect(anotherNode.getProofHash()).to.equal(null);685 expect(anotherNode.getChild('test').getProofHash()).to.equal(null);686 expect(level1Node.getProofHash()).to.equal(buildProofHashOfStateNode(level1Node));687 expect(level0Node.getProofHash()).to.equal(buildProofHashOfStateNode(level0Node));688 expect(stateTree.getProofHash()).to.equal(buildProofHashOfStateNode(stateTree));689 });690 });691 describe("makeCopyOfStateTree and deleteStateTree", () => {692 it("copy with proof", () => {693 const jsObject = {694 level0: {695 level1: {696 level2: {697 foo: 'bar',698 baz: 'caz'699 }700 },701 another_route: {702 test: -1000703 }704 }705 };706 const stateTree = jsObjectToStateTree(jsObject);707 setProofHashForStateTree(stateTree);708 const copyTree = makeCopyOfStateTree(stateTree);709 expect(copyTree.getProofHash()).to.equal(stateTree.getProofHash());710 });711 it("delete with proof", () => {712 const jsObject = {713 level0: {714 level1: {715 level2: {716 foo: 'bar',717 baz: 'caz'718 }719 },720 another_route: {721 test: -1000722 }723 }724 };725 const stateTree = jsObjectToStateTree(jsObject);726 setProofHashForStateTree(stateTree);727 deleteStateTree(stateTree);728 expect(stateTree.getProofHash()).to.equal(null);729 });730 });...

Full Screen

Full Screen

test.js

Source:test.js Github

copy

Full Screen

1var assert = require("assert");2var safe = require("../index");3describe("safe", function() {4 var nest = {5 foo: {6 bar: {7 baz: 1,8 qux: ["quux", "corge"]9 }10 }11 };12 var validPath = "foo.bar.baz";13 var invalidPath = "foo.bar.qux.2";14 var fallback = "grault";15 var callback = function() {16 console.log("nothing here!");17 return "grault";18 };19 it("should return value when the value is present", function() {20 assert.equal(safe(validPath, nest), 1);21 });22 it("should return fallback when the value is missing", function() {23 assert.equal(safe(invalidPath, nest, fallback), fallback);24 });25 it("should return fallback when arguments are invalid", function() {26 assert.equal(safe(1, nest, fallback), fallback);27 assert.equal(safe({ foo: "bar" }, nest, fallback), fallback);28 assert.equal(safe([1, 2, 3], nest, fallback), fallback);29 assert.equal(safe(validPath, 1, fallback), fallback);30 assert.equal(safe(validPath, 1, fallback), fallback);31 assert.equal(safe(invalidPath, "foo", fallback), fallback);32 assert.equal(safe(invalidPath, "foo", fallback), fallback);33 });34 it("should return undefined when no arguments are given", function() {35 assert.equal(safe(), undefined);36 });37 it("should return undefined when one argument is given", function() {38 assert.equal(safe(fallback), undefined);39 });40 it("should return fallback if it's a function", function() {41 assert.equal(safe(invalidPath, nest, callback), callback);42 assert.equal(safe(invalidPath, nest, callback()), callback());43 assert.equal(44 safe(45 invalidPath,46 nest,47 (function() {48 console.log("nothing here!");49 return "grault";50 })()51 ),52 "grault"53 );54 });...

Full Screen

Full Screen

App.js

Source:App.js Github

copy

Full Screen

1import React from 'react';2import './App.css';3import Home from './Components/Home/Home';4import {5 BrowserRouter as Router,6 Switch,7 Route,8} from "react-router-dom";9import PostDetail from './Components/PostsDetail/PostDetail';10import NavBar from './Components/NavBar/NavBar';11import InvalidPath from './Components/invalidpath/InvalidPath';12function App() {13 return (14 <div>15 <Router>16 <NavBar></NavBar>17 <Switch>18 <Route path="/post/postDetails/:id">19 <PostDetail></PostDetail>20 </Route>21 <Route exact path="/">22 <Home></Home>23 </Route>24 <Route path="*">25 <InvalidPath></InvalidPath>26 </Route>27 </Switch>28 </Router>29 </div>30 );31}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 console.log(data);4});5{ statusCode: 400,6 data: 'Unknown test option: invalidPath' }7{ statusCode: 400,8 data: 'Unknown test option: invalidPath' }

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2wpt.invalidPath(function(err, data) {3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9{ statusCode: 400,10 data: 'API Key is required' }

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3});4var wpt = require('wpt');5var wpt = new WebPageTest('www.webpagetest.org');6});7var wpt = require('wpt');8var wpt = new WebPageTest('www.webpagetest.org');9});10var wpt = require('wpt');11var wpt = new WebPageTest('www.webpagetest.org');12});13var wpt = require('wpt');14var wpt = new WebPageTest('www.webpagetest.org');15});16var wpt = require('wpt');17var wpt = new WebPageTest('www.webpagetest.org');18});19var wpt = require('wpt');20var wpt = new WebPageTest('www.webpagetest.org');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var options = {3 timelineParams: {4 },5};6var wpt = new WebPageTest('www.webpagetest.org', options.key);7wpt.runTest(testURL, options, function(err, data) {8 if (err) return console.log(err);9 console.log('Test initiated for ' + testURL);10 console.log('Test ID: ' + data.data.testId);11});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt.js');2wpt.getTesters('invalidPath', function (err, response) {3 if (err) {4 console.log(err);5 } else {6 console.log(response);7 }8});9{ message: 'Invalid API Key', statusCode: 401 }10var wpt = require('wpt.js');11wpt.getTesters('invalidPath', function (err, response) {12 if (err) {13 console.log(err);14 } else {15 console.log(response);16 }17});18{ message: 'Invalid API Key', statusCode: 401 }19var wpt = require('wpt.js');20wpt.getTesters('invalidPath', function (err, response) {21 if (err) {22 console.log(err);23 } else {24 console.log(response);25 }26});27{ message: 'Invalid API Key', statusCode: 401 }28var wpt = require('wpt.js');29wpt.getTesters('invalidPath', function (err, response) {30 if (err) {31 console.log(err);32 } else {33 console.log(response);34 }35});36{ message: 'Invalid API Key', statusCode: 401 }37var wpt = require('wpt.js');38wpt.getTesters('invalidPath', function (err, response) {39 if (err) {40 console.log(err);41 } else {42 console.log(response);43 }44});45{ message: 'Invalid API Key', statusCode: 401 }46var wpt = require('wpt.js');47wpt.getTesters('invalidPath', function (err, response) {48 if (err) {49 console.log(err);50 } else {51 console.log(response);52 }53});54{ message: 'Invalid API Key', statusCode: 401 }55var wpt = require('wpt.js');56wpt.getTesters('invalidPath', function (err, response) {57 if (err) {58 console.log(err);59 } else {

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 wpt 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