StorageKey map decoding test (#2009)
This commit is contained in:
@@ -235,9 +235,7 @@ describe('StorageKey', (): void => {
|
||||
describe('with MetadataV11', (): void => {
|
||||
const metadata = new Metadata(registry, rpcDataV11);
|
||||
|
||||
// 0x426e15054d267946093858132eb537f191ca57b0c4b20b29ae7e99d6201d680cc906f7710aa165d62c709012f807af8fc3f0d2abb0c51ca9a88d4ef24d1a092bf89dacf5ce63ea1d
|
||||
|
||||
it('should allow decoding of a key', (): void => {
|
||||
it('should allow decoding of a DoubleMap key', (): void => {
|
||||
const key = new StorageKey(registry, '0x5f3e4907f716ac89b6347d15ececedca8bde0a0ea8864605e3b68ed9cb2da01b66ccada06515787c10000000e535263148daaf49be5ddb1579b72e84524fc29e78609e3caf42e85aa118ebfe0b0ad404b5bdd25f');
|
||||
|
||||
key.setMeta(metadata.query.staking.erasStakers.meta);
|
||||
@@ -249,5 +247,17 @@ describe('StorageKey', (): void => {
|
||||
'5GNJqTPyNqANBkUVMN1LPPrxXnFouWXoe2wNSmmEoLctxiZY'
|
||||
]);
|
||||
});
|
||||
|
||||
it('should allow decoding of a Map key', (): void => {
|
||||
const key = new StorageKey(registry, '0x426e15054d267946093858132eb537f191ca57b0c4b20b29ae7e99d6201d680cc906f7710aa165d62c709012f807af8fc3f0d2abb0c51ca9a88d4ef24d1a092bf89dacf5ce63ea1d');
|
||||
|
||||
key.setMeta(metadata.query.society.defenderVotes.meta);
|
||||
|
||||
expect(
|
||||
key.args.map((arg) => arg.toHuman())
|
||||
).toEqual([
|
||||
'5D4yQHKfqCQYThhHmTfN1JEDi47uyDJc1xg9eZfAG1R7FC7J'
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -122,7 +122,7 @@ function decodeArgsFromMeta (registry: Registry, value: Uint8Array, meta?: Stora
|
||||
const mapInfo = meta.type.asMap;
|
||||
|
||||
return decodeHashers(registry, value, [
|
||||
[mapInfo.hasher, mapInfo.value.toString()]
|
||||
[mapInfo.hasher, mapInfo.key.toString()]
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -249,7 +249,7 @@ export default class StorageKey extends Bytes {
|
||||
try {
|
||||
this._args = decodeArgsFromMeta(this.registry, this.toU8a(true), meta || this.meta);
|
||||
} catch (error) {
|
||||
// ignore
|
||||
// ignore...
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
Reference in New Issue
Block a user