diff --git a/.travis.yml b/.travis.yml index 1a5d0c5d5..91efc2c1f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,7 +20,6 @@ before_script: - git clone https://github.com/oceanprotocol/barge - cd barge - git checkout v3 - - export PROVIDER_VERSION=latest - export ADDRESS_FILE="${HOME}/.ocean/ocean-contracts/artifacts/address.json" - export AQUARIUS_URI="http://172.15.0.5:5000" - export DEPLOY_CONTRACTS=true @@ -47,4 +46,4 @@ deploy: api_key: ${NPM_TOKEN} skip_cleanup: true on: - tags: true \ No newline at end of file + tags: true diff --git a/package-lock.json b/package-lock.json index d6d6346e3..447d9e3ed 100644 --- a/package-lock.json +++ b/package-lock.json @@ -939,9 +939,9 @@ } }, "@oceanprotocol/contracts": { - "version": "0.4.2", - "resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-0.4.2.tgz", - "integrity": "sha512-IKRUe60pcBcEmQhkpusSc+w2CIEHxmyNzth+VRU5Je6lrP6/XnDaFRHjeYbSy306I/WxLjma88S1xOn86BMCOA==" + "version": "0.4.4", + "resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-0.4.4.tgz", + "integrity": "sha512-0+Tp6UdoDTBJZp4yX3kkSrV+CcOS/hJ3SJ4HuWiL5FE5Nlj3JCeV86iuWPkFuXzIdgri00DaGvQhP58knzJ2Uw==" }, "@octokit/auth-token": { "version": "2.4.2", diff --git a/package.json b/package.json index 612b07320..b6a7374a1 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ }, "dependencies": { "@ethereum-navigator/navigator": "^0.5.0", - "@oceanprotocol/contracts": "^0.4.2", + "@oceanprotocol/contracts": "^0.4.4", "decimal.js": "^10.2.0", "fs": "0.0.1-security", "lzma": "^2.3.2", diff --git a/src/datatokens/Datatokens.ts b/src/datatokens/Datatokens.ts index a68d89683..22f7fb004 100644 --- a/src/datatokens/Datatokens.ts +++ b/src/datatokens/Datatokens.ts @@ -356,7 +356,6 @@ export class DataTokens { /** Start Order * @param {String} dataTokenAddress * @param {String} amount - * @param {String} did * @param {Number} serviceId * @param {String} mpFeeAddress * @param {String} address consumer Address @@ -365,7 +364,6 @@ export class DataTokens { public async startOrder( dataTokenAddress: string, amount: string, - did: string, serviceId: number, mpFeeAddress: string, address: string @@ -376,7 +374,7 @@ export class DataTokens { if (!mpFeeAddress) mpFeeAddress = '0x0000000000000000000000000000000000000000' try { const trxReceipt = await datatoken.methods - .startOrder(this.web3.utils.toWei(amount), did, String(serviceId), mpFeeAddress) + .startOrder(this.web3.utils.toWei(amount), String(serviceId), mpFeeAddress) .send({ from: address, gas: 600000 }) return trxReceipt } catch (e) { @@ -397,7 +395,6 @@ export class DataTokens { public async getPreviousValidOrders( dataTokenAddress: string, amount: string, - did: string, serviceId: number, timeout: number, address: string @@ -411,8 +408,7 @@ export class DataTokens { }) for (let i = 0; i < events.length; i++) { if ( - events[i].returnValues.did === did && - 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) ) { const transaction = await this.web3.eth.getTransaction(events[i].transactionHash) diff --git a/src/metadatastore/OnChainMetaData.ts b/src/metadatastore/OnChainMetaData.ts index 85ca016ff..aa679ecac 100644 --- a/src/metadatastore/OnChainMetaData.ts +++ b/src/metadatastore/OnChainMetaData.ts @@ -3,7 +3,7 @@ import { TransactionReceipt } from 'web3-core' import { Contract } from 'web3-eth-contract' import { AbiItem } from 'web3-utils/types' import Web3 from 'web3' -import defaultDDOContractABI from '@oceanprotocol/contracts/artifacts/DDO.json' +import defaultDDOContractABI from '@oceanprotocol/contracts/artifacts/Metadata.json' import { didZeroX } from '../utils' import { LZMA } from 'lzma' @@ -102,15 +102,16 @@ export class OnChainMetadataStore { return null } try { - const estGas = await this.DDOContract.methods - .create(did, flags, data) + /* const estGas = await this.DDOContract.methods + .create(didZeroX(did), flags, data) .estimateGas(function (err, estGas) { - if (err) console.log('OnChainMetadataStore: ' + err) + if (err) console.log('OnChainMetadataStoreEstimateGas: ' + err) return estGas }) + */ const trxReceipt = await this.DDOContract.methods - .create(did, flags, data) - .send({ from: consumerAccount, gas: estGas + 1 }) + .create(didZeroX(did), flags, data) + .send({ from: consumerAccount }) return trxReceipt } catch (e) { console.error(e) @@ -138,7 +139,7 @@ export class OnChainMetadataStore { } try { const trxReceipt = await this.DDOContract.methods - .update(did, flags, data) + .update(didZeroX(did), flags, data) .send({ from: consumerAccount }) return trxReceipt } catch (e) { diff --git a/src/models/Config.ts b/src/models/Config.ts index c09140fc0..c95c0e7bd 100644 --- a/src/models/Config.ts +++ b/src/models/Config.ts @@ -89,13 +89,13 @@ export class Config { * DDOContractAddress * @type {string} */ - public DDOContractAddress?: string + public metadataContractAddress?: string /** * DDOContractABI * @type {any} */ - public DDOContractABI?: AbiItem | AbiItem[] + public metadataContractABI?: AbiItem | AbiItem[] /** * Log level. * @type {boolean | LogLevel} diff --git a/src/ocean/Assets.ts b/src/ocean/Assets.ts index 8e7edc804..0cbf68110 100644 --- a/src/ocean/Assets.ts +++ b/src/ocean/Assets.ts @@ -108,7 +108,7 @@ export class Assets extends Instantiable { observer.next(CreateProgressStep.DataTokenCreated) } - const did: DID = DID.generate() + const did: DID = DID.generate(dtAddress) this.logger.log('Encrypting files') observer.next(CreateProgressStep.EncryptingFiles) @@ -118,7 +118,7 @@ export class Assets extends Instantiable { provider.setBaseUrl(providerUri) } else provider = this.ocean.provider const encryptedFiles = await provider.encrypt( - did.getId(), + did.getDid(), metadata.main.files, publisher ) @@ -486,7 +486,6 @@ export class Assets extends Instantiable { const previousOrder = await datatokens.getPreviousValidOrders( providerData.dataToken, providerData.numTokens, - didZeroX(did), serviceIndex, service.attributes.main.timeout, consumerAddress @@ -495,9 +494,7 @@ export class Assets extends Instantiable { const balance = new BigNumber( await datatokens.balance(providerData.dataToken, consumerAddress) ) - const totalCost = new BigNumber( - this.web3.utils.fromWei(String(providerData.numTokens)) - ) + const totalCost = new BigNumber(String(providerData.numTokens)) if (balance.isLessThanOrEqualTo(totalCost)) { console.error( 'Not enough funds. Needed ' + @@ -509,8 +506,7 @@ export class Assets extends Instantiable { } const txid = await datatokens.startOrder( providerData.dataToken, - this.web3.utils.fromWei(String(providerData.numTokens)), - didZeroX(did), + String(providerData.numTokens), serviceIndex, mpAddress, consumerAddress diff --git a/src/ocean/DID.ts b/src/ocean/DID.ts index 708b45dda..900070f6e 100644 --- a/src/ocean/DID.ts +++ b/src/ocean/DID.ts @@ -1,5 +1,4 @@ -import { generateId } from '../utils/GeneratorHelpers' - +import { noZeroX } from '../utils' const prefix = 'did:op:' /** @@ -16,8 +15,7 @@ export default class DID { didString = didString.getDid() } let did: DID - const didMatch = didString.match(/^did:op:([a-f0-9]{64})$/i) - + const didMatch = didString.match(/^did:op:([a-f0-9]{40})$/i) if (didMatch) { did = new DID(didMatch[1]) } @@ -30,11 +28,12 @@ export default class DID { } /** - * Returns a new DID. + * Generate a new DID. + * @param {string} dataTokenAddress Address of data token to use for DID. * @return {DID} */ - public static generate(): DID { - return new DID(generateId()) + public static generate(dataTokenAddress: string): DID { + return new DID(noZeroX(dataTokenAddress)) } /** diff --git a/src/ocean/Ocean.ts b/src/ocean/Ocean.ts index b92febd94..22f525fe1 100644 --- a/src/ocean/Ocean.ts +++ b/src/ocean/Ocean.ts @@ -67,8 +67,8 @@ export class Ocean extends Instantiable { ) instance.OnChainMetadataStore = new OnChainMetadataStore( instanceConfig.config.web3Provider, - instanceConfig.config.DDOContractAddress, - instanceConfig.config.DDOContractABI + instanceConfig.config.metadataContractAddress, + instanceConfig.config.metadataContractABI ) instance.versions = await Versions.getInstance(instanceConfig) instance.network = new Network() diff --git a/src/utils/ConfigHelper.ts b/src/utils/ConfigHelper.ts index d1df332ca..68aab390b 100644 --- a/src/utils/ConfigHelper.ts +++ b/src/utils/ConfigHelper.ts @@ -25,19 +25,19 @@ const configs: ConfigHelperConfig[] = [ providerUri: 'http://127.0.0.1:8030', poolFactoryAddress: null, fixedRateExchangeAddress: null, - DDOContractAddress: null + metadataContractAddress: null }, { chainId: 4, network: 'rinkeby', nodeUri: 'https://rinkeby.infura.io/v3', - factoryAddress: '0x3ECd1429101f93149D799Ef257C07a2B1Dc30897', + factoryAddress: '0x732cad3502e2A543118C8047D6bb20D5DB9c3242', oceanTokenAddress: '0x8967BCF84170c91B0d24D4302C2376283b0B3a07', metadataStoreUri: 'https://aquarius.rinkeby.v3.dev-ocean.com', providerUri: 'https://provider.rinkeby.v3.dev-ocean.com', - poolFactoryAddress: '0x9B90A1358fbeEC1C4bB1DA7D4E85C708f87556Ec', - fixedRateExchangeAddress: '0x991c08bD00761A299d3126a81a985329096896D4', - DDOContractAddress: '0xEfA25E39192b3175d451D79C1c0a41Fa3C32c87d' + poolFactoryAddress: '0x1735C3A59EcedC617bB570b79A71A6FC7C0380E8', + fixedRateExchangeAddress: '0x2B8da1F6DE33EfCDEc254ebE57d1D854a314b81b', + metadataContractAddress: '0x01906293EAd697f6038b0E3E1f0591F56ABf8EC0' }, { chainId: 1, @@ -49,7 +49,7 @@ const configs: ConfigHelperConfig[] = [ providerUri: null, poolFactoryAddress: null, fixedRateExchangeAddress: null, - DDOContractAddress: null + metadataContractAddress: null } ] @@ -64,7 +64,8 @@ export class ConfigHelper { if (data.ganache.BFactory) configs[0].poolFactoryAddress = data.ganache.BFactory if (data.ganache.FixedRateExchange) configs[0].fixedRateExchangeAddress = data.ganache.FixedRateExchange - if (data.ganache.DDO) configs[0].DDOContractAddress = data.ganache.DDO + if (data.ganache.Metadata) + configs[0].metadataContractAddress = data.ganache.Metadata } } if (process.env.AQUARIUS_URI) configs[0].metadataStoreUri = process.env.AQUARIUS_URI diff --git a/src/utils/ConversionTypeHelpers.ts b/src/utils/ConversionTypeHelpers.ts index 520150214..04e91a2e0 100644 --- a/src/utils/ConversionTypeHelpers.ts +++ b/src/utils/ConversionTypeHelpers.ts @@ -14,7 +14,7 @@ export const noDidPrefixed = (input: string): string => didTransformer(input, fa export function didTransformer(input = '', prefixOutput: boolean): string { const { valid, output } = inputMatch( input, - /^(?:0x|did:op:)*([a-f0-9]{64})$/i, + /^(?:0x|did:op:)*([a-f0-9]{40})$/i, 'didTransformer' ) return (prefixOutput && valid ? 'did:op:' : '') + output diff --git a/test/integration/ComputeFlow.test.ts b/test/integration/ComputeFlow.test.ts index 10b9a9021..7eb17b788 100644 --- a/test/integration/ComputeFlow.test.ts +++ b/test/integration/ComputeFlow.test.ts @@ -29,6 +29,9 @@ describe('Compute flow', () => { let contracts let datatoken let tokenAddress + let tokenAddressNoRawAlgo + let tokenAddressWithTrustedAlgo + let tokenAddressAlgorithm let price let ocean let computeService @@ -79,7 +82,7 @@ describe('Compute flow', () => { await contracts.deployContracts(owner.getId()) }) - it('Alice deploys datatoken contract', async () => { + it('Alice deploys datatoken contracts', async () => { datatoken = new DataTokens( contracts.factoryAddress, factory.abi as AbiItem[], @@ -94,6 +97,32 @@ describe('Compute flow', () => { 'DTA' ) 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 () => { @@ -120,7 +149,7 @@ describe('Compute flow', () => { }) 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') servers = [ ocean.compute.createServerAttributes( @@ -165,7 +194,6 @@ describe('Compute flow', () => { await sleep(6000) }) - // alex it('should publish a dataset with a compute service object that does not allow rawAlgo', async () => { const origComputePrivacy = { allowRawAlgorithm: false, @@ -184,9 +212,9 @@ describe('Compute flow', () => { asset, alice, [computeService], - tokenAddress + tokenAddressNoRawAlgo ) - assert(datasetNoRawAlgo.dataToken === tokenAddress) + assert(datasetNoRawAlgo.dataToken === tokenAddressNoRawAlgo) await sleep(6000) }) @@ -208,9 +236,9 @@ describe('Compute flow', () => { asset, alice, [computeService], - tokenAddress + tokenAddressWithTrustedAlgo ) - assert(datasetWithTrustedAlgo.dataToken === tokenAddress) + assert(datasetWithTrustedAlgo.dataToken === tokenAddressWithTrustedAlgo) await sleep(6000) }) @@ -248,13 +276,21 @@ describe('Compute flow', () => { dateCreated, 0 ) - algorithmAsset = await ocean.assets.create(algoAsset, alice, [service1], tokenAddress) - assert(algorithmAsset.dataToken === tokenAddress) + algorithmAsset = await ocean.assets.create( + algoAsset, + alice, + [service1], + tokenAddressAlgorithm + ) + assert(algorithmAsset.dataToken === tokenAddressAlgorithm) await sleep(6000) }) it('Alice mints 100 DTs and tranfers them to the compute marketplace', async () => { 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 () => { @@ -270,6 +306,24 @@ describe('Compute flow', () => { const balance = await datatoken.balance(tokenAddress, bob.getId()) 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 () => { diff --git a/test/integration/Marketplaceflow.test.ts b/test/integration/Marketplaceflow.test.ts index e4a39dc8c..b827bad08 100644 --- a/test/integration/Marketplaceflow.test.ts +++ b/test/integration/Marketplaceflow.test.ts @@ -101,7 +101,7 @@ describe('Marketplace flow', () => { }) 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 timeout = 0 service1 = await ocean.assets.createAccessServiceAttributes( @@ -157,7 +157,7 @@ describe('Marketplace flow', () => { it('Marketplace posts asset for sale', async () => { accessService = await ocean.assets.getServiceByType(ddo.id, 'access') 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 () => { @@ -223,7 +223,7 @@ describe('Marketplace flow', () => { }) 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 timeout = 0 service1 = await ocean.assets.createAccessServiceAttributes( @@ -238,7 +238,7 @@ describe('Marketplace flow', () => { }) 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 timeout = 0 service1 = await ocean.assets.createAccessServiceAttributes( diff --git a/test/unit/metadatastore/MetadataStore.test.ts b/test/unit/metadatastore/MetadataStore.test.ts index 5909224f6..8c5357c98 100644 --- a/test/unit/metadatastore/MetadataStore.test.ts +++ b/test/unit/metadatastore/MetadataStore.test.ts @@ -73,7 +73,7 @@ describe('MetadataStore', () => { describe('#storeDDO()', () => { it('should store a ddo', async () => { - const did: DID = DID.generate() + const did: DID = DID.generate('0x858048e3Ebdd3754e14F63d1185F8252eF142393') const ddo: DDO = new DDO({ id: did.getId() }) @@ -88,7 +88,7 @@ describe('MetadataStore', () => { describe('#retrieveDDO()', () => { it('should store a ddo', async () => { - const did: DID = DID.generate() + const did: DID = DID.generate('0x8248b0E583B9db96Ca3764EadF36e0024035Cc3A') const ddo: DDO = new DDO({ id: did.getId() }) diff --git a/test/unit/ocean/DID.test.ts b/test/unit/ocean/DID.test.ts index c8bca5e9d..9765931c0 100644 --- a/test/unit/ocean/DID.test.ts +++ b/test/unit/ocean/DID.test.ts @@ -4,14 +4,14 @@ import DID from '../../../src/ocean/DID' describe('DID', () => { describe('#generate()', () => { it('should generate a new did', () => { - const did: DID = DID.generate() + const did: DID = DID.generate('0x8248b0E583B9db96Ca3764EadF36e0024035Cc3A') assert(did) }) }) describe('#parse()', () => { it('should parse a valid did', () => { - const id = 'a'.repeat(64) + const id = 'a'.repeat(40) const did: DID = DID.parse(`did:op:${id}`) assert(did) @@ -41,7 +41,7 @@ describe('DID', () => { describe('#getDid()', () => { it('should return the full did', () => { - const did: DID = DID.generate() + const did: DID = DID.generate('0x8248b0E583B9db96Ca3764EadF36e0024035Cc3A') assert(did) assert(did.getDid().startsWith('did:op:')) @@ -50,7 +50,7 @@ describe('DID', () => { describe('#getDid()', () => { it('should return only the id part of the did', () => { - const id = 'a'.repeat(64) + const id = 'a'.repeat(40) const did: DID = DID.parse(`did:op:${id}`) assert(did) diff --git a/test/unit/utils/ConversionTypeHelpers.test.ts b/test/unit/utils/ConversionTypeHelpers.test.ts index 5e9704357..f62b4c71d 100644 --- a/test/unit/utils/ConversionTypeHelpers.test.ts +++ b/test/unit/utils/ConversionTypeHelpers.test.ts @@ -31,7 +31,7 @@ describe('ConversionTypeHelpers', () => { }) describe('#didTransformer()', () => { - const did = 'a'.repeat(64) + const did = 'a'.repeat(40) it("should return the input if it's not valid", async () => { const result1 = didPrefixed('Test 1')