1
0
mirror of https://github.com/oceanprotocol/ocean.js.git synced 2024-11-26 20:39:05 +01:00

fix all tests

This commit is contained in:
alexcos20 2020-09-23 05:45:48 -07:00
parent 4aee155c46
commit e563f556d1
4 changed files with 71 additions and 19 deletions

View File

@ -408,7 +408,7 @@ export class DataTokens {
}) })
for (let i = 0; i < events.length; i++) { for (let i = 0; i < events.length; i++) {
if ( if (
String(events[i].returnValues.amount) === String(amount) && String(events[i].returnValues.amount) === this.web3.utils.toWei(String(amount)) &&
String(events[i].returnValues.serviceId) === String(serviceId) String(events[i].returnValues.serviceId) === String(serviceId)
) { ) {
const transaction = await this.web3.eth.getTransaction(events[i].transactionHash) const transaction = await this.web3.eth.getTransaction(events[i].transactionHash)

View File

@ -118,7 +118,7 @@ export class Assets extends Instantiable {
provider.setBaseUrl(providerUri) provider.setBaseUrl(providerUri)
} else provider = this.ocean.provider } else provider = this.ocean.provider
const encryptedFiles = await provider.encrypt( const encryptedFiles = await provider.encrypt(
did.getId(), did.getDid(),
metadata.main.files, metadata.main.files,
publisher publisher
) )
@ -494,9 +494,7 @@ export class Assets extends Instantiable {
const balance = new BigNumber( const balance = new BigNumber(
await datatokens.balance(providerData.dataToken, consumerAddress) await datatokens.balance(providerData.dataToken, consumerAddress)
) )
const totalCost = new BigNumber( const totalCost = new BigNumber(String(providerData.numTokens))
this.web3.utils.fromWei(String(providerData.numTokens))
)
if (balance.isLessThanOrEqualTo(totalCost)) { if (balance.isLessThanOrEqualTo(totalCost)) {
console.error( console.error(
'Not enough funds. Needed ' + 'Not enough funds. Needed ' +
@ -508,7 +506,7 @@ export class Assets extends Instantiable {
} }
const txid = await datatokens.startOrder( const txid = await datatokens.startOrder(
providerData.dataToken, providerData.dataToken,
this.web3.utils.fromWei(String(providerData.numTokens)), String(providerData.numTokens),
serviceIndex, serviceIndex,
mpAddress, mpAddress,
consumerAddress consumerAddress

View File

@ -29,6 +29,9 @@ describe('Compute flow', () => {
let contracts let contracts
let datatoken let datatoken
let tokenAddress let tokenAddress
let tokenAddressNoRawAlgo
let tokenAddressWithTrustedAlgo
let tokenAddressAlgorithm
let price let price
let ocean let ocean
let computeService let computeService
@ -79,7 +82,7 @@ describe('Compute flow', () => {
await contracts.deployContracts(owner.getId()) await contracts.deployContracts(owner.getId())
}) })
it('Alice deploys datatoken contract', async () => { it('Alice deploys datatoken contracts', async () => {
datatoken = new DataTokens( datatoken = new DataTokens(
contracts.factoryAddress, contracts.factoryAddress,
factory.abi as AbiItem[], factory.abi as AbiItem[],
@ -94,6 +97,32 @@ describe('Compute flow', () => {
'DTA' 'DTA'
) )
assert(tokenAddress != null) assert(tokenAddress != null)
tokenAddressNoRawAlgo = await datatoken.create(
blob,
alice.getId(),
'10000000000',
'AliceDT',
'DTA'
)
assert(tokenAddressNoRawAlgo != null)
tokenAddressWithTrustedAlgo = await datatoken.create(
blob,
alice.getId(),
'10000000000',
'AliceDT',
'DTA'
)
assert(tokenAddressWithTrustedAlgo != null)
tokenAddressAlgorithm = await datatoken.create(
blob,
alice.getId(),
'10000000000',
'AliceDT',
'DTA'
)
assert(tokenAddressAlgorithm != null)
}) })
it('Generates metadata', async () => { it('Generates metadata', async () => {
@ -120,7 +149,7 @@ describe('Compute flow', () => {
}) })
it('Alice publishes dataset with a compute service that allows Raw Algo', async () => { it('Alice publishes dataset with a compute service that allows Raw Algo', async () => {
price = datatoken.toWei('2') // in datatoken price = '2' // in datatoken
cluster = ocean.compute.createClusterAttributes('Kubernetes', 'http://10.0.0.17/xxx') cluster = ocean.compute.createClusterAttributes('Kubernetes', 'http://10.0.0.17/xxx')
servers = [ servers = [
ocean.compute.createServerAttributes( ocean.compute.createServerAttributes(
@ -165,7 +194,6 @@ describe('Compute flow', () => {
await sleep(6000) await sleep(6000)
}) })
// alex
it('should publish a dataset with a compute service object that does not allow rawAlgo', async () => { it('should publish a dataset with a compute service object that does not allow rawAlgo', async () => {
const origComputePrivacy = { const origComputePrivacy = {
allowRawAlgorithm: false, allowRawAlgorithm: false,
@ -184,9 +212,9 @@ describe('Compute flow', () => {
asset, asset,
alice, alice,
[computeService], [computeService],
tokenAddress tokenAddressNoRawAlgo
) )
assert(datasetNoRawAlgo.dataToken === tokenAddress) assert(datasetNoRawAlgo.dataToken === tokenAddressNoRawAlgo)
await sleep(6000) await sleep(6000)
}) })
@ -208,9 +236,9 @@ describe('Compute flow', () => {
asset, asset,
alice, alice,
[computeService], [computeService],
tokenAddress tokenAddressWithTrustedAlgo
) )
assert(datasetWithTrustedAlgo.dataToken === tokenAddress) assert(datasetWithTrustedAlgo.dataToken === tokenAddressWithTrustedAlgo)
await sleep(6000) await sleep(6000)
}) })
@ -248,13 +276,21 @@ describe('Compute flow', () => {
dateCreated, dateCreated,
0 0
) )
algorithmAsset = await ocean.assets.create(algoAsset, alice, [service1], tokenAddress) algorithmAsset = await ocean.assets.create(
assert(algorithmAsset.dataToken === tokenAddress) algoAsset,
alice,
[service1],
tokenAddressAlgorithm
)
assert(algorithmAsset.dataToken === tokenAddressAlgorithm)
await sleep(6000) await sleep(6000)
}) })
it('Alice mints 100 DTs and tranfers them to the compute marketplace', async () => { it('Alice mints 100 DTs and tranfers them to the compute marketplace', async () => {
await datatoken.mint(tokenAddress, alice.getId(), tokenAmount) await datatoken.mint(tokenAddress, alice.getId(), tokenAmount)
await datatoken.mint(tokenAddressNoRawAlgo, alice.getId(), tokenAmount)
await datatoken.mint(tokenAddressWithTrustedAlgo, alice.getId(), tokenAmount)
await datatoken.mint(tokenAddressAlgorithm, alice.getId(), tokenAmount)
}) })
it('Marketplace posts compute service for sale', async () => { it('Marketplace posts compute service for sale', async () => {
@ -270,6 +306,24 @@ describe('Compute flow', () => {
const balance = await datatoken.balance(tokenAddress, bob.getId()) const balance = await datatoken.balance(tokenAddress, bob.getId())
assert(balance.toString() === dTamount.toString()) assert(balance.toString() === dTamount.toString())
}) })
await datatoken
.transfer(tokenAddressNoRawAlgo, bob.getId(), dTamount, alice.getId())
.then(async () => {
const balance = await datatoken.balance(tokenAddressNoRawAlgo, bob.getId())
assert(balance.toString() === dTamount.toString())
})
await datatoken
.transfer(tokenAddressWithTrustedAlgo, bob.getId(), dTamount, alice.getId())
.then(async () => {
const balance = await datatoken.balance(tokenAddressWithTrustedAlgo, bob.getId())
assert(balance.toString() === dTamount.toString())
})
await datatoken
.transfer(tokenAddressAlgorithm, bob.getId(), dTamount, alice.getId())
.then(async () => {
const balance = await datatoken.balance(tokenAddressAlgorithm, bob.getId())
assert(balance.toString() === dTamount.toString())
})
}) })
it('Bob starts compute job with a raw Algo', async () => { it('Bob starts compute job with a raw Algo', async () => {

View File

@ -101,7 +101,7 @@ describe('Marketplace flow', () => {
}) })
it('Alice publishes a dataset', async () => { it('Alice publishes a dataset', async () => {
price = datatoken.toWei('10') // in datatoken price = '10' // in datatoken
const publishedDate = new Date(Date.now()).toISOString().split('.')[0] + 'Z' const publishedDate = new Date(Date.now()).toISOString().split('.')[0] + 'Z'
const timeout = 0 const timeout = 0
service1 = await ocean.assets.createAccessServiceAttributes( service1 = await ocean.assets.createAccessServiceAttributes(
@ -157,7 +157,7 @@ describe('Marketplace flow', () => {
it('Marketplace posts asset for sale', async () => { it('Marketplace posts asset for sale', async () => {
accessService = await ocean.assets.getServiceByType(ddo.id, 'access') accessService = await ocean.assets.getServiceByType(ddo.id, 'access')
price = 20 price = 20
assert.equal(accessService.attributes.main.cost * price, datatoken.toWei('200')) assert.equal(accessService.attributes.main.cost * price, 200)
}) })
it('Bob gets datatokens', async () => { it('Bob gets datatokens', async () => {
@ -223,7 +223,7 @@ describe('Marketplace flow', () => {
}) })
it('Alice publishes a dataset but passed data token is invalid', async () => { it('Alice publishes a dataset but passed data token is invalid', async () => {
price = datatoken.toWei('10') // in datatoken price = '10' // in datatoken
const publishedDate = new Date(Date.now()).toISOString().split('.')[0] + 'Z' const publishedDate = new Date(Date.now()).toISOString().split('.')[0] + 'Z'
const timeout = 0 const timeout = 0
service1 = await ocean.assets.createAccessServiceAttributes( service1 = await ocean.assets.createAccessServiceAttributes(
@ -238,7 +238,7 @@ describe('Marketplace flow', () => {
}) })
it('Alice publishes a dataset but created data token is invalid', async () => { it('Alice publishes a dataset but created data token is invalid', async () => {
price = datatoken.toWei('10') // in datatoken price = '10' // in datatoken
const publishedDate = new Date(Date.now()).toISOString().split('.')[0] + 'Z' const publishedDate = new Date(Date.now()).toISOString().split('.')[0] + 'Z'
const timeout = 0 const timeout = 0
service1 = await ocean.assets.createAccessServiceAttributes( service1 = await ocean.assets.createAccessServiceAttributes(