Opaque{Metadata, Multiaddr, PeerId} -> WrapperOpaque<Bytes> (#5038)
* Opaque{Metadata, Multiaddr, PeerId} -> WrapperOpaque<Bytes>
* Adjust
* Adjust
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
|
||||
import type { AnyJson, AnyU8a, Codec, CodecClass, Inspect, Registry } from '../types';
|
||||
|
||||
import { compactAddLength, compactStripLength, compactToU8a, isHex, isU8a } from '@polkadot/util';
|
||||
import { compactAddLength, compactStripLength, compactToU8a, isHex, isU8a, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
import { Raw } from '../native/Raw';
|
||||
import { typeToConstructor } from '../utils';
|
||||
@@ -20,9 +20,11 @@ function decodeRaw<T extends Codec> (registry: Registry, typeName: CodecClass<T>
|
||||
|
||||
if (isU8a(value) || isHex(value)) {
|
||||
try {
|
||||
const [, u8a] = isHex(value) || (value instanceof Raw)
|
||||
? [0, value]
|
||||
: compactStripLength(value);
|
||||
const [, u8a] = isHex(value)
|
||||
? [0, u8aToU8a(value)]
|
||||
: (value instanceof Raw)
|
||||
? [0, value.subarray()]
|
||||
: compactStripLength(value);
|
||||
|
||||
return [Type, new Type(registry, u8a), value];
|
||||
} catch {
|
||||
|
||||
@@ -36,7 +36,7 @@ describe('WrapperOpaque', (): void => {
|
||||
it('has the correct unwrap', (): void => {
|
||||
expect(
|
||||
new WrapperOpaque(registry, 'u32', '0x12345678').unwrap().toHex()
|
||||
).toEqual('0x12345678');
|
||||
).toEqual('0x78563412');
|
||||
});
|
||||
|
||||
it('has the correct toRawType', (): void => {
|
||||
@@ -47,7 +47,7 @@ describe('WrapperOpaque', (): void => {
|
||||
|
||||
it('has a sane inspect', (): void => {
|
||||
expect(
|
||||
new WrapperOpaque(registry, 'u32', '0x12345678').inspect()
|
||||
new WrapperOpaque(registry, 'u32', '0x78563412').inspect()
|
||||
).toEqual({
|
||||
inner: [{ outer: [new Uint8Array([0x78, 0x56, 0x34, 0x12])] }],
|
||||
outer: [new Uint8Array([4 << 2])]
|
||||
|
||||
Reference in New Issue
Block a user