2018-07-23 09:45:01 +02:00
|
|
|
const { describe, it } = require('mocha')
|
2018-06-25 08:25:12 +02:00
|
|
|
const assert = require('assert')
|
2019-01-04 10:33:02 +01:00
|
|
|
const types = require('../src/types')
|
2018-06-25 08:25:12 +02:00
|
|
|
const typeforce = require('typeforce')
|
2015-08-25 05:52:24 +02:00
|
|
|
|
|
|
|
describe('types', function () {
|
2016-02-02 13:06:16 +01:00
|
|
|
describe('Buffer Hash160/Hash256', function () {
|
2018-06-25 08:37:45 +02:00
|
|
|
const buffer20byte = Buffer.alloc(20)
|
|
|
|
const buffer32byte = Buffer.alloc(32)
|
2016-02-02 13:06:16 +01:00
|
|
|
|
2016-02-05 04:15:23 +01:00
|
|
|
it('return true for valid size', function () {
|
2016-02-02 13:06:16 +01:00
|
|
|
assert(types.Hash160bit(buffer20byte))
|
|
|
|
assert(types.Hash256bit(buffer32byte))
|
|
|
|
})
|
|
|
|
|
2016-02-05 04:15:23 +01:00
|
|
|
it('return true for oneOf', function () {
|
2016-09-30 08:25:13 +02:00
|
|
|
assert.doesNotThrow(function () {
|
|
|
|
typeforce(types.oneOf(types.Hash160bit, types.Hash256bit), buffer32byte)
|
|
|
|
})
|
|
|
|
|
|
|
|
assert.doesNotThrow(function () {
|
|
|
|
typeforce(types.oneOf(types.Hash256bit, types.Hash160bit), buffer32byte)
|
|
|
|
})
|
2016-02-05 04:15:23 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
it('throws for invalid size', function () {
|
2016-02-02 13:06:16 +01:00
|
|
|
assert.throws(function () {
|
|
|
|
types.Hash160bit(buffer32byte)
|
2016-09-30 08:25:13 +02:00
|
|
|
}, /Expected Buffer\(Length: 20\), got Buffer\(Length: 32\)/)
|
2016-02-02 13:06:16 +01:00
|
|
|
|
|
|
|
assert.throws(function () {
|
|
|
|
types.Hash256bit(buffer20byte)
|
2016-09-30 08:25:13 +02:00
|
|
|
}, /Expected Buffer\(Length: 32\), got Buffer\(Length: 20\)/)
|
2016-02-02 13:06:16 +01:00
|
|
|
})
|
|
|
|
})
|
2016-09-27 05:54:03 +02:00
|
|
|
|
|
|
|
describe('Satoshi', function () {
|
|
|
|
[
|
|
|
|
{ value: -1, result: false },
|
|
|
|
{ value: 0, result: true },
|
|
|
|
{ value: 1, result: true },
|
|
|
|
{ value: 20999999 * 1e8, result: true },
|
|
|
|
{ value: 21000000 * 1e8, result: true },
|
|
|
|
{ value: 21000001 * 1e8, result: false }
|
|
|
|
].forEach(function (f) {
|
|
|
|
it('returns ' + f.result + ' for valid for ' + f.value, function () {
|
|
|
|
assert.strictEqual(types.Satoshi(f.value), f.result)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2015-08-25 05:52:24 +02:00
|
|
|
})
|