diff --git a/package.json b/package.json index 8419a86..c722b6e 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ ], "scripts": { "build": "rm -rf dist/* && tsc", - "test": "yarn build && mocha", + "test": "yarn build && mocha test", "prepublishOnly": "yarn test" }, "repository": { diff --git a/src/index.ts b/src/index.ts index a322365..cd74597 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,9 +1,9 @@ import createExplorerLink from './explorer-link' import createAccountLink from './account-link' -import createTokenTrackerLink './token-tracker-link' +import createTokenTrackerLink from './token-tracker-link' export = { createExplorerLink, createAccountLink, - createTokenTrackerLink + createTokenTrackerLink, } diff --git a/src/token-tracker-link.ts b/src/token-tracker-link.ts index c38ea96..17e63ab 100644 --- a/src/token-tracker-link.ts +++ b/src/token-tracker-link.ts @@ -1,6 +1,12 @@ import prefixForNetwork from './prefix-for-network' -export = function getTokenTrackerLink(tokenAddress: string, network: string, holderAddress?: string): string { +export = function getTokenTrackerLink( + tokenAddress: string, + network: string, + holderAddress?: string, +): string { const prefix = prefixForNetwork(network) - return `https://${prefix}etherscan.io/token/${tokenAddress}${ holderAddress ? `?a=${ holderAddress }` : '' }` + return `https://${prefix}etherscan.io/token/${tokenAddress}${ + holderAddress ? `?a=${ holderAddress }` : '' + }` } diff --git a/test/account-link-test.js b/test/account-link-test.js deleted file mode 100644 index bc3f078..0000000 --- a/test/account-link-test.js +++ /dev/null @@ -1,15 +0,0 @@ -const assert = require('assert') -const linkGen = require('../dist/explorer-link') - -describe('explorer-link', function () { - it('adds ropsten prefix to ropsten test network', function () { - const result = linkGen('hash', '3') - assert.notStrictEqual(result.indexOf('ropsten'), -1, 'ropsten injected') - }) - - it('adds kovan prefix to kovan test network', function () { - const result = linkGen('hash', '42') - assert.notStrictEqual(result.indexOf('kovan'), -1, 'kovan injected') - }) -}) - diff --git a/test/hash-link-test.js b/test/hash-link-test.js deleted file mode 100644 index 6353252..0000000 --- a/test/hash-link-test.js +++ /dev/null @@ -1,14 +0,0 @@ -const assert = require('assert') -const linkGen = require('../dist/explorer-link') - -describe('explorer-link', function () { - it('adds ropsten prefix to ropsten test network', function () { - const result = linkGen('hash', '3') - assert.notStrictEqual(result.indexOf('ropsten'), -1, 'ropsten injected') - }) - - it('adds kovan prefix to kovan test network', function () { - const result = linkGen('hash', '42') - assert.notStrictEqual(result.indexOf('kovan'), -1, 'kovan injected') - }) -}) diff --git a/test/index.test.js b/test/index.test.js new file mode 100644 index 0000000..00f0de5 --- /dev/null +++ b/test/index.test.js @@ -0,0 +1,59 @@ +const assert = require('assert') +const { + createAccountLink, + createExplorerLink, + createTokenTrackerLink, +} = require('../dist') + +// `https://${prefix}etherscan.io/address/${address}` +describe('account-link', function () { + it('should handle mainnet correctly', function () { + const result = createAccountLink('foo', '1') + assert.strictEqual(result, 'https://etherscan.io/address/foo', 'should handle mainnet') + }) + + it('should handle ropsten correctly', function () { + const result = createAccountLink('foo', '3') + assert.strictEqual(result, 'https://ropsten.etherscan.io/address/foo', 'should handle ropsten') + }) +}) + +// `https://${prefix}etherscan.io/tx/${hash}` +describe('explorer-link', function () { + it('should handle mainnet correctly', function () { + const result = createExplorerLink('foo', '1') + assert.strictEqual(result, 'https://etherscan.io/tx/foo', 'should handle mainnet') + }) + + it('should handle ropsten correctly', function () { + const result = createExplorerLink('foo', '3') + assert.strictEqual(result, 'https://ropsten.etherscan.io/tx/foo', 'should handle ropsten') + }) +}) + +/** + * `https://${prefix}etherscan.io/token/${tokenAddress}${ + * holderAddress ? `?a=${ holderAddress }` : '' + * }` + */ +describe('token-tracker-link', function () { + it('should handle mainnet correctly (no account)', function () { + const result = createTokenTrackerLink('foo', '1') + assert.strictEqual(result, 'https://etherscan.io/token/foo', 'should handle mainnet') + }) + + it('should handle ropsten correctly (no account)', function () { + const result = createTokenTrackerLink('foo', '3') + assert.strictEqual(result, 'https://ropsten.etherscan.io/token/foo', 'should handle ropsten') + }) + + it('should handle mainnet correctly (account)', function () { + const result = createTokenTrackerLink('foo', '1', '0xabc') + assert.strictEqual(result, 'https://etherscan.io/token/foo?a=0xabc', 'should handle mainnet') + }) + + it('should handle ropsten correctly (account)', function () { + const result = createTokenTrackerLink('foo', '3', '0xabc') + assert.strictEqual(result, 'https://ropsten.etherscan.io/token/foo?a=0xabc', 'should handle ropsten') + }) +})