|
1 | 1 | import tape from 'tape'
|
2 | 2 | import Common from '../src/'
|
3 | 3 | import testnet from './data/testnet.json'
|
| 4 | +import energyWebChain from './data/energyWebChain.json' |
| 5 | +import volta from './data/volta.json' |
4 | 6 |
|
5 | 7 | tape('[Common]: Custom chains', function (t: tape.Test) {
|
6 | 8 | t.test(
|
@@ -35,23 +37,39 @@ tape('[Common]: Custom chains', function (t: tape.Test) {
|
35 | 37 | 'should throw an exception on missing parameter'
|
36 | 38 | ) // eslint-disable-line no-new
|
37 | 39 |
|
38 |
| - st.comment('-----------------------------------------------------------------') |
39 | 40 | st.end()
|
40 | 41 | }
|
41 | 42 | )
|
42 | 43 |
|
43 |
| - t.test('customChains parameter: ', (st) => { |
44 |
| - const c = new Common({ chain: testnet, hardfork: 'byzantium' }) |
45 |
| - st.equal(c.chainName(), 'testnet', 'should initialize with chain name') |
46 |
| - st.equal(c.chainId(), 12345, 'should return correct chain Id') |
47 |
| - st.equal(c.networkId(), 12345, 'should return correct network Id') |
48 |
| - st.equal( |
49 |
| - c.genesis().hash, |
50 |
| - '0xaa00000000000000000000000000000000000000000000000000000000000000', |
51 |
| - 'should return correct genesis hash' |
52 |
| - ) |
53 |
| - st.equal(c.hardforks()[3]['block'], 3, 'should return correct hardfork data') |
54 |
| - st.equal(c.bootstrapNodes()[1].ip, '10.0.0.2', 'should return a bootstrap node array') |
| 44 | + t.test('customChains parameter: initialization exception', (st) => { |
| 45 | + st.throws( |
| 46 | + function () { |
| 47 | + new Common({ chain: testnet, customChains: [testnet] }) |
| 48 | + }, |
| 49 | + /Chain must be a string or number when initialized with customChains passed in/, |
| 50 | + 'should throw an exception on wrong initialization' |
| 51 | + ) // eslint-disable-line no-new |
| 52 | + |
| 53 | + st.end() |
| 54 | + }) |
| 55 | + |
| 56 | + t.test('customChains parameter: initialization', (st) => { |
| 57 | + let c = new Common({ chain: 'mainnet', hardfork: 'byzantium', customChains: [testnet] }) |
| 58 | + st.equal(c.chainName(), 'mainnet', 'customChains, chain set to supported chain') |
| 59 | + st.equal(c.hardforkBlock(), 4370000, 'customChains, chain set to supported chain') |
| 60 | + |
| 61 | + c.setChain('testnet') |
| 62 | + st.equal(c.chainName(), 'testnet', 'customChains, chain switched to custom chain') |
| 63 | + st.equal(c.hardforkBlock(), 4, 'customChains, chain switched to custom chain') |
| 64 | + |
| 65 | + c = new Common({ chain: 'testnet', hardfork: 'byzantium', customChains: [testnet] }) |
| 66 | + st.equal(c.chainName(), 'testnet', 'customChains, chain initialized with custom chain') |
| 67 | + st.equal(c.hardforkBlock(), 4, 'customChains, chain initialized with custom chain') |
| 68 | + |
| 69 | + const customChains = [testnet, energyWebChain, volta] |
| 70 | + c = new Common({ chain: 'energyWebChain', hardfork: 'istanbul', customChains }) |
| 71 | + st.equal(c.chainName(), 'energyWebChain', 'customChains, chain initialized with custom chain') |
| 72 | + st.equal(c.hardforkBlock(), 4922294, 'customChains, chain initialized with custom chain') |
55 | 73 |
|
56 | 74 | st.end()
|
57 | 75 | })
|
|
0 commit comments