DoubleMap extended tests (#1179)

* DoubleMap extended tests

* TwoX64Concat test (aligned with Rust)

* Remove .only

* Update Type.ts

* And working

* Check the full JSON output for the keys (future-proof)

* Renames
This commit is contained in:
Jaco Greeff
2019-07-24 16:04:55 +02:00
committed by GitHub
parent e15db8aed9
commit 48159cfb5a
7 changed files with 83 additions and 10 deletions
@@ -58,6 +58,7 @@ export default function createFunction ({ meta, method, prefix, section }: Creat
if (meta.type.isDoubleMap) {
assert(!isUndefined(arg) && !isNull(arg) && !isUndefined(arg[0]) && !isNull(arg[0]) && !isUndefined(arg[1]) && !isNull(arg[1]), `${meta.name} expects two arguments`);
const type1 = meta.type.asDoubleMap.key1.toString();
const type2 = meta.type.asDoubleMap.key2.toString();
const param1Encoded = u8aConcat(key, createType(type1, arg[0]).toU8a(true));
@@ -0,0 +1,27 @@
// Copyright 2017-2019 @polkadot/api-metadata authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { StorageHasher } from '@polkadot/types';
import { stringToU8a } from '@polkadot/util';
import { xxhashAsU8a } from '@polkadot/util-crypto';
import getHasher from './getHasher';
describe('getHasher', (): void => {
describe('Twox64Concat', (): void => {
it('matches the foo test from Rust', (): void => {
const hasher = getHasher(new StorageHasher('Twox64Concat'));
const hash = hasher('foo');
const xxhash = xxhashAsU8a('foo', 128);
expect([
hash.subarray(0, 8),
hash.subarray(8)
]).toEqual([
xxhash.subarray(0, 8),
stringToU8a('foo')
]);
});
});
});