Apply fallback on non-sub storage (e.g. at) (#1004)

* Apply fallback on non-sub storage (e.g. at)

* Fallback test in rpc-code (getStorage)
This commit is contained in:
Jaco Greeff
2019-06-14 09:59:59 +02:00
committed by GitHub
parent 732936280a
commit 6d9699a090
3 changed files with 32 additions and 3 deletions
@@ -40,6 +40,19 @@ describe.skip('Promise e2e queries', () => {
expect(api.derive).toBeDefined();
});
it('allows retrieval of an fallback entry (once-off query)', async () => {
const nonce = await api.query.system.accountNonce('5DSo5RVtfrtgHoz2c7jK7Tca7FgJgpCzFnxoRVDeYUQcKPng');
expect(nonce.toHex()).toEqual('0x0000000000000000');
});
it('allows retrieval of fallback when at query is made', async () => {
const header = await api.rpc.chain.getHeader() as Header;
const nonce = await api.query.system.accountNonce.at(header.hash, '5DSo5RVtfrtgHoz2c7jK7Tca7FgJgpCzFnxoRVDeYUQcKPng');
expect(nonce.toHex()).toEqual('0x0000000000000000');
});
it('queries state for a balance', async () => {
return (
api.query.balances.freeBalance(keyring.alice.address, (balance) => {
+18 -2
View File
@@ -15,6 +15,10 @@ import Api from '.';
const ADDR_ONE = '5DkQbYAExs3M2sZgT1Ec3mKfZnAQCL4Dt9beTCknkCUn5jzo';
const ADDR_TWO = '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF';
const BALANCE_KEYS = [
/* v3- */ '0x4af2c53fce3ec33c6ccccf22e926f1a7',
/* v4+ */ '0xec8f96437274a883afcac82d01a9defeb68209cd4f2c084632813692aa5e65ad'
];
function formattingTests (version: string, storage: Storage, encodedValues: [String, String]) {
const [ENC_ONE, ENC_TWO] = encodedValues;
@@ -25,8 +29,12 @@ function formattingTests (version: string, storage: Storage, encodedValues: [Str
beforeEach(() => {
provider = {
send: jest.fn((method, params) =>
Promise.resolve('0x01020000000000000000000000000000')
send: jest.fn((method, [key]) =>
Promise.resolve(
BALANCE_KEYS.includes(key)
? '0x01020000000000000000000000000000'
: null
)
),
subscribe: jest.fn((type, method, params, subscription) =>
subscription(null, {
@@ -55,6 +63,14 @@ function formattingTests (version: string, storage: Storage, encodedValues: [Str
});
});
it('returns the fallback result on not-found values', () => {
return api.state
.getStorage([storage.system.accountNonce, ADDR_ONE])
.then((value) => {
expect(value.toHex()).toEqual('0x0000000000000000');
});
});
it('encodes multiple keys, decoding multiple results', (done) => {
return api.state.subscribeStorage(
[
+1 -1
View File
@@ -242,7 +242,7 @@ export default class Rpc implements RpcInterface {
);
}
return createType(type, base, true);
return createType(type, isNull ? meta.fallback : base, true);
}
private formatStorageSet (key: StorageKey, base: StorageChangeSet): Codec | undefined {