How to use the @polkadot/rpc-provider/mock function in @polkadot/rpc-provider

To help you get started, we’ve selected a few @polkadot/rpc-provider examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github polkadot-js / api / packages / api-derive / src / index.spec.ts View on Github external
describe('custom', (): void => {
    const api = new ApiRx({
      derives: {
        balances: {
          fees: (): any => (): Observable => from(['a', 'b'])
        },
        custom: {
          test: (): any => (): Observable => from([1, 2, 3])
        }
      },
      provider: new MockProvider(registry),
      registry
    });

    beforeAll((done): void => {
      api.isReady.subscribe((): void => done());
    });

    // override
    testFunction(api)('balances', 'fees', ['a', 'b']);

    // new
    testFunction(api)('custom' as any, 'test', [1, 2, 3]);

    // existing
    testFunction(api)('chain', 'bestNumber', []);
  });
github polkadot-js / api / packages / rpc-core / src / index.spec.ts View on Github external
it('allows for the definition of user RPCs', (): void => {
    const rpc = new Rpc(registry, new MockProvider(registry), {
      testing: [
        {
          name: 'foo',
          params: [{ name: 'bar', type: 'u32' }],
          type: 'Balance'
        }
      ]
    });

    expect(isFunction((rpc as any).testing.foo)).toBe(true);
    expect(rpc.sections.includes('testing')).toBe(true);
    expect(rpc.mapping.get('testing_foo')).toEqual({
      description: 'User defined',
      isDeprecated: false,
      isHidden: false,
      isOptional: false,
github polkadot-js / api / packages / rpc-core / src / replay.spec.ts View on Github external
beforeEach((): void => {
    rpc = new Rpc(registry, new MockProvider(registry));
  });
github polkadot-js / api / packages / rpc-core / src / cached.spec.ts View on Github external
beforeEach((): void => {
    rpc = new Rpc(registry, new MockProvider(registry));
  });
github polkadot-js / apps / packages / ui-react-rx / src / demo.tsx View on Github external
import React from 'react';
import ReactDOM from 'react-dom';
import Mock from '@polkadot/rpc-provider/mock';

import Api from './Api';
import Balance from './Balance';
import BestNumber from './BestNumber';
import Chain from './Chain';
import Connected from './Connected';
import NodeName from './NodeName';
import NodeVersion from './NodeVersion';
import Nonce from './Nonce';
import { withApi } from './with/index';

const provider = new Mock();

const ALICE_ADDR = '5GoKvZWG5ZPYL1WUovuHW3zJBWBP5eT8CbqjdRY4Q6iMaDtZ';
const ALICE_PUBLIC = '0xd172a74cda4c865912c32ba0a80a57ae69abae410e5ccb59dee84e2f4432db4f';

const element = document.getElementById('demo');

if (!element) {
  throw new Error('Unable to find #demo element');
}

const WithApiDebug = withApi(
  (apiProps) => (
    <pre style="{{">      {JSON.stringify(apiProps, undefined, 2)}
    </pre>
  )

@polkadot/rpc-provider

Transport providers for the API

Apache-2.0
Latest version published 9 days ago

Package Health Score

90 / 100
Full package analysis

Similar packages