diff --git a/src/index.js b/src/index.js index 6095b2b..854d63a 100644 --- a/src/index.js +++ b/src/index.js @@ -13,6 +13,10 @@ class Vain extends Emitter { super(); this.addressFormat = addressFormats.get(addressFormat); + if (typeof prefix !== 'string' || prefix.length === 0) { + throw new Error('Prefix must be set'); + } + prefix.split('').forEach(char => { if (!this.addressFormat.charset.includes(char)) { throw new Error(`Invalid characters for address format "${addressFormat}"`); diff --git a/test/unit.js b/test/unit.js index 951c716..b926090 100644 --- a/test/unit.js +++ b/test/unit.js @@ -88,3 +88,9 @@ test('Vain throws on invalid charset', t => { t.true(error.message.includes('Invalid characters for address format')); }); }); + +test('Vain throws on undefined prefix', t => { + const options = {}; + const error = t.throws(() => new Vain(options)); + t.is(error.message, 'Prefix must be set'); +});