diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2d19198..e759be6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,9 +36,24 @@ jobs: node-version: ${{ matrix.node }} cache: npm + # ocean.js#2216 build; remove with the link step after its release + - name: Checkout ocean.js + uses: actions/checkout@v7 + with: + persist-credentials: false + repository: 'oceanprotocol/ocean.js' + ref: 'feat/node-neutral-query' + path: 'ocean.js' + - name: Build and link ocean.js + working-directory: ${{ github.workspace }}/ocean.js + run: npm ci && npm run build && npm link + - name: Install dependencies run: npm ci + - name: Use the ocean.js build + run: npm link @oceanprotocol/lib + - name: Run build run: npm run build @@ -143,6 +158,9 @@ jobs: test_system: runs-on: ubuntu-latest + env: + # ocean-node#1601 image; remove after its release + NODE_VERSION: pr-1601 strategy: fail-fast: false matrix: @@ -183,8 +201,23 @@ jobs: working-directory: ${{ github.workspace }}/barge run: | bash -x start_ocean.sh --with-typesense 2>&1 > start_ocean.log & + # ocean.js#2216 build; remove with the link step after its release + - name: Checkout ocean.js + uses: actions/checkout@v7 + with: + persist-credentials: false + repository: 'oceanprotocol/ocean.js' + ref: 'feat/node-neutral-query' + path: 'ocean.js' + - name: Build and link ocean.js + working-directory: ${{ github.workspace }}/ocean.js + run: npm ci && npm run build && npm link + - name: Install dependencies run: npm ci + - name: Use the ocean.js build + run: npm link @oceanprotocol/lib + - run: npm run build - run: docker image ls - name: Wait for node to be ready diff --git a/CLAUDE.md b/CLAUDE.md index 1229045..cea2810 100755 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -118,7 +118,7 @@ One big class holding all command logic. The constructor: - sets `this.config = config || new ConfigHelper().getConfig(network)` — ocean.js's `ConfigHelper` maps a chainId (or name) to a network config object, - sets `this.oceanNodeUrl = process.env.NODE_URL` and `this.config.nodeUri = this.oceanNodeUrl`, -- creates `this.aquarius = new Aquarius(this.oceanNodeUrl)` (the Ocean Node also serves the Aquarius/indexer API), +- resolves and validates DDOs with `ProviderInstance` against `this.oceanNodeUrl` (`waitForIndexer`, `validateDdo`), - loads `this.indexingParams` from `getIndexingWaitSettings()`. ### Config & chain selection — one mechanism (important) @@ -157,9 +157,9 @@ uses directly. `destroyProviders()` tears providers down on exit (next to `stopP `helpers.ts` is the seam between the CLI and ocean.js: - `createAssetUtil(...)` wraps ocean.js `createAsset` (used by publish/publishAlgo and the interactive publisher). It resolves the active ERC20 template (`calculateActiveTemplateIndex` reads and `JSON.parse`s the `@oceanprotocol/contracts` `ERC20Template.json` ABI, resolved via `createRequire`/`require.resolve` so it works from any cwd — e.g. a global install — not a cwd-relative `node_modules` path), and for **Oasis Sapphire** (`config.sdk === 'oasis'`) wraps the signer with `wrapEthersSigner` from `@oasisprotocol/sapphire-ethers-v6` (`getSignerAccordingSdk`; sapphire-paratime v2 moved its ethers integration into that package, and it throws `SignerHasNoProviderError` for a provider-less signer) and deploys an allow access list before creating the asset. -- `updateAssetMetadata(...)` — used by `editAsset`, `allowAlgo`, `disallowAlgo` and the interactive publisher. It validates the DDO via `aquarius.validate`, then either `ProviderInstance.encrypt`s the DDO (flags = 2) or hexlifies raw JSON (flags = 0) depending on the `encryptDDO` flag, then calls `nft.setMetadata`. +- `updateAssetMetadata(...)` — used by `editAsset`, `allowAlgo`, `disallowAlgo` and the interactive publisher. It validates the DDO via `ProviderInstance.validateDdo`, then either `ProviderInstance.encrypt`s the DDO (flags = 2) or hexlifies raw JSON (flags = 0) depending on the `encryptDDO` flag, then calls `nft.setMetadata`. - `handleComputeOrder(...)` — the ordering state machine used in compute: validOrder + no fees → reuse as-is; validOrder + fees → `datatoken.reuseOrder` paying only provider fees; no order → `orderAsset` (pay 1 datatoken + fees). Approves provider-fee tokens first when the fee amount > 0. -- `resolveComputeInputs(...)` + `parseComputeInput(...)` — parse the datasets/algo CLI strings (DID | JSON object | array | mixed | legacy `[did:a,did:b]`), resolve DID entries through `aquarius.waitForIndexer`, pass raw entries through (a `fileObject`, or for an algorithm inline `meta.rawcode`; aligned with a `null` DDO slot), and pick `providerURI` from the first DID-based DDO's `serviceEndpoint` (else fall back to `NODE_URL`). +- `resolveComputeInputs(...)` + `parseComputeInput(...)` — parse the datasets/algo CLI strings (DID | JSON object | array | mixed | legacy `[did:a,did:b]`), resolve DID entries through `ProviderInstance.waitForIndexer` on the node, pass raw entries through (a `fileObject`, or for an algorithm inline `meta.rawcode`; aligned with a `null` DDO slot), and pick `providerURI` from the first DID-based DDO's `serviceEndpoint` (else fall back to `NODE_URL`). - `fixAndParseProviderFees(...)` — regex-based repair of the stringified provider-initialize response that is round-tripped from `initializeCompute` into `computeStart` (adds quotes to keys, DIDs, hex addresses). Fragile by design; touch carefully. - `getIndexingWaitSettings()` — reads the `INDEXING_*` env vars. - Signing/encryption is always done via the `Signer` and `ProviderInstance` from ocean.js; the CLI never handles raw keys beyond constructing the `ethers.Wallet`. @@ -222,7 +222,7 @@ Most tests are **integration/system tests that require a running Ocean stack** ( - `test/setup.test.ts` — asserts `npm run cli h` help output and the env-var validation error messages. - `test/consumeFlow.test.ts`, `paidComputeFlow.test.ts`, `escrow.test.ts`, `accessList.test.ts`, `storage.test.ts` — end-to-end flows against the live node. - `test/http.test.ts` — hits the node HTTP API (`localhost:8001`) directly. -- `test/resolveComputeInputs.test.ts` — a **true unit test** using a fake `Aquarius`; runs with no infra. +- `test/resolveComputeInputs.test.ts` — a **true unit test** that stubs `ProviderInstance.waitForIndexer`; runs with no infra. - `test/interactivePublishFlow.ts` — the enquirer wizard (note: no `.test.ts` suffix, so it is not picked up by the `test:system` glob). CI (`.github/workflows/ci.yml`) has three jobs: `build`, `lint`, and `test_system` (matrix over `transport: [http, p2p]`), which checks out `oceanprotocol/barge`, runs `start_ocean.sh --with-typesense`, waits for `ocean-node-1`, sets `NODE_URL` (HTTP `http://127.0.0.1:8001`, or the peer id for P2P), and runs `npm run test:system` with `AVOID_LOOP_RUN=true` and `INDEXING_RETRY_INTERVAL=4000` / `INDEXING_MAX_RETRIES=120`. diff --git a/src/commands.ts b/src/commands.ts index c042385..f73f6ed 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -25,7 +25,6 @@ import { listChains, } from "./rpcRegistry.js"; import { - Aquarius, ComputeAsset, ComputeJob, Config, @@ -145,7 +144,6 @@ function formatAmountDiff(total: number, share: string): string { export class Commands { public signer: Signer; public config: Config; - public aquarius: Aquarius; public oceanNodeUrl: string; // optional settings for indexing wait time private indexingParams: IndexerWaitParams; @@ -167,7 +165,6 @@ export class Commands { this.indexingParams = getIndexingWaitSettings(); console.log("Using Ocean Node URL :", this.oceanNodeUrl); this.config.nodeUri = this.oceanNodeUrl; - this.aquarius = new Aquarius(this.oceanNodeUrl); } // --------------------------------------------------------------------------- @@ -310,7 +307,7 @@ export class Commands { public async start() { console.log("Starting the interactive CLI flow...\n\n"); const data = await interactiveFlow(this.oceanNodeUrl); // Collect data via CLI - await publishAsset(this.aquarius, data, this.signer, this.config); // Publish asset with collected data + await publishAsset(data, this.signer, this.config); // Publish asset with collected data } // utils @@ -351,7 +348,6 @@ export class Commands { asset, this.oceanNodeUrl, this.config, - this.aquarius, encryptDDO, ); console.log("Asset published. ID: " + urlAssetId); @@ -392,7 +388,6 @@ export class Commands { algoAsset, this.oceanNodeUrl, this.config, - this.aquarius, encryptDDO, ); // add some more checks @@ -405,7 +400,8 @@ export class Commands { } public async editAsset(args: string[]) { - const asset = await this.aquarius.waitForIndexer( + const asset = await ProviderInstance.waitForIndexer( + this.oceanNodeUrl, args[1], null, null, @@ -440,7 +436,6 @@ export class Commands { this.signer, asset, this.oceanNodeUrl, - this.aquarius, encryptDDO, ); console.log("Asset updated. Tx: " + JSON.stringify(updateAssetTx, null, 2)); @@ -448,7 +443,8 @@ export class Commands { public async getDDO(args: string[]) { console.log("Resolving Asset with DID: " + args[1]); - const resolvedDDO = await this.aquarius.waitForIndexer( + const resolvedDDO = await ProviderInstance.waitForIndexer( + this.oceanNodeUrl, args[1], null, null, @@ -517,7 +513,8 @@ export class Commands { public async download(args: string[]) { const did = args[1]; - const dataDdo = await this.aquarius.waitForIndexer( + const dataDdo = await ProviderInstance.waitForIndexer( + this.oceanNodeUrl, did, null, null, @@ -641,7 +638,6 @@ export class Commands { const resolved = await resolveComputeInputs( args[1], args[2], - this.aquarius, this.indexingParams, this.oceanNodeUrl, ); @@ -1049,7 +1045,6 @@ export class Commands { const resolved = await resolveComputeInputs( args[1], args[2], - this.aquarius, this.indexingParams, this.oceanNodeUrl, ); @@ -1675,7 +1670,6 @@ export class Commands { const resolved = await resolveComputeInputs( args[1], args[2], - this.aquarius, this.indexingParams, this.oceanNodeUrl, ); @@ -1864,7 +1858,8 @@ export class Commands { } public async computeStop(args: string[]) { - const dataDdo = await this.aquarius.waitForIndexer( + const dataDdo = await ProviderInstance.waitForIndexer( + this.oceanNodeUrl, args[1], null, null, @@ -2980,7 +2975,8 @@ export class Commands { } public async allowAlgo(args: string[]) { - const asset = await this.aquarius.waitForIndexer( + const asset = await ProviderInstance.waitForIndexer( + this.oceanNodeUrl, args[1], null, null, @@ -3014,7 +3010,8 @@ export class Commands { ); return; } - const algoAsset = await this.aquarius.waitForIndexer( + const algoAsset = await ProviderInstance.waitForIndexer( + this.oceanNodeUrl, args[2], null, null, @@ -3062,7 +3059,6 @@ export class Commands { this.signer, asset, this.oceanNodeUrl, - this.aquarius, encryptDDO, ); console.log("Successfully updated asset metadata: " + txid); @@ -3073,7 +3069,8 @@ export class Commands { } public async disallowAlgo(args: string[]) { - const asset = await this.aquarius.waitForIndexer( + const asset = await ProviderInstance.waitForIndexer( + this.oceanNodeUrl, args[1], null, null, @@ -3138,7 +3135,6 @@ export class Commands { this.signer, asset, this.oceanNodeUrl, - this.aquarius, encryptDDO, ); console.log("Asset updated " + txid); @@ -3150,7 +3146,8 @@ export class Commands { // args[3] - agreementId const hasAgreementId = args.length === 4; - const dataDdo = await this.aquarius.waitForIndexer( + const dataDdo = await ProviderInstance.waitForIndexer( + this.oceanNodeUrl, args[1], null, null, diff --git a/src/helpers.ts b/src/helpers.ts index c1f2c80..3a7e304 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -5,7 +5,6 @@ import { wrapEthersSigner } from "@oasisprotocol/sapphire-ethers-v6"; import { Asset, DDO, DDOManager } from "@oceanprotocol/ddo-js"; import { AccesslistFactory, - Aquarius, Nft, NftFactory, ProviderInstance, @@ -135,7 +134,6 @@ export async function createAssetUtil( ddo: DDO, oceanNodeUrl: string, config: Config, - aquariusInstance: Aquarius, encryptDDO: boolean = true, templateIDorAddress: string | number = 1, // If string, it's template address , otherwise, it's templateId, providerFeeToken: string = ZERO_ADDRESS, @@ -178,7 +176,6 @@ export async function createAssetUtil( encryptDDO, oceanNodeUrl, providerFeeToken, - aquariusInstance, accessListFactory, allowAccessList, denyAccessList, @@ -194,7 +191,6 @@ export async function createAssetUtil( encryptDDO, oceanNodeUrl, providerFeeToken, - aquariusInstance, ); } @@ -202,7 +198,6 @@ export async function updateAssetMetadata( owner: Signer, updatedDdo: Asset, oceanNodeUrl: string, - aquariusInstance: Aquarius, encryptDDO: boolean = true, ): Promise { const nft = new Nft( @@ -211,11 +206,12 @@ export async function updateAssetMetadata( ); let flags; let metadata; - const validateResult = await aquariusInstance.validate( + const validateResult = await ProviderInstance.validateDdo( + oceanNodeUrl, updatedDdo, owner, - oceanNodeUrl, ); + if (!validateResult) throw new Error("DDO validation failed"); const ddoInstance = DDOManager.getDDOClass(updatedDdo); const { chainId, nftAddress } = ddoInstance.getDDOFields(); if (encryptDDO) { @@ -424,14 +420,13 @@ export function parseComputeInput( // Resolves the raw datasets/algo CLI strings into fully-built ComputeAsset[] and // ComputeAlgorithm, plus index-aligned DDO arrays (null where the entry is raw). -// DID entries are resolved via Aquarius; raw (fileObject) entries are passed through +// DID entries are resolved on nodeUri; raw (fileObject) entries are passed through // untouched. Returns null (after logging) when a DID cannot be resolved. export async function resolveComputeInputs( datasetsInput: string, algoInput: string, - aquarius: Aquarius, indexingParams: IndexerWaitParams, - fallbackProviderURI: string, + nodeUri: string, ): Promise { const datasetTokens = parseComputeInput(datasetsInput); @@ -440,7 +435,8 @@ export async function resolveComputeInputs( for (const token of datasetTokens) { if (typeof token === "string") { - const dataDdo = await aquarius.waitForIndexer( + const dataDdo = await ProviderInstance.waitForIndexer( + nodeUri, token, undefined, undefined, @@ -484,7 +480,7 @@ export async function resolveComputeInputs( } } - let providerURI = fallbackProviderURI; + let providerURI = nodeUri; const firstDdo = ddos.find((d) => d !== null); if (firstDdo) { const { services } = DDOManager.getDDOClass(firstDdo).getDDOFields(); @@ -498,7 +494,8 @@ export async function resolveComputeInputs( let algoDdo: Asset | DDO | null = null; if (typeof algoToken === "string") { - algoDdo = await aquarius.waitForIndexer( + algoDdo = await ProviderInstance.waitForIndexer( + nodeUri, algoToken, undefined, undefined, diff --git a/src/publishAsset.ts b/src/publishAsset.ts index 75e078c..05199a4 100644 --- a/src/publishAsset.ts +++ b/src/publishAsset.ts @@ -1,6 +1,6 @@ // src/publishAsset.ts import { Signer } from "ethers"; -import { Config, Aquarius } from "@oceanprotocol/lib"; +import { Config } from "@oceanprotocol/lib"; import { Asset } from "@oceanprotocol/ddo-js"; import { createAssetUtil, updateAssetMetadata } from "./helpers.js"; @@ -21,7 +21,6 @@ export interface PublishAssetParams { } export async function publishAsset( - aquarius: Aquarius, params: PublishAssetParams, signer: Signer, config: Config, @@ -105,7 +104,6 @@ export async function publishAsset( metadata, params.providerUrl, config, - aquarius, ); console.log(`Asset successfully published with DID: ${did}`); @@ -116,7 +114,7 @@ export async function publishAsset( metadata.services[0].datatokenAddress = assetUrl.datatokenAddress; // Update with the correct Datatoken address // Use the helper function to update the metadata on the NFT - await updateAssetMetadata(signer, metadata, params.providerUrl, aquarius); + await updateAssetMetadata(signer, metadata, params.providerUrl); console.log(`Metadata successfully updated for DID: ${did}`); } catch (error) { diff --git a/test/resolveComputeInputs.test.ts b/test/resolveComputeInputs.test.ts index 3b4b28c..7d9c07f 100644 --- a/test/resolveComputeInputs.test.ts +++ b/test/resolveComputeInputs.test.ts @@ -1,26 +1,23 @@ import { expect } from "chai"; -import { Aquarius } from "@oceanprotocol/lib"; +import { ProviderInstance } from "@oceanprotocol/lib"; import { resolveComputeInputs, IndexerWaitParams } from "../src/helpers.js"; -// A fake Aquarius whose waitForIndexer returns a deterministic DDO per DID, -// so the resolver can be exercised without a live indexer. -function makeAquarius(known?: Set): Aquarius { +const realWaitForIndexer = ProviderInstance.waitForIndexer; + +// a node that knows every DID except did:op:missing +async function fakeWaitForIndexer(nodeUri: string, did: string) { + if (did === "did:op:missing") return null; return { - waitForIndexer: async (did: string) => { - if (known && !known.has(did)) return null; - return { - id: did, - version: "4.1.0", - services: [ - { - id: `service-${did}`, - serviceEndpoint: `http://provider-for-${did}`, - }, - ], - metadata: { algorithm: { container: { image: "img" } } }, - }; - }, - } as unknown as Aquarius; + id: did, + version: "4.1.0", + services: [ + { + id: `service-${did}`, + serviceEndpoint: `http://provider-for-${did}`, + }, + ], + metadata: { algorithm: { container: { image: "img" } } }, + }; } const indexingParams: IndexerWaitParams = { @@ -46,11 +43,18 @@ const RAW_ALGO = { }; describe("resolveComputeInputs", function () { + before(function () { + ProviderInstance.waitForIndexer = + fakeWaitForIndexer as unknown as typeof realWaitForIndexer; + }); + after(function () { + ProviderInstance.waitForIndexer = realWaitForIndexer; + }); + it("resolves a single dataset DID and a single algorithm DID", async function () { const res = await resolveComputeInputs( "did:op:dataset1", "did:op:algo1", - makeAquarius(), indexingParams, FALLBACK, ); @@ -68,7 +72,6 @@ describe("resolveComputeInputs", function () { const res = await resolveComputeInputs( "[did:op:a,did:op:b]", "did:op:algo1", - makeAquarius(), indexingParams, FALLBACK, ); @@ -84,7 +87,6 @@ describe("resolveComputeInputs", function () { const res = await resolveComputeInputs( "did:op:a,did:op:b", "did:op:algo1", - makeAquarius(), indexingParams, FALLBACK, ); @@ -100,7 +102,6 @@ describe("resolveComputeInputs", function () { const res = await resolveComputeInputs( JSON.stringify(RAW_DATASET), "did:op:algo1", - makeAquarius(), indexingParams, FALLBACK, ); @@ -115,7 +116,6 @@ describe("resolveComputeInputs", function () { const res = await resolveComputeInputs( JSON.stringify(["did:op:dataset1", RAW_DATASET]), "did:op:algo1", - makeAquarius(), indexingParams, FALLBACK, ); @@ -131,7 +131,6 @@ describe("resolveComputeInputs", function () { const res = await resolveComputeInputs( JSON.stringify([RAW_DATASET, "did:op:dataset1"]), "did:op:algo1", - makeAquarius(), indexingParams, FALLBACK, ); @@ -144,7 +143,6 @@ describe("resolveComputeInputs", function () { const res = await resolveComputeInputs( "did:op:dataset1", JSON.stringify(RAW_ALGO), - makeAquarius(), indexingParams, FALLBACK, ); @@ -157,7 +155,6 @@ describe("resolveComputeInputs", function () { const res = await resolveComputeInputs( "[]", "did:op:algo1", - makeAquarius(), indexingParams, FALLBACK, ); @@ -169,7 +166,6 @@ describe("resolveComputeInputs", function () { const res = await resolveComputeInputs( JSON.stringify({ documentId: "x" }), "did:op:algo1", - makeAquarius(), indexingParams, FALLBACK, ); @@ -182,7 +178,6 @@ describe("resolveComputeInputs", function () { JSON.stringify({ meta: { rawcode: "print(1)", container: { image: "python" } }, }), - makeAquarius(), indexingParams, FALLBACK, ); @@ -196,7 +191,6 @@ describe("resolveComputeInputs", function () { const res = await resolveComputeInputs( "did:op:dataset1", JSON.stringify({ meta: { container: {} } }), - makeAquarius(), indexingParams, FALLBACK, ); @@ -207,7 +201,6 @@ describe("resolveComputeInputs", function () { const res = await resolveComputeInputs( "did:op:missing", "did:op:algo1", - makeAquarius(new Set(["did:op:algo1"])), indexingParams, FALLBACK, );