1
0
mirror of https://github.com/oceanprotocol/ocean.js.git synced 2024-11-26 20:39:05 +01:00
ocean.js/test/integration/Assets.test.ts
Matthias Kretschmann d8914a8380
Replace Travis with GitHub Actions (#847)
* GitHub CI actions

* add coverage job

* test run tweaks

* windows build fix

* barge tweaks

* deal with env vars

* add npm publish job

* trial & error

* remove Travis

* publish as single workflow

* handle Docker Hub login

* maybe preparing ~/.ocean is needed

* downgrade barge contracts, run with barge defaults

* put back ADDRESS_FILE env var

* AQUARIUS_URI test

* ddo creation test logging

* make failing DDO creation test actually fail

* separate unit/integration Asset tests

* set AQUARIUS_URI again

* readme updates

* prepare ~/.ocean folder

* separate tests into multiple jobs

* address.json debugging

* windows build fixes

* address.json trials

* env var expansion workaround

* cleanup

* debug coverage output

* fix coverage

* bump codeclimate-action

* use barge instead of ganache (#855)

* use barge instead of ganache

* small unit test job cleanup

Co-authored-by: Matthias Kretschmann <m@kretschmann.io>

* barge detach workaround

Co-authored-by: Alex Coseru <alex.coseru@gmail.com>
2021-06-22 12:21:27 +02:00

162 lines
4.9 KiB
TypeScript

import { assert } from 'chai'
import { Ocean } from '../../src/ocean/Ocean'
import Web3 from 'web3'
import { Account, DDO, CredentialType, ConfigHelper, Metadata } from '../../src/lib'
const web3 = new Web3('http://127.0.0.1:8545')
describe('Assets', () => {
let ocean: Ocean
let alice: Account
let bob: Account
let charlie: Account
let ddo: DDO
let ddoWithAddressAnd3Box: DDO
const addressType = CredentialType.address
const threeBoxType = CredentialType.credential3Box
let walletA: string
let walletB: string
let walletC: string
const threeBoxValue = 'did:3:bafyre'
beforeEach(async () => {
const config = new ConfigHelper().getConfig('development')
config.web3Provider = web3
ocean = await Ocean.getInstance(config)
alice = (await ocean.accounts.list())[1]
walletA = alice.getId()
bob = (await ocean.accounts.list())[2]
walletB = bob.getId()
charlie = (await ocean.accounts.list())[3]
walletC = charlie.getId()
})
it('Alice creates a DDO', async () => {
const metadata: Metadata = {
main: {
type: 'dataset',
name: 'test-dataset',
dateCreated: new Date(Date.now()).toISOString().split('.')[0] + 'Z', // remove milliseconds
author: 'oceanprotocol-team',
license: 'MIT',
files: [
{
url: 'https://s3.amazonaws.com/testfiles.oceanprotocol.com/info.0.json',
checksum: 'efb2c764274b745f5fc37f97c6b0e761',
contentLength: '4535431',
contentType: 'text/csv',
encoding: 'UTF-8',
compression: 'zip'
}
]
}
}
const price = '10' // in datatoken
const publishedDate = new Date(Date.now()).toISOString().split('.')[0] + 'Z'
const timeout = 0
const service1 = await ocean.assets.createAccessServiceAttributes(
alice,
price,
publishedDate,
timeout
)
ddo = await ocean.assets.create(metadata, alice, [service1])
assert.isDefined(ddo)
assert.isDefined(ddo.id)
// const storeTx = await ocean.onChainMetadata.publish(ddo.id, ddo, alice.getId())
// assert(storeTx)
// await waitForAqua(ocean, ddo.id)
})
it('should add allow credential', async () => {
assert(ocean.assets.checkCredential(ddo, addressType, walletA).status === 0)
assert(ocean.assets.checkCredential(ddo, addressType, walletC).status === 0)
const allowWalletAddressList = [walletA, walletB]
console.error(JSON.stringify(ddo.credentials))
const newDdo = await ocean.assets.updateCredentials(
ddo,
addressType,
allowWalletAddressList,
[]
)
assert(newDdo.credentials.allow.length === 1)
assert(ocean.assets.checkCredential(ddo, addressType, walletA).status === 0)
assert(ocean.assets.checkCredential(ddo, addressType, walletC).status === 2)
})
it('should append allow credential', async () => {
const allowWalletAddressList = [walletA, walletB]
const allow3BoxList = [threeBoxValue]
ddoWithAddressAnd3Box = await ocean.assets.updateCredentials(
ddo,
addressType,
allowWalletAddressList,
[]
)
ddoWithAddressAnd3Box = await ocean.assets.updateCredentials(
ddo,
threeBoxType,
allow3BoxList,
[]
)
assert(ddoWithAddressAnd3Box.credentials.allow.length === 2)
})
it('should add deny credential', async () => {
const denyWalletAddressList = [walletC]
const newDdo = await ocean.assets.updateCredentials(
ddo,
addressType,
[],
denyWalletAddressList
)
assert(newDdo.credentials.deny.length === 1)
assert(ocean.assets.checkCredential(ddo, addressType, walletA).status === 0)
assert(ocean.assets.checkCredential(ddo, addressType, walletC).status === 3)
})
it('should append deny credential', async () => {
const denyWalletAddressList = [walletC]
const deny3BoxList = [threeBoxValue]
let newDdo = await ocean.assets.updateCredentials(
ddo,
addressType,
[],
denyWalletAddressList
)
newDdo = await ocean.assets.updateCredentials(ddo, threeBoxType, [], deny3BoxList)
assert(newDdo.credentials.deny.length === 2)
})
it('should only remove allow credential by credential type', async () => {
const allowWalletAddressList = [walletA, walletB]
const allow3BoxList = [threeBoxValue]
let newDdo = await ocean.assets.updateCredentials(
ddo,
addressType,
allowWalletAddressList,
[]
)
newDdo = await ocean.assets.updateCredentials(
ddoWithAddressAnd3Box,
threeBoxType,
allow3BoxList,
[]
)
assert(newDdo.credentials.allow.length === 2)
newDdo = await ocean.assets.updateCredentials(
ddoWithAddressAnd3Box,
threeBoxType,
[],
[]
)
assert(newDdo.credentials.allow.length === 1)
assert(ocean.assets.checkCredential(ddo, addressType, walletA).status === 0)
assert(ocean.assets.checkCredential(ddo, addressType, walletC).status === 2)
})
})