Option toJSON output same as from Substrate input (#4212)
* Option toJSON output same as from Substrate input * CHANGELOG
This commit is contained in:
@@ -102,6 +102,24 @@ describe('Option', (): void => {
|
||||
).toEqual(new Uint8Array([0]));
|
||||
});
|
||||
|
||||
it('converts toJSON() as null without', (): void => {
|
||||
expect(
|
||||
new Option(registry, Text).toJSON()
|
||||
).toEqual(null);
|
||||
});
|
||||
|
||||
it('converts toJSON() as non-null with Bytes', (): void => {
|
||||
expect(
|
||||
new Option(registry, Bytes, 'abcde').toJSON()
|
||||
).toEqual('0x6162636465');
|
||||
});
|
||||
|
||||
it('converts toJSON() as non-null with Text', (): void => {
|
||||
expect(
|
||||
new Option(registry, Text, 'abcde').toJSON()
|
||||
).toEqual('abcde');
|
||||
});
|
||||
|
||||
describe('utils', (): void => {
|
||||
const test = new Option(registry, Text, '1234');
|
||||
|
||||
|
||||
@@ -155,7 +155,9 @@ export class Option<T extends Codec> implements IOption<T> {
|
||||
* @description Converts the Object to JSON, typically used for RPC transfers
|
||||
*/
|
||||
public toJSON (): AnyJson {
|
||||
return this.#raw.toJSON();
|
||||
return this.isNone
|
||||
? null
|
||||
: this.#raw.toJSON();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user