Skip to content

Commit fbc3ce8

Browse files
make issue Permissionless-Software-Foundation#10 unit tests run
1 parent 9162525 commit fbc3ce8

File tree

131 files changed

+170
-9
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+170
-9
lines changed

.eslintrc.json

100644100755
File mode changed.

.gitignore

100644100755
File mode changed.

.travis.yml

100644100755
File mode changed.

CONTRIBUTING.md

100644100755
File mode changed.

LICENSE.md

100644100755
File mode changed.

README.md

100644100755
File mode changed.

examples/README.md

100644100755
File mode changed.

package-lock.json

100644100755
File mode changed.

package.json

100644100755
File mode changed.

src/address.js

100644100755
File mode changed.

src/bch-js.js

100644100755
File mode changed.

src/bitcoincash.js

100644100755
File mode changed.

src/blockbook.js

100644100755
File mode changed.

src/blockchain.js

100644100755
File mode changed.

src/control.js

100644100755
File mode changed.

src/crypto.js

100644100755
File mode changed.

src/ecpair.js

100644100755
File mode changed.

src/electrumx.js

100644100755
File mode changed.

src/encryption.js

100644100755
File mode changed.

src/generating.js

100644100755
File mode changed.

src/hdnode.js

100644100755
File mode changed.

src/ipfs.js

100644100755
File mode changed.

src/mining.js

100644100755
File mode changed.

src/mnemonic.js

100644100755
File mode changed.

src/ninsight.js

100644100755
Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ class Ninsight {
6666
*/
6767
async utxo(address) {
6868
try {
69-
_checkParam(address)
70-
_callAxios(address, 'utxo')
69+
_this._validateParam(address)
70+
return _this._callAxios(address, 'utxo')
7171
} catch (e) {
72-
_handleError(e)
72+
_this._handleError(e);
7373
}
7474
}
7575

@@ -90,20 +90,59 @@ class Ninsight {
9090
* })()
9191
*
9292
* // [
93-
* // //TODO PASTE LOG OUTPUT SAMPLE HERE
93+
* // {
94+
* // 'address': 'bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9',
95+
* // 'satoshis': 2782729129,
96+
* // 'height': 534105,
97+
* // 'confirmations': 123,
98+
* // 'timestamp': 1441068774,
99+
* // 'fees': 35436,
100+
* // 'outputIndexes': [
101+
* // 0
102+
* // ],
103+
* // 'inputIndexes': [],
104+
* // 'tx': {
105+
* // 'hash': 'bb0ec3b96209fac9529570ea6f83a86af2cceedde4aaf2bfcc4796680d23f1c7',
106+
* // 'version': 1,
107+
* // 'inputs': [
108+
* // {
109+
* // 'prevTxId': 'ea5e5bafbf29cdf6f6097ab344128477e67889d4d6203cb43594836daa6cc425',
110+
* // 'outputIndex': 1,
111+
* // 'sequenceNumber': 4294967294,
112+
* // 'script': '483045022100f4d169783bef70e3943d2a617cce55d9fe4e33fc6f9880b8277265e2f619a97002201238648abcdf52960500664e969046d41755f7fc371971ebc78002fc418465a6012103acdcd31d51272403ce0829447e59e2ac9e08ed0bf92011cbf7420addf24534e6',
113+
* // 'scriptString': '72 0x3045022100f4d169783bef70e3943d2a617cce55d9fe4e33fc6f9880b8277265e2f619a97002201238648abcdf52960500664e969046d41755f7fc371971ebc78002fc418465a601 33 0x03acdcd31d51272403ce0829447e59e2ac9e08ed0bf92011cbf7420addf24534e6',
114+
* // 'output': {
115+
* // 'satoshis': 2796764565,
116+
* // 'script': '76a91488b1fe8aec5ae4358a11447a2f22b2781faedb9b88ac'
117+
* // }
118+
* // }
119+
* // ],
120+
* // 'outputs': [
121+
* // {
122+
* // 'satoshis': 2782729129,
123+
* // 'script': '76a9143583efb5e64a4668c6c54bb5fcc30af4417b4f2d88ac'
124+
* // },
125+
* // {
126+
* // 'satoshis': 14000000,
127+
* // 'script': '76a9149713201957f42379e574d7c70d506ee49c2c8ad688ac'
128+
* // }
129+
* // ],
130+
* // 'nLockTime': 534089
131+
* // }
132+
* // }
94133
* // ]
95134
*
96135
*/
97136
async details(address) {
98137
try {
99-
_checkParam(address)
100-
_callAxios(address, 'details')
138+
_this._validateParam(address)
139+
return _this._callAxios(address, 'details')
101140
} catch (e) {
102-
_handleError(e)
141+
_this._handleError(e)
103142
}
104143
}
105144

