-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcore_spec.js
123 lines (104 loc) · 3.95 KB
/
core_spec.js
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
process.env.NODE_ENV = 'test'
const chai = require('chai')
const expect = chai.expect
const core = require('../lib/core')
const docproof = core.docproof
const transaction = core.transaction
const wallet = core.wallet
const Insights = require('./fixtures/insight')
const insights = new Insights()
const records = require('./fixtures/records')
describe('get docproof price', () => {
it('it should get the docproof price unit', (done) => {
docproofPrice = docproof.price().toSatoshis()
expect(docproofPrice).to.equal(200000)
done()
})
it('it should get an adjusted price based on the fee per KB', (done) => {
feePerKb = 124099
docproofPrice = docproof.adjustedPrice(feePerKb).toSatoshis()
expect(docproofPrice).to.equal(50000)
docproofPrice = docproof.adjustedPrice(feePerKb, 4).toSatoshis()
expect(docproofPrice).to.equal(125000)
done()
})
})
describe('estimate docproof fees', () => {
it('it should estimate a fee based on fee per kb', (done) => {
feePerKb = 100000
docproofFee = docproof.estimateFee(feePerKb)
expect(docproofFee).to.equal(24200)
done()
})
it('it should estimate a fee based on fee per kb, with a multiplier', (done) => {
feePerKb = 124099
docproofFee = docproof.estimateFee(feePerKb, 4)
expect(docproofFee).to.equal(120128)
done()
})
})
describe('validate a document digest hash', () => {
it('it should return true for valid digests', (done) => {
expect(docproof.isValidDigest(records.digest)).to.be.true
done()
})
it('it should return false for invalid digests', (done) => {
expect(docproof.isValidDigest('test')).to.be.false
expect(docproof.isValidDigest(null)).to.be.false
expect(docproof.isValidDigest('')).to.be.false
expect(docproof.isValidDigest()).to.be.false
done()
})
})
describe('check if an address is a transaction input', () => {
it('it should return true when an address is an input', (done) => {
let tx = insights.txsAddress.txs[0]
let address = 'ms6zWKUFA1txnncwcFvxc99899wjXrbGRH'
let isAddressAnInput = transaction.isAddressAnInput(address, tx)
expect(isAddressAnInput).to.be.true
done()
})
it('it should return false when an address is an not input', (done) => {
let tx = insights.txsAddress.txs[0]
let address = 'moCXE9C7sB8zoEM673naWb1YSDwmdgNkw7'
let isAddressAnInput = transaction.isAddressAnInput(address, tx)
expect(isAddressAnInput).to.be.false
done()
})
it('it should return false if any values are missing', (done) => {
expect(transaction.isAddressAnInput('test', {})).to.be.false
expect(transaction.isAddressAnInput('test', {vin: []})).to.be.false
expect(transaction.isAddressAnInput('test', {vin: [{}]})).to.be.false
done()
})
})
describe('check if an address is a transaction output', () => {
it('it should return true when an address is an output', (done) => {
let tx = insights.txsAddress.txs[1]
let address = 'ms6zWKUFA1txnncwcFvxc99899wjXrbGRH'
let isAddressAnOutput = transaction.isAddressAnOutput(address, tx)
expect(isAddressAnOutput).to.be.true
done()
})
it('it should return false when an address is not an output', (done) => {
let tx = insights.txsAddress.txs[1]
let address = 'moCXE9C7sB8zoEM673naWb1YSDwmdgNkw7'
let isAddressAnOutput = transaction.isAddressAnOutput(address, tx)
expect(isAddressAnOutput).to.be.false
done()
})
it('it should return false if any values are missing', (done) => {
expect(transaction.isAddressAnOutput('test', {})).to.be.false
expect(transaction.isAddressAnOutput('test', {vout: []})).to.be.false
expect(transaction.isAddressAnOutput('test', {vout: [{}]})).to.be.false
done()
})
})
describe('generate a random non-hardened HD child key derivation path', () => {
it('it should generate a path with three levels', (done) => {
randomPath = wallet.getRandomPath()
expect(randomPath).to.be.a('string')
expect(randomPath).to.match(/^m\/\d+\/\d+\/\d+$/)
done()
})
})