From 5b1b2f76ca2d680e43f25c1cccafd3bf2e6e9ed2 Mon Sep 17 00:00:00 2001 From: krlosMata Date: Tue, 15 Jan 2019 13:00:13 +0100 Subject: [PATCH] update smttestvectors.js --- .gitignore | 3 + package-lock.json | 177 ++++++++++++------- test/smttestvectors.js | 382 ++++++++++++++++++++++------------------- 3 files changed, 322 insertions(+), 240 deletions(-) diff --git a/.gitignore b/.gitignore index 50d8b98..c43d29d 100644 --- a/.gitignore +++ b/.gitignore @@ -60,6 +60,9 @@ typings/ # next.js build output .next +# Visual code configuration +.vscode + tmp .DS_Store \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 220a734..3c10258 100644 --- a/package-lock.json +++ b/package-lock.json @@ -37,9 +37,9 @@ } }, "acorn": { - "version": "6.0.4", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.0.4.tgz", - "integrity": "sha512-VY4i5EKSKkofY2I+6QLTbTTN/UvEQPCo6eiwzzSaSWfpaDhOmStMCMod6wmuPciNq+XS0faCglFu2lHZpdHUtg==" + "version": "6.0.5", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.0.5.tgz", + "integrity": "sha512-i33Zgp3XWtmZBMNvCr4azvOFeWVw1Rk6p3hfi3LUDvIFraOMywb1kAtrbi+med14m4Xfpqm3zRZMT+c0FNE7kg==" }, "acorn-jsx": { "version": "5.0.1", @@ -64,7 +64,7 @@ }, "ansi-escapes": { "version": "3.1.0", - "resolved": "http://registry.npmjs.org/ansi-escapes/-/ansi-escapes-3.1.0.tgz", + "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-3.1.0.tgz", "integrity": "sha512-UgAb8H9D41AQnu/PbWlCofQVcnV4Gs2bBJi9eZPxfU/hgglFh3SMDMENRIqdr7H6XFnXdoknctFByVsCOotTVw==" }, "ansi-regex": { @@ -389,18 +389,10 @@ "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz", "integrity": "sha1-0ygVQE1olpn4Wk6k+odV3ROpYEg=" }, - "caller-path": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/caller-path/-/caller-path-0.1.0.tgz", - "integrity": "sha1-lAhe9jWB7NPaqSREqP6U6CV3dR8=", - "requires": { - "callsites": "^0.2.0" - } - }, "callsites": { - "version": "0.2.0", - "resolved": "http://registry.npmjs.org/callsites/-/callsites-0.2.0.tgz", - "integrity": "sha1-r6uWJikQp/M8GaV3WCXGnzTjUMo=" + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.0.0.tgz", + "integrity": "sha512-tWnkwu9YEq2uzlBDI4RcLn8jrFvF9AOi8PxDNU3hZZjJcjkcRAq3vCI+vZcg1SuxISDYe86k9VZFwAxDiJGoAw==" }, "camelcase": { "version": "5.0.0", @@ -426,9 +418,9 @@ } }, "chalk": { - "version": "2.4.1", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.1.tgz", - "integrity": "sha512-ObN6h1v2fTJSmUXoS3nMQ92LbDK9be4TV+6G+omQlGJFdcUX5heKi1LZ1YnRMIgwTLEj3E24bT6tYni50rlCfQ==", + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", + "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", "requires": { "ansi-styles": "^3.2.1", "escape-string-regexp": "^1.0.5", @@ -870,9 +862,9 @@ "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=" }, "eslint": { - "version": "5.10.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-5.10.0.tgz", - "integrity": "sha512-HpqzC+BHULKlnPwWae9MaVZ5AXJKpkxCVXQHrFaRw3hbDj26V/9ArYM4Rr/SQ8pi6qUPLXSSXC4RBJlyq2Z2OQ==", + "version": "5.12.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-5.12.0.tgz", + "integrity": "sha512-LntwyPxtOHrsJdcSwyQKVtHofPHdv+4+mFwEe91r2V13vqpM8yLr7b1sW+Oo/yheOPkWYsYlYJCkzlFAt8KV7g==", "requires": { "@babel/code-frame": "^7.0.0", "ajv": "^6.5.3", @@ -891,6 +883,7 @@ "glob": "^7.1.2", "globals": "^11.7.0", "ignore": "^4.0.6", + "import-fresh": "^3.0.0", "imurmurhash": "^0.1.4", "inquirer": "^6.1.0", "js-yaml": "^3.12.0", @@ -905,7 +898,6 @@ "pluralize": "^7.0.0", "progress": "^2.0.0", "regexpp": "^2.0.1", - "require-uncached": "^1.0.3", "semver": "^5.5.1", "strip-ansi": "^4.0.0", "strip-json-comments": "^2.0.1", @@ -1102,17 +1094,27 @@ } }, "execa": { - "version": "0.10.0", - "resolved": "https://registry.npmjs.org/execa/-/execa-0.10.0.tgz", - "integrity": "sha512-7XOMnz8Ynx1gGo/3hyV9loYNPWM94jG3+3T3Y8tsfSstFmETmENCMU/A/zj8Lyaj1lkgEepKepvd6240tBRvlw==", + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/execa/-/execa-1.0.0.tgz", + "integrity": "sha512-adbxcyWV46qiHyvSp50TKt05tB4tK3HcmF7/nxfAdhnox83seTDbwnaqKO4sXRy7roHAIFqJP/Rw/AuEbX61LA==", "requires": { "cross-spawn": "^6.0.0", - "get-stream": "^3.0.0", + "get-stream": "^4.0.0", "is-stream": "^1.1.0", "npm-run-path": "^2.0.0", "p-finally": "^1.0.0", "signal-exit": "^3.0.0", "strip-eof": "^1.0.0" + }, + "dependencies": { + "get-stream": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-4.1.0.tgz", + "integrity": "sha512-GMat4EJ5161kIy2HevLlr4luNjBgvmj413KaQA7jt4V8B4RDsfpHk7WQ9GVqfYyyx8OS/L66Kox+rJRNklLK7w==", + "requires": { + "pump": "^3.0.0" + } + } } }, "express": { @@ -7610,9 +7612,9 @@ } }, "globals": { - "version": "11.9.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-11.9.0.tgz", - "integrity": "sha512-5cJVtyXWH8PiJPVLZzzoIizXx944O4OmRro5MWKx5fT4MgcN7OfaMutPeaTdJCCURwbWdhhcCWcKIffPnmTzBg==" + "version": "11.10.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-11.10.0.tgz", + "integrity": "sha512-0GZF1RiPKU97IHUO5TORo9w1PwrH/NBPl+fS7oMLdaTRiYmYbwK4NWoZWrAdd0/abG9R2BU+OiwyQpTpE6pdfQ==" }, "got": { "version": "7.1.0", @@ -7776,6 +7778,15 @@ "resolved": "https://registry.npmjs.org/ignore/-/ignore-4.0.6.tgz", "integrity": "sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==" }, + "import-fresh": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.0.0.tgz", + "integrity": "sha512-pOnA9tfM3Uwics+SaBLCNyZZZbK+4PTu0OPZtLlMIrv17EdBoC15S9Kn8ckJ9TZTyKb3ywNE5y1yeDxxGA7nTQ==", + "requires": { + "parent-module": "^1.0.0", + "resolve-from": "^4.0.0" + } + }, "imurmurhash": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", @@ -7930,9 +7941,9 @@ "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==" }, "js-yaml": { - "version": "3.12.0", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.12.0.tgz", - "integrity": "sha512-PIt2cnwmPfL4hKNwqeiuz4bKfnzHTBv6HyVgjahA6mPLwPDzjDWrplJBMjHUFxku/N3FlmrbyPclad+I+4mJ3A==", + "version": "3.12.1", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.12.1.tgz", + "integrity": "sha512-um46hB9wNOKlwkHgiuyEVAybXBjwFUV0Z/RaHJblRd9DXltue9FTYvzCr9ErQrK9Adz5MU4gHWVaNUfdmrC8qA==", "requires": { "argparse": "^1.0.7", "esprima": "^4.0.0" @@ -8150,7 +8161,7 @@ }, "minimist": { "version": "0.0.10", - "resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz", "integrity": "sha1-3j+YVD2/lggr5IrRoMfNqDYwHc8=", "dev": true }, @@ -8393,18 +8404,18 @@ } }, "os-locale": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/os-locale/-/os-locale-3.0.1.tgz", - "integrity": "sha512-7g5e7dmXPtzcP4bgsZ8ixDVqA7oWYuEz4lOSujeWyliPai4gfVDiFIcwBg3aGCPnmSGfzOKTK3ccPn0CKv3DBw==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/os-locale/-/os-locale-3.1.0.tgz", + "integrity": "sha512-Z8l3R4wYWM40/52Z+S265okfFj8Kt2cC2MKY+xNi3kFs+XGI7WXu/I309QQQYbRW4ijiZ+yxs9pqEhJh0DqW3Q==", "requires": { - "execa": "^0.10.0", + "execa": "^1.0.0", "lcid": "^2.0.0", "mem": "^4.0.0" } }, "os-tmpdir": { "version": "1.0.2", - "resolved": "http://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", + "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=" }, "p-cancelable": { @@ -8424,13 +8435,13 @@ }, "p-is-promise": { "version": "1.1.0", - "resolved": "http://registry.npmjs.org/p-is-promise/-/p-is-promise-1.1.0.tgz", + "resolved": "https://registry.npmjs.org/p-is-promise/-/p-is-promise-1.1.0.tgz", "integrity": "sha1-nJRWmJ6fZYgBewQ01WCXZ1w9oF4=" }, "p-limit": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.0.0.tgz", - "integrity": "sha512-fl5s52lI5ahKCernzzIyAP0QAZbGIovtVHGwpcu1Jr/EpzLVDI2myISHwGqK7m8uQFugVWSrbxH7XnhGtvEc+A==", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.1.0.tgz", + "integrity": "sha512-NhURkNcrVB+8hNfLuysU8enY5xn2KXphsHBaC2YmRNTZRc7RWusw6apSpdEj3jo4CMb6W9nrF6tTnsJsJeyu6g==", "requires": { "p-try": "^2.0.0" } @@ -8456,6 +8467,14 @@ "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.0.0.tgz", "integrity": "sha512-hMp0onDKIajHfIkdRk3P4CdCmErkYAxxDtP3Wx/4nZ3aGlau2VKh3mZpcuFkH27WQkL/3WBCPOktzA9ZOAnMQQ==" }, + "parent-module": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.0.tgz", + "integrity": "sha512-8Mf5juOMmiE4FcmzYc4IaiS9L3+9paz2KOiXzkRviCP6aDmN49Hz6EMWz0lGNp9pX80GvvAuLADtyGfW/Em3TA==", + "requires": { + "callsites": "^3.0.0" + } + }, "parse-asn1": { "version": "5.1.1", "resolved": "http://registry.npmjs.org/parse-asn1/-/parse-asn1-5.1.1.tgz", @@ -8609,6 +8628,15 @@ "safe-buffer": "^5.1.2" } }, + "pump": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz", + "integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==", + "requires": { + "end-of-stream": "^1.1.0", + "once": "^1.3.1" + } + }, "punycode": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", @@ -8739,19 +8767,10 @@ "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-1.0.1.tgz", "integrity": "sha1-l/cXtp1IeE9fUmpsWqj/3aBVpNE=" }, - "require-uncached": { - "version": "1.0.3", - "resolved": "http://registry.npmjs.org/require-uncached/-/require-uncached-1.0.3.tgz", - "integrity": "sha1-Tg1W1slmL9MeQwEcS5WqSZVUIdM=", - "requires": { - "caller-path": "^0.1.0", - "resolve-from": "^1.0.0" - } - }, "resolve-from": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-1.0.1.tgz", - "integrity": "sha1-Jsv+k10a7uq7Kbw/5a6wHpPUQiY=" + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", + "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==" }, "restore-cursor": { "version": "2.0.0", @@ -9080,7 +9099,7 @@ }, "strip-eof": { "version": "1.0.0", - "resolved": "http://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz", + "resolved": "https://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz", "integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=" }, "strip-hex-prefix": { @@ -9125,9 +9144,9 @@ } }, "table": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/table/-/table-5.1.1.tgz", - "integrity": "sha512-NUjapYb/qd4PeFW03HnAuOJ7OMcBkJlqeClWxeNlQ0lXGSb52oZXGzkO0/I0ARegQ2eUT1g2VDJH0eUxDRcHmw==", + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/table/-/table-5.2.1.tgz", + "integrity": "sha512-qmhNs2GEHNqY5fd2Mo+8N1r2sw/rvTAAvBZTaTx+Y7PHLypqyrxr1MdIu0pLw6Xvl/Gi4ONu/sdceP8vvUjkyA==", "requires": { "ajv": "^6.6.1", "lodash": "^4.17.11", @@ -9283,6 +9302,14 @@ "mime-types": "~2.1.18" } }, + "typedarray-to-buffer": { + "version": "3.1.5", + "resolved": "https://registry.npmjs.org/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz", + "integrity": "sha512-zdu8XMNEDepKKR+XYOXAVPtWui0ly0NtohUscw+UmaHiAWT8hrV1rr//H6V+0DvJ3OQ19S979M0laLfX8rm82Q==", + "requires": { + "is-typedarray": "^1.0.0" + } + }, "ultron": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ultron/-/ultron-1.1.1.tgz", @@ -9690,6 +9717,31 @@ } } }, + "websocket": { + "version": "git://github.com/frozeman/WebSocket-Node.git#6c72925e3f8aaaea8dc8450f97627e85263999f2", + "from": "git://github.com/frozeman/WebSocket-Node.git#browserifyCompatible", + "requires": { + "debug": "^2.2.0", + "nan": "^2.3.3", + "typedarray-to-buffer": "^3.1.2", + "yaeti": "^0.0.6" + }, + "dependencies": { + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "requires": { + "ms": "2.0.0" + } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + } + } + }, "which": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", @@ -9711,7 +9763,7 @@ }, "wrap-ansi": { "version": "2.1.0", - "resolved": "http://registry.npmjs.org/wrap-ansi/-/wrap-ansi-2.1.0.tgz", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-2.1.0.tgz", "integrity": "sha1-2Pw9KE3QV5T+hJc8rs3Rz4JP3YU=", "requires": { "string-width": "^1.0.1", @@ -9743,7 +9795,7 @@ }, "strip-ansi": { "version": "3.0.1", - "resolved": "http://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", "requires": { "ansi-regex": "^2.0.0" @@ -9830,6 +9882,11 @@ "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz", "integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==" }, + "yaeti": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/yaeti/-/yaeti-0.0.6.tgz", + "integrity": "sha1-8m9ITXJoTPQr7ft2lwqhYI+/lXc=" + }, "yargs": { "version": "12.0.5", "resolved": "https://registry.npmjs.org/yargs/-/yargs-12.0.5.tgz", diff --git a/test/smttestvectors.js b/test/smttestvectors.js index a95d1b6..3e73b22 100644 --- a/test/smttestvectors.js +++ b/test/smttestvectors.js @@ -9,6 +9,29 @@ const expect = chai.expect; const bigInt = snarkjs.bigInt; +const bytesToHex = function (buff) { + return `0x${buff.toString("hex")}`; +}; + +const hexToBytes = function (hex) { + if (hex.substr(0, 2) === "0x") { + return Buffer.from(hex.substr(2), "hex"); + } + + return Buffer.from(hex, "hex"); +}; + +function bigIntToBuffer(number) { + const buff = Buffer.alloc(32); + let pos = buff.length - 1; + while (!number.isZero()) { + buff[pos] = number.and(255); + number = number.shiftRight(8); + pos -= 1; + } + return buff; +} + function stringifyBigInts(o) { if ((typeof(o) == "bigint") || (o instanceof bigInt)) { return o.toString(10); @@ -25,10 +48,10 @@ function stringifyBigInts(o) { } } -function newEntryFromInts(a, b, c, d) { +function newEntryFromBigInts(a, b, c, d) { return { - hi: mimcjs.hash(c, d), - hv: mimcjs.hash(a, b), + hi: mimcjs.multiHash([c, d]), + hv: mimcjs.multiHash([a, b]), }; } @@ -40,192 +63,191 @@ function smtHash(arr) { return r; } -describe("SMT Javascript test", function () { +describe("[sparse-merkle-tree] Javascript test", function () { + this.timeout(100000); before( async () => { }); - it("test MIMC7", async() => { - //const h = mimcjs.multiHash(1,2,3); - //const h = smtHash([1,2,3]); - //console.log(h.toString(10)); - -const mimcjs = require("../src/mimc7.js"); -const snarkjs = require("snarkjs"); -const bigInt = snarkjs.bigInt; -const smt = require("../src/smt.js"); - -h = mimcjs.hash(1,2,91); -console.log(h); - -function smtHash(arr) { - let r = bigInt(0); - for (let i=0; i { + const entries = [bigInt(12), bigInt(45), bigInt(78), bigInt(41)]; + const test = entries.slice(2); + const hi = mimcjs.multiHash(entries.slice(2)); + const hiHex = bytesToHex(bigIntToBuffer(hi)); + //"0x0a546e62170e636895398e3831a7834affd35adad67016ff2d5215828e643aaf" }); - //it("Should calculate hindex", async() => { - // const entry = newEntryFromInts(12, 45, 78, 41); - // //console.log(entry.hi.toString(16)); - // expect(entry.hi.toString(16)).to.be. - // equal("114438e8321f62c4a1708f443a5a66f9c8fcb0958e7b7008332b71442610b7a0"); - //}); - //it("Should insert 2 elements and empty them", async () => { - // const tree = await smt.newMemEmptyTrie(); - // const key1 = bigInt(111); - // const value1 = bigInt(222); - // const key2 = bigInt(333); - // const value2 = bigInt(444); + // it("Add one claim", async () => { + // const entries = newEntryFromBigInts(bigInt(12), bigInt(45), bigInt(78), bigInt(41)); + // const tree = await smt.newMemEmptyTrie(); + // const key1 = entries.hi; + // const value1 = entries.hv; - // await tree.insert(key1,value1); - // await tree.insert(key2,value2); - // await tree.delete(key2); - // await tree.delete(key1); - - // assert(tree.root.isZero()); - //}); - - //it("Should insert 3 elements in dferent order and should be the same", async () => { - // const keys = [bigInt(8), bigInt(9), bigInt(32)]; - // const values = [bigInt(88), bigInt(99), bigInt(3232)]; - // const tree1 = await smt.newMemEmptyTrie(); - // const tree2 = await smt.newMemEmptyTrie(); - // const tree3 = await smt.newMemEmptyTrie(); - // const tree4 = await smt.newMemEmptyTrie(); - // const tree5 = await smt.newMemEmptyTrie(); - // const tree6 = await smt.newMemEmptyTrie(); - - // await tree1.insert(keys[0],values[0]); - // await tree1.insert(keys[1],values[1]); - // await tree1.insert(keys[2],values[2]); - - // await tree2.insert(keys[0],values[0]); - // await tree2.insert(keys[2],values[2]); - // await tree2.insert(keys[1],values[1]); - - // await tree3.insert(keys[1],values[1]); - // await tree3.insert(keys[0],values[0]); - // await tree3.insert(keys[2],values[2]); - - // await tree4.insert(keys[1],values[1]); - // await tree4.insert(keys[2],values[2]); - // await tree4.insert(keys[0],values[0]); - - // await tree5.insert(keys[2],values[2]); - // await tree5.insert(keys[0],values[0]); - // await tree5.insert(keys[1],values[1]); - - // await tree6.insert(keys[2],values[2]); - // await tree6.insert(keys[1],values[1]); - // await tree6.insert(keys[0],values[0]); - - // assert(tree1.root.equals(tree2.root)); - // assert(tree2.root.equals(tree3.root)); - // assert(tree3.root.equals(tree4.root)); - // assert(tree4.root.equals(tree5.root)); - // assert(tree5.root.equals(tree6.root)); - - // assert.equal(Object.keys(tree1.db.nodes).length, Object.keys(tree2.db.nodes).length); - // assert.equal(Object.keys(tree2.db.nodes).length, Object.keys(tree3.db.nodes).length); - // assert.equal(Object.keys(tree3.db.nodes).length, Object.keys(tree4.db.nodes).length); - // assert.equal(Object.keys(tree4.db.nodes).length, Object.keys(tree5.db.nodes).length); - // assert.equal(Object.keys(tree5.db.nodes).length, Object.keys(tree6.db.nodes).length); - - // await tree1.delete(keys[0]); - // await tree1.delete(keys[1]); - // await tree2.delete(keys[1]); - // await tree2.delete(keys[0]); - // assert(tree1.root.equals(tree2.root)); - - // await tree3.delete(keys[0]); - // await tree3.delete(keys[2]); - // await tree4.delete(keys[2]); - // await tree4.delete(keys[0]); - // assert(tree3.root.equals(tree4.root)); - - // await tree5.delete(keys[1]); - // await tree5.delete(keys[2]); - // await tree6.delete(keys[2]); - // await tree6.delete(keys[1]); - // assert(tree5.root.equals(tree6.root)); - - // await tree1.delete(keys[2]); - // await tree2.delete(keys[2]); - // await tree3.delete(keys[1]); - // await tree4.delete(keys[1]); - // await tree5.delete(keys[0]); - // await tree6.delete(keys[0]); - - // assert(tree1.root.isZero()); - // assert(tree2.root.isZero()); - // assert(tree3.root.isZero()); - // assert(tree4.root.isZero()); - // assert(tree5.root.isZero()); - // assert(tree6.root.isZero()); - - // assert.equal(Object.keys(tree1.db.nodes).length, 0); - // assert.equal(Object.keys(tree2.db.nodes).length, 0); - // assert.equal(Object.keys(tree3.db.nodes).length, 0); - // assert.equal(Object.keys(tree4.db.nodes).length, 0); - // assert.equal(Object.keys(tree5.db.nodes).length, 0); - // assert.equal(Object.keys(tree6.db.nodes).length, 0); - //}); - - //it("Insert and remove 100 numbers randomly", async () => { - // function perm(a) { - // const arr = a.slice(); - // const rArr = []; - // for (let i=0; i { - // const tree1 = await smt.newMemEmptyTrie(); - // const tree2 = await smt.newMemEmptyTrie(); - - // await tree1.insert(8,88); - // await tree1.insert(9,99,); - // await tree1.insert(32,3232); - - // await tree2.insert(8,888); - // await tree2.insert(9,999); - // await tree2.insert(32,323232); - - // await tree1.update(8, 888); - // await tree1.update(9, 999); - // await tree1.update(32, 323232); - - // assert(tree1.root.equals(tree2.root)); + // await tree.insert(key1,value1); + // const root = tree.root; + // const rootBuff = bigIntToBuffer(root); + // const rootHex = bytesToHex(rootBuff); + // //0x2e4bd3b61579f9ed4d814dfa4228c743b853fb6d0b5d6a80735bd5aab579231f + // assert(tree.root.isZero()); //}); }); +// describe("SMT Javascript test", function () { +// this.timeout(100000); +// before( async () => { +// }); + +// it("Should insert 2 elements and empty them", async () => { +// const tree = await smt.newMemEmptyTrie(); +// const key1 = bigInt(111); +// const value1 = bigInt(222); +// const key2 = bigInt(333); +// const value2 = bigInt(444); + +// await tree.insert(key1,value1); +// await tree.insert(key2,value2); +// await tree.delete(key2); +// await tree.delete(key1); + +// assert(tree.root.isZero()); +// }); + +// it("Should insert 3 elements in dferent order and should be the same", async () => { +// const keys = [bigInt(8), bigInt(9), bigInt(32)]; +// const values = [bigInt(88), bigInt(99), bigInt(3232)]; +// const tree1 = await smt.newMemEmptyTrie(); +// const tree2 = await smt.newMemEmptyTrie(); +// const tree3 = await smt.newMemEmptyTrie(); +// const tree4 = await smt.newMemEmptyTrie(); +// const tree5 = await smt.newMemEmptyTrie(); +// const tree6 = await smt.newMemEmptyTrie(); + +// await tree1.insert(keys[0],values[0]); +// await tree1.insert(keys[1],values[1]); +// await tree1.insert(keys[2],values[2]); + +// await tree2.insert(keys[0],values[0]); +// await tree2.insert(keys[2],values[2]); +// await tree2.insert(keys[1],values[1]); + +// await tree3.insert(keys[1],values[1]); +// await tree3.insert(keys[0],values[0]); +// await tree3.insert(keys[2],values[2]); + +// await tree4.insert(keys[1],values[1]); +// await tree4.insert(keys[2],values[2]); +// await tree4.insert(keys[0],values[0]); + +// await tree5.insert(keys[2],values[2]); +// await tree5.insert(keys[0],values[0]); +// await tree5.insert(keys[1],values[1]); + +// await tree6.insert(keys[2],values[2]); +// await tree6.insert(keys[1],values[1]); +// await tree6.insert(keys[0],values[0]); + +// assert(tree1.root.equals(tree2.root)); +// assert(tree2.root.equals(tree3.root)); +// assert(tree3.root.equals(tree4.root)); +// assert(tree4.root.equals(tree5.root)); +// assert(tree5.root.equals(tree6.root)); + +// assert.equal(Object.keys(tree1.db.nodes).length, Object.keys(tree2.db.nodes).length); +// assert.equal(Object.keys(tree2.db.nodes).length, Object.keys(tree3.db.nodes).length); +// assert.equal(Object.keys(tree3.db.nodes).length, Object.keys(tree4.db.nodes).length); +// assert.equal(Object.keys(tree4.db.nodes).length, Object.keys(tree5.db.nodes).length); +// assert.equal(Object.keys(tree5.db.nodes).length, Object.keys(tree6.db.nodes).length); + +// await tree1.delete(keys[0]); +// await tree1.delete(keys[1]); +// await tree2.delete(keys[1]); +// await tree2.delete(keys[0]); +// assert(tree1.root.equals(tree2.root)); + +// await tree3.delete(keys[0]); +// await tree3.delete(keys[2]); +// await tree4.delete(keys[2]); +// await tree4.delete(keys[0]); +// assert(tree3.root.equals(tree4.root)); + +// await tree5.delete(keys[1]); +// await tree5.delete(keys[2]); +// await tree6.delete(keys[2]); +// await tree6.delete(keys[1]); +// assert(tree5.root.equals(tree6.root)); + +// await tree1.delete(keys[2]); +// await tree2.delete(keys[2]); +// await tree3.delete(keys[1]); +// await tree4.delete(keys[1]); +// await tree5.delete(keys[0]); +// await tree6.delete(keys[0]); + +// assert(tree1.root.isZero()); +// assert(tree2.root.isZero()); +// assert(tree3.root.isZero()); +// assert(tree4.root.isZero()); +// assert(tree5.root.isZero()); +// assert(tree6.root.isZero()); + +// assert.equal(Object.keys(tree1.db.nodes).length, 0); +// assert.equal(Object.keys(tree2.db.nodes).length, 0); +// assert.equal(Object.keys(tree3.db.nodes).length, 0); +// assert.equal(Object.keys(tree4.db.nodes).length, 0); +// assert.equal(Object.keys(tree5.db.nodes).length, 0); +// assert.equal(Object.keys(tree6.db.nodes).length, 0); +// }); + +// it("Insert and remove 100 numbers randomly", async () => { +// function perm(a) { +// const arr = a.slice(); +// const rArr = []; +// for (let i=0; i { +// const tree1 = await smt.newMemEmptyTrie(); +// const tree2 = await smt.newMemEmptyTrie(); + +// await tree1.insert(8,88); +// await tree1.insert(9,99,); +// await tree1.insert(32,3232); + +// await tree2.insert(8,888); +// await tree2.insert(9,999); +// await tree2.insert(32,323232); + +// await tree1.update(8, 888); +// await tree1.update(9, 999); +// await tree1.update(32, 323232); + +// assert(tree1.root.equals(tree2.root)); +// }); + +// }); +