Skip to content

Commit 8cf605b

Browse files
committed
Refactor parsing of initialize response.
1 parent 89c5af0 commit 8cf605b

3 files changed

Lines changed: 6 additions & 12 deletions

File tree

src/cli.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ export async function createCLI() {
229229
.option('-a, --algo <algoDid>', 'Algorithm DID')
230230
.option('-e, --env <computeEnvId>', 'Compute environment ID')
231231
.option('--maxJobDuration <maxJobDuration>', 'Compute maxJobDuration')
232-
.option('--token <paymentToken>', 'Compute payment token')
232+
.option('-t, --token <paymentToken>', 'Compute payment token')
233233
.option('--resources <resources>', 'Compute resources')
234234
.option('--amount <amountToDeposit>', 'AMount to deposit in escrow')
235235
.action(async (datasetDids, algoDid, computeEnvId, maxJobDuration, paymentToken, resources, amountToDeposit, options) => {
@@ -247,7 +247,7 @@ export async function createCLI() {
247247
}
248248
const { signer, chainId } = await initializeSigner();
249249
const commands = new Commands(signer, chainId);
250-
await commands.computeStart([null, dsDids, aDid, envId, jobDuration, token, res, amount]);
250+
await commands.computeStart([null, dsDids, aDid, envId, jobDuration.toString(), token, JSON.stringify(res), amount.toString()]);
251251
});
252252

253253
// startFreeCompute command

src/commands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ export class Commands {
414414
);
415415
return;
416416
}
417-
console.log(`computeEnv.fees[chainId].feeToken: `, computeEnv.fees[chainId].feeToken)
417+
console.log(`computeEnv.fees[chainId]: `, JSON.stringify(computeEnv.fees[chainId.toString()]))
418418
let found: boolean = false;
419419
for (const fee of computeEnv.fees[chainId.toString()]) {
420420
if (fee.feeToken.toLowerCase() === paymentToken.toLowerCase()) {

test/computeFlow.test.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -202,19 +202,13 @@ describe("Ocean CLI Compute", function() {
202202
console.error("Raw output:", output);
203203
throw new Error("Could not find initialize response in the output");
204204
}
205-
const match = jsonMatch[0].match(/initialize compute details:\s*(.*)/s);
206-
const result = match ? match[1].trim() : null;
207-
if (!result) {
208-
console.error("Raw output:", output);
209-
throw new Error("Could not find initialize compute response in the output");
210-
}
205+
const result = jsonMatch[0].split('initialize compute details:')[1]?.trim();
211206
try {
212-
providerInitializeResponse = eval(result);
207+
providerInitializeResponse = JSON.parse(result);
213208
} catch (error) {
214-
console.error("Extracted output:", jsonMatch[0]);
209+
console.error(`Extracted output: ${jsonMatch[0]} and final result: ${result}`);
215210
throw new Error("Failed to parse the extracted output:\n" + error);
216211
}
217-
console.log(`providerInitializeResponse: ${JSON.stringify(providerInitializeResponse)}`)
218212
expect(providerInitializeResponse).to.have.property("payment").that.is.an("object");
219213
// expect(providerInitializeResponse).to.have.property("consumerAddress").that.is.a("string");
220214
// expect(providerInitializeResponse).to.have.property("resources").that.is.an("array");

0 commit comments

Comments
 (0)