psf-multisig-approval 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,5 +2,73 @@
2
2
 
3
3
  This is an npm library for node.js. It implements the [PS009 specification for multisignature approval](https://github.com/Permissionless-Software-Foundation/specifications/blob/master/ps009-multisig-approval.md).
4
4
 
5
+ ## Instancing Library
6
+ This library depends on [minimal-slp-wallet](https://www.npmjs.com/package/minimal-slp-wallet). An instance of that library is expected to injected into this this one when instantiated. Here is an example:
7
+
8
+ ```javascript
9
+ const SlpWallet = require('minimal-slp-wallet')
10
+ const MultisigApproval = require('psf-multisig-approval')
11
+
12
+ async function start() {
13
+ // Instance the BCH wallet
14
+ const wallet = new SlpWallet(undefined, {
15
+ interface: 'consumer-api',
16
+ restURL: 'https://free-bch.fullstack.cash'
17
+ })
18
+ await wallet.initialize()
19
+
20
+ // Instance this library
21
+ const ps009 = new MultisigApproval({wallet})
22
+ }
23
+ start()
24
+ ```
25
+
26
+ ## Get NFT Holder Information
27
+ PS009 uses NFTs as 'homing beacons'. It generates a multisignature wallet from the public keys of the NFT holders. Finding the addresses and public keys of the NFT holders is a foundational feature of the protocol. Here is how you do that:
28
+
29
+ ```javascript
30
+ const groupTokenId = '8e8d90ebdb1791d58eba7acd428ff3b1e21c47fb7aba2ba3b5b815aa0fe7d6d5'
31
+
32
+ const result = await ps009.getNftInfo(groupTokenId)
33
+ console.log(result)
34
+
35
+ /*
36
+ {
37
+ keys: [
38
+ {
39
+ addr: 'bitcoincash:qz4zsa22glal5c4jqm748xge657gwuw2d5t9nvg64p',
40
+ pubKey: '021ca211a04a1d489ae77e01c28c97b02e733893890fda00a359ca8956c2e0d259',
41
+ nft: 'e86164aaa06efac1d6453951f67beafe042f0bceb9312845a95355b1e93aa846'
42
+ },
43
+ {
44
+ addr: 'bitcoincash:qpfvh07mdt7yq5czndaz5qq4g9q3m87qpspy7xaxgu',
45
+ pubKey: '0361fd21512b9072e8f6b984d9b04c57e5779867c2ad002999372268770fcb2674',
46
+ nft: 'da7ccbd5e24e468c9e7402489ca9148b5e76e588b73cc4aa4bbf1ca41d5808ab'
47
+ },
48
+ {
49
+ addr: 'bitcoincash:qpsxtzaa7rg677akcc2znpenpsy5jr2ygywmfd45p2',
50
+ pubKey: '03b9bdc40c478ab0536be29c368b26c48a5e8d6867fc34b77c727ab690365aae91',
51
+ nft: '0ec318bede8c2f229db840a24cb63d662ad91e8e6c840e46e6a8ff2d173049ce'
52
+ },
53
+ {
54
+ addr: 'bitcoincash:qqk3aczzggvxnfm7rwm0f9yz20yr00dmpv2f3tasdr',
55
+ pubKey: '033c930d4cff4ba68a70f7a21443e20ad4176173380d21f8c3ce27f7ce947f3246',
56
+ nft: '51624e772adafd7c6a9da38774e4f654282199bd5402e049ee087fc2bd900882'
57
+ },
58
+ {
59
+ addr: 'bitcoincash:qpszha37cjn6n83hpxn7zz5ndaa35vygtcgslxhpuc',
60
+ pubKey: '024be54accec310c2636140336ae548d610ba9b7ce300b3f42494b4a6f2963731f',
61
+ nft: 'e70cc72eeb15c82e96b1f8127d3b138b2fc8ea101fe9c62302ec641c05d4b97d'
62
+ }
63
+ ],
64
+ keysNotFound: []
65
+ }
66
+ */
67
+ ```
68
+
69
+ If the holder of the NFT has not made any transactions, then their public key will not be on the blockchain. In that case, the NFT and address will be added to the `keysNotFound` array. Those holders will not be included in the multisignature wallet.
70
+
71
+
72
+
5
73
  # License
6
74
  [MIT](LICENSE.md)
package/index.js CHANGED
@@ -5,22 +5,43 @@
5
5
 
6
6
  /* eslint-disable no-async-promise-executor */
7
7
 
8
- 'use strict'
8
+ // global libraries
9
9
 
10
- const BCHJS = require('@psf/bch-js')
10
+ // Local libraries
11
+ const NFTs = require('./lib/nfts')
11
12
 
12
- const Util = require('./lib/util')
13
- const util = new Util()
13
+ class MultisigApproval {
14
+ constructor (localConfig = {}) {
15
+ this.wallet = localConfig.wallet
16
+ if (!this.wallet) {
17
+ throw new Error('Instance of minimal-slp-wallet must be passed in as a property called \'wallet\', when initializing the psf-multisig-approval library.')
18
+ }
14
19
 
15
- let _this // local global for 'this'.
20
+ // Encapsulate dependencies
21
+ this.nfts = new NFTs(localConfig)
22
+ }
23
+
24
+ // This function retrieves the NFTs associated with a Group token ID. It then
25
+ // tries to retrieve the BCH addresses and public keys of the holders of those
26
+ // NFTs. It returns an object with all that information in it.
27
+ // The function defaults to the PSF Minting Council, but any Group token ID
28
+ // can be used.
29
+ async getNftInfo (groupTokenId = '8e8d90ebdb1791d58eba7acd428ff3b1e21c47fb7aba2ba3b5b815aa0fe7d6d5') {
30
+ try {
31
+ // console.log('groupTokenId: ', groupTokenId)
32
+
33
+ const nfts = await this.nfts.getNftsFromGroup()
34
+
35
+ const addrs = await this.nfts.getAddrsFromNfts(nfts)
16
36
 
17
- class BoilplateLib {
18
- constructor () {
19
- _this = this
37
+ const { keys, keysNotFound } = await this.nfts.findKeys(addrs, nfts)
20
38
 
21
- _this.bchjs = new BCHJS()
22
- _this.util = util
39
+ return { keys, keysNotFound }
40
+ } catch (err) {
41
+ console.error('Error in getNftInfo(): ', err)
42
+ throw err
43
+ }
23
44
  }
24
45
  }
25
46
 
26
- module.exports = BoilplateLib
47
+ module.exports = MultisigApproval
package/lib/nfts.js ADDED
@@ -0,0 +1,106 @@
1
+ /*
2
+ This library contains code for handling NFT and Group SLP tokens. Specifically
3
+ it has functions around looking up the NFTs related to a Group token, then
4
+ retrieving data on the holders of those NFTs.
5
+ */
6
+
7
+ class NFTs {
8
+ constructor (localConfig = {}) {
9
+ this.wallet = localConfig.wallet
10
+ if (!this.wallet) {
11
+ throw new Error('Instance of minimal-slp-wallet must be passed in as a property called \'wallet\', when initializing the nfts.js library.')
12
+ }
13
+ }
14
+
15
+ // Retrieve a list of NFTs from the Group token that spawned them.
16
+ // The default value is the PSF Minting Council Group token.
17
+ async getNftsFromGroup (groupId = '8e8d90ebdb1791d58eba7acd428ff3b1e21c47fb7aba2ba3b5b815aa0fe7d6d5') {
18
+ try {
19
+ const groupData = await this.wallet.getTokenData(groupId)
20
+ // console.log('groupData: ', groupData)
21
+
22
+ const nfts = groupData.genesisData.nfts
23
+
24
+ return nfts
25
+ } catch (err) {
26
+ console.error('Error in getNftsFromGroup()')
27
+ throw err
28
+ }
29
+ }
30
+
31
+ // This function expects an array of strings as input. Each element in the
32
+ // input array is expected to be the Token ID of the an NFT. The address
33
+ // holding each NFT is looked up on the blockchain. The array of returned
34
+ // addresses are filtered for duplicates, before being returned.
35
+ async getAddrsFromNfts (nfts = []) {
36
+ try {
37
+ let addrs = []
38
+
39
+ // Loop through each NFT Token ID in the array.
40
+ for (let i = 0; i < nfts.length; i++) {
41
+ const thisNft = nfts[i]
42
+
43
+ const nftData = await this.wallet.getTokenData(thisNft, true)
44
+ // console.log('nftData: ', nftData)
45
+
46
+ addrs.push(nftData.genesisData.nftHolder)
47
+ }
48
+
49
+ // Remove duplicate addresses
50
+ addrs = [...new Set(addrs)]
51
+
52
+ return addrs
53
+ } catch (err) {
54
+ console.error('Error in getAddrsFromNfts(): ', err)
55
+ throw err
56
+ }
57
+ }
58
+
59
+ // The input to this function is the output of getNftsFromGroup() and
60
+ // getAddrsFromNfts(). It expects two arrays of strings, one an array of
61
+ // NFT Token IDs, the other an array of addresses holding those NFTs.
62
+ //
63
+ // For each address, it attempts to lookup the public key for that address.
64
+ // It returns an object with a keys and keysNotFound property:
65
+ // - keys - Object containing address and public key
66
+ // - keysNotFound - Array of addresses whos public keys could not be found.
67
+ async findKeys (addrs, nfts) {
68
+ // It is assumed that element 1 in the addrs array is associated with
69
+ // element 1 in the nfts array.
70
+
71
+ try {
72
+ const keys = []
73
+ const keysNotFound = []
74
+
75
+ for (let i = 0; i < addrs.length; i++) {
76
+ const thisAddr = addrs[i]
77
+ const thisNft = nfts[i]
78
+
79
+ // console.log('this.wallet: ', this.wallet)
80
+ // console.log('this.wallet.interface: ', this.wallet.interface)
81
+ // console.log('this.wallet.restURL: ', this.wallet.restURL)
82
+
83
+ // Get public Key for reciever from the blockchain.
84
+ const publicKey = await this.wallet.getPubKey(thisAddr)
85
+ // console.log(`publicKey: ${JSON.stringify(publicKey, null, 2)}`)
86
+
87
+ if (publicKey.includes('not found')) {
88
+ keysNotFound.push(thisAddr)
89
+ } else {
90
+ keys.push({
91
+ addr: thisAddr,
92
+ pubKey: publicKey,
93
+ nft: thisNft
94
+ })
95
+ }
96
+ }
97
+
98
+ return { keys, keysNotFound }
99
+ } catch (err) {
100
+ console.error('Error in findKeys()')
101
+ throw err
102
+ }
103
+ }
104
+ }
105
+
106
+ module.exports = NFTs
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "psf-multisig-approval",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Utility library implementing the PS009 specification",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "start": "node index.js",
8
8
  "test": "npm run lint && TEST=unit nyc mocha test/unit/",
9
- "test:integration": "mocha --timeout 25000 test/integration/",
9
+ "test:integration": "mocha --timeout 120000 test/integration/",
10
10
  "lint": "standard --env mocha --fix",
11
11
  "docs": "./node_modules/.bin/apidoc -i src/ -o docs",
12
12
  "coverage:report": "nyc --reporter=html mocha test/unit/ --exit"
@@ -39,6 +39,7 @@
39
39
  "chai": "4.3.7",
40
40
  "husky": "8.0.3",
41
41
  "lodash.clonedeep": "4.5.0",
42
+ "minimal-slp-wallet": "5.8.8",
42
43
  "mocha": "10.2.0",
43
44
  "nyc": "15.1.0",
44
45
  "semantic-release": "19.0.5",
@@ -0,0 +1,30 @@
1
+ /*
2
+ Integration tests for the main library.
3
+ */
4
+
5
+ // Global npm libraries
6
+ const SlpWallet = require('minimal-slp-wallet')
7
+
8
+ // Local libraries
9
+ const MultisigApproval = require('../../index')
10
+
11
+ describe('#psf-multisig-approval', () => {
12
+ let uut
13
+
14
+ before(async () => {
15
+ const wallet = new SlpWallet(undefined, {
16
+ interface: 'consumer-api',
17
+ restURL: 'https://bch-consumer-anacortes-wa-usa.fullstackcash.nl'
18
+ })
19
+ await wallet.walletInfoPromise
20
+
21
+ uut = new MultisigApproval({ wallet })
22
+ })
23
+
24
+ describe('#getNftInfo', () => {
25
+ it('should get address and pubkeys for Minting Council NFT holders', async () => {
26
+ const result = await uut.getNftInfo()
27
+ console.log('result: ', result)
28
+ })
29
+ })
30
+ })
@@ -0,0 +1,84 @@
1
+ /*
2
+ Unit tests for the main index.js library file.
3
+ */
4
+
5
+ // npm libraries
6
+ const assert = require('chai').assert
7
+ const sinon = require('sinon')
8
+ // const cloneDeep = require('lodash.clonedeep')
9
+ const SlpWallet = require('minimal-slp-wallet')
10
+
11
+ // Mocking data libraries.
12
+ // const mockDataLib = require('./mocks/util-mocks')
13
+
14
+ // Unit under test
15
+ const MultisigApproval = require('../../index')
16
+
17
+ describe('#MultisigApproval.js', () => {
18
+ let sandbox
19
+ // let mockData
20
+ let uut
21
+ let wallet
22
+
23
+ before(async () => {
24
+ wallet = new SlpWallet(undefined, { interface: 'consumer-api' })
25
+ await wallet.walletInfoPromise
26
+ })
27
+
28
+ beforeEach(() => {
29
+ // Restore the sandbox before each test.
30
+ sandbox = sinon.createSandbox()
31
+
32
+ // Clone the mock data.
33
+ // mockData = cloneDeep(mockDataLib)
34
+
35
+ uut = new MultisigApproval({ wallet })
36
+ })
37
+
38
+ afterEach(() => sandbox.restore())
39
+
40
+ describe('#constructor', () => {
41
+ it('should throw an error if wallet is not passed', () => {
42
+ try {
43
+ uut = new MultisigApproval()
44
+
45
+ assert.fail('Unexpected result')
46
+ } catch (err) {
47
+ assert.include(err.message, 'Instance of minimal-slp-wallet must be passed in as a property called \'wallet\', when initializing the psf-multisig-approval library.')
48
+ }
49
+ })
50
+
51
+ it('should have encapsulated dependencies', () => {
52
+ assert.property(uut, 'nfts')
53
+ })
54
+ })
55
+
56
+ describe('#getNftInfo', () => {
57
+ it('should get info about NFTs associated with a group token', async () => {
58
+ // Mock dependencies and force desired code path
59
+ sandbox.stub(uut.nfts, 'getNftsFromGroup').resolves()
60
+ sandbox.stub(uut.nfts, 'getAddrsFromNfts').resolves()
61
+ sandbox.stub(uut.nfts, 'findKeys').resolves({ keys: [], keysNotFound: [] })
62
+
63
+ const result = await uut.getNftInfo()
64
+
65
+ assert.property(result, 'keys')
66
+ assert.property(result, 'keysNotFound')
67
+ assert.isArray(result.keys)
68
+ assert.isArray(result.keysNotFound)
69
+ })
70
+
71
+ it('should catch, report, and throw errors', async () => {
72
+ try {
73
+ // Mock dependencies and force desired code path
74
+ sandbox.stub(uut.nfts, 'getNftsFromGroup').rejects(new Error('test error'))
75
+
76
+ await uut.getNftInfo()
77
+
78
+ assert.fail('Unexpected code path')
79
+ } catch (err) {
80
+ assert.include(err.message, 'test error')
81
+ }
82
+ })
83
+ })
84
+ })
@@ -0,0 +1,173 @@
1
+ /*
2
+ Unit tests for the nfts.js utility library.
3
+ */
4
+
5
+ // npm libraries
6
+ const chai = require('chai')
7
+ const sinon = require('sinon')
8
+ // const cloneDeep = require('lodash.clonedeep')
9
+ const SlpWallet = require('minimal-slp-wallet')
10
+
11
+ // Locally global variables.
12
+ const assert = chai.assert
13
+
14
+ // Mocking data libraries.
15
+ // const mockDataLib = require('./mocks/util-mocks')
16
+
17
+ // Unit under test
18
+ const NftsLib = require('../../lib/nfts')
19
+
20
+ describe('#NFTs', () => {
21
+ let sandbox
22
+ // let mockData
23
+ let uut
24
+ let wallet
25
+
26
+ before(async () => {
27
+ wallet = new SlpWallet(undefined, { interface: 'consumer-api' })
28
+ await wallet.walletInfoPromise
29
+ })
30
+
31
+ beforeEach(() => {
32
+ // Restore the sandbox before each test.
33
+ sandbox = sinon.createSandbox()
34
+
35
+ // Clone the mock data.
36
+ // mockData = cloneDeep(mockDataLib)
37
+
38
+ uut = new NftsLib({ wallet })
39
+ })
40
+
41
+ afterEach(() => sandbox.restore())
42
+
43
+ describe('#constructor', () => {
44
+ it('should throw an error if wallet is not passed', () => {
45
+ try {
46
+ uut = new NftsLib()
47
+ console.log('uut: ', uut)
48
+
49
+ assert.fail('Unexpected result')
50
+ } catch (err) {
51
+ assert.include(err.message, 'Instance of minimal-slp-wallet must be passed in as a property called \'wallet\', when initializing the nfts.js library.')
52
+ }
53
+ })
54
+ })
55
+
56
+ describe('#getNftsFromGroup', () => {
57
+ it('should get NFT token IDs from a Group token', async () => {
58
+ // Mock dependencies and force desired code path
59
+ sandbox.stub(uut.wallet, 'getTokenData').resolves({
60
+ genesisData: {
61
+ nfts: ['a', 'b', 'c']
62
+ }
63
+ })
64
+
65
+ const result = await uut.getNftsFromGroup('fake-group-id')
66
+
67
+ assert.isArray(result)
68
+ })
69
+
70
+ it('should catch and throw errors', async () => {
71
+ try {
72
+ // Mock dependencies and force desired code path
73
+ sandbox.stub(uut.wallet, 'getTokenData').rejects(new Error('test error'))
74
+
75
+ await uut.getNftsFromGroup()
76
+
77
+ assert.fail('Unexpected code path')
78
+ } catch (err) {
79
+ assert.include(err.message, 'test error')
80
+ }
81
+ })
82
+ })
83
+
84
+ describe('#getAddrsFromNfts', () => {
85
+ it('should should return addresses associated with each NFT', async () => {
86
+ // Mock dependencies and force desired code path.
87
+ sandbox.stub(uut.wallet, 'getTokenData').resolves({
88
+ genesisData: {
89
+ nftHolder: 'sam'
90
+ }
91
+ })
92
+
93
+ const nfts = ['a']
94
+
95
+ const result = await uut.getAddrsFromNfts(nfts)
96
+
97
+ assert.isArray(result)
98
+ assert.equal(result[0], 'sam')
99
+ })
100
+
101
+ it('should catch and throw errors', async () => {
102
+ try {
103
+ // Force an error
104
+ sandbox.stub(uut.wallet, 'getTokenData').rejects(new Error('test error'))
105
+
106
+ const nfts = ['a']
107
+
108
+ await uut.getAddrsFromNfts(nfts)
109
+
110
+ assert.fail('Unexpected code path')
111
+ } catch (err) {
112
+ assert.include(err.message, 'test error')
113
+ }
114
+ })
115
+ })
116
+
117
+ describe('#findKeys', () => {
118
+ it('should collect public keys for an addresses', async () => {
119
+ const addrs = ['bitcoincash:qzwahhjldv0qsecfxlmcenzvkjv9rlv9au2hcfggl6']
120
+ const nfts = ['fb707a9d8a4d6ba47ef0c510714ca46d4523cd29c8f4e3fd6a63a85edb8b05d2']
121
+
122
+ // Mock dependencies and force desired code path.
123
+ sandbox.stub(uut.wallet, 'getPubKey').resolves('02055962631b236ddcd2c17cd0b711f12438b93bcf01b206cadb351cc3e6e3e269')
124
+
125
+ const result = await uut.findKeys(addrs, nfts)
126
+ // console.log('result: ', result)
127
+
128
+ // Assert expected properties exist
129
+ assert.property(result, 'keys')
130
+ assert.property(result, 'keysNotFound')
131
+
132
+ // Assert that each property is an array.
133
+ assert.isArray(result.keys)
134
+ assert.isArray(result.keysNotFound)
135
+
136
+ // Assert expected values exist
137
+ assert.equal(result.keys[0].addr, 'bitcoincash:qzwahhjldv0qsecfxlmcenzvkjv9rlv9au2hcfggl6')
138
+ assert.equal(result.keys[0].pubKey, '02055962631b236ddcd2c17cd0b711f12438b93bcf01b206cadb351cc3e6e3e269')
139
+ })
140
+
141
+ it('should handle address without a public key', async () => {
142
+ const addrs = ['bitcoincash:qzwahhjldv0qsecfxlmcenzvkjv9rlv9au2hcfggl6']
143
+ const nfts = ['fb707a9d8a4d6ba47ef0c510714ca46d4523cd29c8f4e3fd6a63a85edb8b05d2']
144
+
145
+ // Mock dependencies and force desired code path.
146
+ sandbox.stub(uut.wallet, 'getPubKey').resolves('not found')
147
+
148
+ const result = await uut.findKeys(addrs, nfts)
149
+ // console.log('result: ', result)
150
+
151
+ // Assert expected properties exist
152
+ assert.property(result, 'keys')
153
+ assert.property(result, 'keysNotFound')
154
+
155
+ // Assert that each property is an array.
156
+ assert.isArray(result.keys)
157
+ assert.isArray(result.keysNotFound)
158
+
159
+ // Assert expected values exist
160
+ assert.equal(result.keysNotFound[0], 'bitcoincash:qzwahhjldv0qsecfxlmcenzvkjv9rlv9au2hcfggl6')
161
+ })
162
+
163
+ it('should catch and throw errors', async () => {
164
+ try {
165
+ await uut.findKeys()
166
+
167
+ assert.fail('Unexpected code path')
168
+ } catch (err) {
169
+ assert.include(err.message, 'Cannot read')
170
+ }
171
+ })
172
+ })
173
+ })
@@ -1,33 +0,0 @@
1
- /*
2
- Integration tests for the util.js utility library.
3
- */
4
-
5
- // npm libraries
6
- const chai = require('chai')
7
-
8
- // Locally global variables.
9
- const assert = chai.assert
10
-
11
- // Unit under test
12
- const UtilLib = require('../../lib/util')
13
- const uut = new UtilLib()
14
-
15
- describe('#util.js', () => {
16
- describe('#getBchData', () => {
17
- it('should get BCH data on an address', async () => {
18
- const addr = 'bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7'
19
-
20
- const bchData = await uut.getBchData(addr)
21
-
22
- // Assert that top-level properties exist.
23
- assert.property(bchData, 'balance')
24
- assert.property(bchData, 'utxos')
25
-
26
- // Assert essential UTXOs properties exist.
27
- assert.isArray(bchData.utxos)
28
- assert.property(bchData.utxos[0], 'tx_pos')
29
- assert.property(bchData.utxos[0], 'tx_hash')
30
- assert.property(bchData.utxos[0], 'value')
31
- })
32
- })
33
- })
@@ -1,70 +0,0 @@
1
- /*
2
- Unit tests for the util.js utility library.
3
- */
4
-
5
- // npm libraries
6
- const chai = require('chai')
7
- const sinon = require('sinon')
8
- const cloneDeep = require('lodash.clonedeep')
9
-
10
- // Locally global variables.
11
- const assert = chai.assert
12
-
13
- // Mocking data libraries.
14
- const mockDataLib = require('./mocks/util-mocks')
15
-
16
- // Unit under test
17
- const UtilLib = require('../../lib/util')
18
- const uut = new UtilLib()
19
-
20
- describe('#util.js', () => {
21
- let sandbox
22
- let mockData
23
-
24
- beforeEach(() => {
25
- // Restore the sandbox before each test.
26
- sandbox = sinon.createSandbox()
27
-
28
- // Clone the mock data.
29
- mockData = cloneDeep(mockDataLib)
30
- })
31
-
32
- afterEach(() => sandbox.restore())
33
-
34
- describe('#getBchData', () => {
35
- it('should throw error if address is not a string', async () => {
36
- try {
37
- const addr = 1234
38
-
39
- await uut.getBchData(addr)
40
-
41
- assert.equal(true, false, 'unexpected result')
42
- } catch (err) {
43
- assert.include(err.message, 'Address must be a string')
44
- }
45
- })
46
-
47
- it('should get BCH data on an address', async () => {
48
- // Mock external dependencies.
49
- sandbox
50
- .stub(uut.bchjs.Electrumx, 'balance')
51
- .resolves(mockData.mockBalance)
52
- sandbox.stub(uut.bchjs.Electrumx, 'utxo').resolves(mockData.mockUtxos)
53
-
54
- const addr = 'bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7'
55
-
56
- const bchData = await uut.getBchData(addr)
57
- // console.log(`bchData: ${JSON.stringify(bchData, null, 2)}`)
58
-
59
- // Assert that top-level properties exist.
60
- assert.property(bchData, 'balance')
61
- assert.property(bchData, 'utxos')
62
-
63
- // Assert essential UTXOs properties exist.
64
- assert.isArray(bchData.utxos)
65
- assert.property(bchData.utxos[0], 'tx_pos')
66
- assert.property(bchData.utxos[0], 'tx_hash')
67
- assert.property(bchData.utxos[0], 'value')
68
- })
69
- })
70
- })