Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"test": "jest --coverage"
},
"devDependencies": {
"@polkadot/dev": "^0.17.12",
"@polkadot/dev": "^0.17.13",
"lerna": "^2.5.1"
}
}
1 change: 1 addition & 0 deletions packages/api-provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"nock": "^9.1.0"
},
"dependencies": {
"@polkadot/storage-substrate": "^0.10.2",
"@polkadot/util": "^0.19.4",
"@polkadot/util-crypto": "^0.19.4",
"@polkadot/util-keyring": "^0.19.4",
Expand Down
18 changes: 13 additions & 5 deletions packages/api-provider/src/mock/mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@

// FIME: This file is way too long and way too messy

import type { StorageDef$Key } from '@polkadot/storage/types';
import type { KeyringPair } from '@polkadot/util-keyring/types';
import type { ProviderInterface$Emitted } from '../types';
import type { MockState, MockState$Subscription$Callback } from './types';

const BN = require('bn.js');
const headerEncode = require('@polkadot/primitives-json/header/encode');
const createKey = require('@polkadot/storage/key');
const keys = require('@polkadot/storage-substrate/keys');
const bnToU8a = require('@polkadot/util/bn/toU8a');
const u8aToHex = require('@polkadot/util/u8a/toHex');
const randomAsU8a = require('@polkadot/util-crypto/random/asU8a');
const testKeyring = require('@polkadot/util-keyring/testing');

const storageKey = require('./storageKey');

const keyring = testKeyring();

const emitEvents: Array<ProviderInterface$Emitted> = ['connected', 'disconnected'];
Expand Down Expand Up @@ -53,8 +55,12 @@ function updateSubs (subscriptions, method, value) {
});
}

function setStorageBn (storage, prefix: string, key: Uint8Array, value: BN): void {
storage[storageKey(prefix, key)] = bnToU8a(value, 64, true);
function setStorageBn (storage, key: StorageDef$Key, value: BN | number, ...keyParams: Array<Uint8Array>): void {
const keyValue = u8aToHex(
createKey(key).apply(null, keyParams)
);

storage[keyValue] = bnToU8a(value, 64, true);
}

module.exports = function mocks ({ emitter, storage, subscriptions }: MockState): void {
Expand All @@ -70,9 +76,11 @@ module.exports = function mocks ({ emitter, storage, subscriptions }: MockState)
newHead = makeBlockHeader(newHead.number);

keyring.getPairs().forEach(({ publicKey }: KeyringPair, index: number) => {
setStorageBn(storage, 'sta:bal:', publicKey(), newHead.number.muln(3).iaddn(index));
setStorageBn(storage, keys.staking.balanceOf, newHead.number.muln(3).iaddn(index), publicKey());
});

setStorageBn(storage, keys.timestamp.current, Date.now());

updateSubs(subscriptions, 'subscribe_newHead', headerEncode(newHead));
}, 5000);
};
20 changes: 0 additions & 20 deletions packages/api-provider/src/mock/storageKey.js

This file was deleted.

29 changes: 22 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@
lodash "^4.2.0"
to-fast-properties "^2.0.0"

"@polkadot/dev@^0.17.12":
version "0.17.12"
resolved "https://registry.yarnpkg.com/@polkadot/dev/-/dev-0.17.12.tgz#90d0d302681c5eae4683eea75949548a99e52831"
"@polkadot/dev@^0.17.13":
version "0.17.13"
resolved "https://registry.yarnpkg.com/@polkadot/dev/-/dev-0.17.13.tgz#cd5690d4c45abcc1e4b2624944c79229a82930e2"
dependencies:
babel-cli "^6.26.0"
babel-core "^6.26.0"
Expand All @@ -106,7 +106,7 @@
eslint-plugin-promise "^3.6.0"
eslint-plugin-react "^7.7.0"
eslint-plugin-standard "^3.0.1"
flow-bin "^0.70.0"
flow-bin "^0.71.0"
flow-copy-source "^1.3.0"
jest "^22.4.2"
makeshift "^1.1.0"
Expand Down Expand Up @@ -166,6 +166,21 @@
"@polkadot/util" "^0.19.4"
babel-runtime "^6.26.0"

"@polkadot/storage-substrate@^0.10.2":
version "0.10.2"
resolved "https://registry.yarnpkg.com/@polkadot/storage-substrate/-/storage-substrate-0.10.2.tgz#2f431d812d57f01fbc2a36c87ba495c5917443ee"
dependencies:
"@polkadot/storage" "^0.10.2"
"@polkadot/util" "^0.19.4"
babel-runtime "^6.26.0"

"@polkadot/storage@^0.10.2":
version "0.10.2"
resolved "https://registry.yarnpkg.com/@polkadot/storage/-/storage-0.10.2.tgz#e01a53123e5c5de421117685c0a390d3beefbbde"
dependencies:
"@polkadot/util" "^0.19.4"
babel-runtime "^6.26.0"

"@polkadot/util-crypto@^0.19.4":
version "0.19.4"
resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-0.19.4.tgz#d6e33197125e9adaf50410478a67e440630e7368"
Expand Down Expand Up @@ -2468,9 +2483,9 @@ flat-cache@^1.2.1:
graceful-fs "^4.1.2"
write "^0.2.1"

flow-bin@^0.70.0:
version "0.70.0"
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.70.0.tgz#080ae83a997f2b4ddb3dc2649bf13336825292b5"
flow-bin@^0.71.0:
version "0.71.0"
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.71.0.tgz#fd1b27a6458c3ebaa5cb811853182ed631918b70"

flow-copy-source@^1.3.0:
version "1.3.0"
Expand Down