mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
test tweaks
This commit is contained in:
parent
6f85014e00
commit
455983f7b6
@ -26,10 +26,8 @@ before_script:
|
||||
- sleep 300
|
||||
|
||||
script:
|
||||
- npm run lint
|
||||
- npm test
|
||||
- npm run build
|
||||
- npm run test:unit:cover
|
||||
- npm run test:integration:cover
|
||||
|
||||
after_script:
|
||||
- ./cc-test-reporter format-coverage -t lcov -o coverage/codeclimate.unit.json coverage/unit/lcov.info # Format unit test coverage
|
||||
|
@ -24,7 +24,7 @@
|
||||
"test:unit": "mocha --config=test/unit/.mocharc.json --node-env=test --exit 'test/unit/**/*.test.ts'",
|
||||
"test:unit:cover": "nyc --report-dir coverage/unit npm run test:unit",
|
||||
"test:integration": "mocha --config=test/integration/.mocharc.json --node-env=test --exit 'test/integration/**/*.test.ts'",
|
||||
"test:integration:cover": "nyc --report-dir coverage/integration npm run test:integration"
|
||||
"test:integration:cover": "nyc --report-dir coverage/integration --no-clean npm run test:integration"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
@ -26,8 +26,9 @@ export class BalancerContractHandler {
|
||||
this.poolBytecode = poolBytecode
|
||||
}
|
||||
|
||||
public async getAccounts() {
|
||||
public async getAccounts(): Promise<string[]> {
|
||||
this.accounts = await this.web3.eth.getAccounts()
|
||||
return this.accounts
|
||||
}
|
||||
|
||||
public async deployContracts(minter: string) {
|
||||
|
@ -1,7 +1,9 @@
|
||||
import Web3 from 'web3'
|
||||
import { Contract } from 'web3-eth-contract'
|
||||
import { AbiItem } from 'web3-utils/types'
|
||||
|
||||
const communityCollector = '0xeE9300b7961e0a01d9f0adb863C7A227A07AaD75'
|
||||
|
||||
export class TestContractHandler {
|
||||
public factory: Contract
|
||||
public template: Contract
|
||||
@ -26,8 +28,9 @@ export class TestContractHandler {
|
||||
this.factoryBytecode = factoryBytecode
|
||||
}
|
||||
|
||||
public async getAccounts() {
|
||||
public async getAccounts(): Promise<string[]> {
|
||||
this.accounts = await this.web3.eth.getAccounts()
|
||||
return this.accounts
|
||||
}
|
||||
|
||||
public async deployContracts(minter: string) {
|
||||
|
@ -53,340 +53,330 @@ describe('Compute flow', () => {
|
||||
}
|
||||
}
|
||||
|
||||
describe('#MarketplaceComputeFlow-Test', () => {
|
||||
it('Initialize Ocean contracts v3', async () => {
|
||||
contracts = new TestContractHandler(
|
||||
factory.abi as AbiItem[],
|
||||
datatokensTemplate.abi as AbiItem[],
|
||||
datatokensTemplate.bytecode,
|
||||
factory.bytecode,
|
||||
web3
|
||||
)
|
||||
it('Initialize Ocean contracts v3', async () => {
|
||||
contracts = new TestContractHandler(
|
||||
factory.abi as AbiItem[],
|
||||
datatokensTemplate.abi as AbiItem[],
|
||||
datatokensTemplate.bytecode,
|
||||
factory.bytecode,
|
||||
web3
|
||||
)
|
||||
|
||||
ocean = await Ocean.getInstance(config)
|
||||
owner = (await ocean.accounts.list())[0]
|
||||
alice = (await ocean.accounts.list())[1]
|
||||
bob = (await ocean.accounts.list())[2]
|
||||
data = { t: 1, url: ocean.config.metadataStoreUri }
|
||||
blob = JSON.stringify(data)
|
||||
await contracts.deployContracts(owner.getId())
|
||||
})
|
||||
ocean = await Ocean.getInstance(config)
|
||||
owner = (await ocean.accounts.list())[0]
|
||||
alice = (await ocean.accounts.list())[1]
|
||||
bob = (await ocean.accounts.list())[2]
|
||||
data = { t: 1, url: ocean.config.metadataStoreUri }
|
||||
blob = JSON.stringify(data)
|
||||
await contracts.deployContracts(owner.getId())
|
||||
})
|
||||
|
||||
it('Alice deploys datatoken contract', async () => {
|
||||
datatoken = new DataTokens(
|
||||
contracts.factoryAddress,
|
||||
factory.abi as AbiItem[],
|
||||
datatokensTemplate.abi as AbiItem[],
|
||||
web3
|
||||
)
|
||||
tokenAddress = await datatoken.create(
|
||||
blob,
|
||||
alice.getId(),
|
||||
'10000000000',
|
||||
'AliceDT',
|
||||
'DTA'
|
||||
)
|
||||
assert(tokenAddress != null)
|
||||
})
|
||||
it('Alice deploys datatoken contract', async () => {
|
||||
datatoken = new DataTokens(
|
||||
contracts.factoryAddress,
|
||||
factory.abi as AbiItem[],
|
||||
datatokensTemplate.abi as AbiItem[],
|
||||
web3
|
||||
)
|
||||
tokenAddress = await datatoken.create(
|
||||
blob,
|
||||
alice.getId(),
|
||||
'10000000000',
|
||||
'AliceDT',
|
||||
'DTA'
|
||||
)
|
||||
assert(tokenAddress != null)
|
||||
})
|
||||
|
||||
it('Generates metadata', async () => {
|
||||
asset = {
|
||||
main: {
|
||||
type: 'dataset',
|
||||
name: 'UK Weather information 2011',
|
||||
dateCreated: dateCreated,
|
||||
author: 'Met Office',
|
||||
license: 'CC-BY',
|
||||
files: [
|
||||
{
|
||||
url:
|
||||
'https://raw.githubusercontent.com/tbertinmahieux/MSongsDB/master/Tasks_Demos/CoverSongs/shs_dataset_test.txt',
|
||||
checksum: 'efb2c764274b745f5fc37f97c6b0e764',
|
||||
contentLength: '4535431',
|
||||
contentType: 'text/csv',
|
||||
encoding: 'UTF-8',
|
||||
compression: 'zip'
|
||||
}
|
||||
]
|
||||
}
|
||||
it('Generates metadata', async () => {
|
||||
asset = {
|
||||
main: {
|
||||
type: 'dataset',
|
||||
name: 'UK Weather information 2011',
|
||||
dateCreated: dateCreated,
|
||||
author: 'Met Office',
|
||||
license: 'CC-BY',
|
||||
files: [
|
||||
{
|
||||
url:
|
||||
'https://raw.githubusercontent.com/tbertinmahieux/MSongsDB/master/Tasks_Demos/CoverSongs/shs_dataset_test.txt',
|
||||
checksum: 'efb2c764274b745f5fc37f97c6b0e764',
|
||||
contentLength: '4535431',
|
||||
contentType: 'text/csv',
|
||||
encoding: 'UTF-8',
|
||||
compression: 'zip'
|
||||
}
|
||||
]
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
it('Alice publishes dataset with a compute service that allows Raw Algo', async () => {
|
||||
price = datatoken.toWei('2') // in datatoken
|
||||
cluster = ocean.compute.createClusterAttributes(
|
||||
'Kubernetes',
|
||||
'http://10.0.0.17/xxx'
|
||||
it('Alice publishes dataset with a compute service that allows Raw Algo', async () => {
|
||||
price = datatoken.toWei('2') // in datatoken
|
||||
cluster = ocean.compute.createClusterAttributes('Kubernetes', 'http://10.0.0.17/xxx')
|
||||
servers = [
|
||||
ocean.compute.createServerAttributes(
|
||||
'1',
|
||||
'xlsize',
|
||||
'50',
|
||||
'16',
|
||||
'0',
|
||||
'128gb',
|
||||
'160gb',
|
||||
timeout
|
||||
)
|
||||
servers = [
|
||||
ocean.compute.createServerAttributes(
|
||||
'1',
|
||||
'xlsize',
|
||||
'50',
|
||||
'16',
|
||||
'0',
|
||||
'128gb',
|
||||
'160gb',
|
||||
timeout
|
||||
)
|
||||
]
|
||||
containers = [
|
||||
ocean.compute.createContainerAttributes(
|
||||
'tensorflow/tensorflow',
|
||||
'latest',
|
||||
'sha256:cb57ecfa6ebbefd8ffc7f75c0f00e57a7fa739578a429b6f72a0df19315deadc'
|
||||
)
|
||||
]
|
||||
provider = ocean.compute.createProviderAttributes(
|
||||
'Azure',
|
||||
'Compute service with 16gb ram for each node.',
|
||||
cluster,
|
||||
containers,
|
||||
servers
|
||||
]
|
||||
containers = [
|
||||
ocean.compute.createContainerAttributes(
|
||||
'tensorflow/tensorflow',
|
||||
'latest',
|
||||
'sha256:cb57ecfa6ebbefd8ffc7f75c0f00e57a7fa739578a429b6f72a0df19315deadc'
|
||||
)
|
||||
const origComputePrivacy = {
|
||||
allowRawAlgorithm: true,
|
||||
allowNetworkAccess: false,
|
||||
trustedAlgorithms: []
|
||||
}
|
||||
const computeService = ocean.compute.createComputeService(
|
||||
alice,
|
||||
price,
|
||||
dateCreated,
|
||||
provider,
|
||||
origComputePrivacy as ServiceComputePrivacy
|
||||
)
|
||||
ddo = await ocean.assets.create(asset, alice, [computeService], tokenAddress)
|
||||
assert(ddo.dataToken === tokenAddress)
|
||||
})
|
||||
]
|
||||
provider = ocean.compute.createProviderAttributes(
|
||||
'Azure',
|
||||
'Compute service with 16gb ram for each node.',
|
||||
cluster,
|
||||
containers,
|
||||
servers
|
||||
)
|
||||
const origComputePrivacy = {
|
||||
allowRawAlgorithm: true,
|
||||
allowNetworkAccess: false,
|
||||
trustedAlgorithms: []
|
||||
}
|
||||
const computeService = ocean.compute.createComputeService(
|
||||
alice,
|
||||
price,
|
||||
dateCreated,
|
||||
provider,
|
||||
origComputePrivacy as ServiceComputePrivacy
|
||||
)
|
||||
ddo = await ocean.assets.create(asset, alice, [computeService], tokenAddress)
|
||||
assert(ddo.dataToken === tokenAddress)
|
||||
})
|
||||
|
||||
// alex
|
||||
it('should publish a dataset with a compute service object that does not allow rawAlgo', async () => {
|
||||
const origComputePrivacy = {
|
||||
allowRawAlgorithm: false,
|
||||
allowNetworkAccess: false,
|
||||
trustedAlgorithms: []
|
||||
}
|
||||
// alex
|
||||
it('should publish a dataset with a compute service object that does not allow rawAlgo', async () => {
|
||||
const origComputePrivacy = {
|
||||
allowRawAlgorithm: false,
|
||||
allowNetworkAccess: false,
|
||||
trustedAlgorithms: []
|
||||
}
|
||||
|
||||
const computeService = ocean.compute.createComputeService(
|
||||
alice,
|
||||
'1000',
|
||||
dateCreated,
|
||||
provider,
|
||||
origComputePrivacy as ServiceComputePrivacy
|
||||
)
|
||||
datasetNoRawAlgo = await ocean.assets.create(
|
||||
asset,
|
||||
alice,
|
||||
[computeService],
|
||||
tokenAddress
|
||||
)
|
||||
assert(datasetNoRawAlgo.dataToken === tokenAddress)
|
||||
})
|
||||
const computeService = ocean.compute.createComputeService(
|
||||
alice,
|
||||
'1000',
|
||||
dateCreated,
|
||||
provider,
|
||||
origComputePrivacy as ServiceComputePrivacy
|
||||
)
|
||||
datasetNoRawAlgo = await ocean.assets.create(
|
||||
asset,
|
||||
alice,
|
||||
[computeService],
|
||||
tokenAddress
|
||||
)
|
||||
assert(datasetNoRawAlgo.dataToken === tokenAddress)
|
||||
})
|
||||
|
||||
it('should publish a dataset with a compute service object that allows only algo with did:op:1234', async () => {
|
||||
const origComputePrivacy = {
|
||||
allowRawAlgorithm: false,
|
||||
allowNetworkAccess: false,
|
||||
trustedAlgorithms: ['did:op:1234']
|
||||
}
|
||||
it('should publish a dataset with a compute service object that allows only algo with did:op:1234', async () => {
|
||||
const origComputePrivacy = {
|
||||
allowRawAlgorithm: false,
|
||||
allowNetworkAccess: false,
|
||||
trustedAlgorithms: ['did:op:1234']
|
||||
}
|
||||
|
||||
const computeService = ocean.compute.createComputeService(
|
||||
alice,
|
||||
'1000',
|
||||
dateCreated,
|
||||
provider,
|
||||
origComputePrivacy as ServiceComputePrivacy
|
||||
)
|
||||
datasetWithTrustedAlgo = await ocean.assets.create(
|
||||
asset,
|
||||
alice,
|
||||
[computeService],
|
||||
tokenAddress
|
||||
)
|
||||
assert(datasetWithTrustedAlgo.dataToken === tokenAddress)
|
||||
})
|
||||
const computeService = ocean.compute.createComputeService(
|
||||
alice,
|
||||
'1000',
|
||||
dateCreated,
|
||||
provider,
|
||||
origComputePrivacy as ServiceComputePrivacy
|
||||
)
|
||||
datasetWithTrustedAlgo = await ocean.assets.create(
|
||||
asset,
|
||||
alice,
|
||||
[computeService],
|
||||
tokenAddress
|
||||
)
|
||||
assert(datasetWithTrustedAlgo.dataToken === tokenAddress)
|
||||
})
|
||||
|
||||
it('should publish an algorithm', async () => {
|
||||
const algoAsset = {
|
||||
main: {
|
||||
type: 'algorithm',
|
||||
name: 'Test Algo',
|
||||
dateCreated: dateCreated,
|
||||
author: 'DevOps',
|
||||
license: 'CC-BY',
|
||||
files: [
|
||||
{
|
||||
url:
|
||||
'https://raw.githubusercontent.com/oceanprotocol/test-algorithm/master/javascript/algo.js',
|
||||
contentType: 'text/js',
|
||||
encoding: 'UTF-8'
|
||||
}
|
||||
],
|
||||
algorithm: {
|
||||
language: 'js',
|
||||
format: 'docker-image',
|
||||
version: '0.1',
|
||||
container: {
|
||||
entrypoint: 'node $ALGO',
|
||||
image: 'node',
|
||||
tag: '10'
|
||||
}
|
||||
it('should publish an algorithm', async () => {
|
||||
const algoAsset = {
|
||||
main: {
|
||||
type: 'algorithm',
|
||||
name: 'Test Algo',
|
||||
dateCreated: dateCreated,
|
||||
author: 'DevOps',
|
||||
license: 'CC-BY',
|
||||
files: [
|
||||
{
|
||||
url:
|
||||
'https://raw.githubusercontent.com/oceanprotocol/test-algorithm/master/javascript/algo.js',
|
||||
contentType: 'text/js',
|
||||
encoding: 'UTF-8'
|
||||
}
|
||||
],
|
||||
algorithm: {
|
||||
language: 'js',
|
||||
format: 'docker-image',
|
||||
version: '0.1',
|
||||
container: {
|
||||
entrypoint: 'node $ALGO',
|
||||
image: 'node',
|
||||
tag: '10'
|
||||
}
|
||||
}
|
||||
}
|
||||
const service1 = await ocean.assets.createAccessServiceAttributes(
|
||||
alice,
|
||||
price,
|
||||
dateCreated,
|
||||
0
|
||||
)
|
||||
algorithmAsset = await ocean.assets.create(
|
||||
algoAsset,
|
||||
alice,
|
||||
[service1],
|
||||
tokenAddress
|
||||
)
|
||||
assert(algorithmAsset.dataToken === tokenAddress)
|
||||
})
|
||||
|
||||
it('Alice mints 100 DTs and tranfers them to the compute marketplace', async () => {
|
||||
await datatoken.mint(tokenAddress, alice.getId(), tokenAmount)
|
||||
})
|
||||
|
||||
it('Marketplace posts compute service for sale', async () => {
|
||||
computeService = await ocean.assets.getServiceByType(ddo.id, 'compute')
|
||||
assert(computeService.attributes.main.cost === price)
|
||||
})
|
||||
|
||||
it('Bob gets datatokens from Alice to be able to try the compute service', async () => {
|
||||
const dTamount = '20'
|
||||
await datatoken
|
||||
.transfer(tokenAddress, bob.getId(), dTamount, alice.getId())
|
||||
.then(async () => {
|
||||
const balance = await datatoken.balance(tokenAddress, bob.getId())
|
||||
assert(balance.toString() === dTamount.toString())
|
||||
})
|
||||
})
|
||||
|
||||
it('Bob starts compute job with a raw Algo', async () => {
|
||||
const output = {}
|
||||
const order = await ocean.compute.order(
|
||||
bob.getId(),
|
||||
ddo.id,
|
||||
computeService.index,
|
||||
undefined,
|
||||
algorithmMeta
|
||||
)
|
||||
assert(order != null)
|
||||
const computeOrder = JSON.parse(order)
|
||||
const tx = await datatoken.transferWei(
|
||||
computeOrder.dataToken,
|
||||
computeOrder.to,
|
||||
String(computeOrder.numTokens),
|
||||
computeOrder.from
|
||||
)
|
||||
const response = await ocean.compute.start(
|
||||
ddo.id,
|
||||
tx.transactionHash,
|
||||
tokenAddress,
|
||||
bob,
|
||||
undefined,
|
||||
algorithmMeta,
|
||||
output,
|
||||
computeService.index,
|
||||
computeService.type
|
||||
)
|
||||
jobId = response.jobId
|
||||
assert(response.status >= 10)
|
||||
})
|
||||
|
||||
it('Bob should get status of a compute job', async () => {
|
||||
const response = await ocean.compute.status(bob, ddo.id, jobId)
|
||||
assert(response[0].jobId === jobId)
|
||||
})
|
||||
|
||||
it('should get status of all compute jobs for an address', async () => {
|
||||
const response = await ocean.compute.status(bob, undefined, undefined)
|
||||
assert(response.length > 0)
|
||||
})
|
||||
it('Bob should stop compute job', async () => {
|
||||
await ocean.compute.stop(bob, ddo.id, jobId)
|
||||
const response = await ocean.compute.status(bob, ddo.id, jobId)
|
||||
assert(response[0].stopreq === 1)
|
||||
})
|
||||
it('should not allow order the compute service with raw algo for dataset that does not allow raw algo', async () => {
|
||||
const service1 = datasetNoRawAlgo.findServiceByType('compute')
|
||||
assert(service1 !== null)
|
||||
const order = await ocean.compute.order(
|
||||
bob.getId(),
|
||||
datasetNoRawAlgo.id,
|
||||
service1.index,
|
||||
undefined,
|
||||
algorithmMeta
|
||||
)
|
||||
assert(order === null)
|
||||
})
|
||||
it('should not allow order the compute service with algoDid != "did:op:1234" for dataset that allows only "did:op:1234" as algo', async () => {
|
||||
const service1 = datasetWithTrustedAlgo.findServiceByType('compute')
|
||||
assert(service1 !== null)
|
||||
const order = await ocean.compute.order(
|
||||
bob.getId(),
|
||||
datasetWithTrustedAlgo.id,
|
||||
service1.index,
|
||||
'did:op:77777',
|
||||
undefined
|
||||
)
|
||||
assert(order === null)
|
||||
})
|
||||
it('should start a compute job with a published algo', async () => {
|
||||
const output = {}
|
||||
const serviceAlgo = algorithmAsset.findServiceByType('access')
|
||||
const orderalgo = await ocean.assets.order(
|
||||
algorithmAsset.id,
|
||||
serviceAlgo.type,
|
||||
bob.getId()
|
||||
)
|
||||
const algoOrder = JSON.parse(orderalgo)
|
||||
const algoTx = await datatoken.transferWei(
|
||||
algoOrder.dataToken,
|
||||
algoOrder.to,
|
||||
String(algoOrder.numTokens),
|
||||
algoOrder.from
|
||||
)
|
||||
const order = await ocean.compute.order(
|
||||
bob.getId(),
|
||||
ddo.id,
|
||||
computeService.index,
|
||||
algorithmAsset.id,
|
||||
undefined
|
||||
)
|
||||
assert(order != null)
|
||||
const computeOrder = JSON.parse(order)
|
||||
const tx = await datatoken.transferWei(
|
||||
computeOrder.dataToken,
|
||||
computeOrder.to,
|
||||
String(computeOrder.numTokens),
|
||||
computeOrder.from
|
||||
)
|
||||
const response = await ocean.compute.start(
|
||||
ddo.id,
|
||||
tx.transactionHash,
|
||||
tokenAddress,
|
||||
bob,
|
||||
algorithmAsset.id,
|
||||
undefined,
|
||||
output,
|
||||
computeService.index,
|
||||
computeService.type,
|
||||
algoTx.transactionHash,
|
||||
algorithmAsset.dataToken
|
||||
)
|
||||
jobId = response.jobId
|
||||
assert(response.status >= 10)
|
||||
})
|
||||
|
||||
// it('Bob restarts compute job', async () => {})
|
||||
// it('Bob gets outputs', async () => {})
|
||||
}
|
||||
const service1 = await ocean.assets.createAccessServiceAttributes(
|
||||
alice,
|
||||
price,
|
||||
dateCreated,
|
||||
0
|
||||
)
|
||||
algorithmAsset = await ocean.assets.create(algoAsset, alice, [service1], tokenAddress)
|
||||
assert(algorithmAsset.dataToken === tokenAddress)
|
||||
})
|
||||
|
||||
it('Alice mints 100 DTs and tranfers them to the compute marketplace', async () => {
|
||||
await datatoken.mint(tokenAddress, alice.getId(), tokenAmount)
|
||||
})
|
||||
|
||||
it('Marketplace posts compute service for sale', async () => {
|
||||
computeService = await ocean.assets.getServiceByType(ddo.id, 'compute')
|
||||
assert(computeService.attributes.main.cost === price)
|
||||
})
|
||||
|
||||
it('Bob gets datatokens from Alice to be able to try the compute service', async () => {
|
||||
const dTamount = '20'
|
||||
await datatoken
|
||||
.transfer(tokenAddress, bob.getId(), dTamount, alice.getId())
|
||||
.then(async () => {
|
||||
const balance = await datatoken.balance(tokenAddress, bob.getId())
|
||||
assert(balance.toString() === dTamount.toString())
|
||||
})
|
||||
})
|
||||
|
||||
it('Bob starts compute job with a raw Algo', async () => {
|
||||
const output = {}
|
||||
const order = await ocean.compute.order(
|
||||
bob.getId(),
|
||||
ddo.id,
|
||||
computeService.index,
|
||||
undefined,
|
||||
algorithmMeta
|
||||
)
|
||||
assert(order != null)
|
||||
const computeOrder = JSON.parse(order)
|
||||
const tx = await datatoken.transferWei(
|
||||
computeOrder.dataToken,
|
||||
computeOrder.to,
|
||||
String(computeOrder.numTokens),
|
||||
computeOrder.from
|
||||
)
|
||||
const response = await ocean.compute.start(
|
||||
ddo.id,
|
||||
tx.transactionHash,
|
||||
tokenAddress,
|
||||
bob,
|
||||
undefined,
|
||||
algorithmMeta,
|
||||
output,
|
||||
computeService.index,
|
||||
computeService.type
|
||||
)
|
||||
jobId = response.jobId
|
||||
assert(response.status >= 10)
|
||||
})
|
||||
|
||||
it('Bob should get status of a compute job', async () => {
|
||||
const response = await ocean.compute.status(bob, ddo.id, jobId)
|
||||
assert(response[0].jobId === jobId)
|
||||
})
|
||||
|
||||
it('should get status of all compute jobs for an address', async () => {
|
||||
const response = await ocean.compute.status(bob, undefined, undefined)
|
||||
assert(response.length > 0)
|
||||
})
|
||||
it('Bob should stop compute job', async () => {
|
||||
await ocean.compute.stop(bob, ddo.id, jobId)
|
||||
const response = await ocean.compute.status(bob, ddo.id, jobId)
|
||||
assert(response[0].stopreq === 1)
|
||||
})
|
||||
it('should not allow order the compute service with raw algo for dataset that does not allow raw algo', async () => {
|
||||
const service1 = datasetNoRawAlgo.findServiceByType('compute')
|
||||
assert(service1 !== null)
|
||||
const order = await ocean.compute.order(
|
||||
bob.getId(),
|
||||
datasetNoRawAlgo.id,
|
||||
service1.index,
|
||||
undefined,
|
||||
algorithmMeta
|
||||
)
|
||||
assert(order === null)
|
||||
})
|
||||
it('should not allow order the compute service with algoDid != "did:op:1234" for dataset that allows only "did:op:1234" as algo', async () => {
|
||||
const service1 = datasetWithTrustedAlgo.findServiceByType('compute')
|
||||
assert(service1 !== null)
|
||||
const order = await ocean.compute.order(
|
||||
bob.getId(),
|
||||
datasetWithTrustedAlgo.id,
|
||||
service1.index,
|
||||
'did:op:77777',
|
||||
undefined
|
||||
)
|
||||
assert(order === null)
|
||||
})
|
||||
it('should start a compute job with a published algo', async () => {
|
||||
const output = {}
|
||||
const serviceAlgo = algorithmAsset.findServiceByType('access')
|
||||
const orderalgo = await ocean.assets.order(
|
||||
algorithmAsset.id,
|
||||
serviceAlgo.type,
|
||||
bob.getId()
|
||||
)
|
||||
const algoOrder = JSON.parse(orderalgo)
|
||||
const algoTx = await datatoken.transferWei(
|
||||
algoOrder.dataToken,
|
||||
algoOrder.to,
|
||||
String(algoOrder.numTokens),
|
||||
algoOrder.from
|
||||
)
|
||||
const order = await ocean.compute.order(
|
||||
bob.getId(),
|
||||
ddo.id,
|
||||
computeService.index,
|
||||
algorithmAsset.id,
|
||||
undefined
|
||||
)
|
||||
assert(order != null)
|
||||
const computeOrder = JSON.parse(order)
|
||||
const tx = await datatoken.transferWei(
|
||||
computeOrder.dataToken,
|
||||
computeOrder.to,
|
||||
String(computeOrder.numTokens),
|
||||
computeOrder.from
|
||||
)
|
||||
const response = await ocean.compute.start(
|
||||
ddo.id,
|
||||
tx.transactionHash,
|
||||
tokenAddress,
|
||||
bob,
|
||||
algorithmAsset.id,
|
||||
undefined,
|
||||
output,
|
||||
computeService.index,
|
||||
computeService.type,
|
||||
algoTx.transactionHash,
|
||||
algorithmAsset.dataToken
|
||||
)
|
||||
jobId = response.jobId
|
||||
assert(response.status >= 10)
|
||||
})
|
||||
|
||||
// it('Bob restarts compute job', async () => {})
|
||||
// it('Bob gets outputs', async () => {})
|
||||
})
|
||||
|
@ -30,160 +30,158 @@ describe('Marketplace flow', () => {
|
||||
const marketplaceAllowance = '20'
|
||||
const tokenAmount = '100'
|
||||
|
||||
describe('#MarketplaceDownloadFlow-Test', () => {
|
||||
it('Initialize Ocean contracts v3', async () => {
|
||||
contracts = new TestContractHandler(
|
||||
factory.abi as AbiItem[],
|
||||
datatokensTemplate.abi as AbiItem[],
|
||||
datatokensTemplate.bytecode,
|
||||
factory.bytecode,
|
||||
web3
|
||||
)
|
||||
it('Initialize Ocean contracts v3', async () => {
|
||||
contracts = new TestContractHandler(
|
||||
factory.abi as AbiItem[],
|
||||
datatokensTemplate.abi as AbiItem[],
|
||||
datatokensTemplate.bytecode,
|
||||
factory.bytecode,
|
||||
web3
|
||||
)
|
||||
|
||||
ocean = await Ocean.getInstance(config)
|
||||
owner = (await ocean.accounts.list())[0]
|
||||
alice = (await ocean.accounts.list())[1]
|
||||
bob = (await ocean.accounts.list())[2]
|
||||
marketplace = (await ocean.accounts.list())[3]
|
||||
data = { t: 1, url: ocean.config.metadataStoreUri }
|
||||
blob = JSON.stringify(data)
|
||||
await contracts.deployContracts(owner.getId())
|
||||
})
|
||||
ocean = await Ocean.getInstance(config)
|
||||
owner = (await ocean.accounts.list())[0]
|
||||
alice = (await ocean.accounts.list())[1]
|
||||
bob = (await ocean.accounts.list())[2]
|
||||
marketplace = (await ocean.accounts.list())[3]
|
||||
data = { t: 1, url: ocean.config.metadataStoreUri }
|
||||
blob = JSON.stringify(data)
|
||||
await contracts.deployContracts(owner.getId())
|
||||
})
|
||||
|
||||
it('Alice publishes a datatoken contract', async () => {
|
||||
datatoken = new DataTokens(
|
||||
contracts.factoryAddress,
|
||||
factory.abi as AbiItem[],
|
||||
datatokensTemplate.abi as AbiItem[],
|
||||
web3
|
||||
)
|
||||
tokenAddress = await datatoken.create(
|
||||
blob,
|
||||
alice.getId(),
|
||||
'10000000000',
|
||||
'AliceDT',
|
||||
'DTA'
|
||||
)
|
||||
assert(tokenAddress != null)
|
||||
})
|
||||
it('Alice publishes a datatoken contract', async () => {
|
||||
datatoken = new DataTokens(
|
||||
contracts.factoryAddress,
|
||||
factory.abi as AbiItem[],
|
||||
datatokensTemplate.abi as AbiItem[],
|
||||
web3
|
||||
)
|
||||
tokenAddress = await datatoken.create(
|
||||
blob,
|
||||
alice.getId(),
|
||||
'10000000000',
|
||||
'AliceDT',
|
||||
'DTA'
|
||||
)
|
||||
assert(tokenAddress != null)
|
||||
})
|
||||
|
||||
it('Generates metadata', async () => {
|
||||
asset = {
|
||||
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://raw.githubusercontent.com/tbertinmahieux/MSongsDB/master/Tasks_Demos/CoverSongs/shs_dataset_test.txt',
|
||||
checksum: 'efb2c764274b745f5fc37f97c6b0e761',
|
||||
contentLength: '4535431',
|
||||
contentType: 'text/csv',
|
||||
encoding: 'UTF-8',
|
||||
compression: 'zip'
|
||||
}
|
||||
]
|
||||
}
|
||||
it('Generates metadata', async () => {
|
||||
asset = {
|
||||
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://raw.githubusercontent.com/tbertinmahieux/MSongsDB/master/Tasks_Demos/CoverSongs/shs_dataset_test.txt',
|
||||
checksum: 'efb2c764274b745f5fc37f97c6b0e761',
|
||||
contentLength: '4535431',
|
||||
contentType: 'text/csv',
|
||||
encoding: 'UTF-8',
|
||||
compression: 'zip'
|
||||
}
|
||||
]
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
it('Alice publishes a dataset', async () => {
|
||||
price = datatoken.toWei('10') // in datatoken
|
||||
const publishedDate = new Date(Date.now()).toISOString().split('.')[0] + 'Z'
|
||||
const timeout = 0
|
||||
service1 = await ocean.assets.createAccessServiceAttributes(
|
||||
alice,
|
||||
price,
|
||||
publishedDate,
|
||||
timeout
|
||||
)
|
||||
ddo = await ocean.assets.create(asset, alice, [service1], tokenAddress)
|
||||
assert(ddo.dataToken === tokenAddress)
|
||||
})
|
||||
it('Alice publishes a dataset', async () => {
|
||||
price = datatoken.toWei('10') // in datatoken
|
||||
const publishedDate = new Date(Date.now()).toISOString().split('.')[0] + 'Z'
|
||||
const timeout = 0
|
||||
service1 = await ocean.assets.createAccessServiceAttributes(
|
||||
alice,
|
||||
price,
|
||||
publishedDate,
|
||||
timeout
|
||||
)
|
||||
ddo = await ocean.assets.create(asset, alice, [service1], tokenAddress)
|
||||
assert(ddo.dataToken === tokenAddress)
|
||||
})
|
||||
|
||||
it('Alice mints 100 tokens', async () => {
|
||||
await datatoken.mint(tokenAddress, alice.getId(), tokenAmount)
|
||||
})
|
||||
it('Alice mints 100 tokens', async () => {
|
||||
await datatoken.mint(tokenAddress, alice.getId(), tokenAmount)
|
||||
})
|
||||
|
||||
it('Alice allows marketplace to sell her datatokens', async () => {
|
||||
await datatoken
|
||||
.approve(tokenAddress, marketplace.getId(), marketplaceAllowance, alice.getId())
|
||||
.then(async () => {
|
||||
const allowance = await datatoken.allowance(
|
||||
tokenAddress,
|
||||
alice.getId(),
|
||||
marketplace.getId()
|
||||
)
|
||||
assert(allowance.toString() === marketplaceAllowance.toString())
|
||||
})
|
||||
})
|
||||
|
||||
it('Marketplace withdraw Alice tokens from allowance', async () => {
|
||||
const allowance = await datatoken.allowance(
|
||||
tokenAddress,
|
||||
alice.getId(),
|
||||
marketplace.getId()
|
||||
)
|
||||
await datatoken
|
||||
.transferFrom(tokenAddress, alice.getId(), allowance, marketplace.getId())
|
||||
.then(async () => {
|
||||
const marketplaceBalance = await datatoken.balance(
|
||||
tokenAddress,
|
||||
marketplace.getId()
|
||||
)
|
||||
assert(marketplaceBalance.toString() === marketplaceAllowance.toString())
|
||||
})
|
||||
})
|
||||
it('Marketplace should resolve asset using DID', async () => {
|
||||
await ocean.assets.resolve(ddo.id).then((newDDO) => {
|
||||
assert(newDDO.id === ddo.id)
|
||||
it('Alice allows marketplace to sell her datatokens', async () => {
|
||||
await datatoken
|
||||
.approve(tokenAddress, marketplace.getId(), marketplaceAllowance, alice.getId())
|
||||
.then(async () => {
|
||||
const allowance = await datatoken.allowance(
|
||||
tokenAddress,
|
||||
alice.getId(),
|
||||
marketplace.getId()
|
||||
)
|
||||
assert(allowance.toString() === marketplaceAllowance.toString())
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('Marketplace posts asset for sale', async () => {
|
||||
accessService = await ocean.assets.getServiceByType(ddo.id, 'access')
|
||||
price = 20
|
||||
assert(accessService.attributes.main.cost * price === datatoken.toWei('200'))
|
||||
})
|
||||
|
||||
it('Bob gets datatokens', async () => {
|
||||
const dTamount = '20'
|
||||
await datatoken
|
||||
.transfer(tokenAddress, bob.getId(), dTamount, alice.getId())
|
||||
.then(async () => {
|
||||
const balance = await datatoken.balance(tokenAddress, bob.getId())
|
||||
assert(balance.toString() === dTamount.toString())
|
||||
})
|
||||
})
|
||||
|
||||
it('Bob consumes asset 1', async () => {
|
||||
await ocean.assets
|
||||
.order(ddo.id, accessService.type, bob.getId())
|
||||
.then(async (res: any) => {
|
||||
res = JSON.parse(res)
|
||||
return await datatoken.transferWei(
|
||||
res.dataToken,
|
||||
res.to,
|
||||
String(res.numTokens),
|
||||
res.from
|
||||
)
|
||||
})
|
||||
.then(async (tx) => {
|
||||
await ocean.assets.download(
|
||||
ddo.id,
|
||||
tx.transactionHash,
|
||||
tokenAddress,
|
||||
bob,
|
||||
'./node_modules/my-datasets'
|
||||
)
|
||||
})
|
||||
})
|
||||
it('owner can list there assets', async () => {
|
||||
const assets = await ocean.assets.ownerAssets(alice.getId())
|
||||
assert(assets.length > 0)
|
||||
it('Marketplace withdraw Alice tokens from allowance', async () => {
|
||||
const allowance = await datatoken.allowance(
|
||||
tokenAddress,
|
||||
alice.getId(),
|
||||
marketplace.getId()
|
||||
)
|
||||
await datatoken
|
||||
.transferFrom(tokenAddress, alice.getId(), allowance, marketplace.getId())
|
||||
.then(async () => {
|
||||
const marketplaceBalance = await datatoken.balance(
|
||||
tokenAddress,
|
||||
marketplace.getId()
|
||||
)
|
||||
assert(marketplaceBalance.toString() === marketplaceAllowance.toString())
|
||||
})
|
||||
})
|
||||
it('Marketplace should resolve asset using DID', async () => {
|
||||
await ocean.assets.resolve(ddo.id).then((newDDO) => {
|
||||
assert(newDDO.id === ddo.id)
|
||||
})
|
||||
})
|
||||
|
||||
it('Marketplace posts asset for sale', async () => {
|
||||
accessService = await ocean.assets.getServiceByType(ddo.id, 'access')
|
||||
price = 20
|
||||
assert(accessService.attributes.main.cost * price === datatoken.toWei('200'))
|
||||
})
|
||||
|
||||
it('Bob gets datatokens', async () => {
|
||||
const dTamount = '20'
|
||||
await datatoken
|
||||
.transfer(tokenAddress, bob.getId(), dTamount, alice.getId())
|
||||
.then(async () => {
|
||||
const balance = await datatoken.balance(tokenAddress, bob.getId())
|
||||
assert(balance.toString() === dTamount.toString())
|
||||
})
|
||||
})
|
||||
|
||||
it('Bob consumes asset 1', async () => {
|
||||
await ocean.assets
|
||||
.order(ddo.id, accessService.type, bob.getId())
|
||||
.then(async (res: any) => {
|
||||
res = JSON.parse(res)
|
||||
return await datatoken.transferWei(
|
||||
res.dataToken,
|
||||
res.to,
|
||||
String(res.numTokens),
|
||||
res.from
|
||||
)
|
||||
})
|
||||
.then(async (tx) => {
|
||||
await ocean.assets.download(
|
||||
ddo.id,
|
||||
tx.transactionHash,
|
||||
tokenAddress,
|
||||
bob,
|
||||
'./node_modules/my-datasets'
|
||||
)
|
||||
})
|
||||
})
|
||||
it('owner can list there assets', async () => {
|
||||
const assets = await ocean.assets.ownerAssets(alice.getId())
|
||||
assert(assets.length > 0)
|
||||
})
|
||||
})
|
||||
|
@ -1,43 +0,0 @@
|
||||
import { TestContractHandler } from '../TestContractHandler'
|
||||
import { DataTokens } from '../../src/datatokens/Datatokens'
|
||||
|
||||
import Web3 from 'web3'
|
||||
import factory from '@oceanprotocol/contracts/artifacts/DTFactory.json'
|
||||
import datatokensTemplate from '@oceanprotocol/contracts/artifacts/DataTokenTemplate.json'
|
||||
const web3 = new Web3('wss://rinkeby.infura.io/ws/v3/357f2fe737db4304bd2f7285c5602d0d')
|
||||
|
||||
describe('Rinkeby test', () => {
|
||||
// let account
|
||||
// let contracts
|
||||
// let datatoken
|
||||
// let tokenAddress
|
||||
// const tokenAmount = 100
|
||||
// const blob = 'http://localhost:8030/api/v1/provider/services'
|
||||
// describe('#test', () => {
|
||||
// it('Initialize Ocean contracts v3', async () => {
|
||||
// contracts = new TestContractHandler(
|
||||
// factory.abi,
|
||||
// datatokensTemplate.abi,
|
||||
// datatokensTemplate.bytecode,
|
||||
// factory.bytecode,
|
||||
// web3
|
||||
// )
|
||||
// const privateKey = 'PRIVATE_KEY'
|
||||
// account = web3.eth.accounts.privateKeyToAccount('0x' + privateKey)
|
||||
// web3.eth.accounts.wallet.add(account)
|
||||
// await contracts.deployContracts(account.address)
|
||||
// })
|
||||
// it('Publish a dataset', async () => {
|
||||
// datatoken = new DataTokens(
|
||||
// contracts.factoryAddress,
|
||||
// factory.abi,
|
||||
// datatokensTemplate.abi,
|
||||
// web3
|
||||
// )
|
||||
// tokenAddress = await datatoken.create(blob, account.address)
|
||||
// })
|
||||
// it('Mint 100 tokens', async () => {
|
||||
// await datatoken.mint(tokenAddress, account.address, tokenAmount)
|
||||
// })
|
||||
// })
|
||||
})
|
@ -18,42 +18,41 @@ describe('Simple flow', () => {
|
||||
const tokenAmount = '100'
|
||||
const transferAmount = '1'
|
||||
const blob = 'http://localhost:8030/api/v1/services/consume'
|
||||
describe('#test', () => {
|
||||
it('Initialize Ocean contracts v3', async () => {
|
||||
contracts = new TestContractHandler(
|
||||
factory.abi as AbiItem[],
|
||||
datatokensTemplate.abi as AbiItem[],
|
||||
datatokensTemplate.bytecode,
|
||||
factory.bytecode,
|
||||
web3
|
||||
)
|
||||
await contracts.getAccounts()
|
||||
owner = contracts.accounts[0]
|
||||
alice = contracts.accounts[1]
|
||||
bob = contracts.accounts[2]
|
||||
await contracts.deployContracts(owner)
|
||||
})
|
||||
it('Alice publishes a dataset', async () => {
|
||||
// Alice creates a Datatoken
|
||||
datatoken = new DataTokens(
|
||||
contracts.factoryAddress,
|
||||
factory.abi as AbiItem[],
|
||||
datatokensTemplate.abi as AbiItem[],
|
||||
web3
|
||||
)
|
||||
tokenAddress = await datatoken.create(blob, alice, '10000000000', 'AliceDT', 'DTA')
|
||||
})
|
||||
it('Alice mints 100 tokens', async () => {
|
||||
await datatoken.mint(tokenAddress, alice, tokenAmount)
|
||||
})
|
||||
it('Alice transfers 1 token to Bob', async () => {
|
||||
const ts = await datatoken.transfer(tokenAddress, bob, transferAmount, alice)
|
||||
transactionId = ts.transactionHash
|
||||
})
|
||||
// it('Bob consumes dataset', async () => {
|
||||
// const config = new Config()
|
||||
// const ocean = await Ocean.getInstance(config)
|
||||
// await ocean.assets.simpleDownload(tokenAddress, blob, transactionId, bob)
|
||||
// })
|
||||
|
||||
it('Initialize Ocean contracts v3', async () => {
|
||||
contracts = new TestContractHandler(
|
||||
factory.abi as AbiItem[],
|
||||
datatokensTemplate.abi as AbiItem[],
|
||||
datatokensTemplate.bytecode,
|
||||
factory.bytecode,
|
||||
web3
|
||||
)
|
||||
await contracts.getAccounts()
|
||||
owner = contracts.accounts[0]
|
||||
alice = contracts.accounts[1]
|
||||
bob = contracts.accounts[2]
|
||||
await contracts.deployContracts(owner)
|
||||
})
|
||||
it('Alice publishes a dataset', async () => {
|
||||
// Alice creates a Datatoken
|
||||
datatoken = new DataTokens(
|
||||
contracts.factoryAddress,
|
||||
factory.abi as AbiItem[],
|
||||
datatokensTemplate.abi as AbiItem[],
|
||||
web3
|
||||
)
|
||||
tokenAddress = await datatoken.create(blob, alice, '10000000000', 'AliceDT', 'DTA')
|
||||
})
|
||||
it('Alice mints 100 tokens', async () => {
|
||||
await datatoken.mint(tokenAddress, alice, tokenAmount)
|
||||
})
|
||||
it('Alice transfers 1 token to Bob', async () => {
|
||||
const ts = await datatoken.transfer(tokenAddress, bob, transferAmount, alice)
|
||||
transactionId = ts.transactionHash
|
||||
})
|
||||
// it('Bob consumes dataset', async () => {
|
||||
// const config = new Config()
|
||||
// const ocean = await Ocean.getInstance(config)
|
||||
// await ocean.assets.simpleDownload(tokenAddress, blob, transactionId, bob)
|
||||
// })
|
||||
})
|
||||
|
@ -19,66 +19,64 @@ describe('DataTokens', () => {
|
||||
const tokenAmount = '100'
|
||||
const blob = 'https://example.com/dataset-1'
|
||||
|
||||
describe('#test', () => {
|
||||
it('should deploy contracts', async () => {
|
||||
contracts = new TestContractHandler(
|
||||
factory.abi as AbiItem[],
|
||||
datatokensTemplate.abi as AbiItem[],
|
||||
datatokensTemplate.bytecode,
|
||||
factory.bytecode,
|
||||
web3
|
||||
)
|
||||
await contracts.getAccounts()
|
||||
minter = contracts.accounts[0]
|
||||
spender = contracts.accounts[1]
|
||||
await contracts.deployContracts(minter)
|
||||
})
|
||||
it('should deploy contracts', async () => {
|
||||
contracts = new TestContractHandler(
|
||||
factory.abi as AbiItem[],
|
||||
datatokensTemplate.abi as AbiItem[],
|
||||
datatokensTemplate.bytecode,
|
||||
factory.bytecode,
|
||||
web3
|
||||
)
|
||||
await contracts.getAccounts()
|
||||
minter = contracts.accounts[0]
|
||||
spender = contracts.accounts[1]
|
||||
await contracts.deployContracts(minter)
|
||||
})
|
||||
|
||||
it('should initialize datatokens class', async () => {
|
||||
datatoken = new DataTokens(
|
||||
contracts.factoryAddress,
|
||||
factory.abi as AbiItem[],
|
||||
datatokensTemplate.abi as AbiItem[],
|
||||
web3
|
||||
)
|
||||
assert(datatoken !== null)
|
||||
})
|
||||
it('should initialize datatokens class', async () => {
|
||||
datatoken = new DataTokens(
|
||||
contracts.factoryAddress,
|
||||
factory.abi as AbiItem[],
|
||||
datatokensTemplate.abi as AbiItem[],
|
||||
web3
|
||||
)
|
||||
assert(datatoken !== null)
|
||||
})
|
||||
|
||||
it('should create datatokens smart contract', async () => {
|
||||
tokenAddress = await datatoken.create(blob, minter, '10000000000', 'AliceDT', 'DTA')
|
||||
assert(tokenAddress !== null)
|
||||
})
|
||||
it('should create datatokens smart contract', async () => {
|
||||
tokenAddress = await datatoken.create(blob, minter, '10000000000', 'AliceDT', 'DTA')
|
||||
assert(tokenAddress !== null)
|
||||
})
|
||||
|
||||
it('should create datatokens with fallback cap, name & symbol', async () => {
|
||||
tokenAddress = await datatoken.create(blob, minter)
|
||||
assert(tokenAddress !== null)
|
||||
it('should create datatokens with fallback cap, name & symbol', async () => {
|
||||
tokenAddress = await datatoken.create(blob, minter)
|
||||
assert(tokenAddress !== null)
|
||||
|
||||
const tokenName = await datatoken.getName(tokenAddress, minter)
|
||||
const tokenSymbol = await datatoken.getSymbol(tokenAddress, minter)
|
||||
assert(tokenName !== null || tokenName !== '')
|
||||
assert(tokenSymbol !== null || tokenSymbol !== '')
|
||||
})
|
||||
const tokenName = await datatoken.getName(tokenAddress, minter)
|
||||
const tokenSymbol = await datatoken.getSymbol(tokenAddress, minter)
|
||||
assert(tokenName !== null || tokenName !== '')
|
||||
assert(tokenSymbol !== null || tokenSymbol !== '')
|
||||
})
|
||||
|
||||
it('should mint datatokens', async () => {
|
||||
await datatoken.mint(tokenAddress, minter, tokenAmount)
|
||||
balance = await datatoken.balance(tokenAddress, minter)
|
||||
assert(balance === tokenAmount)
|
||||
})
|
||||
it('should mint datatokens', async () => {
|
||||
await datatoken.mint(tokenAddress, minter, tokenAmount)
|
||||
balance = await datatoken.balance(tokenAddress, minter)
|
||||
assert(balance === tokenAmount)
|
||||
})
|
||||
|
||||
it('should transfer datatokens', async () => {
|
||||
await datatoken.transfer(tokenAddress, spender, tokenAmount, minter)
|
||||
balance = await datatoken.balance(tokenAddress, spender)
|
||||
assert(balance === tokenAmount)
|
||||
})
|
||||
it('should transfer datatokens', async () => {
|
||||
await datatoken.transfer(tokenAddress, spender, tokenAmount, minter)
|
||||
balance = await datatoken.balance(tokenAddress, spender)
|
||||
assert(balance === tokenAmount)
|
||||
})
|
||||
|
||||
it('should approve datatokens transfer', async () => {
|
||||
await datatoken.approve(tokenAddress, minter, tokenAmount, spender)
|
||||
})
|
||||
it('should approve datatokens transfer', async () => {
|
||||
await datatoken.approve(tokenAddress, minter, tokenAmount, spender)
|
||||
})
|
||||
|
||||
it('should transferFrom datatokens', async () => {
|
||||
await datatoken.transferFrom(tokenAddress, spender, tokenAmount, minter)
|
||||
balance = await datatoken.balance(tokenAddress, minter)
|
||||
assert(balance === tokenAmount)
|
||||
})
|
||||
it('should transferFrom datatokens', async () => {
|
||||
await datatoken.transferFrom(tokenAddress, spender, tokenAmount, minter)
|
||||
balance = await datatoken.balance(tokenAddress, minter)
|
||||
assert(balance === tokenAmount)
|
||||
})
|
||||
})
|
||||
|
@ -155,7 +155,7 @@ describe('Balancer flow', () => {
|
||||
|
||||
it('Get dtPrice from the pool ', async () => {
|
||||
currentDtPrice = await Pool.getDTPrice(alice, alicePoolAddress)
|
||||
assert(currentDtPrice > 0)
|
||||
assert(Number(currentDtPrice) > 0)
|
||||
})
|
||||
it('Get dtToken pool reserve ', async () => {
|
||||
const currentDtReserve = await Pool.getDTReserve(alice, alicePoolAddress)
|
||||
|
@ -23,7 +23,7 @@ describe('FixedRateExchange flow', () => {
|
||||
let datatoken: DataTokens
|
||||
let tokenAddress: string
|
||||
|
||||
let owner
|
||||
let owner: string
|
||||
let contracts: TestContractHandler
|
||||
|
||||
const consoleDebug = false
|
||||
@ -33,197 +33,192 @@ describe('FixedRateExchange flow', () => {
|
||||
const swapAmount = '1'
|
||||
const blob = 'http://localhost:8030/api/v1/services/consume'
|
||||
|
||||
describe('#test', () => {
|
||||
before(async () => {
|
||||
// deploy SFactory
|
||||
const Contracts = new FixedPricedContractHandler(
|
||||
FixedRateExchangeContract.abi as AbiItem[],
|
||||
FixedRateExchangeContract.bytecode,
|
||||
web3
|
||||
)
|
||||
await Contracts.getAccounts()
|
||||
owner = Contracts.accounts[0]
|
||||
before(async () => {
|
||||
// deploy SFactory
|
||||
const Contracts = new FixedPricedContractHandler(
|
||||
FixedRateExchangeContract.abi as AbiItem[],
|
||||
FixedRateExchangeContract.bytecode,
|
||||
web3
|
||||
)
|
||||
await Contracts.getAccounts()
|
||||
owner = Contracts.accounts[0]
|
||||
|
||||
await Contracts.deployContracts()
|
||||
FixedRateExchangeAddress = Contracts.contractAddress
|
||||
assert(FixedRateExchangeAddress !== null)
|
||||
await Contracts.deployContracts()
|
||||
FixedRateExchangeAddress = Contracts.contractAddress
|
||||
assert(FixedRateExchangeAddress !== null)
|
||||
|
||||
// deploy DT Factory
|
||||
contracts = new TestContractHandler(
|
||||
factory.abi as AbiItem[],
|
||||
datatokensTemplate.abi as AbiItem[],
|
||||
datatokensTemplate.bytecode,
|
||||
factory.bytecode,
|
||||
web3
|
||||
)
|
||||
await contracts.getAccounts()
|
||||
owner = contracts.accounts[0]
|
||||
alice = contracts.accounts[1]
|
||||
bob = contracts.accounts[2]
|
||||
await contracts.deployContracts(owner)
|
||||
// deploy DT Factory
|
||||
contracts = new TestContractHandler(
|
||||
factory.abi as AbiItem[],
|
||||
datatokensTemplate.abi as AbiItem[],
|
||||
datatokensTemplate.bytecode,
|
||||
factory.bytecode,
|
||||
web3
|
||||
)
|
||||
await contracts.getAccounts()
|
||||
owner = contracts.accounts[0]
|
||||
alice = contracts.accounts[1]
|
||||
bob = contracts.accounts[2]
|
||||
await contracts.deployContracts(owner)
|
||||
|
||||
// initialize DataTokens
|
||||
datatoken = new DataTokens(
|
||||
contracts.factoryAddress,
|
||||
factory.abi as AbiItem[],
|
||||
datatokensTemplate.abi as AbiItem[],
|
||||
web3
|
||||
)
|
||||
assert(datatoken !== null)
|
||||
})
|
||||
// initialize DataTokens
|
||||
datatoken = new DataTokens(
|
||||
contracts.factoryAddress,
|
||||
factory.abi as AbiItem[],
|
||||
datatokensTemplate.abi as AbiItem[],
|
||||
web3
|
||||
)
|
||||
assert(datatoken !== null)
|
||||
})
|
||||
|
||||
it('should create datatokens smart contract', async () => {
|
||||
tokenAddress = await datatoken.create(
|
||||
blob,
|
||||
alice,
|
||||
'1000000000000000',
|
||||
'AliceDT',
|
||||
'DTA'
|
||||
)
|
||||
assert(tokenAddress !== null)
|
||||
if (consoleDebug) console.log("Alice's address:" + alice)
|
||||
if (consoleDebug) console.log('data Token address:' + tokenAddress)
|
||||
})
|
||||
it('Create a dummy OceanToken', async () => {
|
||||
// Bob creates a Datatoken
|
||||
oceandatatoken = new DataTokens(
|
||||
contracts.factoryAddress,
|
||||
factory.abi as AbiItem[],
|
||||
datatokensTemplate.abi as AbiItem[],
|
||||
web3
|
||||
)
|
||||
oceanTokenAddress = await oceandatatoken.create(
|
||||
blob,
|
||||
bob,
|
||||
'1000000000000000',
|
||||
'BobDT',
|
||||
'DTB'
|
||||
)
|
||||
if (consoleDebug) console.log("Bob's address:" + bob)
|
||||
if (consoleDebug) console.log('oceanTokenAddress:' + oceanTokenAddress)
|
||||
})
|
||||
it('should create datatokens smart contract', async () => {
|
||||
tokenAddress = await datatoken.create(
|
||||
blob,
|
||||
alice,
|
||||
'1000000000000000',
|
||||
'AliceDT',
|
||||
'DTA'
|
||||
)
|
||||
assert(tokenAddress !== null)
|
||||
if (consoleDebug) console.log("Alice's address:" + alice)
|
||||
if (consoleDebug) console.log('data Token address:' + tokenAddress)
|
||||
})
|
||||
it('Create a dummy OceanToken', async () => {
|
||||
// Bob creates a Datatoken
|
||||
oceandatatoken = new DataTokens(
|
||||
contracts.factoryAddress,
|
||||
factory.abi as AbiItem[],
|
||||
datatokensTemplate.abi as AbiItem[],
|
||||
web3
|
||||
)
|
||||
oceanTokenAddress = await oceandatatoken.create(
|
||||
blob,
|
||||
bob,
|
||||
'1000000000000000',
|
||||
'BobDT',
|
||||
'DTB'
|
||||
)
|
||||
if (consoleDebug) console.log("Bob's address:" + bob)
|
||||
if (consoleDebug) console.log('oceanTokenAddress:' + oceanTokenAddress)
|
||||
})
|
||||
|
||||
it('should initialize FixedExchangeRate class', async () => {
|
||||
FixedRateClass = new OceanFixedRateExchange(
|
||||
web3,
|
||||
FixedRateExchangeAddress,
|
||||
FixedRateExchangeContract.abi as AbiItem[],
|
||||
oceanTokenAddress
|
||||
)
|
||||
assert(FixedRateClass !== null)
|
||||
})
|
||||
it('should initialize FixedExchangeRate class', async () => {
|
||||
FixedRateClass = new OceanFixedRateExchange(
|
||||
web3,
|
||||
FixedRateExchangeAddress,
|
||||
FixedRateExchangeContract.abi as AbiItem[],
|
||||
oceanTokenAddress
|
||||
)
|
||||
assert(FixedRateClass !== null)
|
||||
})
|
||||
|
||||
it('Alice mints 1000 tokens', async () => {
|
||||
const txid = await datatoken.mint(tokenAddress, alice, tokenAmount)
|
||||
if (consoleDebug) console.log(txid)
|
||||
assert(txid !== null)
|
||||
})
|
||||
it('Bob mints 1000 Ocean tokens', async () => {
|
||||
const txid = await oceandatatoken.mint(oceanTokenAddress, bob, tokenAmount)
|
||||
if (consoleDebug) console.log(txid)
|
||||
assert(txid !== null)
|
||||
})
|
||||
it('Alice should have 1000 tokens', async () => {
|
||||
const balance = await datatoken.balance(tokenAddress, alice)
|
||||
if (consoleDebug) console.log("Alice's datatoke balance:" + balance)
|
||||
assert(balance === tokenAmount)
|
||||
})
|
||||
it('Bob should have 1000 ocean tokens', async () => {
|
||||
const balance = await oceandatatoken.balance(oceanTokenAddress, bob)
|
||||
if (consoleDebug) console.log("Bob's ocean balance:" + balance)
|
||||
assert(balance === tokenAmount)
|
||||
})
|
||||
it('Alice allows Exchange to spend 1000 data tokens', async () => {
|
||||
const txid = await datatoken.approve(
|
||||
tokenAddress,
|
||||
FixedRateExchangeAddress,
|
||||
tokenAmount,
|
||||
alice
|
||||
)
|
||||
if (consoleDebug) console.log(txid)
|
||||
})
|
||||
it('Bob allows Exchange to spend 1000 ocean tokens', async () => {
|
||||
const txid = await oceandatatoken.approve(
|
||||
oceanTokenAddress,
|
||||
FixedRateExchangeAddress,
|
||||
tokenAmount,
|
||||
bob
|
||||
)
|
||||
if (consoleDebug) console.log(txid)
|
||||
})
|
||||
it('Alice should aproved speding datatokens', async () => {
|
||||
const balance = await datatoken.allowance(
|
||||
tokenAddress,
|
||||
alice,
|
||||
FixedRateExchangeAddress
|
||||
)
|
||||
if (consoleDebug) console.log('Alice datatoken allowance:' + balance)
|
||||
})
|
||||
it('Bob should aproved speding oceantokens', async () => {
|
||||
const balance = await oceandatatoken.allowance(
|
||||
oceanTokenAddress,
|
||||
bob,
|
||||
FixedRateExchangeAddress
|
||||
)
|
||||
if (consoleDebug) console.log('Bob ocean allowance:' + balance)
|
||||
})
|
||||
it('Alice creates a new FixedRate Exchange with a rate of 0.5', async () => {
|
||||
aliceExchangeId = await FixedRateClass.create(tokenAddress, fixedPriceRate, alice)
|
||||
if (consoleDebug) console.log('aliceExchangeId:' + aliceExchangeId)
|
||||
})
|
||||
it('Bob should find the exchange', async () => {
|
||||
const exchangeDetails = await FixedRateClass.searchforDT(tokenAddress, '0')
|
||||
assert(exchangeDetails[0].exchangeID === aliceExchangeId)
|
||||
})
|
||||
it('Bob should get the exchange details', async () => {
|
||||
const exchangeDetails = await FixedRateClass.getExchange(aliceExchangeId)
|
||||
if (consoleDebug) console.log(exchangeDetails)
|
||||
})
|
||||
it('Alice mints 1000 tokens', async () => {
|
||||
const txid = await datatoken.mint(tokenAddress, alice, tokenAmount)
|
||||
if (consoleDebug) console.log(txid)
|
||||
assert(txid !== null)
|
||||
})
|
||||
it('Bob mints 1000 Ocean tokens', async () => {
|
||||
const txid = await oceandatatoken.mint(oceanTokenAddress, bob, tokenAmount)
|
||||
if (consoleDebug) console.log(txid)
|
||||
assert(txid !== null)
|
||||
})
|
||||
it('Alice should have 1000 tokens', async () => {
|
||||
const balance = await datatoken.balance(tokenAddress, alice)
|
||||
if (consoleDebug) console.log("Alice's datatoke balance:" + balance)
|
||||
assert(balance === tokenAmount)
|
||||
})
|
||||
it('Bob should have 1000 ocean tokens', async () => {
|
||||
const balance = await oceandatatoken.balance(oceanTokenAddress, bob)
|
||||
if (consoleDebug) console.log("Bob's ocean balance:" + balance)
|
||||
assert(balance === tokenAmount)
|
||||
})
|
||||
it('Alice allows Exchange to spend 1000 data tokens', async () => {
|
||||
const txid = await datatoken.approve(
|
||||
tokenAddress,
|
||||
FixedRateExchangeAddress,
|
||||
tokenAmount,
|
||||
alice
|
||||
)
|
||||
if (consoleDebug) console.log(txid)
|
||||
})
|
||||
it('Bob allows Exchange to spend 1000 ocean tokens', async () => {
|
||||
const txid = await oceandatatoken.approve(
|
||||
oceanTokenAddress,
|
||||
FixedRateExchangeAddress,
|
||||
tokenAmount,
|
||||
bob
|
||||
)
|
||||
if (consoleDebug) console.log(txid)
|
||||
})
|
||||
it('Alice should aproved speding datatokens', async () => {
|
||||
const balance = await datatoken.allowance(
|
||||
tokenAddress,
|
||||
alice,
|
||||
FixedRateExchangeAddress
|
||||
)
|
||||
if (consoleDebug) console.log('Alice datatoken allowance:' + balance)
|
||||
})
|
||||
it('Bob should aproved speding oceantokens', async () => {
|
||||
const balance = await oceandatatoken.allowance(
|
||||
oceanTokenAddress,
|
||||
bob,
|
||||
FixedRateExchangeAddress
|
||||
)
|
||||
if (consoleDebug) console.log('Bob ocean allowance:' + balance)
|
||||
})
|
||||
it('Alice creates a new FixedRate Exchange with a rate of 0.5', async () => {
|
||||
aliceExchangeId = await FixedRateClass.create(tokenAddress, fixedPriceRate, alice)
|
||||
if (consoleDebug) console.log('aliceExchangeId:' + aliceExchangeId)
|
||||
})
|
||||
it('Bob should find the exchange', async () => {
|
||||
const exchangeDetails = await FixedRateClass.searchforDT(tokenAddress, '0')
|
||||
assert(exchangeDetails[0].exchangeID === aliceExchangeId)
|
||||
})
|
||||
it('Bob should get the exchange details', async () => {
|
||||
const exchangeDetails = await FixedRateClass.getExchange(aliceExchangeId)
|
||||
if (consoleDebug) console.log(exchangeDetails)
|
||||
})
|
||||
|
||||
it('Bob should get the amount of Ocean needed', async () => {
|
||||
const OceansNeeded = await FixedRateClass.CalcInGivenOut(
|
||||
aliceExchangeId,
|
||||
swapAmount
|
||||
)
|
||||
if (consoleDebug) console.log('Oceans needed:' + OceansNeeded)
|
||||
assert(OceansNeeded !== null)
|
||||
})
|
||||
it('Bob should swap 1 DataToken', async () => {
|
||||
const swapResult = await FixedRateClass.buyDT(aliceExchangeId, swapAmount, bob)
|
||||
if (consoleDebug) console.log(swapResult)
|
||||
assert(swapResult !== null)
|
||||
})
|
||||
it('Alice datatoken balance after swap', async () => {
|
||||
const balance = await datatoken.balance(tokenAddress, alice)
|
||||
if (consoleDebug) console.log('Alice datatoken balance:' + balance)
|
||||
})
|
||||
it('Alice ocean balance after swap', async () => {
|
||||
const balance = await oceandatatoken.balance(oceanTokenAddress, alice)
|
||||
if (consoleDebug) console.log('Alice ocean balance:' + balance)
|
||||
})
|
||||
it('Bob datatoken balance after swap', async () => {
|
||||
const balance = await datatoken.balance(tokenAddress, bob)
|
||||
if (consoleDebug) console.log('Bob datatoken balance:' + balance)
|
||||
})
|
||||
it('Bob ocean balance after swap', async () => {
|
||||
const balance = await oceandatatoken.balance(oceanTokenAddress, bob)
|
||||
if (consoleDebug) console.log('Bob ocean balance:' + balance)
|
||||
})
|
||||
it('Alice should update the rate', async () => {
|
||||
const tx = await FixedRateClass.setRate(aliceExchangeId, updatedPriceRate, alice)
|
||||
assert(tx !== null)
|
||||
})
|
||||
it('Alice should be able to deactivate the exchange', async () => {
|
||||
const tx = await FixedRateClass.deactivate(aliceExchangeId, alice)
|
||||
assert(tx !== null)
|
||||
const exchangeDetails = await FixedRateClass.getExchange(aliceExchangeId)
|
||||
assert(exchangeDetails.active === false)
|
||||
})
|
||||
it('Alice should be able to activate the exchange', async () => {
|
||||
const tx = await FixedRateClass.activate(aliceExchangeId, alice)
|
||||
assert(tx !== null)
|
||||
const exchangeDetails = await FixedRateClass.getExchange(aliceExchangeId)
|
||||
assert(exchangeDetails.active === true)
|
||||
})
|
||||
it('Bob should get the amount of Ocean needed', async () => {
|
||||
const OceansNeeded = await FixedRateClass.CalcInGivenOut(aliceExchangeId, swapAmount)
|
||||
if (consoleDebug) console.log('Oceans needed:' + OceansNeeded)
|
||||
assert(OceansNeeded !== null)
|
||||
})
|
||||
it('Bob should swap 1 DataToken', async () => {
|
||||
const swapResult = await FixedRateClass.buyDT(aliceExchangeId, swapAmount, bob)
|
||||
if (consoleDebug) console.log(swapResult)
|
||||
assert(swapResult !== null)
|
||||
})
|
||||
it('Alice datatoken balance after swap', async () => {
|
||||
const balance = await datatoken.balance(tokenAddress, alice)
|
||||
if (consoleDebug) console.log('Alice datatoken balance:' + balance)
|
||||
})
|
||||
it('Alice ocean balance after swap', async () => {
|
||||
const balance = await oceandatatoken.balance(oceanTokenAddress, alice)
|
||||
if (consoleDebug) console.log('Alice ocean balance:' + balance)
|
||||
})
|
||||
it('Bob datatoken balance after swap', async () => {
|
||||
const balance = await datatoken.balance(tokenAddress, bob)
|
||||
if (consoleDebug) console.log('Bob datatoken balance:' + balance)
|
||||
})
|
||||
it('Bob ocean balance after swap', async () => {
|
||||
const balance = await oceandatatoken.balance(oceanTokenAddress, bob)
|
||||
if (consoleDebug) console.log('Bob ocean balance:' + balance)
|
||||
})
|
||||
it('Alice should update the rate', async () => {
|
||||
const tx = await FixedRateClass.setRate(aliceExchangeId, updatedPriceRate, alice)
|
||||
assert(tx !== null)
|
||||
})
|
||||
it('Alice should be able to deactivate the exchange', async () => {
|
||||
const tx = await FixedRateClass.deactivate(aliceExchangeId, alice)
|
||||
assert(tx !== null)
|
||||
const exchangeDetails = await FixedRateClass.getExchange(aliceExchangeId)
|
||||
assert(exchangeDetails.active === false)
|
||||
})
|
||||
it('Alice should be able to activate the exchange', async () => {
|
||||
const tx = await FixedRateClass.activate(aliceExchangeId, alice)
|
||||
assert(tx !== null)
|
||||
const exchangeDetails = await FixedRateClass.getExchange(aliceExchangeId)
|
||||
assert(exchangeDetails.active === true)
|
||||
})
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user