mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-03 14:44:27 +01:00
3ba3b330f6
The `assert` module has two modes: "Legacy" and "strict". When using strict mode, the "strict" version of each assertion method is implied. Whereas in legacy mode, by default it will use the deprecated, "loose" version of each assertion. We now use strict mode everywhere. A few tests required updates where they were asserting the wrong thing, and it was passing beforehand due to the loose matching.
89 lines
2.7 KiB
JavaScript
89 lines
2.7 KiB
JavaScript
import { strict as assert } from 'assert';
|
|
import { obj as createThoughStream } from 'through2';
|
|
import metaRPCClientFactory from './metaRPCClientFactory';
|
|
|
|
describe('metaRPCClientFactory', function () {
|
|
it('should be able to make an rpc request with the method', function (done) {
|
|
const streamTest = createThoughStream((chunk) => {
|
|
assert.strictEqual(chunk.method, 'foo');
|
|
done();
|
|
});
|
|
const metaRPCClient = metaRPCClientFactory(streamTest);
|
|
metaRPCClient.foo();
|
|
});
|
|
it('should be able to make an rpc request/response with the method and params and node-style callback', function (done) {
|
|
const streamTest = createThoughStream();
|
|
const metaRPCClient = metaRPCClientFactory(streamTest);
|
|
|
|
// make a "foo" method call
|
|
metaRPCClient.foo('bar', (_, result) => {
|
|
assert.strictEqual(result, 'foobarbaz');
|
|
done();
|
|
});
|
|
|
|
// fake a response
|
|
metaRPCClient.requests.forEach((_, key) => {
|
|
streamTest.write({
|
|
jsonrpc: '2.0',
|
|
id: key,
|
|
result: 'foobarbaz',
|
|
});
|
|
});
|
|
});
|
|
it('should be able to make an rpc request/error with the method and params and node-style callback', function (done) {
|
|
const streamTest = createThoughStream();
|
|
const metaRPCClient = metaRPCClientFactory(streamTest);
|
|
|
|
// make a "foo" method call
|
|
metaRPCClient.foo('bar', (err) => {
|
|
assert.strictEqual(err.message, 'foo-message');
|
|
assert.strictEqual(err.code, 1);
|
|
done();
|
|
});
|
|
|
|
metaRPCClient.requests.forEach((_, key) => {
|
|
streamTest.write({
|
|
jsonrpc: '2.0',
|
|
id: key,
|
|
error: {
|
|
code: 1,
|
|
message: 'foo-message',
|
|
},
|
|
});
|
|
});
|
|
});
|
|
|
|
it('should be able to make an rpc request/response with the method and params and node-style callback with multiple instances of metaRPCClientFactory and the same connectionStream', function (done) {
|
|
const streamTest = createThoughStream();
|
|
const metaRPCClient = metaRPCClientFactory(streamTest);
|
|
const metaRPCClient2 = metaRPCClientFactory(streamTest);
|
|
|
|
// make a "foo" method call, followed by "baz" call on metaRPCClient2
|
|
metaRPCClient.foo('bar', (_, result) => {
|
|
assert.strictEqual(result, 'foobarbaz');
|
|
metaRPCClient2.baz('bar', (err) => {
|
|
assert.strictEqual(err, null);
|
|
done();
|
|
});
|
|
});
|
|
|
|
// fake a response
|
|
metaRPCClient.requests.forEach((_, key) => {
|
|
streamTest.write({
|
|
jsonrpc: '2.0',
|
|
id: key,
|
|
result: 'foobarbaz',
|
|
});
|
|
});
|
|
|
|
// fake client2's response
|
|
metaRPCClient2.requests.forEach((_, key) => {
|
|
streamTest.write({
|
|
jsonrpc: '2.0',
|
|
id: key,
|
|
result: 'foobarbaz',
|
|
});
|
|
});
|
|
});
|
|
});
|