diff --git a/packages/types/src/codec/Option.spec.js b/packages/types/src/codec/Option.spec.js index 381301939f..16ded2d718 100644 --- a/packages/types/src/codec/Option.spec.js +++ b/packages/types/src/codec/Option.spec.js @@ -27,6 +27,12 @@ describe('Option', () => { expect(new Option(Text, 'test').isNone).toBe(false); }); + it('converts an option to an option', () => { + expect( + new Option(Text, new Option(Text, 'hello')).toString() + ).toEqual('hello'); + }); + testDecode('string (with)', 'foo', 'foo'); testDecode('string (without)', undefined, ''); testDecode('Uint8Array (with)', Uint8Array.from([1, 12, 102, 111, 111]), 'foo'); diff --git a/packages/types/src/codec/Option.ts b/packages/types/src/codec/Option.ts index 655d3058d7..a1f15b5231 100644 --- a/packages/types/src/codec/Option.ts +++ b/packages/types/src/codec/Option.ts @@ -25,11 +25,11 @@ export default class Option extends Base implements Codec { static decodeOption (Type: Constructor, value?: any): Codec { if (isU8a(value)) { - if (value[0] === 0) { - return new Null(); - } - - return new Type(value.subarray(1)); + return value[0] === 0 + ? new Null() + : new Type(value.subarray(1)); + } else if (value instanceof Option) { + return Option.decodeOption(Type, value.value); } return isNull(value) || isUndefined(value) || value instanceof Null