Option instantiates from Option (#465)
This commit is contained in:
@@ -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');
|
||||
|
||||
@@ -25,11 +25,11 @@ export default class Option<T extends Codec> extends Base<T> implements Codec {
|
||||
|
||||
static decodeOption<O> (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
|
||||
|
||||
Reference in New Issue
Block a user