aboutsummaryrefslogtreecommitdiffstats
path: root/Godeps/_workspace/src/github.com/ethereum/ethash/js/test.js
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-03-25 21:57:49 +0800
committerobscuren <geffobscura@gmail.com>2015-03-25 21:58:12 +0800
commitff5578fc715262cd8ae62e7d0f961a6e977a8727 (patch)
tree41e4ae3d9e2ebda853bf68f0746dfbc35a534c40 /Godeps/_workspace/src/github.com/ethereum/ethash/js/test.js
parenta2e3bf6f3002e9914f56e08b1d6e323409ff3b4f (diff)
downloadgo-tangerine-ff5578fc715262cd8ae62e7d0f961a6e977a8727.tar
go-tangerine-ff5578fc715262cd8ae62e7d0f961a6e977a8727.tar.gz
go-tangerine-ff5578fc715262cd8ae62e7d0f961a6e977a8727.tar.bz2
go-tangerine-ff5578fc715262cd8ae62e7d0f961a6e977a8727.tar.lz
go-tangerine-ff5578fc715262cd8ae62e7d0f961a6e977a8727.tar.xz
go-tangerine-ff5578fc715262cd8ae62e7d0f961a6e977a8727.tar.zst
go-tangerine-ff5578fc715262cd8ae62e7d0f961a6e977a8727.zip
updated ethash
Diffstat (limited to 'Godeps/_workspace/src/github.com/ethereum/ethash/js/test.js')
-rw-r--r--Godeps/_workspace/src/github.com/ethereum/ethash/js/test.js53
1 files changed, 53 insertions, 0 deletions
diff --git a/Godeps/_workspace/src/github.com/ethereum/ethash/js/test.js b/Godeps/_workspace/src/github.com/ethereum/ethash/js/test.js
new file mode 100644
index 000000000..7ebb733ff
--- /dev/null
+++ b/Godeps/_workspace/src/github.com/ethereum/ethash/js/test.js
@@ -0,0 +1,53 @@
+// test.js
+// Tim Hughes <tim@twistedfury.com>
+
+/*jslint node: true, shadow:true */
+"use strict";
+
+var ethash = require('./ethash');
+var util = require('./util');
+var Keccak = require('./keccak');
+
+// sanity check hash functions
+var src = util.stringToBytes("");
+if (util.bytesToHexString(new Keccak().digest(32, src)) != "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470") throw Error("Keccak-256 failed");
+if (util.bytesToHexString(new Keccak().digest(64, src)) != "0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e") throw Error("Keccak-512 failed");
+
+src = new Uint32Array(src.buffer);
+var dst = new Uint32Array(8);
+new Keccak().digestWords(dst, 0, dst.length, src, 0, src.length);
+if (util.wordsToHexString(dst) != "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470") throw Error("Keccak-256 Fast failed");
+
+var dst = new Uint32Array(16);
+new Keccak().digestWords(dst, 0, dst.length, src, 0, src.length);
+if (util.wordsToHexString(dst) != "0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e") throw Error("Keccak-512 Fast failed");
+
+
+// init params
+var ethashParams = ethash.defaultParams();
+//ethashParams.cacheRounds = 0;
+
+// create hasher
+var seed = util.hexStringToBytes("9410b944535a83d9adf6bbdcc80e051f30676173c16ca0d32d6f1263fc246466")
+var startTime = new Date().getTime();
+var hasher = new ethash.Ethash(ethashParams, seed);
+console.log('Ethash startup took: '+(new Date().getTime() - startTime) + "ms");
+console.log('Ethash cache hash: ' + util.bytesToHexString(hasher.cacheDigest()));
+
+var testHexString = "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470";
+if (testHexString != util.bytesToHexString(util.hexStringToBytes(testHexString)))
+ throw Error("bytesToHexString or hexStringToBytes broken");
+
+
+var header = util.hexStringToBytes("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470");
+var nonce = util.hexStringToBytes("0000000000000000");
+var hash;
+
+startTime = new Date().getTime();
+var trials = 10;
+for (var i = 0; i < trials; ++i)
+{
+ hash = hasher.hash(header, nonce);
+}
+console.log("Light client hashes averaged: " + (new Date().getTime() - startTime)/trials + "ms");
+console.log("Hash = " + util.bytesToHexString(hash));