-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c0cd322
commit 44b0d6b
Showing
31 changed files
with
954 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const isHex = require('is-hex'); | ||
|
||
const hashHexLength = 64; | ||
|
||
/** Determine if a string looks like a regular 256 bit hex encoded hash | ||
{ | ||
[hash]: <Hash String> | ||
} | ||
@returns | ||
{ | ||
is_hash: <Looks Like Regular Hash Bool> | ||
} | ||
*/ | ||
module.exports = ({hash}) => { | ||
return {is_hash: !!hash && isHex(hash) && hash.length === hashHexLength}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const isHex = require('is-hex'); | ||
const {Transaction} = require('bitcoinjs-lib'); | ||
|
||
/** Determine if a hex string is a regular Transaction | ||
{ | ||
[transaction]: <Transaction Hex String> | ||
} | ||
@returns | ||
<Looks Like Regular Transaction Bool> | ||
*/ | ||
module.exports = ({transaction}) => { | ||
if (!transaction || !isHex(transaction)) { | ||
return false; | ||
} | ||
|
||
try { | ||
Transaction.fromHex(transaction); | ||
} catch (err) { | ||
return false; | ||
} | ||
|
||
return true; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
const authenticatedLndGrpc = require('./authenticated_lnd_grpc'); | ||
const isLnd = require('./is_lnd'); | ||
const unauthenticatedLndGrpc = require('./unauthenticated_lnd_grpc'); | ||
|
||
module.exports = {authenticatedLndGrpc, unauthenticatedLndGrpc}; | ||
module.exports = {authenticatedLndGrpc, isLnd, unauthenticatedLndGrpc}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** Determine if object is an expected LND Object | ||
{ | ||
[lnd]: <LND Object> | ||
[method]: <Method Name String> | ||
[type]: <Method Type String> | ||
} | ||
@returns | ||
<Is Expected LND Object Bool> | ||
*/ | ||
module.exports = ({lnd, method, type}) => { | ||
return !!lnd && !!lnd[type] && !!lnd[type][method]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
const {test} = require('tap'); | ||
|
||
const {getBackup} = require('./../../'); | ||
|
||
const txId = Buffer.alloc(32).toString('hex'); | ||
|
||
const tests = [ | ||
{ | ||
args: {}, | ||
description: 'LND object is required', | ||
error: [400, 'ExpectedGrpcApiConnectionToGetChannelBackup'], | ||
}, | ||
{ | ||
args: {lnd: {}}, | ||
description: 'LND object with default methods is required', | ||
error: [400, 'ExpectedGrpcApiConnectionToGetChannelBackup'], | ||
}, | ||
{ | ||
args: {lnd: {default: {}}}, | ||
description: 'A funding transaction id is required', | ||
error: [400, 'ExpectedTxIdOfChannelToGetChannelBackup'], | ||
}, | ||
{ | ||
args: {lnd: {default: {}}, transaction_id: txId}, | ||
description: 'A funding transaction vout is required', | ||
error: [400, 'ExpectedTxOutputIndexToGetChannelBackup'], | ||
}, | ||
{ | ||
args: { | ||
lnd: {default: {exportChannelBackup: ({}, cbk) => cbk('err')}}, | ||
transaction_id: txId, | ||
transaction_vout: 0, | ||
}, | ||
description: 'An unexpected error is returned', | ||
error: [503, 'UnexpectedErrExportingBackupForChannel', {err: 'err'}], | ||
}, | ||
{ | ||
args: { | ||
lnd: {default: {exportChannelBackup: ({}, cbk) => cbk()}}, | ||
transaction_id: txId, | ||
transaction_vout: 0, | ||
}, | ||
description: 'A result is returned', | ||
error: [503, 'ExpectedResultOfGetChannelBackupRequest'], | ||
}, | ||
{ | ||
args: { | ||
lnd: {default: {exportChannelBackup: ({}, cbk) => cbk(null, {})}}, | ||
transaction_id: txId, | ||
transaction_vout: 0, | ||
}, | ||
description: 'A chan backup result is returned', | ||
error: [503, 'UnexpectedResponseForChannelBackupRequest'], | ||
}, | ||
{ | ||
args: { | ||
lnd: { | ||
default: { | ||
exportChannelBackup: ({}, cbk) => cbk(null, { | ||
chan_backup: Buffer.alloc(0), | ||
}), | ||
}, | ||
}, | ||
transaction_id: txId, | ||
transaction_vout: 0, | ||
}, | ||
description: 'A non empty chan backup result is returned', | ||
error: [503, 'UnexpectedResponseForChannelBackupRequest'], | ||
}, | ||
{ | ||
args: { | ||
lnd: { | ||
default: { | ||
exportChannelBackup: ({}, cbk) => cbk(null, { | ||
chan_backup: Buffer.alloc(1), | ||
}), | ||
}, | ||
}, | ||
transaction_id: txId, | ||
transaction_vout: 0, | ||
}, | ||
description: 'A non empty chan backup result is returned', | ||
expected: {backup: '00'}, | ||
}, | ||
]; | ||
|
||
tests.forEach(({args, description, error, expected}) => { | ||
return test(description, async ({deepEqual, end, equal, rejects}) => { | ||
if (!!error) { | ||
rejects(() => getBackup(args), error, 'Got expected error'); | ||
} else { | ||
const {backup} = await getBackup(args); | ||
|
||
equal(backup, expected.backup, 'Got expected backup'); | ||
} | ||
|
||
return end(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
const {test} = require('tap'); | ||
|
||
const {createChainAddress} = require('./../../'); | ||
|
||
const tests = [ | ||
{ | ||
args: {}, | ||
description: 'An address format is required', | ||
error: [400, 'ExpectedKnownAddressFormat'], | ||
}, | ||
{ | ||
args: {format: 'foo'}, | ||
description: 'A known address format is required', | ||
error: [400, 'ExpectedKnownAddressFormat'], | ||
}, | ||
{ | ||
args: {format: 'p2wpkh'}, | ||
description: 'LND is required', | ||
error: [400, 'ExpectedLndForAddressCreation'], | ||
}, | ||
{ | ||
args: {format: 'p2wpkh', lnd: {}}, | ||
description: 'LND with default is required', | ||
error: [400, 'ExpectedLndForAddressCreation'], | ||
}, | ||
{ | ||
args: {format: 'p2wpkh', lnd: {default: {}}}, | ||
description: 'LND with default is required', | ||
error: [400, 'ExpectedLndForAddressCreation'], | ||
}, | ||
{ | ||
args: { | ||
format: 'p2wpkh', | ||
lnd: { | ||
default: { | ||
newAddress: ({}, cbk) => cbk({ | ||
message: '14 UNAVAILABLE: Connect Failed', | ||
}), | ||
}, | ||
}, | ||
}, | ||
description: 'Connection failure error is returned', | ||
error: [503, 'FailedToConnectToDaemonToCreateChainAddress'], | ||
}, | ||
{ | ||
args: { | ||
format: 'p2wpkh', | ||
lnd: {default: {newAddress: ({}, cbk) => cbk('err')}}, | ||
}, | ||
description: 'Unanticipated errors are returned', | ||
error: [503, 'UnexpectedErrorCreatingAddress', {err: 'err'}], | ||
}, | ||
{ | ||
args: {format: 'p2wpkh', lnd: {default: {newAddress: ({}, cbk) => cbk()}}}, | ||
description: 'A result is required', | ||
error: [503, 'ExpectedResponseForAddressCreation'], | ||
}, | ||
{ | ||
args: { | ||
format: 'p2wpkh', | ||
lnd: {default: {newAddress: ({}, cbk) => cbk(null, {})}}, | ||
}, | ||
description: 'An address is required', | ||
error: [503, 'ExpectedAddressInCreateAddressResponse'], | ||
}, | ||
{ | ||
args: { | ||
format: 'p2wpkh', | ||
lnd: {default: {newAddress: ({}, cbk) => cbk(null, {address: 'addr'})}}, | ||
}, | ||
description: 'An address is required', | ||
expected: {address: 'addr'}, | ||
}, | ||
{ | ||
args: { | ||
format: 'p2wpkh', | ||
is_unused: true, | ||
lnd: { | ||
default: { | ||
newAddress: (args, cbk) => { | ||
if (args.type !== 2) { | ||
return cbk([500, 'FailedToSetUnusedFlagForAddress', args.type]); | ||
} | ||
|
||
return cbk(null, {address: 'addr'}); | ||
}, | ||
}, | ||
}, | ||
}, | ||
description: 'An unused address gets an unused address', | ||
expected: {address: 'addr'}, | ||
}, | ||
]; | ||
|
||
tests.forEach(({args, description, error, expected}) => { | ||
return test(description, async ({deepEqual, end, equal, rejects}) => { | ||
if (!!error) { | ||
rejects(() => createChainAddress(args), error, 'Got expected error'); | ||
} else { | ||
const {address} = await createChainAddress(args); | ||
|
||
equal(address, expected.address, 'Got expected new address'); | ||
} | ||
|
||
return end(); | ||
}); | ||
}); |
Oops, something went wrong.