Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"scripts": {
"build": "rm -rf dist/* && tsc",
"test": "yarn build && mocha",
"test": "yarn build && mocha test",
"prepublishOnly": "yarn test"
},
"repository": {
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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,
}
10 changes: 8 additions & 2 deletions src/token-tracker-link.ts
Original file line number Diff line number Diff line change
@@ -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 }` : ''
}`
}
15 changes: 0 additions & 15 deletions test/account-link-test.js

This file was deleted.

14 changes: 0 additions & 14 deletions test/hash-link-test.js

This file was deleted.

59 changes: 59 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
@@ -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')
})
})