mirror of
https://github.com/Permissionless-Software-Foundation/bch-js.git
synced 2026-09-22 00:52:01 -07:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cf8f48ffe1 | ||
|
|
fc96b04a64 | ||
|
|
661a759f80 | ||
|
|
ba915e84cf | ||
|
|
eae7172e3d | ||
|
|
6dd2a0590f | ||
|
|
3152e87b5d | ||
|
|
4b66f3841d | ||
|
|
9f98a47682 | ||
|
|
0833e8ca78 | ||
|
|
e01a18b65e | ||
|
|
055cd7feca | ||
|
|
906d9b2094 | ||
|
|
9326fd6e59 | ||
|
|
1d91eed5df | ||
|
|
62e56c832b | ||
|
|
d5b7e4ab1d | ||
|
|
2137a75fce | ||
|
|
8966cac210 | ||
|
|
9d32f828bc | ||
|
|
91a7106818 | ||
|
|
44e671dfbe | ||
|
|
979fb481de | ||
|
|
66253ed5a6 | ||
|
|
6ef5ac0f7c | ||
|
|
21c322d0df | ||
|
|
1b0e9ef0ff | ||
|
|
78776bee93 | ||
|
|
a6e3155f37 |
Generated
+8269
-9520
File diff suppressed because it is too large
Load Diff
+3
-3
@@ -12,14 +12,14 @@
|
||||
"test": "nyc mocha --trace-warnings --unhandled-rejections=strict --timeout 30000 test/unit/",
|
||||
"test:integration": "npm run test:integration:bchn",
|
||||
"test:integration:nft": "export RESTURL=https://bchn.fullstack.cash/v5/ && export IS_USING_FREE_TIER=true && mocha --timeout 30000 -g '#nft1' test/integration/chains/bchn/slp.js",
|
||||
"test:integration:abc": "export RESTURL=https://abc.fullstack.cash/v5/ && export IS_USING_FREE_TIER=true && mocha --timeout 30000 test/integration/ && mocha --timeout 30000 test/integration/chains/abc/",
|
||||
"test:integration:abc": "export RESTURL=https://abc.fullstack.cash/v5/ && mocha --timeout 30000 test/integration/ && mocha --timeout 30000 test/integration/chains/abc/",
|
||||
"test:integration:bchn": "export RESTURL=https://bchn.fullstack.cash/v5/ && export IS_USING_FREE_TIER=true && mocha --timeout 30000 test/integration/ && mocha --timeout 30000 test/integration/chains/bchn/",
|
||||
"test:integration:bchn:slpdb": "export TESTSLP=1 && export RESTURL=https://bchn.fullstack.cash/v5/ && export IS_USING_FREE_TIER=true && mocha --timeout 30000 test/integration/ && mocha --timeout 30000 test/integration/chains/bchn/",
|
||||
"test:integration:local:abc": "export RESTURL=http://localhost:3000/v5/ && mocha --timeout 30000 test/integration && mocha --timeout 30000 test/integration/chains/abc/",
|
||||
"test:integration:local:bchn": "export RESTURL=http://localhost:3000/v5/ && mocha --timeout 30000 test/integration/ && mocha --timeout 30000 test/integration/chains/bchn/",
|
||||
"test:integration:local:testnet": "RESTURL=http://localhost:4000/v5/ mocha --timeout 30000 test/integration/chains/testnet",
|
||||
"test:integration:decatur:bchn": "export RESTURL=http://192.168.2.129:3000/v5/ && mocha --timeout 30000 test/integration/ && mocha --timeout 30000 test/integration/chains/bchn/",
|
||||
"test:integration:decatur:abc": "export RESTURL=http://192.168.2.141:3000/v5/ && mocha --timeout 30000 test/integration && mocha --timeout 30000 test/integration/chains/abc/",
|
||||
"test:integration:decatur:abc": "export RESTURL=http://192.168.2.142:3000/v5/ && mocha --timeout 30000 test/integration && mocha --timeout 30000 test/integration/chains/abc/",
|
||||
"test:integration:temp:bchn": "export RESTURL=http://157.90.174.219:3000/v5/ && mocha --timeout 30000 test/integration/",
|
||||
"test:temp": "export RESTURL=http://localhost:3000/v5/ && mocha --timeout 30000 -g '#Encryption' test/integration/",
|
||||
"test:temp2": "mocha --timeout=30000 -g '#TransactionLib' test/unit/",
|
||||
@@ -40,7 +40,7 @@
|
||||
"@chris.troutner/bip32-utils": "1.0.5",
|
||||
"@psf/bip21": "2.0.1",
|
||||
"@psf/bitcoincash-ops": "2.0.0",
|
||||
"@psf/bitcoincashjs-lib": "4.0.2",
|
||||
"@psf/bitcoincashjs-lib": "4.0.3",
|
||||
"@psf/coininfo": "4.0.0",
|
||||
"axios": "0.26.1",
|
||||
"bc-bip68": "1.0.5",
|
||||
|
||||
+5
-3
@@ -289,12 +289,12 @@ class ElectrumX {
|
||||
* }
|
||||
*
|
||||
*/
|
||||
async transactions (address, usrObj = null) {
|
||||
async transactions (address, usrObj = null, allTxs = false) {
|
||||
try {
|
||||
// Handle single address.
|
||||
if (typeof address === 'string') {
|
||||
const response = await axios.get(
|
||||
`${this.restURL}electrumx/transactions/${address}`,
|
||||
`${this.restURL}electrumx/transactions/${address}/${allTxs}`,
|
||||
this.axiosOptions
|
||||
)
|
||||
return response.data
|
||||
@@ -305,7 +305,8 @@ class ElectrumX {
|
||||
`${this.restURL}electrumx/transactions`,
|
||||
{
|
||||
addresses: address,
|
||||
usrObj // pass user data when making an internal call.
|
||||
usrObj, // pass user data when making an internal call.
|
||||
allTxs
|
||||
},
|
||||
this.axiosOptions
|
||||
)
|
||||
@@ -315,6 +316,7 @@ class ElectrumX {
|
||||
|
||||
throw new Error('Input address must be a string or array of strings.')
|
||||
} catch (error) {
|
||||
// console.log('Error in transactions(): ', error)
|
||||
if (error.response && error.response.data) throw error.response.data
|
||||
else throw error
|
||||
}
|
||||
|
||||
@@ -32,6 +32,28 @@ class Encryption {
|
||||
_this = this
|
||||
}
|
||||
|
||||
/**
|
||||
* @api encryption.getPubKey() getPubKey()
|
||||
* @apiName Encryption getPubKey()
|
||||
* @apiGroup Encryption
|
||||
* @apiDescription Get the public key for an address
|
||||
* Given an address, the command will search the blockchain for a public
|
||||
* key associated with that address. The address needs to have made at least
|
||||
* one spend transaction, in order for its public key to be retrievable.
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
*(async () => {
|
||||
* try {
|
||||
* const addr = 'bitcoincash:qqlrzp23w08434twmvr4fxw672whkjy0py26r63g3d'
|
||||
* const pubkey = await bchjs.encryption.getPubKey(addr);
|
||||
* console.log(pubkey);
|
||||
* } catch(err) {
|
||||
* console.error(err)
|
||||
* }
|
||||
*})()
|
||||
*
|
||||
*/
|
||||
|
||||
// Search the blockchain for a public key associated with a BCH address.
|
||||
async getPubKey (addr) {
|
||||
try {
|
||||
|
||||
+13
-13
@@ -30,19 +30,19 @@ class Price {
|
||||
}
|
||||
|
||||
// This endpoint is deprecated. Documentation removed.
|
||||
async current (currency = 'usd') {
|
||||
try {
|
||||
const response = await this.axios.get(
|
||||
`https://index-api.bitcoin.com/api/v0/cash/price/${currency.toLowerCase()}`
|
||||
)
|
||||
// console.log(`response.data: ${JSON.stringify(response.data, null, 2)}`)
|
||||
|
||||
return response.data.price
|
||||
} catch (err) {
|
||||
if (err.response && err.response.data) throw err.response.data
|
||||
else throw err
|
||||
}
|
||||
}
|
||||
// async current (currency = 'usd') {
|
||||
// try {
|
||||
// const response = await this.axios.get(
|
||||
// `https://index-api.bitcoin.com/api/v0/cash/price/${currency.toLowerCase()}`
|
||||
// )
|
||||
// // console.log(`response.data: ${JSON.stringify(response.data, null, 2)}`)
|
||||
//
|
||||
// return response.data.price
|
||||
// } catch (err) {
|
||||
// if (err.response && err.response.data) throw err.response.data
|
||||
// else throw err
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* @api price.getUsd() getUsd()
|
||||
|
||||
+98
-2
@@ -194,6 +194,7 @@ class PsfSlpIndexer {
|
||||
* }
|
||||
* }
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
async tokenStats (tokenId, withTxHistory = false) {
|
||||
@@ -420,7 +421,7 @@ class PsfSlpIndexer {
|
||||
* }
|
||||
*
|
||||
*/
|
||||
async getTokenData (tokenId) {
|
||||
async getTokenData (tokenId, withTxHistory = false) {
|
||||
try {
|
||||
const url = `${this.restURL}psf/slp/token/data`
|
||||
// console.log(`url: ${url}`)
|
||||
@@ -430,7 +431,7 @@ class PsfSlpIndexer {
|
||||
const response = await axios.post(
|
||||
// 'https://bchn.fullstack.cash/v5/psf/slp/token/data/',
|
||||
url,
|
||||
{ tokenId },
|
||||
{ tokenId, withTxHistory },
|
||||
this.axiosOptions
|
||||
)
|
||||
return response.data
|
||||
@@ -441,6 +442,101 @@ class PsfSlpIndexer {
|
||||
else throw error
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api PsfSlpIndexer.getTokenData2() getTokenData2()
|
||||
* @apiName Token Data
|
||||
* @apiGroup PSF SLP
|
||||
* @apiDescription Get token icon and other media associated with a token.
|
||||
*
|
||||
* Get the icon for a token, given it's token ID.
|
||||
* This function expects a string input of a token ID property.
|
||||
* This function returns an object with a tokenIcon property that contains
|
||||
* the URL to the icon.
|
||||
*
|
||||
* The output object always have these properties:
|
||||
* - tokenIcon: A url to the token icon, if it exists.
|
||||
* - tokenStats: Data about the token from psf-slp-indexer.
|
||||
* - optimizedTokenIcon: An alternative, potentially more optimal, url to the token icon, if it exists.
|
||||
* - iconRepoCompatible: true if the token icon is available via token.bch.sx
|
||||
* - ps002Compatible: true if the token icon is compatible with PS007 specification.
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* (async () => {
|
||||
* try {
|
||||
* let tokenData = await bchjs.PsfSlpIndexer.getTokenData2('a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2')
|
||||
* console.log(tokenData)
|
||||
* } catch(error) {
|
||||
* console.error(error)
|
||||
* }
|
||||
* })()
|
||||
*
|
||||
* {
|
||||
* tokenStats: {
|
||||
* type: 1,
|
||||
* ticker: 'CTAIA006',
|
||||
* name: 'CTAIA006 - AI Art by Chris Troutner',
|
||||
* tokenId: '0e4543f820699294ab57e02ee2b1815a8bbc7b17a4333e4a138034e4b2324a61',
|
||||
* documentUri: 'ipfs://bafybeia5yuq7rg6jmwquako7t277cwrobcunz7cumqrv4wn6bgfvthemku',
|
||||
* documentHash: '78a00e9db312b8fff4e5c37cf592be83e6bab7f3bd5a54c9545bad5d4f3ee0f5',
|
||||
* decimals: 0,
|
||||
* mintBatonIsActive: false,
|
||||
* tokensInCirculationBN: '1',
|
||||
* tokensInCirculationStr: '1',
|
||||
* blockCreated: 757507,
|
||||
* totalBurned: '0',
|
||||
* totalMinted: '1'
|
||||
* },
|
||||
* mutableData: {
|
||||
* tokenIcon: 'https://bafybeihiv5jvlhoymmbous3h2akotogj6b7hruhjcj3zq7dsfteimuuttm.ipfs.w3s.link/whale-night-sky-01.png',
|
||||
* fullSizedUrl: '',
|
||||
* about: 'This NFT was created using the PSF Token Studio at https://nft-creator.fullstack.cash',
|
||||
* userData: ''
|
||||
* },
|
||||
* immutableData: {
|
||||
* issuer: 'http://psfoundation.cash',
|
||||
* website: 'https://nft-creator.fullstack.cash',
|
||||
* dateCreated: '9/12/2022, 5:17:38 PM',
|
||||
* userData: '{\n' +
|
||||
* ' "title": "CTAIA006 - AI Art by Chris Troutner",\n' +
|
||||
* ' "about": "AI generated art. Generated from DALL-E at https://labs.openai.com",\n' +
|
||||
* ' "prompt": "whale swimming through a sky full of stars",\n' +
|
||||
* ' "algorithm": "DALL-E (stable diffusion)",\n' +
|
||||
* ' "set": "1-of-2"\n' +
|
||||
* '}'
|
||||
* },
|
||||
* tokenIcon: 'https://bafybeihiv5jvlhoymmbous3h2akotogj6b7hruhjcj3zq7dsfteimuuttm.ipfs.w3s.link/whale-night-sky-01.png',
|
||||
* fullSizedUrl: '',
|
||||
* optimizedTokenIcon: 'https://p2wdb-gateway-678.fullstack.cash/ipfs/bafybeihiv5jvlhoymmbous3h2akotogj6b7hruhjcj3zq7dsfteimuuttm/whale-night-sky-01.png',
|
||||
* optimizedFullSizedUrl: '',
|
||||
* iconRepoCompatible: false,
|
||||
* ps002Compatible: true
|
||||
* }
|
||||
*
|
||||
*/
|
||||
async getTokenData2 (tokenId, updateCache = false) {
|
||||
try {
|
||||
const url = `${this.restURL}psf/slp/token/data2`
|
||||
// console.log(`url: ${url}`)
|
||||
|
||||
// Handle single address.
|
||||
if (typeof tokenId === 'string') {
|
||||
const response = await axios.post(
|
||||
// 'https://bchn.fullstack.cash/v5/psf/slp/token/data/',
|
||||
url,
|
||||
{ tokenId, updateCache },
|
||||
this.axiosOptions
|
||||
)
|
||||
return response.data
|
||||
}
|
||||
|
||||
throw new Error('Input tokenId must be a string.')
|
||||
} catch (error) {
|
||||
// console.log('error: ', error)
|
||||
if (error.response && error.response.data) throw error.response.data
|
||||
else throw error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = PsfSlpIndexer
|
||||
|
||||
@@ -407,6 +407,7 @@ class RawTransactions {
|
||||
// pass back the raw transaction data.
|
||||
/* exit quietly */
|
||||
}
|
||||
// console.log(`txDetails: ${JSON.stringify(txDetails, null, 2)}`)
|
||||
|
||||
return txDetails
|
||||
} catch (error) {
|
||||
|
||||
+14
@@ -109,6 +109,11 @@ class UTXO {
|
||||
}
|
||||
}
|
||||
|
||||
// Get the sync status of the SLP indexer
|
||||
const syncStatus = await this.psfSlpIndexer.status()
|
||||
const slpIndexerHeight = syncStatus.status.syncedBlockHeight
|
||||
const chainBlockHeight = syncStatus.status.chainBlockHeight
|
||||
|
||||
// Loop through the Fulcrum UTXOs.
|
||||
for (let i = 0; i < utxos.length; i++) {
|
||||
const thisUtxo = utxos[i]
|
||||
@@ -152,6 +157,15 @@ class UTXO {
|
||||
thisUtxo.isSlp = false
|
||||
}
|
||||
// console.log(`thisUtxo.isSlp: ${thisUtxo.isSlp}`)
|
||||
|
||||
// If the SLP indexer more than 1 block behind the full node, then
|
||||
// move any BCH UTXOs of 600 sats or less into the null array. This
|
||||
// protects token UTXOs from being burned accidentally.
|
||||
if (slpIndexerHeight < chainBlockHeight - 1) {
|
||||
if (thisUtxo.value < 601) {
|
||||
thisUtxo.isSlp = null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
This test is used to interrogate the behavior of bch-js when a psf-slp-indexer
|
||||
panicks and starts indexing from SLP genesis. In this corner-case, bch-js
|
||||
should detect the indexer is out of sync, and protect any token UTXOs by
|
||||
moving any UTXO under 600 sats into the null array.
|
||||
|
||||
TO RUN THIS TEST:
|
||||
- Reset a local instance of psf-slp-indexer to sync from genesis.
|
||||
- Start a local copy of bch-api
|
||||
*/
|
||||
|
||||
const BCHJS = require('../../../src/bch-js.js')
|
||||
const bchjs = new BCHJS({
|
||||
restURL: 'http://localhost:3000/v5/'
|
||||
})
|
||||
|
||||
async function startTest () {
|
||||
try {
|
||||
const addr = 'bitcoincash:qzkvas58zag9tjry693mflkjze2m20ps7vx7uw7z9d'
|
||||
|
||||
const result = await bchjs.Utxo.get(addr)
|
||||
console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||
} catch (err) {
|
||||
console.error('Error in startTest(): ', err)
|
||||
}
|
||||
}
|
||||
startTest()
|
||||
@@ -318,7 +318,9 @@ describe('#blockchain', () => {
|
||||
it('should get info about the blockchain', async () => {
|
||||
const result = await bchjs.Blockchain.getBlockchainInfo()
|
||||
|
||||
console.log(`blockchain info: ${JSON.stringify(result, null, 2)}`)
|
||||
// console.log(`blockchain info: ${JSON.stringify(result, null, 2)}`)
|
||||
|
||||
assert.property(result, 'blocks')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -145,7 +145,39 @@ describe('#psf-slp-indexer', () => {
|
||||
assert.isString(result.immutableData)
|
||||
assert.isString(result.mutableData)
|
||||
})
|
||||
|
||||
it('should get token data with a transaction history', async () => {
|
||||
const tokenId = '43eddfb11c9941edffb8c8815574bb0a43969a7b1de39ad14cd043eaa24fd38d'
|
||||
|
||||
const result = await bchjs.PsfSlpIndexer.getTokenData(tokenId, true)
|
||||
// console.log('result: ', result)
|
||||
|
||||
assert.isArray(result.genesisData.txs)
|
||||
})
|
||||
})
|
||||
|
||||
// This test is commented out because it can not succeed in the BVT without
|
||||
// tripping rate limits.
|
||||
// describe('#getTokenData2', () => {
|
||||
// it('should get token data', async () => {
|
||||
// const tokenId =
|
||||
// 'd9aafa7acb514c597caf440ae268b5e4e955f2687e05f044cdf8fd9550d9a27b'
|
||||
//
|
||||
// // bchjs.PsfSlpIndexer.restURL = 'http://localhost:3000/v5/'
|
||||
// const result = await bchjs.PsfSlpIndexer.getTokenData2(tokenId)
|
||||
// // console.log('result: ', result)
|
||||
//
|
||||
// assert.property(result, 'tokenStats')
|
||||
// assert.property(result, 'mutableData')
|
||||
// assert.property(result, 'immutableData')
|
||||
// assert.property(result, 'tokenIcon')
|
||||
// assert.property(result, 'fullSizedUrl')
|
||||
// assert.property(result, 'optimizedTokenIcon')
|
||||
// assert.property(result, 'optimizedFullSizedUrl')
|
||||
// assert.property(result, 'iconRepoCompatible')
|
||||
// assert.property(result, 'ps002Compatible')
|
||||
// })
|
||||
// })
|
||||
})
|
||||
|
||||
// Promise-based sleep function
|
||||
|
||||
@@ -126,7 +126,7 @@ describe('#UTXO', () => {
|
||||
describe('#isValid', () => {
|
||||
it('should return true for valid UTXO with fullnode properties', async () => {
|
||||
const utxo = {
|
||||
txid: 'b94e1ff82eb5781f98296f0af2488ff06202f12ee92b0175963b8dba688d1b40',
|
||||
txid: '260d4fb4006a330660c805327c840d569d7547b7e3e9659fb423b3a041c2e254',
|
||||
vout: 0
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ describe('#UTXO', () => {
|
||||
|
||||
it('should return true for valid UTXO with fulcrum properties', async () => {
|
||||
const utxo = {
|
||||
tx_hash: 'b94e1ff82eb5781f98296f0af2488ff06202f12ee92b0175963b8dba688d1b40',
|
||||
tx_hash: '260d4fb4006a330660c805327c840d569d7547b7e3e9659fb423b3a041c2e254',
|
||||
tx_pos: 0
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@ describe('#UTXO', () => {
|
||||
})
|
||||
|
||||
it('should process output of Utxo.get()', async () => {
|
||||
const utxo = await bchjs.Utxo.get('bitcoincash:qr4yscpw9jgq8ltajfeknpj32kamkf9knujffcdhyq')
|
||||
const utxo = await bchjs.Utxo.get('bitcoincash:qqgahqa5zkknmhmvsc98jndpwn3r77gqgc02x03jce')
|
||||
// console.log(`utxo: ${JSON.stringify(utxo, null, 2)}`)
|
||||
|
||||
const result = await bchjs.Utxo.isValid(utxo.bchUtxos[0])
|
||||
|
||||
@@ -15,7 +15,7 @@ describe('#control', () => {
|
||||
describe('#getNetworkInfo', () => {
|
||||
it('should get info on the full node', async () => {
|
||||
const result = await bchjs.Control.getNetworkInfo()
|
||||
console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||
|
||||
assert.property(result, 'version')
|
||||
})
|
||||
|
||||
@@ -373,6 +373,9 @@ describe('#ElectrumX', () => {
|
||||
|
||||
describe('#sortAllTxs', () => {
|
||||
it('should GET transaction history for a single address', async () => {
|
||||
// Add delay for this endpoint.
|
||||
await sleep(6000)
|
||||
|
||||
const addr = 'bitcoincash:qpdh9s677ya8tnx7zdhfrn8qfyvy22wj4qa7nwqa5v'
|
||||
|
||||
const txs = await bchjs.Electrumx.transactions(addr)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const assert = require('chai').assert
|
||||
// const assert = require('chai').assert
|
||||
|
||||
const BCHJS = require('../../src/bch-js')
|
||||
const bchjs = new BCHJS()
|
||||
// const BCHJS = require('../../src/bch-js')
|
||||
// const bchjs = new BCHJS()
|
||||
|
||||
describe('#Encryption', () => {
|
||||
beforeEach(async () => {
|
||||
@@ -9,7 +9,12 @@ describe('#Encryption', () => {
|
||||
})
|
||||
|
||||
describe('#getPubKey', () => {
|
||||
// Commenting out these tests since they are failing in BVT due to 429 errors
|
||||
/*
|
||||
it('should get a public key', async () => {
|
||||
// Add delay for this endpoint.
|
||||
await sleep(8000)
|
||||
|
||||
const addr = 'bitcoincash:qpf8jv9hmqcda0502gjp7nm3g24y5h5s4unutghsxq'
|
||||
|
||||
const result = await bchjs.encryption.getPubKey(addr)
|
||||
@@ -21,6 +26,9 @@ describe('#Encryption', () => {
|
||||
})
|
||||
|
||||
it('should report when public key can not be found', async () => {
|
||||
// Add delay for this endpoint.
|
||||
await sleep(8000)
|
||||
|
||||
const addr = 'bitcoincash:qrgqqkky28jdkv3w0ctrah0mz3jcsnsklc34gtukrh'
|
||||
|
||||
const result = await bchjs.encryption.getPubKey(addr)
|
||||
@@ -31,6 +39,7 @@ describe('#Encryption', () => {
|
||||
assert.property(result, 'publicKey')
|
||||
assert.equal(result.publicKey, 'not found')
|
||||
})
|
||||
*/
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -7,14 +7,14 @@ describe('#price', () => {
|
||||
if (process.env.IS_USING_FREE_TIER) await sleep(1500)
|
||||
})
|
||||
|
||||
describe('#current', () => {
|
||||
describe('#single currency', () => {
|
||||
it('should get current price for single currency', async () => {
|
||||
const result = await bchjs.Price.current('usd')
|
||||
assert.notEqual(0, result)
|
||||
})
|
||||
})
|
||||
})
|
||||
// describe('#current', () => {
|
||||
// describe('#single currency', () => {
|
||||
// it('should get current price for single currency', async () => {
|
||||
// const result = await bchjs.Price.current('usd')
|
||||
// assert.notEqual(0, result)
|
||||
// })
|
||||
// })
|
||||
// })
|
||||
|
||||
describe('#getUsd', () => {
|
||||
it('should get the USD price of BCH', async () => {
|
||||
@@ -33,6 +33,7 @@ describe('#price', () => {
|
||||
assert.isNumber(result)
|
||||
})
|
||||
})
|
||||
|
||||
describe('#getBchUsd', () => {
|
||||
it('should get the USD price of BCH', async () => {
|
||||
const result = await bchjs.Price.getBchUsd()
|
||||
|
||||
@@ -204,7 +204,9 @@ describe('#rawtransaction', () => {
|
||||
const result = await bchjs.RawTransactions.decodeScript(hex)
|
||||
// console.log(`result ${JSON.stringify(result, null, 2)}`)
|
||||
|
||||
assert.hasAllKeys(result, ['asm', 'type', 'p2sh'])
|
||||
assert.property(result, 'asm')
|
||||
assert.property(result, 'type')
|
||||
assert.property(result, 'p2sh')
|
||||
})
|
||||
|
||||
// CT 2/20/19 - Waiting for this PR to be merged complete the test:
|
||||
|
||||
@@ -150,11 +150,65 @@ const tokenData = {
|
||||
mutableData: 'ipfs://bafybeie6t5uyupddc7azms737xg4hxrj7i5t5ov3lb5g2qeehaujj6ak64'
|
||||
}
|
||||
|
||||
const tokenMedia01 = {
|
||||
tokenStats: {
|
||||
type: 65,
|
||||
ticker: 'TEST02',
|
||||
name: 'How to Send BCH and Tokens',
|
||||
tokenId: 'd9aafa7acb514c597caf440ae268b5e4e955f2687e05f044cdf8fd9550d9a27b',
|
||||
documentUri: 'ipfs://bafybeigjujbb55wqr5lns7z7vleg5cfp4yjwqp4swisxpgxl4xsp5tngai',
|
||||
documentHash: '845f803d8dd3c2b6be94a6cf3a445b54c36f2e01bd5c9ab4c23f37dbd531489e',
|
||||
decimals: 0,
|
||||
mintBatonIsActive: false,
|
||||
tokensInCirculationBN: '0',
|
||||
tokensInCirculationStr: '0',
|
||||
blockCreated: 740089,
|
||||
totalBurned: '1',
|
||||
totalMinted: '1',
|
||||
parentGroupId: 'c9c425f2c6352697c6665a53e035cbad8a44c4b1e36491a1838dc4655479aa09'
|
||||
},
|
||||
mutableData: {
|
||||
updated: '2022-05-14T15:27:44.429Z',
|
||||
tokenIcon: 'https://bafybeiefg3nd5iognbqztkpi5hj34dmwkqfe7v7xeayn2nhhatinmjmzcy.ipfs.dweb.link/send-bch-token-icon.png',
|
||||
tokenInfo: 'https://token.fullstack.cash/?tokenid=d9aafa7acb514c597caf440ae268b5e4e955f2687e05f044cdf8fd9550d9a27b',
|
||||
description: 'This is an NFT representing a video. This is a test token.',
|
||||
issuer: 'Chris Troutner',
|
||||
forSale: false,
|
||||
display: true,
|
||||
currentOwner: {
|
||||
bchAddr: 'bitcoincash:qqy7jcrm3vmtqs96r878hy2kx90mn84f25ujqw9z5h',
|
||||
name: 'Chris Troutner',
|
||||
contactEmail: 'chris.troutner@gmail.com'
|
||||
},
|
||||
content: {
|
||||
youtube: 'https://youtu.be/WZRwkLPtkaI',
|
||||
rumble: 'https://rumble.com/v14n00h-how-to-send-bch-and-tokens.html',
|
||||
odysee: 'https://odysee.com/@trout:5/how-to-send-bch-tokens:0',
|
||||
lbry: 'lbry://@trout#5/how-to-send-bch-tokens#0',
|
||||
ipfs: 'bafybeigf3ky5i6fyxwk5bjmtsr6urqmlx4zq2lqathgguytey67iinh4be',
|
||||
filecoin: 'https://bafybeigf3ky5i6fyxwk5bjmtsr6urqmlx4zq2lqathgguytey67iinh4be.ipfs.dweb.link/send-bch-2022-02-20_08.22.45.mp4'
|
||||
}
|
||||
},
|
||||
immutableData: {
|
||||
creationDate: '2022-05-13T21:32:11.619Z',
|
||||
issuer: 'Chris Troutner',
|
||||
license: 'https://bafybeidnkhjfsbihp4gquwqrs6y35jfpcriafymceszwvkundjkwk546pi.ipfs.dweb.link/copyright.txt',
|
||||
name: 'How to Send BCH and Tokens'
|
||||
},
|
||||
tokenIcon: 'https://bafybeiefg3nd5iognbqztkpi5hj34dmwkqfe7v7xeayn2nhhatinmjmzcy.ipfs.dweb.link/send-bch-token-icon.png',
|
||||
fullSizedUrl: '',
|
||||
optimizedTokenIcon: 'https://p2wdb-gateway-678.fullstack.cash/ipfs/bafybeiefg3nd5iognbqztkpi5hj34dmwkqfe7v7xeayn2nhhatinmjmzcy/send-bch-token-icon.png',
|
||||
optimizedFullSizedUrl: '',
|
||||
iconRepoCompatible: false,
|
||||
ps002Compatible: true
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
tokenStats,
|
||||
txData,
|
||||
balance,
|
||||
status,
|
||||
tokenData01,
|
||||
tokenData
|
||||
tokenData,
|
||||
tokenMedia01
|
||||
}
|
||||
|
||||
+12
-12
@@ -19,18 +19,18 @@ describe('#price', () => {
|
||||
|
||||
afterEach(() => sandbox.restore())
|
||||
|
||||
describe('#current', () => {
|
||||
it('should get current price for single currency', async () => {
|
||||
sandbox
|
||||
.stub(bchjs.Price.axios, 'get')
|
||||
.resolves({ data: { price: 24905 } })
|
||||
|
||||
const result = await bchjs.Price.current('usd')
|
||||
// console.log(result)
|
||||
|
||||
assert.isNumber(result)
|
||||
})
|
||||
})
|
||||
// describe('#current', () => {
|
||||
// it('should get current price for single currency', async () => {
|
||||
// sandbox
|
||||
// .stub(bchjs.Price.axios, 'get')
|
||||
// .resolves({ data: { price: 24905 } })
|
||||
//
|
||||
// const result = await bchjs.Price.current('usd')
|
||||
// // console.log(result)
|
||||
//
|
||||
// assert.isNumber(result)
|
||||
// })
|
||||
// })
|
||||
|
||||
describe('#getUsd', () => {
|
||||
it('should get the USD price of BCH', async () => {
|
||||
|
||||
@@ -411,4 +411,28 @@ describe('#PsfSlpIndexer', () => {
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('#getTokenData2', () => {
|
||||
it('should get token data', async () => {
|
||||
// Stub the network call.
|
||||
sandbox.stub(axios, 'post').resolves({ data: mockData.tokenMedia01 })
|
||||
|
||||
const tokenId =
|
||||
'd9aafa7acb514c597caf440ae268b5e4e955f2687e05f044cdf8fd9550d9a27b'
|
||||
|
||||
// bchjs.PsfSlpIndexer.restURL = 'http://localhost:3000/v5/'
|
||||
const result = await bchjs.PsfSlpIndexer.getTokenData2(tokenId)
|
||||
// console.log('result: ', result)
|
||||
|
||||
assert.property(result, 'tokenStats')
|
||||
assert.property(result, 'mutableData')
|
||||
assert.property(result, 'immutableData')
|
||||
assert.property(result, 'tokenIcon')
|
||||
assert.property(result, 'fullSizedUrl')
|
||||
assert.property(result, 'optimizedTokenIcon')
|
||||
assert.property(result, 'optimizedFullSizedUrl')
|
||||
assert.property(result, 'iconRepoCompatible')
|
||||
assert.property(result, 'ps002Compatible')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -121,6 +121,8 @@ describe('#utxo', () => {
|
||||
sandbox
|
||||
.stub(bchjs.Utxo.psfSlpIndexer, 'tx')
|
||||
.resolves({ txData: { isValidSlp: false } })
|
||||
sandbox.stub(bchjs.Utxo.psfSlpIndexer, 'status')
|
||||
.resolves({ status: { syncedBlockHeight: 600000, chainBlockHeight: 600000 } })
|
||||
|
||||
// Mock function to return the same input. Good enough for this test.
|
||||
sandbox.stub(bchjs.Utxo, 'hydrateTokenData').resolves(x => x)
|
||||
@@ -154,6 +156,8 @@ describe('#utxo', () => {
|
||||
sandbox
|
||||
.stub(bchjs.Utxo.psfSlpIndexer, 'tx')
|
||||
.resolves({ txData: { isValidSlp: false } })
|
||||
sandbox.stub(bchjs.Utxo.psfSlpIndexer, 'status')
|
||||
.resolves({ status: { syncedBlockHeight: 600000, chainBlockHeight: 600000 } })
|
||||
|
||||
// Force psf-slp-indexer to return no UTXOs
|
||||
sandbox
|
||||
|
||||
Reference in New Issue
Block a user