How to use the @polkadot/keyring/testing function in @polkadot/keyring

To help you get started, we’ve selected a few @polkadot/keyring 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 paritytech / srml-contracts-waterfall / tests / contracts-rust.spec.ts View on Github external
import { u8aToHex } from "@polkadot/util";
import { randomAsU8a } from "@polkadot/util-crypto";
import { KeyringPair } from "@polkadot/keyring/types";
import { Option } from "@polkadot/types";
import { Address, ContractInfo, Hash } from "@polkadot/types/interfaces";

import { ALICE, CREATION_FEE, WSURL } from "./consts";
import {
  callContract,
  instantiate,
  getContractStorage,
  putCode
} from "./utils";

// This is a test account that is going to be created and funded each test.
const keyring = testKeyring({ type: "sr25519" });
const alicePair = keyring.getPair(ALICE);
let testAccount: KeyringPair;
let api: ApiPromise;

beforeAll((): void => {
  jest.setTimeout(30000);
});

beforeEach(
  async (done): Promise<() => void> => {
    api = await ApiPromise.create({ provider: new WsProvider(WSURL) });
    testAccount = keyring.addFromSeed(randomAsU8a(32));

    return api.tx.balances
      .transfer(testAccount.address, CREATION_FEE.muln(3))
      .signAndSend(alicePair, (result: SubmittableResult): void => {
github paritytech / srml-contracts-waterfall / tests / contracts-assemblyscript.spec.ts View on Github external
import { hexStripPrefix, hexToBn, u8aToHex, u8aToString } from "@polkadot/util";
import { randomAsU8a } from "@polkadot/util-crypto";
import { KeyringPair } from "@polkadot/keyring/types";
import { Address, ContractInfo, Balance, Hash } from "@polkadot/types/interfaces";
import BN from "bn.js";

import { ALICE, BOB, CREATION_FEE, WSURL } from "./consts";
import {
  callContract,
  instantiate,
  getContractStorage,
  putCode
} from "./utils";

// This is a test account that is going to be created and funded each test.
const keyring = testKeyring({ type: "sr25519" });
const bobPair = keyring.getPair(BOB);
const randomSeed = randomAsU8a(32);
let testAccount: KeyringPair;
let api: ApiPromise;

beforeAll((): void => {
  jest.setTimeout(30000);
});

beforeEach(
  async (done): Promise<() => void> => {
    api = await ApiPromise.create({ provider: new WsProvider(WSURL) });
    testAccount = keyring.addFromSeed(randomSeed);

    return api.tx.balances
      .transfer(testAccount.address, CREATION_FEE.muln(3))
github polkadot-js / api / packages / rpc-provider / src / mock / mocks.ts View on Github external
// FIXME: This file is way too long and way too messy

import { StorageFunction } from '@polkadot/types/StorageKey';
import { KeyringPair } from '@polkadot/keyring/types';
import { ProviderInterface$Emitted } from '../types';
import { MockState, MockState$Db, MockState$Subscriptions } from './types';

import BN from 'bn.js';
import storage from '@polkadot/storage/static';
import Header from '@polkadot/types/Header';
import { bnToU8a, u8aToHex } from '@polkadot/util';
import { randomAsU8a } from '@polkadot/util-crypto';
import testKeyring from '@polkadot/keyring/testing';

const keyring = testKeyring();

const emitEvents: Array = ['connected', 'disconnected'];
let emitIndex = 0;

function makeBlockHeader (prevNumber: BN) {
  const blockNumber = prevNumber.addn(1);

  return {
    digest: {
      logs: []
    },
    extrinsicsRoot: randomAsU8a(),
    number: blockNumber,
    parentHash: prevNumber.eqn(-1)
      ? new Uint8Array(32)
      : bnToU8a(prevNumber, 256, false),
github polkadot-js / ui / packages / ui-keyring / src / Base.ts View on Github external
protected initKeyring (options: KeyringOptions): void {
    const keyring = testKeyring({ ss58Format: this._ss58Format, ...options }, true);

    if (isBoolean(options.isDevelopment)) {
      this.setDevMode(options.isDevelopment);
    }

    this._keyring = keyring;
    this._genesisHash = options.genesisHash && options.genesisHash.toHex();
    this._store = options.store || new BrowserStore();

    this.addAccountPairs();
  }
github vue-polkadot / vue-ui / packages / vue-keyring / src / Keyring.ts View on Github external
protected initKeyring(options: KeyringOptions): void {
    const keyring = testKeyring({ ss58Format: this._ss58Format, ...options }, true);

    if (isBoolean(options.isDevelopment)) {
      this.setDevMode(options.isDevelopment);
    }

    this._keyring = keyring;
    this._genesisHash = options.genesisHash && options.genesisHash.toHex();
    this._store = options.store || new BrowserStore();

    this.addAccountPairs();
  }
github vue-polkadot / vue-ui / packages / vue-keyring / src / Base.ts View on Github external
protected initKeyring(options: KeyringOptions): void {
    const keyring = testKeyring({ addressPrefix: this._prefix, ...options }, true);

    if (isBoolean(options.isDevelopment)) {
      this.setDevMode(options.isDevelopment);
    }

    this._keyring = keyring;
    this._genesisHash = options.genesisHash && options.genesisHash.toHex();
    this._store = options.store || new BrowserStore();

    this.addAccountPairs();
  }
github polkadot-js / api / packages / rpc-provider / src / mock / index.ts View on Github external
const INTERVAL = 1000;
const SUBSCRIPTIONS: string[] = Array.prototype.concat.apply(
  [], Object.values(interfaces).map((area): string[] =>
    Object
      .values(area.methods)
      .filter((method): boolean =>
        method.isSubscription
      )
      .map(({ method, section }): string =>
        `${section}_${method}`
      )
      .concat('chain_subscribeNewHead')
  )
);

const keyring = testKeyring({ type: 'ed25519' });
const l = logger('api-mock');

/**
 * A mock provider mainly used for testing.
 * @return {ProviderInterface} The mock provider
 */
export default class Mock implements ProviderInterface {
  private db: MockStateDb = {};

  private emitter = new EventEmitter();

  public isUpdating = true;

  private registry: Registry;

  private requests: Record any> = {

@polkadot/keyring

Keyring management

Apache-2.0
Latest version published 1 month ago

Package Health Score

87 / 100
Full package analysis

Similar packages