Option toJSON output same as from Substrate input (#4212)

* Option toJSON output same as from Substrate input

* CHANGELOG
This commit is contained in:
Jaco
2021-11-13 07:53:15 +02:00
committed by GitHub
parent 6e1e8e622b
commit ef37c421ac
3 changed files with 22 additions and 1 deletions
+18
View File
@@ -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');
+3 -1
View File
@@ -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();
}
/**