106-
_checkParam(address) {
145+
_validateParam(address) {
107146
if (typeof address !== "string" && !Array.isArray(address))
108147
throw new Error(`Input address must be a string or array of strings.`)
109148
}

src/openbazaar.js

100644100755
File mode changed.

src/price.js

100644100755
File mode changed.

src/raw-transactions.js

100644100755
File mode changed.

src/schnorr.js

100644100755
File mode changed.

src/script.js

100644100755
File mode changed.

src/slp/address.js

100644100755
File mode changed.

src/slp/ecpair.js

100644100755
File mode changed.

src/slp/nft1.js

100644100755
File mode changed.

src/slp/slp.js

100644100755
File mode changed.

src/slp/tokentype1.js

100644100755
File mode changed.

src/slp/utils.js

100644100755
File mode changed.

src/socket.js

100644100755
File mode changed.

src/transaction-builder.js

100644100755
File mode changed.

src/util.js

100644100755
File mode changed.

src/wallet.js

100644100755
File mode changed.

test/e2e/bch-js-e2e-tests.js

100644100755
File mode changed.

test/e2e/ipfs/ipfs-e2e.js

100644100755
File mode changed.

test/e2e/rate-limits/anonymous-rate-limits.js

100644100755
File mode changed.

test/e2e/rate-limits/free-rate-limits.js

100644100755
File mode changed.

test/e2e/rate-limits/full-node-rate-limits.js

100644100755
File mode changed.

test/e2e/rate-limits/indexer-rate-limits.js

100644100755
File mode changed.

test/e2e/send-raw-transaction-bulk/package.json

100644100755
File mode changed.

test/e2e/send-raw-transaction-bulk/sendrawtransaction.js

100644100755
File mode changed.

test/e2e/send-raw-transaction-single/package.json

100644100755
File mode changed.

test/e2e/send-raw-transaction-single/sendrawtransaction.js

100644100755
File mode changed.

test/e2e/send-token/send-token.js

100644100755
File mode changed.

test/e2e/util/e2e-util.js

100644100755
File mode changed.

test/e2e/wallet1.json

100644100755
File mode changed.

test/e2e/wallet2.json

100644100755
File mode changed.

test/integration/bchn/blockchain.js

100644100755
File mode changed.

test/integration/bchn/control.js

100644100755
File mode changed.

test/integration/bchn/electrumx.js

100644100755
File mode changed.

test/integration/bchn/encryption.js

100644100755
File mode changed.

test/integration/bchn/ninsight.js

100644100755
File mode changed.

test/integration/bchn/openbazaar.js

100644100755
File mode changed.

test/integration/bchn/price.js

100644100755
File mode changed.

test/integration/bchn/rawtransaction.js

100644100755
File mode changed.

test/integration/bchn/slp.js

100644100755
File mode changed.

test/integration/bchn/util.js

100644100755
File mode changed.

test/integration/blockbook.js

100644100755
File mode changed.

test/integration/blockchain.js

100644100755
File mode changed.

test/integration/control.js

100644100755
File mode changed.

test/integration/electrumx.js

100644100755
File mode changed.

test/integration/encryption.js

100644100755
File mode changed.

test/integration/ninsight.js

100644100755
File mode changed.

test/integration/openbazaar.js

100644100755
File mode changed.

test/integration/price.js

100644100755
File mode changed.

test/integration/rawtransaction.js

100644100755
File mode changed.

test/integration/slp.js

100644100755
File mode changed.

test/integration/testnet/blockbook.js

100644100755
File mode changed.

test/integration/testnet/blockchain.js

100644100755
File mode changed.

test/integration/testnet/control.js

100644100755
File mode changed.

test/integration/testnet/electrumx.js

100644100755
File mode changed.

test/integration/testnet/ninsight.js

100644100755
File mode changed.

test/integration/testnet/rawtransaction.js

100644100755
File mode changed.

test/integration/testnet/slp.js

100644100755
File mode changed.

test/integration/testnet/util.js

100644100755
File mode changed.

test/unit/address.js

100644100755
File mode changed.

test/unit/bitbox-shim.js

100644100755
File mode changed.

test/unit/bitcoin-cash.js

100644100755
File mode changed.

test/unit/blockbook.js

100644100755
File mode changed.

test/unit/blockchain.js

100644100755
File mode changed.

test/unit/control.js

100644100755
File mode changed.

test/unit/crypto.js

100644100755
File mode changed.

test/unit/ecpairs.js

100644100755
File mode changed.

test/unit/electrumx.js

100644100755
File mode changed.

test/unit/encryption.js

100644100755
File mode changed.

test/unit/fixtures/address.json

100644100755
File mode changed.

test/unit/fixtures/bitcoincash.json

100644100755
File mode changed.

test/unit/fixtures/bitcore-mock.js

100644100755
File mode changed.

test/unit/fixtures/block-mock.js

100644100755
File mode changed.

test/unit/fixtures/blockbook-mock.js

100644100755
File mode changed.

test/unit/fixtures/blockchain-mock.js

100644100755
File mode changed.

test/unit/fixtures/blockchain.json

100644100755
File mode changed.

test/unit/fixtures/crypto.json

100644100755
File mode changed.

test/unit/fixtures/ecpair.json

100644100755
File mode changed.

test/unit/fixtures/electrumx-mock.js

100644100755
File mode changed.

test/unit/fixtures/encryption-mock.js

100644100755
File mode changed.

test/unit/fixtures/hdnode.json

100644100755
File mode changed.

test/unit/fixtures/ipfs-mock.js

100644100755
File mode changed.

test/unit/fixtures/mnemonic.json

100644100755
File mode changed.

test/unit/fixtures/ninsight-mock.js

100644100755
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,47 @@
22
Mocking data for unit tests for the Ninsight library.
33
*/
44

5+
const details = {
6+
'address': 'mkPvAKZ2rar6qeG3KjBtJHHMSP1wFZH7Er',
7+
'satoshis': 2782729129,
8+
'height': 534105,
9+
'confirmations': 123,
10+
'timestamp': 1441068774,
11+
'fees': 35436,
12+
'outputIndexes': [
13+
0
14+
],
15+
'inputIndexes': [],
16+
'tx': {
17+
'hash': 'bb0ec3b96209fac9529570ea6f83a86af2cceedde4aaf2bfcc4796680d23f1c7',
18+
'version': 1,
19+
'inputs': [
20+
{
21+
'prevTxId': 'ea5e5bafbf29cdf6f6097ab344128477e67889d4d6203cb43594836daa6cc425',
22+
'outputIndex': 1,
23+
'sequenceNumber': 4294967294,
24+
'script': '483045022100f4d169783bef70e3943d2a617cce55d9fe4e33fc6f9880b8277265e2f619a97002201238648abcdf52960500664e969046d41755f7fc371971ebc78002fc418465a6012103acdcd31d51272403ce0829447e59e2ac9e08ed0bf92011cbf7420addf24534e6',
25+
'scriptString': '72 0x3045022100f4d169783bef70e3943d2a617cce55d9fe4e33fc6f9880b8277265e2f619a97002201238648abcdf52960500664e969046d41755f7fc371971ebc78002fc418465a601 33 0x03acdcd31d51272403ce0829447e59e2ac9e08ed0bf92011cbf7420addf24534e6',
26+
'output': {
27+
'satoshis': 2796764565,
28+
'script': '76a91488b1fe8aec5ae4358a11447a2f22b2781faedb9b88ac'
29+
}
30+
}
31+
],
32+
'outputs': [
33+
{
34+
'satoshis': 2782729129,
35+
'script': '76a9143583efb5e64a4668c6c54bb5fcc30af4417b4f2d88ac'
36+
},
37+
{
38+
'satoshis': 14000000,
39+
'script': '76a9149713201957f42379e574d7c70d506ee49c2c8ad688ac'
40+
}
41+
],
42+
'nLockTime': 534089
43+
}
44+
}
45+
546
const utxo = {
647
utxos: [
748
{
@@ -22,8 +63,11 @@ const utxo = {
2263
}
2364

2465
const utxoPost = [utxo, utxo]
66+
const detailsPost = [details, details]
2567

2668
module.exports = {
69+
details,
70+
detailsPost,
2771
utxo,
2872
utxoPost
2973
}

test/unit/fixtures/openbazaar-mock.js

100644100755
File mode changed.

test/unit/fixtures/price-mocks.js

100644100755
File mode changed.

test/unit/fixtures/script.json

100644100755
File mode changed.

test/unit/fixtures/slp/address.json

100644100755
File mode changed.

test/unit/fixtures/slp/ecpair.json

100644100755
File mode changed.

test/unit/fixtures/slp/mock-utils.js

100644100755
File mode changed.

test/unit/fixtures/transaction-builder.json

100644100755
File mode changed.

test/unit/generating.js

100644100755
File mode changed.

test/unit/hdnode.js

100644100755
File mode changed.

test/unit/ipfs.js

100644100755
File mode changed.

test/unit/mining.js

100644100755
File mode changed.

test/unit/mnemonic.js

100644100755
File mode changed.

test/unit/ninsight.js

100644100755
Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,82 @@ describe(`#Ninsight`, () => {
7878
assert.property(result[0], "asm")
7979
})
8080
})
81-
})
81+
82+
83+
describe(`#details`, () => {
84+
it(`should throw an error for improper input`, async () => {
85+
try {
86+
const addr = 12345
87+
88+
await bchjs.Ninsight.details(addr)
89+
assert.equal(true, false, "Unexpected result!")
90+
} catch (err) {
91+
//console.log(`err: `, err)
92+
assert.include(
93+
err.message,
94+
`Input address must be a string or array of strings.`
95+
)
96+
}
97+
})
98+
99+
it(`should GET details for a single address`, async () => {
100+
// Stub the network call.
101+
sandbox.stub(axios, "post").resolves({ data: mockData.details })
102+
103+
const addr = "mkPvAKZ2rar6qeG3KjBtJHHMSP1wFZH7Er"
104+
105+
const result = await bchjs.Ninsight.details(addr)
106+
console.log(`result: ${JSON.stringify(result, null, 2)}`)
107+
108+
assert.property(result, "satoshis")
109+
assert.property(result, "height")
110+
assert.property(result, "confirmations")
111+
assert.property(result, "timestamp")
112+
assert.property(result, "fees")
113+
assert.property(result, "outputIndexes")
114+
assert.property(result, "inputIndexes")
115+
assert.property(result, "tx")
116+
})
117+
118+
it(`should GET details for an array of addresses`, async () => {
119+
// Mock the network call.
120+
sandbox.stub(axios, "post").resolves({ data: mockData.detailsPost })
121+
122+
const addr = [
123+
"bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7",
124+
"bitcoincash:qz0us0z6ucpqt07jgpad0shgh7xmwxyr3ynlcsq0wr"
125+
]
126+
127+
const result = await bchjs.Ninsight.utxo(addr)
128+
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
129+
130+
assert.isArray(result)
131+
132+
assert.property(result[0], "satoshis")
133+
assert.property(result[0], "height")
134+
assert.property(result[0], "confirmations")
135+
assert.property(result[0], "timestamp")
136+
assert.property(result[0], "fees")
137+
assert.property(result[0], "outputIndexes")
138+
assert.property(result[0], "inputIndexes")
139+
assert.property(result[0], "tx")
140+
141+
/*
142+
I would like to refactor this test according to the DRY principle
143+
144+
assertDetails(result[0])
145+
146+
assertDetails(data) {
147+
assert.property(data, "satoshis")
148+
assert.property(data, "height")
149+
assert.property(data, "confirmations")
150+
assert.property(data, "timestamp")
151+
assert.property(data, "fees")
152+
assert.property(data, "outputIndexes")
153+
assert.property(data, "inputIndexes")
154+
assert.property(data, "tx")
155+
}
156+
*/
157+
})
158+
})
159+
})

test/unit/openbazaar.js

100644100755
File mode changed.

test/unit/price.js

100644100755
File mode changed.

test/unit/raw-tranactions.js

100644100755
File mode changed.

test/unit/scripts.js

100644100755
File mode changed.

test/unit/slp-address.js

100644100755
File mode changed.

test/unit/slp-ecpair.js

100644100755
File mode changed.

test/unit/slp-nft1.js

100644100755
File mode changed.

test/unit/slp-tokentype1.js

100644100755
File mode changed.

test/unit/slp-utils.js

100644100755
File mode changed.

test/unit/transaction-builder.js

100644100755
File mode changed.

test/unit/util.js

100644100755
File mode changed.

0 commit comments

Comments
 (0)