Skip to content

Commit 6aea23c

Browse files
committed
Fix all tests, refactor code for startCompute. Added tests for compute status and get job results.
1 parent f6cfcd7 commit 6aea23c

16 files changed

Lines changed: 193 additions & 135 deletions

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,23 @@ npm run cli <command> [options] <arguments>
287287
`-d, --did <did>`
288288
`-f, --folder [destinationFolder]` (Default: `.`)
289289

290+
- **initializeCompute:**
291+
`-d, --datasets <datasetDids>`
292+
`-a, --algo <algoDid>`
293+
`-e, --env <computeEnvId>`
294+
`--validUntil <validUntil>`
295+
`-t, --token <paymentToken>`
296+
`--resources <resources>`
297+
290298
- **startCompute:**
291299
`-d, --datasets <datasetDids>`
292300
`-a, --algo <algoDid>`
293301
`-e, --env <computeEnvId>`
302+
`--init <initializeResponse>`
303+
`--maxJobDuration <maxJobDuration>`
304+
`-t, --token <paymentToken>`
305+
`--resources <resources>`
306+
`--amountToDeposit <amountToDeposit>` (Id `''`, it will fallback to initialize compute payment amount.)
294307

295308
- **startFreeCompute:**
296309
`-d, --datasets <datasetDids>`

metadata/downloadAssetPaymentUSDC.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,15 @@
5555
"purgatory": {
5656
"state": false
5757
},
58-
"stats": {
58+
"stats": [{
5959
"orders": 0,
60-
"price": {
61-
"value": "2",
62-
"tokenAddress": "0xf08A50178dfcDe18524640EA6618a1f965821715",
63-
"tokenSymbol": "USDC"
64-
}
65-
}
60+
"token": "0xf08A50178dfcDe18524640EA6618a1f965821715",
61+
"prices": [
62+
{
63+
"price": "2"
64+
}
65+
]
66+
}]
6667
},
6768
"datatokens": [
6869
],

metadata/jsAlgo.json

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,16 @@
6868
"purgatory": {
6969
"state": false
7070
},
71-
"stats": {
72-
"allocated": 0,
71+
"stats": [
72+
{
7373
"orders": 0,
74-
"price": {
75-
"value": "2"
76-
}
74+
"prices": [
75+
{
76+
"price": "0"
77+
}
78+
]
7779
}
78-
},
80+
],
7981
"datatokens": []
82+
}
8083
}

metadata/jsIPFSAlgo.json

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,16 @@
6565
"purgatory": {
6666
"state": false
6767
},
68-
"stats": {
69-
"allocated": 0,
68+
"stats": [
69+
{
7070
"orders": 0,
71-
"price": {
72-
"value": "2"
73-
}
71+
"prices": [
72+
{
73+
"price": "0"
74+
}
75+
]
7476
}
75-
},
77+
],
7678
"datatokens": []
79+
}
7780
}

metadata/pythonAlgo.json

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,16 @@
6262
"purgatory": {
6363
"state": false
6464
},
65-
"stats": {
66-
"allocated": 0,
65+
"stats": [
66+
{
6767
"orders": 0,
68-
"price": {
69-
"value": "2"
70-
}
68+
"prices": [
69+
{
70+
"price": "0"
71+
}
72+
]
7173
}
72-
},
74+
],
7375
"datatokens": []
76+
}
7477
}

metadata/simpleComputeDataset.json

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,16 @@
6161
"purgatory": {
6262
"state": false
6363
},
64-
"stats": {
65-
"allocated": 0,
64+
"stats": [
65+
{
6666
"orders": 0,
67-
"price": {
68-
"value": "2"
69-
}
67+
"prices": [
68+
{
69+
"price": "0"
70+
}
71+
]
7072
}
71-
},
73+
],
7274
"datatokens": []
75+
}
7376
}

metadata/simpleDownloadDataset.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,16 @@
5555
"purgatory": {
5656
"state": false
5757
},
58-
"stats": {
59-
"allocated": 0,
58+
"stats": [
59+
{
6060
"orders": 0,
61-
"price": {
62-
"value": "2"
63-
}
61+
"prices": [
62+
{
63+
"price": "0"
64+
}
65+
]
6466
}
65-
},
67+
],
6668
"datatokens": []
67-
69+
}
6870
}

