mirror of
https://github.com/fluencelabs/fluence-js.git
synced 2025-05-10 08:27:12 +00:00
Implement debug.stringify service (#125)
This commit is contained in:
parent
25f63f0b0d
commit
5cb4c8974f
@ -5,6 +5,18 @@ import { KeyPair } from '../../internal/KeyPair';
|
|||||||
import { Sig, defaultSigGuard, allowServiceFn } from '../../internal/builtins/Sig';
|
import { Sig, defaultSigGuard, allowServiceFn } from '../../internal/builtins/Sig';
|
||||||
import { toUint8Array } from 'js-base64';
|
import { toUint8Array } from 'js-base64';
|
||||||
|
|
||||||
|
const a10b20 = `{
|
||||||
|
"a": 10,
|
||||||
|
"b": 20
|
||||||
|
}`;
|
||||||
|
|
||||||
|
const oneTwoThreeFour = `[
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
4
|
||||||
|
]`;
|
||||||
|
|
||||||
describe('Tests for default handler', () => {
|
describe('Tests for default handler', () => {
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
each`
|
each`
|
||||||
@ -49,6 +61,10 @@ describe('Tests for default handler', () => {
|
|||||||
${'peer'} | ${'timeout'} | ${[]} | ${1} | ${'timeout accepts exactly two arguments: timeout duration in ms and a message string'}}
|
${'peer'} | ${'timeout'} | ${[]} | ${1} | ${'timeout accepts exactly two arguments: timeout duration in ms and a message string'}}
|
||||||
${'peer'} | ${'timeout'} | ${[200, 'test', 1]} | ${1} | ${'timeout accepts exactly two arguments: timeout duration in ms and a message string'}}
|
${'peer'} | ${'timeout'} | ${[200, 'test', 1]} | ${1} | ${'timeout accepts exactly two arguments: timeout duration in ms and a message string'}}
|
||||||
|
|
||||||
|
${'debug'} | ${'stringify'} | ${[]} | ${0} | ${'"<empty argument list>"'}}
|
||||||
|
${'debug'} | ${'stringify'} | ${[{a: 10, b: 20}]} | ${0} | ${a10b20}}
|
||||||
|
${'debug'} | ${'stringify'} | ${[1, 2, 3, 4]} | ${0} | ${oneTwoThreeFour}}
|
||||||
|
|
||||||
`.test(
|
`.test(
|
||||||
//
|
//
|
||||||
'$fnName with $args expected retcode: $retCode and result: $result',
|
'$fnName with $args expected retcode: $retCode and result: $result',
|
||||||
|
@ -18,6 +18,7 @@ import { CallServiceResult } from '@fluencelabs/avm-runner-interface';
|
|||||||
import { encode, decode } from 'bs58';
|
import { encode, decode } from 'bs58';
|
||||||
import { sha256 } from 'multiformats/hashes/sha2';
|
import { sha256 } from 'multiformats/hashes/sha2';
|
||||||
import { ResultCodes } from '../commonTypes';
|
import { ResultCodes } from '../commonTypes';
|
||||||
|
import { jsonify } from '../utils'
|
||||||
import Buffer from '../Buffer';
|
import Buffer from '../Buffer';
|
||||||
|
|
||||||
const success = (result: any): CallServiceResult => {
|
const success = (result: any): CallServiceResult => {
|
||||||
@ -128,6 +129,22 @@ export const builtInServices = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
debug: {
|
||||||
|
stringify: (req) => {
|
||||||
|
let out;
|
||||||
|
|
||||||
|
if (req.args.length === 0) {
|
||||||
|
out = '<empty argument list>';
|
||||||
|
} else if (req.args.length === 1) {
|
||||||
|
out = req.args[0];
|
||||||
|
} else {
|
||||||
|
out = req.args;
|
||||||
|
}
|
||||||
|
|
||||||
|
return success(jsonify(out));
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
peer: {
|
peer: {
|
||||||
timeout: (req) => {
|
timeout: (req) => {
|
||||||
if (req.args.length !== 2) {
|
if (req.args.length !== 2) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user