Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ipfs CID. #1851

Merged
merged 26 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ jobs:
env:
PROVIDER_URL: 'http://172.15.0.4:8030'
- name: docker logs
run: docker logs ocean_aquarius_1 && docker logs ocean_provider_1 && docker logs ocean_provider2_1 && docker logs ocean_computetodata_1
run: docker logs ocean-ipfs-1
bogdanfazakas marked this conversation as resolved.
Show resolved Hide resolved
if: ${{ failure() }}
- name: Upload coverage
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -224,7 +224,7 @@ jobs:
# needs: [test_unit, test_integration]
# steps:
# - uses: actions/checkout@v3
# - uses: actions/setup-node@v2
# - uses: actions/setup-node@v4
# with:
# node-version: '16'

Expand Down
77 changes: 73 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"web3": "^1.8.0"
},
"dependencies": {
"axios": "^1.7.7",
bogdanfazakas marked this conversation as resolved.
Show resolved Hide resolved
"@oasisprotocol/sapphire-paratime": "^1.3.2",
"@oceanprotocol/contracts": "^2.2.0",
"cross-fetch": "^4.0.0",
Expand Down
5 changes: 3 additions & 2 deletions src/services/Provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ export class Provider {
let initializeUrl = this.getEndpointURL(serviceEndpoints, 'initialize')
? this.getEndpointURL(serviceEndpoints, 'initialize').urlPath
: null

console.log(initializeUrl)
bogdanfazakas marked this conversation as resolved.
Show resolved Hide resolved
if (!initializeUrl) return null
initializeUrl += `?documentId=${did}`
initializeUrl += `&serviceId=${serviceId}`
Expand All @@ -389,12 +389,13 @@ export class Provider {
headers: { 'Content-Type': 'application/json' },
signal
})
console.log(response)
bogdanfazakas marked this conversation as resolved.
Show resolved Hide resolved
} catch (e) {
LoggerInstance.error('Provider initialized failed: ')
LoggerInstance.error(e)
throw new Error(`Provider initialize failed url: ${initializeUrl} `)
}
if (response?.ok) {
if (response?.status === 200) {
const results: ProviderInitialize = await response.json()
return results
}
Expand Down
74 changes: 49 additions & 25 deletions test/integration/PublishEditConsume.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from '../../src'
import { Files, Smartcontract } from '../../src/@types'
import { createAsset, orderAsset, updateAssetMetadata } from './helpers'
import axios from 'axios'

let config: Config

Expand Down Expand Up @@ -72,17 +73,6 @@ const arweaveFile: Files = {
]
}

const ifpsFile: Files = {
datatokenAddress: '0x0',
nftAddress: '0x0',
files: [
{
type: 'ipfs',
hash: 'QmRhsp7eghZtW4PktPC2wAHdKoy2LiF1n6UXMKmAhqQJUA'
}
]
}

const onchainFile: Files = {
datatokenAddress: '0x0',
nftAddress: '0x0',
Expand Down Expand Up @@ -146,6 +136,31 @@ function delay(interval: number) {
}).timeout(interval + 100)
}

function uploadToIpfs(data: any): Promise<string> {
return new Promise((resolve, reject) => {
axios
bogdanfazakas marked this conversation as resolved.
Show resolved Hide resolved
.post(
'http://172.15.0.16:5001/api/v0/add',
mariacarmina marked this conversation as resolved.
Show resolved Hide resolved
'--------------------------a28d68b1c872c96f\r\nContent-Disposition: form-data; name="file"; filename="ddo.json"\r\nContent-Type: application/octet-stream\r\n\r\n' +
data +
'\r\n--------------------------a28d68b1c872c96f--\r\n',
{
headers: {
'Content-Type':
'multipart/form-data; boundary=------------------------a28d68b1c872c96f'
}
}
)
.then(function (response: any) {
console.log('hash: ', response.data.Hash)
bogdanfazakas marked this conversation as resolved.
Show resolved Hide resolved
resolve(response.data.Hash)
})
.catch(function (error: any) {
reject(error)
})
})
}

describe('Publish consume test', async () => {
before(async () => {
publisherAccount = (await provider.getSigner(0)) as Signer
Expand Down Expand Up @@ -210,33 +225,42 @@ describe('Publish consume test', async () => {
)
assert(urlAssetId, 'Failed to publish url DDO')
})

it('Should publish ipfs asset', async () => {
ipfsAssetId = await createAsset(
'IpfsDatatoken',
'IPFSDT',
it('Should publish arweave asset', async () => {
arweaveAssetId = await createAsset(
'ArwaveDatatoken',
'ARWAVEDT',
publisherAccount,
ifpsFile,
arweaveFile,
assetDdo,
providerUrl,
addresses.ERC721Factory,
aquarius
)
assert(ipfsAssetId, 'Failed to publish ipfs DDO')
assert(arweaveAssetId, 'Failed to arwave publish DDO')
})

it('Should publish arwave asset', async () => {
arweaveAssetId = await createAsset(
'ArweaveDatatoken',
'ARWEAVEDT',
it('Should publish ipfs asset', async () => {
const ipfsCID = await uploadToIpfs(JSON.stringify(assetDdo))
const ipfsFile: Files = {
datatokenAddress: '0x0',
nftAddress: '0x0',
files: [
{
type: 'ipfs',
hash: ipfsCID
}
]
}
ipfsAssetId = await createAsset(
'IpfsDatatoken',
'IPFSDT',
publisherAccount,
arweaveFile,
ipfsFile,
assetDdo,
providerUrl,
addresses.ERC721Factory,
aquarius
)
assert(arweaveAssetId, 'Failed to publish ipfs DDO')
assert(ipfsAssetId, 'Failed to publish ipfs DDO')
})

it('Should publish onchain asset', async () => {
Expand Down
1 change: 1 addition & 0 deletions test/integration/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export async function orderAsset(
datatoken: Datatoken,
providerUrl: string
) {
console.log(did)
bogdanfazakas marked this conversation as resolved.
Show resolved Hide resolved
const initializeData = await ProviderInstance.initialize(
did,
serviceId,
Expand Down
Loading