1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 09:57:02 +01:00

test - unit - use ganache instead of deprecated block-tracker test util

This commit is contained in:
kumavis 2018-04-27 17:11:44 -07:00
parent 2b9925a9e4
commit b487dab2e7
2 changed files with 22 additions and 5 deletions

View File

@ -217,9 +217,10 @@
"eslint-plugin-json": "^1.2.0", "eslint-plugin-json": "^1.2.0",
"eslint-plugin-mocha": "^5.0.0", "eslint-plugin-mocha": "^5.0.0",
"eslint-plugin-react": "^7.4.0", "eslint-plugin-react": "^7.4.0",
"eth-json-rpc-middleware": "^1.2.7", "eth-json-rpc-middleware": "^1.6.0",
"fs-promise": "^2.0.3", "fs-promise": "^2.0.3",
"ganache-cli": "^6.1.0", "ganache-cli": "^6.1.0",
"ganache-core": "^2.1.0",
"gifencoder": "^1.1.0", "gifencoder": "^1.1.0",
"gulp": "github:gulpjs/gulp#6d71a658c61edb3090221579d8f97dbe086ba2ed", "gulp": "github:gulpjs/gulp#6d71a658c61edb3090221579d8f97dbe086ba2ed",
"gulp-babel": "^7.0.0", "gulp-babel": "^7.0.0",

View File

@ -1,14 +1,28 @@
const JsonRpcEngine = require('json-rpc-engine') const JsonRpcEngine = require('json-rpc-engine')
const scaffoldMiddleware = require('eth-json-rpc-middleware/scaffold') const scaffoldMiddleware = require('eth-json-rpc-middleware/scaffold')
const TestBlockchain = require('eth-block-tracker/test/util/testBlockMiddleware') const providerAsMiddleware = require('eth-json-rpc-middleware/providerAsMiddleware')
const GanacheCore = require('ganache-core')
module.exports = { module.exports = {
createEngineForTestData, createEngineForTestData,
providerFromEngine, providerFromEngine,
scaffoldMiddleware, scaffoldMiddleware,
createTestProviderTools, createTestProviderTools,
getTestSeed,
getTestAccounts,
} }
function getTestSeed () {
return 'people carpet cluster attract ankle motor ozone mass dove original primary mask'
}
function getTestAccounts () {
return [
{ address: '0x88bb7F89eB5e5b30D3e15a57C68DBe03C6aCCB21', key: Buffer.from('254A8D551474F35CCC816388B4ED4D20B945C96B7EB857A68064CB9E9FB2C092', 'hex') },
{ address: '0x1fe9aAB565Be19629fF4e8541ca2102fb42D7724', key: Buffer.from('6BAB5A4F2A6911AF8EE2BD32C6C05F6643AC48EF6C939CDEAAAE6B1620805A9B', 'hex') },
{ address: '0xbda5c89aa6bA1b352194291AD6822C92AbC87c7B', key: Buffer.from('9B11D7F833648F26CE94D544855558D7053ECD396E4F4563968C232C012879B0', 'hex') },
]
}
function createEngineForTestData () { function createEngineForTestData () {
return new JsonRpcEngine() return new JsonRpcEngine()
@ -21,11 +35,13 @@ function providerFromEngine (engine) {
function createTestProviderTools (opts = {}) { function createTestProviderTools (opts = {}) {
const engine = createEngineForTestData() const engine = createEngineForTestData()
const testBlockchain = new TestBlockchain()
// handle provided hooks // handle provided hooks
engine.push(scaffoldMiddleware(opts.scaffold || {})) engine.push(scaffoldMiddleware(opts.scaffold || {}))
// handle block tracker methods // handle block tracker methods
engine.push(testBlockchain.createMiddleware()) engine.push(providerAsMiddleware(GanacheCore.provider({
mnemonic: getTestSeed(),
})))
// wrap in standard provider interface
const provider = providerFromEngine(engine) const provider = providerFromEngine(engine)
return { provider, engine, testBlockchain } return { provider, engine }
} }