* Docs renames (& removal for re-gen) * Rename api, api-provider & api-rx * Apoi -> Rpc, RxApi -> RpcRx (classes) * Add .nodoc * Bump version * Link updates (summary) * Cleanup deleted (master version) * Deleted re-instated * More... ;) * Types... * Revert .nodoc
61 lines
1.5 KiB
JavaScript
61 lines
1.5 KiB
JavaScript
// Copyright 2017-2018 @polkadot/rpc-core authors & contributors
|
|
// This software may be modified and distributed under the terms
|
|
// of the ISC license. See the LICENSE file for details.
|
|
|
|
import Api from './index';
|
|
|
|
describe('methodSend', () => {
|
|
let api;
|
|
let methods;
|
|
let provider;
|
|
|
|
beforeEach(() => {
|
|
methods = {
|
|
blah: {
|
|
method: 'blah',
|
|
params: [
|
|
{ name: 'foo', type: 'Bytes' }
|
|
],
|
|
type: 'Bytes'
|
|
},
|
|
bleh: {
|
|
method: 'bleh',
|
|
params: [],
|
|
type: 'Bytes'
|
|
}
|
|
};
|
|
|
|
provider = {
|
|
send: jest.fn((method, params) => {
|
|
return Promise.resolve(params[0]);
|
|
})
|
|
};
|
|
|
|
api = new Api(provider);
|
|
});
|
|
|
|
it('wraps errors with the call signature', () => {
|
|
const method = api.createMethodSend('test_blah', methods.blah);
|
|
|
|
return method().catch((error) => {
|
|
expect(error.message).toMatch(/blah \(foo: Bytes\): Bytes/);
|
|
});
|
|
});
|
|
|
|
it('checks for mismatched parameters', () => {
|
|
const method = api.createMethodSend('test_bleh', methods.bleh);
|
|
|
|
return method(1).catch((error) => {
|
|
expect(error.message).toMatch(/parameters, 1 found instead/);
|
|
});
|
|
});
|
|
|
|
it('calls the provider with the correct parameters', () => {
|
|
const method = api.createMethodSend('test_blah', methods.blah);
|
|
|
|
return method(new Uint8Array([0x12, 0x34])).then(() => {
|
|
expect(provider.send).toHaveBeenCalledWith('test_blah', ['0x1234']);
|
|
});
|
|
});
|
|
});
|