Merge pull request #197 from Permissionless-Software-Foundation/ct-unstable

fix(psf-slp-indexer getAddress): Letting ecash addrs pass through
This commit is contained in:
Chris Troutner
2022-07-10 18:26:46 -07:00
committed by GitHub
3 changed files with 44 additions and 21 deletions
+1 -1
View File
@@ -42,6 +42,6 @@ logs/*
docs/* docs/*
docker/mainnet/start-local-mainnet.sh docker/mainnet/start-local-mainnet.sh
docker/testnet/start-local-testnet.sh docker/testnet/start-local-testnet.sh
start-local-bchn.sh
!logs/README.md !logs/README.md
+22 -20
View File
@@ -97,27 +97,29 @@ class PsfSlpIndexer {
}) })
} }
// Ensure the input is a valid BCH address. if (!address.includes('ecash')) {
try { // Ensure the input is a valid BCH address.
_this.bchjs.SLP.Address.toCashAddress(address) try {
} catch (err) { _this.bchjs.SLP.Address.toCashAddress(address)
res.status(400) } catch (err) {
return res.json({ res.status(400)
success: false, return res.json({
error: `Invalid BCH address. Double check your address is valid: ${address}` success: false,
}) error: `Invalid BCH address. Double check your address is valid: ${address}`
} })
}
// Prevent a common user error. Ensure they are using the correct network address. // Prevent a common user error. Ensure they are using the correct network address.
const cashAddr = _this.bchjs.SLP.Address.toCashAddress(address) const cashAddr = _this.bchjs.SLP.Address.toCashAddress(address)
const networkIsValid = _this.routeUtils.validateNetwork(cashAddr) const networkIsValid = _this.routeUtils.validateNetwork(cashAddr)
if (!networkIsValid) { if (!networkIsValid) {
res.status(400) res.status(400)
return res.json({ return res.json({
success: false, success: false,
error: error:
'Invalid network. Trying to use a testnet address on mainnet, or vice versa.' 'Invalid network. Trying to use a testnet address on mainnet, or vice versa.'
}) })
}
} }
const response = await _this.axios.post( const response = await _this.axios.post(
+21
View File
@@ -430,6 +430,27 @@ describe('#PsfSlpIndexer', () => {
assert.isArray(balance.txs) assert.isArray(balance.txs)
assert.isArray(balance.balances) assert.isArray(balance.balances)
}) })
it('should GET data for ecash address', async function () {
req.body.address =
'ecash:qr5c4hfy52zn87484cucvzle5pljz0gtr5vhtw9z09'
// Mock the RPC call for unit tests.
if (process.env.TEST === 'unit') {
sandbox.stub(uut.axios, 'post').resolves({ data: mockData.balance })
} else {
return this.skip()
}
const result = await uut.getAddress(req, res)
const balance = result.balance
assert.property(balance, 'utxos')
assert.property(balance, 'txs')
assert.property(balance, 'balances')
assert.isArray(balance.utxos)
assert.isArray(balance.txs)
assert.isArray(balance.balances)
})
}) })
describe('#getStatus', async () => { describe('#getStatus', async () => {