Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Copyright 2017-2019 @polkadot/types authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import BN from 'bn.js';
import testingPairs from '@polkadot/keyring/testingPairs';
import Decorated from '@polkadot/metadata/Decorated';
import Metadata from '@polkadot/metadata/Metadata';
import metadataStatic from '@polkadot/metadata/Metadata/static';
import { TypeRegistry } from '../../../codec/create';
import Extrinsic from './Extrinsic';
const registry = new TypeRegistry();
const decorated = new Decorated(registry, metadataStatic);
const keyring = testingPairs({ type: 'ed25519' }, false);
// eslint-disable-next-line no-new
new Metadata(registry, metadataStatic);
describe('ExtrinsicV4', (): void => {
it('constructs a sane Uint8Array (default)', (): void => {
expect(
new Extrinsic(registry).toU8a()
).toEqual(new Uint8Array([0, 0]));
});
it('creates a unsigned extrinsic', (): void => {
expect(
new Extrinsic(
registry,
decorated.tx.balances.transfer(keyring.bob.publicKey, 6969)
// Copyright 2017-2019 @polkadot/metadata authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import BN from 'bn.js';
import testingPairs from '@polkadot/keyring/testingPairs';
import { createType, Metadata, TypeRegistry } from '@polkadot/types';
import metadataStatic from '../../Metadata/static';
import fromMetadata from './fromMetadata';
const keyring = testingPairs({ type: 'ed25519' }, false);
const registry = new TypeRegistry();
const metadata = new Metadata(registry, metadataStatic);
const extrinsics = fromMetadata(registry, metadata);
describe('extrinsics', (): void => {
it('encodes an actual transfer (actual data)', (): void => {
expect(
createType(registry, 'Extrinsic',
extrinsics.balances.transfer(keyring.bob.publicKey, 6969)
).sign(keyring.alice, {
blockHash: '0xec7afaf1cca720ce88c1d1b689d81f0583cc15a97d621cf046dd9abf605ef22f',
genesisHash: '0xdcd1346701ca8396496e52aa2785b1748deb6db09551b72159dcb3e08991025b',
nonce: 0,
runtimeVersion: {
apis: [],
authoringVersion: new BN(123),
// Copyright 2017-2019 @polkadot/metadata authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import testingPairs from '@polkadot/keyring/testingPairs';
import { TypeRegistry } from '@polkadot/types';
import { u8aToHex } from '@polkadot/util';
import rpcMetadata from '../../../Metadata/static';
import rpcMetadataV8 from '../../../Metadata/v8/static';
import Decorated from '../../Decorated';
const keyring = testingPairs({ type: 'ed25519' });
describe('fromMetadata', (): void => {
describe('latest', (): void => {
const registry = new TypeRegistry();
const decorated = new Decorated(registry, rpcMetadata);
it('should throw if the storage function expects an argument', (): void => {
expect((): any => decorated.query.balances.freeBalance()).toThrowError(/requires one argument/);
});
it('should return a value if the storage function does not expect an argument', (): void => {
expect((): any => decorated.query.timestamp.now()).not.toThrow();
});
it('should return the correct length-prefixed storage key', (): void => {
expect(
// Copyright 2017-2019 @polkadot/types authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import BN from 'bn.js';
import Decorated from '@polkadot/metadata/Decorated';
import Metadata from '@polkadot/metadata/Metadata';
import rpcMetadata from '@polkadot/metadata/Metadata/static';
import testingPairs from '@polkadot/keyring/testingPairs';
import { TypeRegistry } from '../../../codec';
import Extrinsic from './Extrinsic';
const registry = new TypeRegistry();
const decorated = new Decorated(registry, rpcMetadata);
const keyring = testingPairs({ type: 'ed25519' }, false);
// eslint-disable-next-line no-new
new Metadata(registry, rpcMetadata);
describe('ExtrinsicV2', (): void => {
it('constructs a sane Uint8Array (default)', (): void => {
expect(
new Extrinsic(registry).toU8a()
).toEqual(new Uint8Array([0, 0]));
});
it('creates a unsigned extrinsic', (): void => {
expect(
new Extrinsic(
registry,
decorated.tx.balances.transfer(keyring.bob.publicKey, 6969)
// Copyright 2017-2018 @polkadot/client-db authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import { hexToU8a, u8aToHex } from '@polkadot/util';
import testingPairs from '@polkadot/keyring/testingPairs';
import db from './index';
const keyring = testingPairs();
describe.skip('balance', () => {
let staking;
describe('get', () => {
beforeEach(() => {
staking = db({
get: (key) => {
switch (u8aToHex(key)) {
case '0x93b3a06afc9ac6777adff1f6ad2cd5d9':
return hexToU8a('0x4500000000000000');
case '0x8e4b46d94b25bb2f5c9fa65f60263160':
return hexToU8a('0x2a00000000000000');
describe('createCachedObservable', () => {
let api: RpcRx;
let creator: (...params: Array) => Observable;
const keyring = testingPairs();
let section: RpcInterface$Section;
beforeEach(() => {
api = new RpcRx();
});
beforeEach(() => {
// Create two methods in our section
const subMethod: any = jest.fn(() => Promise.resolve('subMethodResult'));
subMethod.unsubscribe = jest.fn(() => Promise.resolve(true));
const subMethod2: any = jest.fn(() => Promise.resolve('subMethod2Result'));
subMethod2.unsubscribe = jest.fn(() => Promise.resolve(true));
section = {
subMethod,
subMethod2
describe('Cached Observables', (): void => {
const registry = new TypeRegistry();
let rpc: Rpc;
const keyring = testingPairs();
beforeEach((): void => {
rpc = new Rpc(registry, new MockProvider(registry));
});
it('creates a single observable for subscriptions (multiple calls)', (): void => {
const observable1 = rpc.state.subscribeStorage([123]);
const observable2 = rpc.state.subscribeStorage([123]);
expect(observable2).toBe(observable1);
});
it('creates a single observable for subscriptions (multiple calls, no arguments)', (): void => {
const observable1 = rpc.chain.subscribeNewHeads();
const observable2 = rpc.chain.subscribeNewHeads();
describe('ApiPromise', (): void => {
const registry = new TypeRegistry();
const keyring = testingPairs({ type: 'ed25519' });
let provider: Mock;
beforeEach((): void => {
jest.setTimeout(3000000);
provider = new Mock(registry);
});
describe('initialization', (): void => {
it('Create API instance with metadata map and makes the runtime, rpc, state & extrinsics available', async (): Promise => {
const rpcData = await provider.send('state_getMetadata', []);
const genesisHash = createType(registry, 'Hash', await provider.send('chain_getBlockHash', [])).toHex();
const specVersion = 0;
const metadata: any = {};
const key = `${genesisHash}-${specVersion}`;
metadata[key] = rpcData;
const api = await ApiPromise.create({ provider, metadata, registry } as unknown as ApiOptions);
async function main (): Promise {
const api = await ApiPromise.create();
const keyring = testKeyring();
consts(api);
derive(api);
query(api, keyring);
rpc(api);
types();
tx(api, keyring);
}