12 Commits

Author SHA1 Message Date
krlosMata
74a7e71c33 Wip update test vectors 2019-05-08 16:29:25 +02:00
krlosMata
d7f7243239 Wip update test vectors smt and mimc 2019-05-08 16:26:56 +02:00
krlosMata
ba2fc931af separate test for mimc and sparse-merkle-tree and update test 2019-05-08 15:21:09 +02:00
krlosMata
b6aa6e5c51 add test to smttestvectors 2019-05-08 15:21:09 +02:00
krlosMata
536268709a update smttestvectors.js 2019-05-08 15:21:09 +02:00
krlosMata
5b1b2f76ca update smttestvectors.js 2019-05-08 15:21:09 +02:00
Dhole
0f87cc7cae WIP smt test 2019-05-08 15:17:59 +02:00
krlosMata
5b7abbc4ec separate test for mimc and sparse-merkle-tree and update test 2019-01-15 15:55:30 +01:00
krlosMata
480d64987a add test to smttestvectors 2019-01-15 15:32:32 +01:00
krlosMata
b34c4228d9 update smttestvectors.js 2019-01-15 14:46:47 +01:00
krlosMata
130e3906fb update smttestvectors.js 2019-01-15 13:00:13 +01:00
Dhole
49244ea6b7 WIP smt test 2019-01-15 10:23:34 +01:00
4 changed files with 318 additions and 60 deletions

3
.gitignore vendored
View File

@@ -60,6 +60,9 @@ typings/
# next.js build output
.next
# Visual code configuration
.vscode
tmp
.DS_Store

177
package-lock.json generated
View File

@@ -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",

51
test/mimctestvectors.js Normal file
View File

