Comparing version 1.4.2 to 1.4.3
@@ -56,16 +56,11 @@ const {blockIndexByteLen} = require('./constants'); | ||
try { | ||
const channelId = !id ? rawChanId({number}).id : id; | ||
const channelId = !id ? rawChanId({number}).id : id; | ||
const channel = componentsFromBuffer({id: Buffer.from(channelId, 'hex')}); | ||
const chan = componentsFromBuffer({id: Buffer.from(channelId, 'hex')}); | ||
return { | ||
block_height: channel.block_height, | ||
block_index: channel.block_index, | ||
output_index: channel.output_index, | ||
}; | ||
} catch (err) { | ||
throw new Error('UnexpectedErrorDecodingChannelIdNumber'); | ||
} | ||
return { | ||
block_height: chan.block_height, | ||
block_index: chan.block_index, | ||
output_index: chan.output_index, | ||
}; | ||
}; | ||
@@ -77,2 +77,1 @@ const BN = require('bn.js'); | ||
}; | ||
@@ -14,2 +14,1 @@ const chanFormat = require('./chan_format'); | ||
}; | ||
@@ -11,3 +11,3 @@ { | ||
"devDependencies": { | ||
"tap": "14.4.2" | ||
"tap": "14.6.1" | ||
}, | ||
@@ -32,3 +32,3 @@ "keywords": [ | ||
}, | ||
"version": "1.4.2" | ||
"version": "1.4.3" | ||
} |
@@ -26,6 +26,17 @@ const {test} = require('tap'); | ||
}, | ||
{ | ||
args: {}, | ||
description: 'An id or number is required', | ||
error: 'ExpectedIdOrNumberToFormatAsChannelComponents', | ||
}, | ||
]; | ||
tests.forEach(({args, description, expected}) => { | ||
return test(description, ({end, equals}) => { | ||
tests.forEach(({args, description, error, expected}) => { | ||
return test(description, ({end, equals, throws}) => { | ||
if (!!error) { | ||
throws(() => chanFormat(args), new Error(error), 'Got expected error'); | ||
return end(); | ||
} | ||
const {channel} = chanFormat(args); | ||
@@ -38,2 +49,1 @@ | ||
}); | ||
@@ -26,6 +26,17 @@ const {test} = require('tap'); | ||
}, | ||
{ | ||
args: {}, | ||
description: 'Channel or id is required', | ||
error: 'ExpectedChannelIdOrComponentsToConvertToNumber', | ||
}, | ||
]; | ||
tests.forEach(({args, description, expected}) => { | ||
return test(description, ({end, equals}) => { | ||
tests.forEach(({args, description, error, expected}) => { | ||
return test(description, ({end, equals, throws}) => { | ||
if (!!error) { | ||
throws(() => chanNumber(args), new Error(error), 'Got expected error'); | ||
return end(); | ||
} | ||
const {number} = chanNumber(args); | ||
@@ -38,2 +49,1 @@ | ||
}); | ||
@@ -36,6 +36,22 @@ const {test} = require('tap'); | ||
}, | ||
{ | ||
args: {}, | ||
description: 'Id or channel or number is required', | ||
error: 'ExpectedShortChannelIdToDecode', | ||
}, | ||
{ | ||
args: {id: '00'}, | ||
description: 'Id needs to be correct length', | ||
error: 'UnexpectedLengthOfShortChannelId', | ||
}, | ||
]; | ||
tests.forEach(({args, description, expected}) => { | ||
return test(description, ({equal, end}) => { | ||
tests.forEach(({args, description, error, expected}) => { | ||
return test(description, ({equal, end, throws}) => { | ||
if (!!error) { | ||
throws(() => decodeChanId(args), new Error(error), 'Got expected err'); | ||
return end(); | ||
} | ||
const decoded = decodeChanId(args); | ||
@@ -50,2 +66,1 @@ | ||
}); | ||
@@ -24,6 +24,27 @@ const {test} = require('tap'); | ||
}, | ||
{ | ||
args: {}, | ||
description: 'Expected block height', | ||
error: 'ExpectedBlockHeightForChannelId', | ||
}, | ||
{ | ||
args: {block_height: 1440743}, | ||
description: 'Expected block index', | ||
error: 'ExpectedBlockIndexForChannelId', | ||
}, | ||
{ | ||
args: {block_height: 1440743, block_index: 2080}, | ||
description: 'Expected output index', | ||
error: 'ExpectedTransactionOutputIndexForChannelId', | ||
}, | ||
]; | ||
tests.forEach(({args, description, expected}) => { | ||
return test(description, ({equal, end}) => { | ||
tests.forEach(({args, description, error, expected}) => { | ||
return test(description, ({equal, end, throws}) => { | ||
if (!!error) { | ||
throws(() => encodeChanId(args), new Error(error), 'Got expected err'); | ||
return end(); | ||
} | ||
const encoded = encodeChanId(args); | ||
@@ -38,2 +59,1 @@ | ||
}); | ||
@@ -26,6 +26,17 @@ const {test} = require('tap'); | ||
}, | ||
{ | ||
args: {}, | ||
description: 'Number is required', | ||
error: 'ExpectedChannelIdInNumericFormat', | ||
}, | ||
]; | ||
tests.forEach(({args, description, expected}) => { | ||
return test(description, ({end, equals}) => { | ||
tests.forEach(({args, description, error, expected}) => { | ||
return test(description, ({end, equals, throws}) => { | ||
if (!!error) { | ||
throws(() => rawChanId(args), new Error(error), 'Got expected error'); | ||
return end(); | ||
} | ||
const {id} = rawChanId(args); | ||
@@ -38,2 +49,1 @@ | ||
}); | ||
21611
19
528