2018-03-07 23:36:05 +00:00
|
|
|
import { Validator, ValidatorResult } from 'jsonschema';
|
2017-11-30 05:35:17 +00:00
|
|
|
import { schema } from '../../common/libs/validators';
|
|
|
|
import 'url-search-params-polyfill';
|
2018-05-29 14:51:42 +00:00
|
|
|
import INodeTestConfig from './RpcNodeTestConfig';
|
2018-02-12 20:43:07 +00:00
|
|
|
import { StaticNodeConfig } from 'types/node';
|
|
|
|
import { staticNodesExpectedState } from '../reducers/config/nodes/staticNodes.spec';
|
2018-05-29 14:51:42 +00:00
|
|
|
import { INode, shepherd, shepherdProvider } from 'libs/nodes';
|
2017-11-30 05:35:17 +00:00
|
|
|
|
|
|
|
const v = new Validator();
|
|
|
|
|
|
|
|
const validRequests = {
|
|
|
|
address: '0x72948fa4200d10ffaa7c594c24bbba6ef627d4a3',
|
|
|
|
transaction: {
|
|
|
|
data: '',
|
|
|
|
from: '0x72948fa4200d10ffaa7c594c24bbba6ef627d4a3',
|
|
|
|
to: '0x72948fa4200d10ffaa7c594c24bbba6ef627d4a3',
|
|
|
|
value: '0xde0b6b3a7640000'
|
|
|
|
},
|
|
|
|
token: {
|
|
|
|
address: '0x4156d3342d5c385a87d264f90653733592000581',
|
|
|
|
symbol: 'SALT',
|
|
|
|
decimal: 8
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-03-07 23:36:05 +00:00
|
|
|
interface RPCTestList {
|
2018-05-29 14:51:42 +00:00
|
|
|
[key: string]: ((n: INode) => Promise<ValidatorResult>);
|
2018-03-07 23:36:05 +00:00
|
|
|
}
|
|
|
|
|
2018-05-29 14:51:42 +00:00
|
|
|
const testGetBalance = (n: INode) => {
|
|
|
|
return n.getBalance(validRequests.address).then(data => v.validate(data, schema.RpcNode));
|
2017-11-30 05:35:17 +00:00
|
|
|
};
|
|
|
|
|
2018-05-29 14:51:42 +00:00
|
|
|
const testEstimateGas = (n: INode) => {
|
|
|
|
return n.estimateGas(validRequests.transaction).then(data => v.validate(data, schema.RpcNode));
|
2017-11-30 05:35:17 +00:00
|
|
|
};
|
|
|
|
|
2018-05-29 14:51:42 +00:00
|
|
|
const testGetTokenBalance = (n: INode) => {
|
2017-11-30 05:35:17 +00:00
|
|
|
const { address, token } = validRequests;
|
2018-05-29 14:51:42 +00:00
|
|
|
return n.getTokenBalance(address, token).then(data => v.validate(data, schema.RpcNode));
|
2017-11-30 05:35:17 +00:00
|
|
|
};
|
|
|
|
|
2018-03-07 23:36:05 +00:00
|
|
|
const RPCTests: RPCTestList = {
|
2017-11-30 05:35:17 +00:00
|
|
|
getBalance: testGetBalance,
|
|
|
|
estimateGas: testEstimateGas,
|
|
|
|
getTokenBalance: testGetTokenBalance
|
|
|
|
};
|
|
|
|
|
2018-05-29 14:51:42 +00:00
|
|
|
function testRpcRequests(node: INode, service: string) {
|
2017-11-30 05:35:17 +00:00
|
|
|
Object.keys(RPCTests).forEach(testType => {
|
|
|
|
describe(`RPC (${service}) should work`, () => {
|
|
|
|
it(
|
|
|
|
`RPC: ${testType} ${service}`,
|
|
|
|
() => {
|
2017-12-06 06:24:40 +00:00
|
|
|
return RPCTests[testType](node).then(d => expect(d.valid).toBeTruthy());
|
2017-11-30 05:35:17 +00:00
|
|
|
},
|
|
|
|
10000
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-02-12 20:43:07 +00:00
|
|
|
const mapNodeEndpoints = (nodes: { [key: string]: StaticNodeConfig }) => {
|
2018-05-29 14:51:42 +00:00
|
|
|
const { INodes } = INodeTestConfig;
|
2017-11-30 05:35:17 +00:00
|
|
|
|
2018-05-29 14:51:42 +00:00
|
|
|
INodes.forEach((n: string) => {
|
|
|
|
shepherd.manual(n, true);
|
|
|
|
testRpcRequests(shepherdProvider, `${nodes[n].service} ${nodes[n].network}`);
|
2017-11-30 05:35:17 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2018-02-12 20:43:07 +00:00
|
|
|
mapNodeEndpoints((staticNodesExpectedState.initialState as any) as {
|
|
|
|
[key: string]: StaticNodeConfig;
|
|
|
|
});
|