@@ -0,0 +1,51 @@
const chai = require("chai");
const snarkjs = require("snarkjs");
const mimcjs = require("../src/mimc7.js");
const expect = chai.expect;
const bigInt = snarkjs.bigInt;
function bytesToHex(buff) {
return `0x${buff.toString("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;
}
describe("[mimc hash] Javascript test", function () {
this.timeout(100000);
before( async () => {
});
it("Mimc7 hash with 1 entry", () => {
const entries = [bigInt(12)];
const hash = mimcjs.multiHash(entries);
const hashHex = bytesToHex(bigIntToBuffer(hash));
expect(hashHex).to.be.equal("0x237c92644dbddb86d8a259e0e923aaab65a93f1ec5758b8799988894ac0958fd");
});
it("Mimc7 hash with 2 entries", () => {
const entries = [bigInt(12), bigInt(45), bigInt(78), bigInt(41)];
const hi = mimcjs.multiHash(entries.slice(2));
const hiHex = bytesToHex(bigIntToBuffer(hi));
expect(hiHex).to.be.equal("0x067f3202335ea256ae6e6aadcd2d5f7f4b06a00b2d1e0de903980d5ab552dc70");
const hv = mimcjs.multiHash(entries.slice(0, 2));
const hvHex = bytesToHex(bigIntToBuffer(hv));
expect(hvHex).to.be.equal("0x15ff7fe9793346a17c3150804bcb36d161c8662b110c50f55ccb7113948d8879");
});
it("Mimc7 hash with 4 entries", () => {
const entries = [bigInt(12), bigInt(45), bigInt(78), bigInt(41)];
const hash = mimcjs.multiHash(entries);
const hashHex = bytesToHex(bigIntToBuffer(hash));
expect(hashHex).to.be.equal("0x284bc1f34f335933a23a433b6ff3ee179d682cd5e5e2fcdd2d964afa85104beb");
});
});

147
test/smttestvectors.js Normal file
View File

@@ -0,0 +1,147 @@
const chai = require("chai");
const snarkjs = require("snarkjs");
const smt = require("../src/smt.js");
const mimcjs = require("../src/mimc7.js");
const expect = chai.expect;
const bigInt = snarkjs.bigInt;
function bytesToHex(buff) {
return `0x${buff.toString("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 newEntry(arr) {
return {
hi: mimcjs.multiHash(arr.slice(2)),
hv: mimcjs.multiHash(arr.slice(0, 2)),
};
}
describe("[sparse-merkle-tree] Javascript test", function () {
this.timeout(100000);
before( async () => {
});
it("Add one claim", async () => {
const claim = [bigInt(12), bigInt(45), bigInt(78), bigInt(41)];
const entries = newEntry(claim);
const tree = await smt.newMemEmptyTrie();
const key1 = entries.hi;
const value1 = entries.hv;
await tree.insert(key1,value1);
const root = tree.root;
const rootBuff = bigIntToBuffer(root);
expect(bytesToHex(rootBuff)).to.be.equal("0x2bf39430aa2482fc1e2f170179c8cab126b0f55f71edc8d333f4c80cb4e798f5");
});
/*
it("Add two claims", async () => {
const firstClaim = [bigInt(12), bigInt(45), bigInt(78), bigInt(41)];
const firstEntries = newEntry(firstClaim);
const secondClaim = [bigInt(33), bigInt(44), bigInt(55), bigInt(66)];
const secondEntries = newEntry(secondClaim);
const tree = await smt.newMemEmptyTrie();
const key1 = firstEntries.hi;
const value1 = firstEntries.hv;
const key2 = secondEntries.hi;
const value2 = secondEntries.hv;
await tree.insert(key1,value1);
await tree.insert(key2,value2);
const root = tree.root;
const rootBuff = bigIntToBuffer(root);
expect(bytesToHex(rootBuff)).to.be.equal("0x1fb755a3677f8fd6c47b5462b69778ef6383c31d2d498b765e953f8cacaa6744");
});
it("Add claims in different orders", async () => {
const tree1 = await smt.newMemEmptyTrie();
for (let i = 0; i < 16; i++) {
const claim = [bigInt(0), bigInt(i), bigInt(0), bigInt(i)];
const entries = newEntry(claim);
await tree1.insert(entries.hi, entries.hv);
}
const tree2 = await smt.newMemEmptyTrie();
for (let i = 0; i < 16; i++) {
const claim = [bigInt(0), bigInt(i), bigInt(0), bigInt(i)];
const entries = newEntry(claim);
await tree2.insert(entries.hi, entries.hv);
}
const root1 = bigIntToBuffer(tree1.root);
const root2 = bigIntToBuffer(tree2.root);
expect(bytesToHex(root1)).to.be.equal(bytesToHex(root2));
expect(bytesToHex(root1)).to.be.equal("0x173fd27f6622526dfb21c4d8d83e3c95adba5d8f46a397113e4e80e629c6de76");
});
it("Insert 3 elements in different order into different trees", async () => {
const claim1 = [bigInt(33), bigInt(44), bigInt(55), bigInt(66)];
const entries1 = newEntry(claim1);
const claim2 = [bigInt(1111), bigInt(2222), bigInt(3333), bigInt(4444)];
const entries2 = newEntry(claim2);
const claim3 = [bigInt(5555), bigInt(6666), bigInt(7777), bigInt(8888)];
const entries3 = newEntry(claim3);
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(entries1.hi,entries1.hv);
await tree1.insert(entries2.hi,entries2.hv);
await tree1.insert(entries3.hi,entries3.hv);
await tree2.insert(entries1.hi,entries1.hv);
await tree2.insert(entries3.hi,entries3.hv);
await tree2.insert(entries2.hi,entries2.hv);
await tree3.insert(entries2.hi,entries2.hv);
await tree3.insert(entries1.hi,entries1.hv);
await tree3.insert(entries3.hi,entries3.hv);
await tree4.insert(entries2.hi,entries2.hv);
await tree4.insert(entries3.hi,entries3.hv);
await tree4.insert(entries1.hi,entries1.hv);
await tree5.insert(entries3.hi,entries3.hv);
await tree5.insert(entries1.hi,entries1.hv);
await tree5.insert(entries2.hi,entries2.hv);
await tree6.insert(entries3.hi,entries3.hv);
await tree6.insert(entries2.hi,entries2.hv);
await tree6.insert(entries1.hi,entries1.hv);
const root1 = bigIntToBuffer(tree1.root);
const root2 = bigIntToBuffer(tree2.root);
const root3 = bigIntToBuffer(tree3.root);
const root4 = bigIntToBuffer(tree4.root);
const root5 = bigIntToBuffer(tree5.root);
const root6 = bigIntToBuffer(tree6.root);
expect(bytesToHex(root1)).to.be.equal(bytesToHex(root2));
expect(bytesToHex(root2)).to.be.equal(bytesToHex(root3));
expect(bytesToHex(root3)).to.be.equal(bytesToHex(root4));
expect(bytesToHex(root4)).to.be.equal(bytesToHex(root5));
expect(bytesToHex(root5)).to.be.equal(bytesToHex(root6));
expect(bytesToHex(root1)).to.be.equal("0x27990ef22656f49f010b2b48b2418c46f2bc93e4afb2e3377a1eb09f129e9802");
});
<<<<<<< HEAD
*/
=======
>>>>>>> 5b7abbc4ec56447e5e2baa31e3b4ce3a0c0617a8
});