Encode mock responses as JSON (#66)

* Encode mock responses as JSON

* Update primitives
This commit is contained in:
Jaco Greeff
2018-04-16 18:07:21 +02:00
committed by GitHub
parent 2e4a9e7793
commit d86cd86251
5 changed files with 73 additions and 79 deletions
+3 -2
View File
@@ -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);
+7 -7
View File
@@ -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])
})
);
});