mirror of
https://github.com/status-im/MyCrypto.git
synced 2025-01-12 20:14:12 +00:00
a043334685
* Initial work on refactoring node definitions to reduce number of places theyre defined, amount of copy pasting. * Use makeAutoNodeNAme instead of manually appending _auto * Add getNetVersion to list of unsupported methods * PR feedback * Rework web template node selector to be a network selector. Refactor some types to help with that. Better handle removing custom nodes. * Remove color dropdown. * Fix selecting custom networks. Show notification if change network intent fails. * Use selectors for current node / network instead of intuiting from nodeSelection * Add id key to all networks, simplify add and remove custom node and network functions. * Fix a lot of uses of network.name to use network.id instead. * Dont allow network chainid conflicts * Fix web3 network by chainid * Add testnet badge to network selector * Change nomenclature from change(Node|Network)(Intent)? to change(Node|Network)(Requested|Succeeded) * tscheck * Better code for chainid collision * Remove console logs * Fix tests * Network selector becomes self contained component used both by web header and electron nav. * Dont select node again * Additional title text * tscheck * Custom node behavior in Electron * Close panel too * Convert node label data into selector function * tscheck * Parens & space
75 lines
2.2 KiB
TypeScript
75 lines
2.2 KiB
TypeScript
import { Validator, ValidatorResult } from 'jsonschema';
|
|
import { schema } from '../../common/libs/validators';
|
|
import 'url-search-params-polyfill';
|
|
import INodeTestConfig from './RpcNodeTestConfig';
|
|
import { StaticNodeConfig } from 'types/node';
|
|
import { staticNodesExpectedState } from '../reducers/config/nodes/staticNodes.spec';
|
|
import { INode, shepherd, shepherdProvider } from 'libs/nodes';
|
|
|
|
const v = new Validator();
|
|
|
|
const validRequests = {
|
|
address: '0x72948fa4200d10ffaa7c594c24bbba6ef627d4a3',
|
|
transaction: {
|
|
data: '',
|
|
from: '0x72948fa4200d10ffaa7c594c24bbba6ef627d4a3',
|
|
to: '0x72948fa4200d10ffaa7c594c24bbba6ef627d4a3',
|
|
value: '0xde0b6b3a7640000'
|
|
},
|
|
token: {
|
|
address: '0x4156d3342d5c385a87d264f90653733592000581',
|
|
symbol: 'SALT',
|
|
decimal: 8
|
|
}
|
|
};
|
|
|
|
interface RPCTestList {
|
|
[key: string]: ((n: INode) => Promise<ValidatorResult>);
|
|
}
|
|
|
|
const testGetBalance = (n: INode) => {
|
|
return n.getBalance(validRequests.address).then(data => v.validate(data, schema.RpcNode));
|
|
};
|
|
|
|
const testEstimateGas = (n: INode) => {
|
|
return n.estimateGas(validRequests.transaction).then(data => v.validate(data, schema.RpcNode));
|
|
};
|
|
|
|
const testGetTokenBalance = (n: INode) => {
|
|
const { address, token } = validRequests;
|
|
return n.getTokenBalance(address, token).then(data => v.validate(data, schema.RpcNode));
|
|
};
|
|
|
|
const RPCTests: RPCTestList = {
|
|
getBalance: testGetBalance,
|
|
estimateGas: testEstimateGas,
|
|
getTokenBalance: testGetTokenBalance
|
|
};
|
|
|
|
function testRpcRequests(node: INode, service: string) {
|
|
Object.keys(RPCTests).forEach(testType => {
|
|
describe(`RPC (${service}) should work`, () => {
|
|
it(
|
|
`RPC: ${testType} ${service}`,
|
|
() => {
|
|
return RPCTests[testType](node).then(d => expect(d.valid).toBeTruthy());
|
|
},
|
|
10000
|
|
);
|
|
});
|
|
});
|
|
}
|
|
|
|
const mapNodeEndpoints = (nodes: { [key: string]: StaticNodeConfig }) => {
|
|
const { INodes } = INodeTestConfig;
|
|
|
|
INodes.forEach((n: string) => {
|
|
shepherd.manual(n, true);
|
|
testRpcRequests(shepherdProvider, `${nodes[n].service} ${nodes[n].network}`);
|
|
});
|
|
};
|
|
|
|
mapNodeEndpoints((staticNodesExpectedState.initialState as any) as {
|
|
[key: string]: StaticNodeConfig;
|
|
});
|