1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-01 13:47:06 +01:00
metamask-extension/test/stub/provider.js
Erik Marks b3963daaab
eth-json-rpc-middleware@8.0.0 (#10738)
We're bumping from `^6` to `^8`. All imports are now named, and they have been updated. This is a breaking change, in that support for `eth_signTransaction` is added in `^8.0.0`. We do not support this method in our UI, so our middleware stack has been instrumented to reject.

In addition, there are some non-breaking behavioral changes in this version that reviewers should be aware of, see the [7.0.0 release](https://github.com/MetaMask/eth-json-rpc-middleware/releases).
2021-11-11 12:26:49 -08:00

63 lines
1.7 KiB
JavaScript

import { JsonRpcEngine, createScaffoldMiddleware } from 'json-rpc-engine';
import { providerAsMiddleware } from 'eth-json-rpc-middleware';
import GanacheCore from 'ganache-core';
export function getTestSeed() {
return 'people carpet cluster attract ankle motor ozone mass dove original primary mask';
}
export function getTestAccounts() {
return [
{
address: '0x88bb7F89eB5e5b30D3e15a57C68DBe03C6aCCB21',
key: Buffer.from(
'254A8D551474F35CCC816388B4ED4D20B945C96B7EB857A68064CB9E9FB2C092',
'hex',
),
},
{
address: '0x1fe9aAB565Be19629fF4e8541ca2102fb42D7724',
key: Buffer.from(
'6BAB5A4F2A6911AF8EE2BD32C6C05F6643AC48EF6C939CDEAAAE6B1620805A9B',
'hex',
),
},
{
address: '0xbda5c89aa6bA1b352194291AD6822C92AbC87c7B',
key: Buffer.from(
'9B11D7F833648F26CE94D544855558D7053ECD396E4F4563968C232C012879B0',
'hex',
),
},
];
}
export function createEngineForTestData() {
return new JsonRpcEngine();
}
export function providerFromEngine(engine) {
const provider = { sendAsync: engine.handle.bind(engine) };
return provider;
}
export function createTestProviderTools(opts = {}) {
const engine = createEngineForTestData();
// handle provided hooks
engine.push(createScaffoldMiddleware(opts.scaffold || {}));
// handle block tracker methods
engine.push(
providerAsMiddleware(
GanacheCore.provider({
mnemonic: getTestSeed(),
network_id: opts.networkId,
_chainId: opts.chainId,
_chainIdRpc: opts.chainId,
}),
),
);
// wrap in standard provider interface
const provider = providerFromEngine(engine);
return { provider, engine };
}