Encode mock responses as JSON (#66)
* Encode mock responses as JSON * Update primitives
This commit is contained in:
@@ -8,6 +8,7 @@ import type { InterfaceOutputType } from '@polkadot/api-jsonrpc/types';
|
||||
const bnDecode = require('@polkadot/primitives-json/bn/decode');
|
||||
const bytesDecode = require('@polkadot/primitives-json/bytes/decode');
|
||||
const headerDecode = require('@polkadot/primitives-json/header/decode');
|
||||
const isNull = require('@polkadot/util/is/null');
|
||||
const isUndefined = require('@polkadot/util/is/undefined');
|
||||
|
||||
const util = require('./util');
|
||||
@@ -20,8 +21,8 @@ const formatters = {
|
||||
};
|
||||
|
||||
module.exports = function formatOutput (output: InterfaceOutputType, value?: mixed): ?mixed {
|
||||
if (isUndefined(value)) {
|
||||
return void 0;
|
||||
if (isUndefined(value) || isNull(value)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return util.format(formatters, output.type, value);
|
||||
|
||||
@@ -11,13 +11,13 @@ describe('formatOutput', () => {
|
||||
expect(
|
||||
JSON.stringify(
|
||||
formatOutput({ type: 'Header' }, {
|
||||
parentHash: '0x1234',
|
||||
number: '0x1234',
|
||||
stateRoot: '0x5678',
|
||||
transactionRoot: '0xabcd',
|
||||
digest: {
|
||||
logs: ['0x5678', '0x789a']
|
||||
}
|
||||
},
|
||||
extrinsicsRoot: '0xabcd',
|
||||
number: '0x1234',
|
||||
parentHash: '0x1234',
|
||||
stateRoot: '0x5678'
|
||||
})
|
||||
)
|
||||
).toEqual(
|
||||
@@ -28,10 +28,10 @@ describe('formatOutput', () => {
|
||||
new Uint8Array([0x78, 0x9a])
|
||||
]
|
||||
},
|
||||
extrinsicsRoot: new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xab, 0xcd]),
|
||||
number: new BN(0x1234),
|
||||
parentHash: new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x12, 0x34]),
|
||||
stateRoot: new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x56, 0x78]),
|
||||
transactionRoot: new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xab, 0xcd])
|
||||
stateRoot: new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x56, 0x78])
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user