JS SDK: fix host functions in mocha tests (#1003)

This commit is contained in:
folex
2020-12-19 23:59:29 +03:00
committed by GitHub
parent f0b4c7a718
commit b79f0920d4
9 changed files with 168 additions and 53 deletions

View File

@ -21,12 +21,7 @@ import * as PeerId from "peer-id";
import Multiaddr from "multiaddr"
import {FluenceConnection} from "./fluenceConnection";
import {Subscriptions} from "./subscriptions";
import {
enqueueParticle,
getCurrentParticleId,
popParticle,
setCurrentParticleId
} from "./globalState";
import {enqueueParticle, getCurrentParticleId, popParticle, setCurrentParticleId} from "./globalState";
import {instantiateInterpreter, InterpreterInvoke} from "./stepper";
import log from "loglevel";
import {waitService} from "./helpers/waitService";
@ -34,6 +29,8 @@ import {ModuleConfig} from "./moduleConfig";
const bs58 = require('bs58')
const INFO_LOG_LEVEL = 2
export class FluenceClient {
readonly selfPeerId: PeerId;
readonly selfPeerIdStr: string;
@ -84,12 +81,21 @@ export class FluenceClient {
let stepperOutcomeStr = this.interpreter(particle.init_peer_id, particle.script, JSON.stringify(prevData), JSON.stringify(particle.data))
let stepperOutcome: StepperOutcome = JSON.parse(stepperOutcomeStr);
log.info("inner interpreter outcome:");
log.info(stepperOutcome);
if (log.getLevel() <= INFO_LOG_LEVEL) {
log.info("inner interpreter outcome:");
let so = {...stepperOutcome}
try {
so.data = JSON.parse(Buffer.from(so.data).toString("utf8"));
log.info(so);
} catch (e) {
log.info("cannot parse StepperOutcome data as JSON: ", e);
}
}
// update data after aquamarine execution
let newParticle: Particle = {...particle};
newParticle.data = JSON.parse(stepperOutcome.call_path)
newParticle.data = stepperOutcome.data
this.subscriptions.update(newParticle)
// do nothing if there is no `next_peer_pks` or if client isn't connected to the network