aboutsummaryrefslogtreecommitdiffstats
path: root/Godeps/_workspace/src/github.com/ethereum/ethash/js/test/seedHash.js
blob: a3666a9ed7bca216b6ba6a338996381b3ca3880a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
var tape = require('tape');
const ethash = require('../ethash.js');

tape('seed hash', function(t) {

  t.test('seed should match TRUTH', function(st) {
    const seed = '290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563';
    const blockNum = 30000;

    var r = new Buffer(ethash.calcSeed(blockNum));
    st.equal(r.toString('hex'), seed);

    st.end();
  });

  t.test('seed should match TRUTH2', function(st) {
    const seed = '510e4e770828ddbf7f7b00ab00a9f6adaf81c0dc9cc85f1f8249c256942d61d9';
    const blockNum = 60000;

    var r = new Buffer(ethash.calcSeed(blockNum));
    st.equal(r.toString('hex'), seed);

    st.end();
  });

  t.test('seed should match TRUTH3', function(st) {
    const seed = '510e4e770828ddbf7f7b00ab00a9f6adaf81c0dc9cc85f1f8249c256942d61d9';
    const blockNum = 60700;

    var r = new Buffer(ethash.calcSeed(blockNum));
    st.equal(r.toString('hex'), seed);

    st.end();
  });

  t.test('randomized tests', function(st) {
    for (var i = 0; i < 100; i++) {
      var x = Math.floor(ethash.params.EPOCH_LENGTH * 2048 * Math.random());
      st.equal(ethash.calcSeed(x).toString('hex'), ethash.calcSeed(Math.floor(x / ethash.params.EPOCH_LENGTH) * ethash.params.EPOCH_LENGTH ).toString('hex'));
    }
    st.end();
  });
  // '510e4e770828ddbf7f7b00ab00a9f6adaf81c0dc9cc85f1f8249c256942d61d9'
  // [7:13:32 PM] Matthew Wampler-Doty: >>> x = randint(0,700000)
  // 
  // >>> pyethash.get_seedhash(x).encode('hex') == pyethash.get_seedhash((x // pyethash.EPOCH_LENGTH) * pyethash.EPOCH_LENGTH).encode('hex')

});