Skip to content
This repository has been archived by the owner on Apr 6, 2020. It is now read-only.

Commit

Permalink
Added support for private network parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
vpulim committed Aug 22, 2018
1 parent 029fec0 commit f7e18e6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
10 changes: 9 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ class Common {
} else {
throw new Error(`Chain with name ${chain} not supported`)
}
} else if (typeof (chain) === 'object') {
const required = ['networkId', 'genesis', 'hardforks', 'bootstrapNodes']
for (let param of required) {
if (chain[param] === undefined) {
throw new Error(`Missing equired chain parameter: ${param}`)
}
}
this._chainParams = chain
} else {
throw new Error('Wrong input format')
}
Expand Down Expand Up @@ -362,7 +370,7 @@ class Common {
* @returns {String} chain name (lower case)
*/
chainName () {
return chainParams['names'][this.chainId()]
return chainParams['names'][this.chainId()] || this._chainParams['name']
}

/**
Expand Down
14 changes: 14 additions & 0 deletions tests/chains.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,18 @@ tape('[Common]: Initialization / Chain params', function (t) {

st.end()
})

t.test('Should be able to set custom chain parameters', function (st) {
let chainParams = require('./testnet.json')
let c = new Common(chainParams, 'byzantium')
st.equal(c.chainName(), 'testnet', 'should initialize with chain name')
st.equal(c.chainId(), 12345, 'should return correct chain Id')
st.equal(c.networkId(), 12345, 'should return correct network Id')
st.equal(c.genesis().hash, '0xaa00000000000000000000000000000000000000000000000000000000000000', 'should return correct genesis hash')
st.equal(c.hardforks()[3]['block'], 3, 'should return correct hardfork data')
st.equal(c.bootstrapNodes()[1].ip, '10.0.0.2', 'should return a bootstrap node array')
st.equal(c.hardfork(), 'byzantium', 'should return correct hardfork name')

st.end()
})
})

0 comments on commit f7e18e6

Please sign in to comment.