Skip to content

Commit

Permalink
Merge 137a2cb into 9bfef9f
Browse files Browse the repository at this point in the history
  • Loading branch information
vbaranov committed Jan 10, 2019
2 parents 9bfef9f + 137a2cb commit 582fa4a
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 12 deletions.
18 changes: 12 additions & 6 deletions helpers/get-explorer-links.js
@@ -1,28 +1,34 @@
const POAIDs = [77, 99, 100]
const RSKIDs = [30]

const getExplorerAccountLinkFor = (account, network) => {
const prefix = getExplorerPrefix(network)
const POAnetwokIDs = [77, 99, 100]
if (POAnetwokIDs.includes(parseInt(network))) {
if (POAIDs.includes(parseInt(network))) {
return `https://blockscout.com/poa/${prefix}/address/${account}`
} else if (RSKIDs.includes(parseInt(network))) {
return `https://explorer.rsk.co/address/${account}`
} else {
return `https://${prefix}etherscan.io/address/${account}`
}
}

const getExplorerTxLinkFor = (hash, network) => {
const prefix = getExplorerPrefix(network)
const POAnetwokIDs = [77, 99, 100]
if (POAnetwokIDs.includes(parseInt(network))) {
if (POAIDs.includes(parseInt(network))) {
return `https://blockscout.com/poa/${prefix}/tx/${hash}`
} else if (RSKIDs.includes(parseInt(network))) {
return `https://explorer.rsk.co/tx/${hash}`
} else {
return `https://${prefix}etherscan.io/tx/${hash}`
}
}

const getExplorerTokenLinkFor = (tokenAddress, account, network) => {
const prefix = getExplorerPrefix(network)
const POAnetwokIDs = [77, 99, 100]
if (POAnetwokIDs.includes(parseInt(network))) {
if (POAIDs.includes(parseInt(network))) {
return `https://blockscout.com/poa/${prefix}/address/${tokenAddress}`
} else if (RSKIDs.includes(parseInt(network))) {
return `https://explorer.rsk.co/token/${tokenAddress}/account/${account}`
} else {
return `https://${prefix}etherscan.io/token/${tokenAddress}?a=${account}`
}
Expand Down
2 changes: 2 additions & 0 deletions helpers/get-faucet-links.js
Expand Up @@ -9,6 +9,8 @@ function getFaucetLinks(network) {
return ['https://faucet.kovan.network/', 'https://gitter.im/kovan-testnet/faucet/']
case 77:
return ['https://faucet.poa.network/']
case 31:
return ['https://faucet.testnet.rsk.co/']
default:
return []
}
Expand Down
8 changes: 8 additions & 0 deletions helpers/get-net-properties.js
Expand Up @@ -15,6 +15,10 @@ function getNetworkDisplayName(network) {
return 'POA Network'
case 100:
return 'xDai Chain'
case 30:
return 'RSK Mainnet'
case 31:
return 'RSK Testnet'
default:
return 'Unknown Private Network'
}
Expand All @@ -26,6 +30,9 @@ function getNetworkCoinName(network) {
case 77:
case 99:
return 'POA'
case 30:
case 31:
return 'RBTC'
case 100:
return 'xDAI'
default:
Expand All @@ -39,6 +46,7 @@ function isTestnet(network) {
case 1:
case 99:
case 100:
case 30:
return false
default:
return true
Expand Down
6 changes: 5 additions & 1 deletion helpers/get-rpc-endpoints.js
Expand Up @@ -12,9 +12,13 @@ function getRPCEndpoints(network) {
case 77:
return ['https://sokol.poa.network/']
case 99:
return ['https://poa.infura.io/', 'https://core.poa.network/']
return ['https://core.poa.network/']
case 100:
return ['https://dai.poa.network/']
case 30:
return ['https://public-node.rsk.co']
case 31:
return ['https://public-node.testnet.rsk.co']
default:
return []
}
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "eth-net-props",
"version": "1.0.10",
"version": "1.0.11",
"description": "Get properties of EMV-based network",
"main": "index.js",
"directories": {
Expand Down
54 changes: 51 additions & 3 deletions test/test.js
Expand Up @@ -32,6 +32,9 @@ describe('eth-net-props', () => {
it(`${claimPrefix} Kovan`, () => {
assert.equal(explorerLinks.getExplorerAccountLinkFor('0x70FDd102DDB03Dc55B1719E76DfeA784916621fd', 42), 'https://kovan.etherscan.io/address/0x70FDd102DDB03Dc55B1719E76DfeA784916621fd')
})
it(`${claimPrefix} RSK Mainnet`, () => {
assert.equal(explorerLinks.getExplorerAccountLinkFor('0x70FDd102DDB03Dc55B1719E76DfeA784916621fd', 30), 'https://explorer.rsk.co/address/0x70FDd102DDB03Dc55B1719E76DfeA784916621fd')
})
})

describe ('getExplorerTxLinkFor()', () => {
Expand All @@ -56,6 +59,9 @@ describe('eth-net-props', () => {
it(`${claimPrefix} Kovan`, () => {
assert.equal(explorerLinks.getExplorerTxLinkFor('0x892c825d1ec25b0a1a27aa5dff5b54fc4488a45029d0087fc40d3d733ded7305', 42), 'https://kovan.etherscan.io/tx/0x892c825d1ec25b0a1a27aa5dff5b54fc4488a45029d0087fc40d3d733ded7305')
})
it(`${claimPrefix} RSK Mainnet`, () => {
assert.equal(explorerLinks.getExplorerTxLinkFor('0x33a7511c7838f5be0ade40d732f0a51cd28c8a641de9079836170cbdac8e7d83', 30), 'https://explorer.rsk.co/tx/0x33a7511c7838f5be0ade40d732f0a51cd28c8a641de9079836170cbdac8e7d83')
})
})

describe ('getExplorerTokenLinkFor()', () => {
Expand All @@ -80,6 +86,9 @@ describe('eth-net-props', () => {
it(`${claimPrefix} Kovan`, () => {
assert.equal(explorerLinks.getExplorerTokenLinkFor('0xcf2AEDCfb4ff2c9020fb61c41226A4DfD77D12dE', '0x70FDd102DDB03Dc55B1719E76DfeA784916621fd', 42), 'https://kovan.etherscan.io/token/0xcf2AEDCfb4ff2c9020fb61c41226A4DfD77D12dE?a=0x70FDd102DDB03Dc55B1719E76DfeA784916621fd')
})
it(`${claimPrefix} RSK Mainnet`, () => {
assert.equal(explorerLinks.getExplorerTokenLinkFor('0x16cb2604ce5951c8506fbf690d816be6d0aa00fb', '0x604056c0f88aed17ef975269aab1ae9d02840bb2', 30), 'https://explorer.rsk.co/token/0x16cb2604ce5951c8506fbf690d816be6d0aa00fb/account/0x604056c0f88aed17ef975269aab1ae9d02840bb2')
})
})
})

Expand Down Expand Up @@ -114,10 +123,18 @@ describe('eth-net-props', () => {
assert.equal(kovanFaucetLinks[1], 'https://gitter.im/kovan-testnet/faucet/')
}
})
it(`${claimPrefix} RSK Testnet`, () => {
const RSKFaucetLinks = faucetLinks.getFaucetLinks(31)
assert.equal(RSKFaucetLinks.length, 1)
if (RSKFaucetLinks.length > 0) {
assert.equal(RSKFaucetLinks[0], 'https://faucet.testnet.rsk.co/')
}
})
it('should not return faucet link for production blockchains', () => {
assert.equal(faucetLinks.getFaucetLinks(1).length, 0)
assert.equal(faucetLinks.getFaucetLinks(99).length, 0)
assert.equal(faucetLinks.getFaucetLinks(100).length, 0)
assert.equal(faucetLinks.getFaucetLinks(30).length, 0)
})
})

Expand Down Expand Up @@ -160,10 +177,9 @@ describe('eth-net-props', () => {
})
it(`${claimPrefix} Core POA Network`, () => {
const POARPCEndpoints = RPCEndpoints.getRPCEndpoints(99)
assert.equal(POARPCEndpoints.length, 2)
assert.equal(POARPCEndpoints.length, 1)
if (POARPCEndpoints.length > 0) {
assert.equal(POARPCEndpoints[0], 'https://poa.infura.io/')
assert.equal(POARPCEndpoints[1], 'https://core.poa.network/')
assert.equal(POARPCEndpoints[0], 'https://core.poa.network/')
}
})
it(`${claimPrefix} xDai chain`, () => {
Expand All @@ -173,6 +189,20 @@ describe('eth-net-props', () => {
assert.equal(xDaiRPCEndpoints[0], 'https://dai.poa.network/')
}
})
it(`${claimPrefix} RSK Mainnet`, () => {
const RSKRPCEndpoints = RPCEndpoints.getRPCEndpoints(30)
assert.equal(RSKRPCEndpoints.length, 1)
if (RSKRPCEndpoints.length > 0) {
assert.equal(RSKRPCEndpoints[0], 'https://public-node.rsk.co')
}
})
it(`${claimPrefix} RSK TestNet`, () => {
const RSKRPCEndpoints = RPCEndpoints.getRPCEndpoints(31)
assert.equal(RSKRPCEndpoints.length, 1)
if (RSKRPCEndpoints.length > 0) {
assert.equal(RSKRPCEndpoints[0], 'https://public-node.testnet.rsk.co')
}
})
})

claimPrefix = 'should return correct display name for'
Expand All @@ -189,6 +219,9 @@ describe('eth-net-props', () => {
it(`${claimPrefix} Mainnet`, () => {
assert.equal(netProps.getNetworkDisplayName(1), 'Main Ethereum Network')
})
it(`${claimPrefix} RSK Mainnet`, () => {
assert.equal(netProps.getNetworkDisplayName(30), 'RSK Mainnet')
})
it(`${claimPrefix} Ropsten`, () => {
assert.equal(netProps.getNetworkDisplayName(3), 'Ropsten Test Network')
})
Expand All @@ -198,6 +231,9 @@ describe('eth-net-props', () => {
it(`${claimPrefix} Kovan`, () => {
assert.equal(netProps.getNetworkDisplayName(42), 'Kovan Test Network')
})
it(`${claimPrefix} RSK Testnet`, () => {
assert.equal(netProps.getNetworkDisplayName(31), 'RSK Testnet')
})

claimPrefix = 'should return correct coin name for'
it(`${claimPrefix} Sokol POA Network`, () => {
Expand All @@ -212,6 +248,9 @@ describe('eth-net-props', () => {
it(`${claimPrefix} Mainnet`, () => {
assert.equal(netProps.getNetworkCoinName(1), 'ETH')
})
it(`${claimPrefix} RSK Mainnet`, () => {
assert.equal(netProps.getNetworkCoinName(30), 'RBTC')
})
it(`${claimPrefix} Ropsten`, () => {
assert.equal(netProps.getNetworkCoinName(3), 'ETH')
})
Expand All @@ -221,6 +260,9 @@ describe('eth-net-props', () => {
it(`${claimPrefix} Kovan`, () => {
assert.equal(netProps.getNetworkCoinName(42), 'ETH')
})
it(`${claimPrefix} RSK Testnet`, () => {
assert.equal(netProps.getNetworkCoinName(31), 'RBTC')
})

it('Sokol POA Network is a testnet', () => {
assert.equal(netProps.isTestnet(77), true)
Expand All @@ -234,6 +276,9 @@ describe('eth-net-props', () => {
it('Mainnet is not a testnet', () => {
assert.equal(netProps.isTestnet(1), false)
})
it('RSK Mainnet is not a testnet', () => {
assert.equal(netProps.isTestnet(30), false)
})
it('Ropsten is a testnet', () => {
assert.equal(netProps.isTestnet(3), true)
})
Expand All @@ -243,5 +288,8 @@ describe('eth-net-props', () => {
it('Kovan is a testnet', () => {
assert.equal(netProps.isTestnet(42), true)
})
it('RSK Testnet is a testnet', () => {
assert.equal(netProps.isTestnet(31), true)
})
})
})

0 comments on commit 582fa4a

Please sign in to comment.