-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublish.test.ts
99 lines (89 loc) · 2.65 KB
/
publish.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { expect } from 'chai'
import { ethers } from 'ethers'
import { Aquarius } from '@oceanprotocol/lib'
import { createAssetUtil } from '../src/helpers/publish'
import * as dotenv from 'dotenv'
dotenv.config()
describe('createAsset function', function () {
this.timeout(60000) // Set timeout to 60 seconds
let provider: ethers.providers.JsonRpcProvider
let signer: ethers.Signer
let aquarius: Aquarius
before(async () => {
// Setup provider and signer
const rpcUrl = process.env.RPC_URL || 'http://localhost:8545'
provider = new ethers.providers.JsonRpcProvider(rpcUrl)
const privateKey = process.env.PRIVATE_KEY
if (!privateKey) {
throw new Error('PRIVATE_KEY not set in environment')
}
signer = new ethers.Wallet(privateKey, provider)
// Setup Aquarius
const aquariusUrl = process.env.OCEAN_NODE_URL || 'http://127.0.0.1:8001'
aquarius = new Aquarius(aquariusUrl)
})
it('should successfully create an asset', async () => {
const name = 'Test Asset'
const symbol = 'TST'
const assetUrl = {
datatokenAddress: '0x0000000000000000000000000000000000000000',
nftAddress: '0x0000000000000000000000000000000000000000',
files: [
{
type: 'url',
url: 'https://example.com/test.txt',
method: 'GET'
}
]
}
const ddo = {
'@context': ['https://w3id.org/did/v1'],
id: '',
version: '4.1.0',
chainId: await signer.getChainId(),
nftAddress: '0x0000000000000000000000000000000000000000',
metadata: {
created: new Date().toISOString(),
updated: new Date().toISOString(),
type: 'dataset',
name: 'Test Dataset',
description: 'This is a test dataset',
author: 'Test Author',
license: 'CC0'
},
services: [
{
id: 'testServiceId',
type: 'access',
files: '',
datatokenAddress: '0x0000000000000000000000000000000000000000',
serviceEndpoint: 'http://localhost:8030',
timeout: 0
}
],
stats: {
price: {
value: 10
}
}
}
const providerUrl = process.env.OCEAN_NODE_URL || 'http://localhost:8001'
try {
const assetId = await createAssetUtil(
name,
symbol,
signer,
assetUrl,
ddo,
providerUrl,
aquarius
)
expect(assetId).to.be.a('string')
expect(assetId).to.match(/^did:op:[a-fA-F0-9]{64}$/)
// You can add more assertions here to check the created asset details
} catch (error) {
console.error('Error creating asset:', error)
throw error
}
})
})