Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 => {
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))
// 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),
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();
}
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();
}
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();
}
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> = {