createType makes new instance, StorageData tests (#417)
* createType makes new instance, StorageData tests * Unused import
This commit is contained in:
@@ -208,7 +208,7 @@ export default class Rpc implements RpcInterface {
|
|||||||
: (
|
: (
|
||||||
item.value.isNone
|
item.value.isNone
|
||||||
? null
|
? null
|
||||||
: createType(type, item.value.value)
|
: createType(type, item.value.unwrap())
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -2,25 +2,50 @@
|
|||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
import { createType } from '@polkadot/types/codec';
|
||||||
|
import json from './json/StorageChangeSet.001.json';
|
||||||
import StorageChangeSet from './StorageChangeSet';
|
import StorageChangeSet from './StorageChangeSet';
|
||||||
|
|
||||||
describe('StorageChangeSet', () => {
|
describe('StorageChangeSet', () => {
|
||||||
const set = new StorageChangeSet({
|
describe('construction', () => {
|
||||||
hash: '0x1234',
|
const set = new StorageChangeSet({
|
||||||
changes: [
|
block: '0x1234',
|
||||||
{ key: '0xab', value: '0xcd' }
|
changes: [
|
||||||
]
|
{ key: '0xab', value: '0xcd' }
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
it('wraps blockHash', () => {
|
||||||
|
expect(
|
||||||
|
set.block.toHex()
|
||||||
|
).toEqual('0x1234');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('wraps key/value', () => {
|
||||||
|
expect(
|
||||||
|
set.changes[0].value.toString()
|
||||||
|
).toEqual('0xcd');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('wraps hash', () => {
|
describe('json', () => {
|
||||||
expect(
|
const set = new StorageChangeSet(json.params.result);
|
||||||
set.hash.toHex()
|
|
||||||
).toEqual('0x1234');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('wraps key/value', () => {
|
it('has the correct hash', () => {
|
||||||
expect(
|
expect(
|
||||||
set.changes[0].value.toString()
|
set.block.toHex()
|
||||||
).toEqual('0xcd');
|
).toEqual('0x2ad8077937e9a5ceb2e0d57c95b95a6a9edcedc4fb1f14e3bc13245e223a569d');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('has the changes', () => {
|
||||||
|
expect(set.changes).toHaveLength(1);
|
||||||
|
expect(set.changes[0].key.toHex()).toEqual('0x54bdbdb5e438d574dd4da05ee6131cee');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('converts result data to Bytes', () => {
|
||||||
|
const bytes = createType('Bytes', set.changes[0].value.unwrap());
|
||||||
|
|
||||||
|
expect(bytes).toHaveLength(4452);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import Hash from './Hash';
|
|||||||
import { KeyValueOption, KeyValueOptionValue } from './KeyValue';
|
import { KeyValueOption, KeyValueOptionValue } from './KeyValue';
|
||||||
|
|
||||||
type StorageChangeSetValue = {
|
type StorageChangeSetValue = {
|
||||||
hash?: AnyU8a,
|
block?: AnyU8a,
|
||||||
changes?: Array<KeyValueOptionValue>
|
changes?: Array<KeyValueOptionValue>
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ type StorageChangeSetValue = {
|
|||||||
export default class StorageChangeSet extends Struct {
|
export default class StorageChangeSet extends Struct {
|
||||||
constructor (value?: StorageChangeSetValue | Uint8Array) {
|
constructor (value?: StorageChangeSetValue | Uint8Array) {
|
||||||
super({
|
super({
|
||||||
hash: Hash,
|
block: Hash,
|
||||||
changes: Vector.with(KeyValueOption)
|
changes: Vector.with(KeyValueOption)
|
||||||
}, value);
|
}, value);
|
||||||
}
|
}
|
||||||
@@ -28,7 +28,7 @@ export default class StorageChangeSet extends Struct {
|
|||||||
return this.get('changes') as Vector<KeyValueOption>;
|
return this.get('changes') as Vector<KeyValueOption>;
|
||||||
}
|
}
|
||||||
|
|
||||||
get hash (): Hash {
|
get block (): Hash {
|
||||||
return this.get('hash') as Hash;
|
return this.get('block') as Hash;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -161,7 +161,5 @@ export default function createType (type: Text | string, value?: any): Codec {
|
|||||||
getTypeDef(type)
|
getTypeDef(type)
|
||||||
);
|
);
|
||||||
|
|
||||||
return value instanceof Type
|
return new Type(value);
|
||||||
? value
|
|
||||||
: new Type(value);
|
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user