2021-11-11 21:26:49 +01:00
|
|
|
import { JsonRpcEngine, createScaffoldMiddleware } from 'json-rpc-engine';
|
2023-02-27 17:49:08 +01:00
|
|
|
import { providerAsMiddleware } from '@metamask/eth-json-rpc-middleware';
|
2022-01-20 17:56:52 +01:00
|
|
|
import Ganache from 'ganache';
|
2017-08-09 00:30:03 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getTestSeed() {
|
2021-02-04 19:15:23 +01:00
|
|
|
return 'people carpet cluster attract ankle motor ozone mass dove original primary mask';
|
2018-04-28 02:11:44 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getTestAccounts() {
|
2018-04-28 02:11:44 +02:00
|
|
|
return [
|
2020-11-03 00:41:28 +01:00
|
|
|
{
|
|
|
|
address: '0x88bb7F89eB5e5b30D3e15a57C68DBe03C6aCCB21',
|
|
|
|
key: Buffer.from(
|
|
|
|
'254A8D551474F35CCC816388B4ED4D20B945C96B7EB857A68064CB9E9FB2C092',
|
|
|
|
'hex',
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
address: '0x1fe9aAB565Be19629fF4e8541ca2102fb42D7724',
|
|
|
|
key: Buffer.from(
|
|
|
|
'6BAB5A4F2A6911AF8EE2BD32C6C05F6643AC48EF6C939CDEAAAE6B1620805A9B',
|
|
|
|
'hex',
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
address: '0xbda5c89aa6bA1b352194291AD6822C92AbC87c7B',
|
|
|
|
key: Buffer.from(
|
|
|
|
'9B11D7F833648F26CE94D544855558D7053ECD396E4F4563968C232C012879B0',
|
|
|
|
'hex',
|
|
|
|
),
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2018-04-28 02:11:44 +02:00
|
|
|
}
|
2017-08-09 00:30:03 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function createEngineForTestData() {
|
2021-02-04 19:15:23 +01:00
|
|
|
return new JsonRpcEngine();
|
2017-08-09 00:30:03 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function providerFromEngine(engine) {
|
2021-02-04 19:15:23 +01:00
|
|
|
const provider = { sendAsync: engine.handle.bind(engine) };
|
|
|
|
return provider;
|
2017-08-09 00:30:03 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function createTestProviderTools(opts = {}) {
|
2021-02-04 19:15:23 +01:00
|
|
|
const engine = createEngineForTestData();
|
2018-01-18 06:43:34 +01:00
|
|
|
// handle provided hooks
|
2021-11-11 21:26:49 +01:00
|
|
|
engine.push(createScaffoldMiddleware(opts.scaffold || {}));
|
2018-01-18 06:43:34 +01:00
|
|
|
// handle block tracker methods
|
2020-11-03 00:41:28 +01:00
|
|
|
engine.push(
|
|
|
|
providerAsMiddleware(
|
2022-01-20 17:56:52 +01:00
|
|
|
Ganache.provider({
|
2020-11-03 00:41:28 +01:00
|
|
|
mnemonic: getTestSeed(),
|
|
|
|
network_id: opts.networkId,
|
2022-01-20 17:56:52 +01:00
|
|
|
chain: { chainId: opts.chainId },
|
|
|
|
hardfork: 'muirGlacier',
|
2020-11-03 00:41:28 +01:00
|
|
|
}),
|
|
|
|
),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-04-28 02:11:44 +02:00
|
|
|
// wrap in standard provider interface
|
2021-02-04 19:15:23 +01:00
|
|
|
const provider = providerFromEngine(engine);
|
|
|
|
return { provider, engine };
|
2018-01-18 04:44:11 +01:00
|
|
|
}
|