metadata/simpleIPFSComputeDataset.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,16 @@
6060
"purgatory": {
6161
"state": false
6262
},
63-
"stats": {
64-
"allocated": 0,
63+
"stats": [
64+
{
6565
"orders": 0,
66-
"price": {
67-
"value": "2"
68-
}
66+
"prices": [
67+
{
68+
"price": "0"
69+
}
70+
]
6971
}
72+
]
7073
},
7174
"datatokens": []
7275
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"lint:fix": "eslint . --fix",
1212
"format": "prettier --parser typescript --ignore-path .gitignore --write '**/*.{js,jsx,ts,tsx}'",
1313
"cli": "npx tsx src/index.ts",
14-
"test:system": "npm run mocha 'test/computeFlow.test.ts'",
14+
"test:system": "npm run mocha 'test/**/*.test.ts'",
1515
"test": "npm run lint && npm run test:system",
1616
"mocha": "mocha --config=test/.mocharc.json --node-env=test --exit"
1717
},

src/cli.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ export async function createCLI() {
243243
}
244244
const { signer, chainId } = await initializeSigner();
245245
const commands = new Commands(signer, chainId);
246-
await commands.computeStart([null, dsDids, aDid, envId, JSON.stringify(initResp), jobDuration, token, JSON.stringify(res), amount.toString()]);
246+
await commands.computeStart([null, dsDids, aDid, envId, JSON.stringify(initResp), jobDuration.toString(), token, JSON.stringify(res), amount.toString()]);
247247
});
248248

249249
// startFreeCompute command
@@ -300,23 +300,22 @@ export async function createCLI() {
300300
.description('Stops a compute job')
301301
.argument('<datasetDid>', 'Dataset DID')
302302
.argument('<jobId>', 'Job ID')
303-
.argument('[agreementId]', 'Agreement ID')
303+
.argument('<agreementId>', 'Agreement ID')
304304
.option('-d, --dataset <datasetDid>', 'Dataset DID')
305305
.option('-j, --job <jobId>', 'Job ID')
306-
.option('-a, --agreement [agreementId]', 'Agreement ID')
306+
.option('-a, --agreement <agreementId>', 'Agreement ID')
307307
.action(async (datasetDid, jobId, agreementId, options) => {
308308
const dsDid = options.dataset || datasetDid;
309309
const jId = options.job || jobId;
310310
const agrId = options.agreement || agreementId;
311-
if (!dsDid || !jId) {
311+
if (!dsDid || !jId || !agrId) {
312312
console.error(chalk.red('Dataset DID and Job ID are required'));
313313
// process.exit(1);
314314
return
315315
}
316316
const { signer, chainId } = await initializeSigner();
317317
const commands = new Commands(signer, chainId);
318-
const args = [null, dsDid, jId];
319-
if (agrId) args.push(agrId);
318+
const args = [null, dsDid, jId, agrId];
320319
await commands.computeStop(args);
321320
});
322321

@@ -326,23 +325,22 @@ export async function createCLI() {
326325
.description('Displays the compute job status')
327326
.argument('<datasetDid>', 'Dataset DID')
328327
.argument('<jobId>', 'Job ID')
329-
.argument('[agreementId]', 'Agreement ID')
328+
.argument('<agreementId>', 'Agreement ID')
330329
.option('-d, --dataset <datasetDid>', 'Dataset DID')
331330
.option('-j, --job <jobId>', 'Job ID')
332-
.option('-a, --agreement [agreementId]', 'Agreement ID')
331+
.option('-a, --agreement <agreementId>', 'Agreement ID')
333332
.action(async (datasetDid, jobId, agreementId, options) => {
334333
const dsDid = options.dataset || datasetDid;
335334
const jId = options.job || jobId;
336335
const agrId = options.agreement || agreementId;
337-
if (!dsDid || !jId) {
336+
if (!dsDid || !jId || !agrId) {
338337
console.error(chalk.red('Dataset DID and Job ID are required'));
339338
// process.exit(1);
340339
return
341340
}
342341
const { signer, chainId } = await initializeSigner();
343342
const commands = new Commands(signer, chainId);
344-
const args = [null, dsDid, jId];
345-
if (agrId) args.push(agrId);
343+
const args = [null, dsDid, jId, agrId];
346344
await commands.getJobStatus(args);
347345
});
348346

0 commit comments

Comments
 (0)