mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
fix conflicts
This commit is contained in:
commit
4b4949126d
@ -1,154 +1,126 @@
|
|||||||
# ocean-lib
|
# Quickstart: Marketplace Flow
|
||||||
|
|
||||||
|
This batteries-included flow includes metadata, multiple services for one datatoken, and compute-to-data.
|
||||||
|
|
||||||
`ocean-lib-js` is a Javascript/Typescript library to privately & securely publish, exchange, and consume data. With it, you can:
|
It focuses on Alice's experience as a publisher, and Bob's experience as a buyer & consumer. The rest are services used by Alice and Bob.
|
||||||
* **Publish** data services: static data, streaming data, or compute-to-data. Every data service gets its own [ERC20](https://github.com/ethereum/EIPs/blob/7f4f0377730f5fc266824084188cc17cf246932e/EIPS/eip-20.md) token.
|
|
||||||
* **Mint** data tokens for a given data service
|
|
||||||
* **Transfer** data tokens to another owner
|
|
||||||
* **Consume** data tokens, to access the service
|
|
||||||
|
|
||||||
`ocean-lib-js` is part of the [Ocean Protocol](www.oceanprotocol.com) toolset.
|
|
||||||
|
|
||||||
# Installation
|
|
||||||
```
|
|
||||||
// ES6
|
|
||||||
import { Ocean, Logger } from '@oceanprotocol/lib'
|
|
||||||
|
|
||||||
// ES2015
|
|
||||||
const { Ocean, Logger } = require('@oceanprotocol/lib')
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
# Quickstart
|
|
||||||
|
|
||||||
This section describes a marketplace flow with multiple services
|
|
||||||
|
|
||||||
Here's the steps.
|
Here's the steps.
|
||||||
1. Alice publishes a dataset (= publishes a datatoken contract)
|
1. Initialize services
|
||||||
|
1. Alice publishes assets for data services (= publishes a datatoken contract and metadata)
|
||||||
1. Alice mints 100 tokens
|
1. Alice mints 100 tokens
|
||||||
1. Alice transfers 1 token to Bob
|
1. Alice allows marketplace to sell her datatokens
|
||||||
1. Bob consumes dataset
|
1. Marketplace posts asset for sale
|
||||||
|
1. Value swap: Bob buys datatokens from marketplace
|
||||||
|
1. Bob uses a service he just purchased (download)
|
||||||
|
|
||||||
Let's go through each of these in detail.
|
Let's go through each step.
|
||||||
|
|
||||||
|
## 0. Installation
|
||||||
|
|
||||||
## 1. Alice hosts the dataset
|
If you haven't installed yet:
|
||||||
|
```console
|
||||||
|
pip install ocean-lib
|
||||||
|
```
|
||||||
|
|
||||||
A locally providerService ,metadatastore and marketplace are required:
|
## 1. Initialize services
|
||||||
|
|
||||||
|
This quickstart treats the publisher service, metadata store, and marketplace as
|
||||||
|
externally-run services. For convenience, we run them locally in default settings.
|
||||||
|
|
||||||
Run the providerService and metadatastore:
|
|
||||||
```
|
```
|
||||||
docker run @oceanprotocol/provider-py:latest
|
docker run @oceanprotocol/provider-py:latest
|
||||||
docker run @oceanprotocol/aquarius:latest
|
docker run @oceanprotocol/metadatastore:latest
|
||||||
docker run @oceanprotocol/marketplace:latest
|
docker run @oceanprotocol/marketplace:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## 2. Alice publishes assets for data services (= publishes a datatoken contract)
|
||||||
|
|
||||||
## 2. Alice publishes a dataset (= publishes a datatoken contract)
|
```python
|
||||||
|
from ocean_lib import Ocean
|
||||||
|
from ocean_lib.web3_internal.utils import get_account
|
||||||
|
|
||||||
For now, you're Alice:) Let's proceed.
|
#Alice's config
|
||||||
|
config = {
|
||||||
|
'network' : 'rinkeby',
|
||||||
```javascript
|
'privateKey' :'8da4ef21b864d2cc526dbdb2a120bd2874c36c9d0a1fb7f8c63d7f7a8b41de8f',
|
||||||
const { Ocean, Logger } = require('@oceanprotocol/lib')
|
'metadataStoreUri' : 'localhost:5000',
|
||||||
|
'providerUri' : 'localhost:8030'
|
||||||
const marketPlaceAddress='0x9876'
|
|
||||||
//Alice's config
|
|
||||||
const config={
|
|
||||||
network: 'rinkeby',
|
|
||||||
privateKey:'8da4ef21b864d2cc526dbdb2a120bd2874c36c9d0a1fb7f8c63d7f7a8b41de8f',
|
|
||||||
metadataStoreURI: 'localhost:5000',
|
|
||||||
providerUri: 'localhost:8030'
|
|
||||||
}
|
}
|
||||||
const ocean = Ocean(alice_config)
|
ocean = Ocean(config)
|
||||||
const account = await ocean.accounts.list()[0]
|
account = get_account(0)
|
||||||
|
|
||||||
|
data_token = ocean.create_data_token(ocean.config.metadata_store_url, account)
|
||||||
|
token_address = data_token.address
|
||||||
|
|
||||||
const myToken = ocean.datatoken.create(config.metadataStoreURI,account)
|
metadata = {"main": {
|
||||||
//Alice allows MarketPlace to transfer 20 DT
|
"type": "dataset", "name": "10 Monkey Species Small", "author": "Mario",
|
||||||
myToken.approve(marketPlaceAddress,20)
|
"license": "CC0: Public Domain", "dateCreated": "2012-02-01T10:55:11Z",
|
||||||
|
"files": [{ "index": 0, "contentType": "application/zip", "url": "https://s3.amazonaws.com/datacommons-seeding-us-east/10_Monkey_Species_Small/assets/training.zip"},
|
||||||
|
{ "index": 1, "contentType": "text/text", "url": "https://s3.amazonaws.com/datacommons-seeding-us-east/10_Monkey_Species_Small/assets/monkey_labels.txt"},
|
||||||
|
{ "index": 2, "contentType": "application/zip", "url": "https://s3.amazonaws.com/datacommons-seeding-us-east/10_Monkey_Species_Small/assets/validation.zip"}]}}
|
||||||
|
asset = ocean.assets.create(metadata, account, data_token_address=token_address)
|
||||||
|
assert token_address == asset._other_values['dataTokenAddress']
|
||||||
|
|
||||||
const dt_address=myToken.getAddress()
|
did = asset.did
|
||||||
|
|
||||||
//create asset 1
|
|
||||||
const metaData={
|
|
||||||
"did":"did:op:1234",
|
|
||||||
"owner":"0xaaaaa",
|
|
||||||
"dtAddress":dt_address,
|
|
||||||
"name":"Asset1",
|
|
||||||
"services="[
|
|
||||||
{ "id":0, "serviceEndpoint":"providerUri", "type":"download", "dtCost":10, "timeout":0,
|
|
||||||
"files":[{"url":"http://example.net"},{"url":"http://example.com" }]
|
|
||||||
},
|
|
||||||
{ "id":1, "type":"compute", "serviceEndpoint":"providerUri", "dtCost":1,"timeout":3600},
|
|
||||||
{ "id":2, "type":"compute", "serviceEndpoint":"providerUri", "dtCost":2, "timeout":7200 },
|
|
||||||
]
|
|
||||||
}
|
|
||||||
//create will encrypt the URLs using publisher and update the ddo before pushing to aquarius
|
|
||||||
//create will require that metaData.dtAddress is a valid DT Contract address
|
|
||||||
const asset = ocean.assets.create(metaData,account)
|
|
||||||
const did = asset.did
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## 3. Alice mints 100 tokens
|
## 3. Alice mints 100 tokens
|
||||||
|
|
||||||
```javascript
|
```python
|
||||||
myToken.mint(100)
|
data_token.mint(account.address, 100, account)
|
||||||
```
|
```
|
||||||
|
|
||||||
## 4. Exchange of value : How Bob gets DT
|
## 4. Alice allows marketplace to sell her datatokens
|
||||||
```javascript
|
|
||||||
const bob_config={
|
|
||||||
network: 'rinkeby',
|
|
||||||
privateKey:'1234ef21b864d2cc526dbdb2a120bd2874c36c9d0a1fb7f8c63d7f7a8b41de8f'
|
|
||||||
marketPlaceUri: 'localhost:3000'
|
|
||||||
}
|
|
||||||
const bob_ocean = Ocean(bob_config)
|
|
||||||
const bob_account = await bob_ocean.accounts.list()[0]
|
|
||||||
|
|
||||||
const asset = ocean.assets.resolve(did)
|
```python
|
||||||
const serviceIndex = assets.findServiceByType('compute')
|
marketplace_address = '0x068ed00cf0441e4829d9784fcbe7b9e26d4bd8d0'
|
||||||
const num_dt_needed = assets.getDtCost(serviceIndex)
|
data_token.approve(marketplace_address, 20)
|
||||||
//Bob need to buy num_dt_needed . DTAddress = asset.dtAddress
|
|
||||||
|
|
||||||
const {price, currency } = ocean.marketplace.getPrice(num_dt_needed,asset.dtAddress)
|
|
||||||
bob_account.approve(price, currency, marketPlaceAddress)
|
|
||||||
ocean.marketplace.buy(num_dt_needed,asset.dtAddress)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## 5. Bob consumes dataset
|
## 5. Marketplace posts asset for sale
|
||||||
|
Now, you're the marketplace:)
|
||||||
|
|
||||||
Now, you are Bob :)
|
```python
|
||||||
|
from ocean_lib import Ocean
|
||||||
|
|
||||||
|
#Market's config
|
||||||
```javascript
|
config = {
|
||||||
|
'network': 'rinkeby',
|
||||||
const bob_config={
|
'privateKey':'1234ef21b864d2cc526dbdb2a120bd2874c36c9d0a1fb7f8c63d7f7a8b41de8f',
|
||||||
network: 'rinkeby',
|
|
||||||
privateKey:'1234ef21b864d2cc526dbdb2a120bd2874c36c9d0a1fb7f8c63d7f7a8b41de8f'
|
|
||||||
}
|
}
|
||||||
const bob_ocean = Ocean(bob_config)
|
market_ocean = Ocean(config)
|
||||||
|
|
||||||
|
asset = ocean.assets.resolve(did)
|
||||||
|
service1 = asset.get_service('download')
|
||||||
|
service2 = asset.get_service('access')
|
||||||
|
price = 10.0 #marketplace-set price of 10 USD / datatoken
|
||||||
|
|
||||||
const account = await bob_ocean.accounts.list()[0]
|
#Display key asset information, such as the cost of each service
|
||||||
const asset = ocean.assets.getFromDID(did)
|
print(f"Service 1 costs {service1.get_num_dt_needed() * price} USD") # 1.5 * 10 = 15
|
||||||
const serviceIndex = assets.findServiceByType('compute')
|
print(f"Service 2 costs {service2.get_num_dt_needed() * price} USD") # 2.5 * 10 = 25
|
||||||
|
|
||||||
export const rawAlgoMeta = {
|
|
||||||
rawcode: `console.log('Hello world'!)`,
|
|
||||||
format: 'docker-image',
|
|
||||||
version: '0.1',
|
|
||||||
container: {
|
|
||||||
entrypoint: 'node $ALGO',
|
|
||||||
image: 'node',
|
|
||||||
tag: '10'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const computeJob=asset.StartCompute(serviceIndex, rawAlgoMeta, account)
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## 6. Value swap: Bob buys datatokens from marketplace
|
||||||
|
|
||||||
|
```python
|
||||||
|
#Not shown: in marketplace GUI, Bob uses Stripe to send USD to marketplace (or other methods / currencies).
|
||||||
|
|
||||||
|
market_token = market_ocean.get_data_token(token_address)
|
||||||
|
market_token.transfer(dst_address=bob_address, 1.0)
|
||||||
|
```
|
||||||
|
|
||||||
|
## 7. Bob uses a service he just purchased (download)
|
||||||
|
Now, you're Bob:)
|
||||||
|
|
||||||
|
```python
|
||||||
|
|
||||||
|
#Bob's config
|
||||||
|
config = {
|
||||||
|
'network': 'rinkeby',
|
||||||
|
'privateKey':'1234ef21b864d2cc526dbdb2a120bd2874c36c9d0a1fb7f8c63d7f7a8b41de8o',
|
||||||
|
}
|
||||||
|
market_ocean = Ocean(config)
|
||||||
|
|
||||||
|
service = asset.get_service('access')
|
||||||
|
file_path = bob_ocean.assets.download(asset.did, service.index, bob_account, '~/my-datasets')
|
||||||
|
```
|
@ -36,47 +36,48 @@ Let's go through each of these in detail.
|
|||||||
|
|
||||||
For now, you're Alice:) Let's proceed.
|
For now, you're Alice:) Let's proceed.
|
||||||
|
|
||||||
|
Run `ganache-cli` locally:
|
||||||
|
```bash
|
||||||
|
ganache-cli
|
||||||
|
```
|
||||||
|
|
||||||
|
Then proceed in with your code:
|
||||||
```javascript
|
```javascript
|
||||||
const { Ocean, Logger } = require('@oceanprotocol/lib')
|
const tokenAmount = 100
|
||||||
const config={
|
const transferAmount = 1
|
||||||
network: 'rinkeby',
|
const blob = 'http://localhost:8030/api/v1/provider/services'
|
||||||
privateKey:'8da4ef21b864d2cc526dbdb2a120bd2874c36c9d0a1fb7f8c63d7f7a8b41de8f',
|
|
||||||
}
|
const alice = await ocean.accounts.list()[0]
|
||||||
const ocean = Ocean(alice_config)
|
const bob = await ocean.accounts.list()[0]
|
||||||
const account = await ocean.accounts.list()[0]
|
// create datatoken class
|
||||||
const myToken = ocean.datatoken.create('localhost:8030',account)
|
const datatoken = new DataTokens(contracts.factoryAddress, factoryABI, datatokensABI, web3)
|
||||||
const dt_address=myToken.getAddress()
|
// deploy datatoken
|
||||||
console.log(dt_address)
|
const tokenAddress = await datatoken.create(blob, alice)
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## 2. Alice hosts the dataset
|
## 2. Alice hosts the dataset
|
||||||
|
|
||||||
A locally providerService is required, which will serve just one file for this demo.
|
Clone [provider-py](https://github.com/oceanprotocol/provider-py) and update your local environment variables:
|
||||||
Let's create the file to be shared:
|
|
||||||
```
|
|
||||||
touch /var/mydata/myFolder1/file
|
|
||||||
````
|
|
||||||
|
|
||||||
Run the providerService:
|
|
||||||
(given that ERC20 contract address from the above is 0x1234)
|
|
||||||
|
|
||||||
```
|
```
|
||||||
ENV DT="{'0x1234':'/var/mydata/myFolder1'}"
|
export FLASK_APP=ocean_provider/run.py
|
||||||
docker run @oceanprotocol/provider-py -e CONFIG=DT
|
export PROVIDER_ADDRESS=your_provider_address
|
||||||
|
export PROVIDER_KEY=your_provider_key
|
||||||
|
export CONFIG='{"File": "https://raw.githubusercontent.com/oceanprotocol/barge/master/README.md"}'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## 3. Alice mints 100 tokens
|
## 3. Alice mints 100 tokens
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
myToken.mint(100)
|
datatoken.mint(tokenAddress, alice, tokenAmount)
|
||||||
```
|
```
|
||||||
|
|
||||||
## 4. Alice transfers 1 token to Bob
|
## 4. Alice transfers 1 token to Bob
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
myToken.transfer(1,BobAddress)
|
const ts = await datatoken.transfer(tokenAddress, bob, transferAmount, alice)
|
||||||
|
const transactionId = ts['transactionHash']
|
||||||
```
|
```
|
||||||
|
|
||||||
## 5. Bob consumes dataset
|
## 5. Bob consumes dataset
|
||||||
@ -86,17 +87,10 @@ Now, you are Bob :)
|
|||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
|
|
||||||
const bob_config={
|
const config = new Config()
|
||||||
network: 'rinkeby',
|
const ocean = await Ocean.getInstance()
|
||||||
privateKey:'1234ef21b864d2cc526dbdb2a120bd2874c36c9d0a1fb7f8c63d7f7a8b41de8f'
|
|
||||||
}
|
|
||||||
const bob_ocean = Ocean(bob_config)
|
|
||||||
|
|
||||||
|
|
||||||
const account = await bob_ocean.accounts.list()[0]
|
|
||||||
const asset=bob_ocean.assets.getFromDTAddress(dt_address)[0]
|
|
||||||
const file=asset.download(account)
|
|
||||||
|
|
||||||
|
await ocean.assets.download(tokenAddress, blob, transactionId, bob)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
12
package-lock.json
generated
12
package-lock.json
generated
@ -9775,6 +9775,12 @@
|
|||||||
"resolved": "https://registry.npmjs.org/semver/-/semver-7.3.2.tgz",
|
"resolved": "https://registry.npmjs.org/semver/-/semver-7.3.2.tgz",
|
||||||
"integrity": "sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ==",
|
"integrity": "sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ==",
|
||||||
"dev": true
|
"dev": true
|
||||||
|
},
|
||||||
|
"uuid": {
|
||||||
|
"version": "8.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.1.0.tgz",
|
||||||
|
"integrity": "sha512-CI18flHDznR0lq54xBycOVmphdCYnQLKn8abKn7PXUiKUGdEd+/l9LWNJmugXel4hXq7S+RMNl34ecyC9TntWg==",
|
||||||
|
"dev": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -11339,9 +11345,9 @@
|
|||||||
"integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM="
|
"integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM="
|
||||||
},
|
},
|
||||||
"uuid": {
|
"uuid": {
|
||||||
"version": "8.1.0",
|
"version": "8.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.2.0.tgz",
|
||||||
"integrity": "sha512-CI18flHDznR0lq54xBycOVmphdCYnQLKn8abKn7PXUiKUGdEd+/l9LWNJmugXel4hXq7S+RMNl34ecyC9TntWg=="
|
"integrity": "sha512-CYpGiFTUrmI6OBMkAdjSDM0k5h8SkkiTP4WAjQgDgNB1S3Ou9VBEvr6q0Kv2H1mMk7IWfxYGpMH5sd5AvcIV2Q=="
|
||||||
},
|
},
|
||||||
"v8-compile-cache": {
|
"v8-compile-cache": {
|
||||||
"version": "2.1.0",
|
"version": "2.1.0",
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
"changelog": "auto-changelog -p",
|
"changelog": "auto-changelog -p",
|
||||||
"prepublishOnly": "npm run build",
|
"prepublishOnly": "npm run build",
|
||||||
"test:unit": "mocha --config=test/unit/.mocharc.json --node-env=test --exit test/unit/**/*.ts",
|
"test:unit": "mocha --config=test/unit/.mocharc.json --node-env=test --exit test/unit/**/*.ts",
|
||||||
"test:integration": "mocha --opts test/integration/mocha.opts",
|
"test:integration": "mocha --config=test/integration/.mocharc.json --node-env=test --exit test/integration/**/*.ts",
|
||||||
"test:cover": "nyc --report-dir coverage/unit npm run test:unit"
|
"test:cover": "nyc --report-dir coverage/unit npm run test:unit"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
@ -42,7 +42,7 @@
|
|||||||
"fs": "0.0.1-security",
|
"fs": "0.0.1-security",
|
||||||
"node-fetch": "^2.6.0",
|
"node-fetch": "^2.6.0",
|
||||||
"save-file": "^2.3.1",
|
"save-file": "^2.3.1",
|
||||||
"uuid": "^8.0.0",
|
"uuid": "^8.2.0",
|
||||||
"web3": "^1.2.9",
|
"web3": "^1.2.9",
|
||||||
"web3-eth-contract": "^1.2.9",
|
"web3-eth-contract": "^1.2.9",
|
||||||
"whatwg-url": "^8.0.0"
|
"whatwg-url": "^8.0.0"
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
import { Contract } from 'web3-eth-contract'
|
import { Contract } from 'web3-eth-contract'
|
||||||
|
|
||||||
const Web3 = require('web3')
|
|
||||||
const web3 = new Web3('http://127.0.0.1:8545')
|
|
||||||
|
|
||||||
export class TestContractHandler {
|
export class TestContractHandler {
|
||||||
public factory: Contract
|
public factory: Contract
|
||||||
public template: Contract
|
public template: Contract
|
||||||
@ -11,21 +8,24 @@ export class TestContractHandler {
|
|||||||
public factoryBytecode: string
|
public factoryBytecode: string
|
||||||
public factoryAddress: string
|
public factoryAddress: string
|
||||||
public templateAddress: string
|
public templateAddress: string
|
||||||
|
public web3: any
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
factoryABI: Contract,
|
factoryABI: Contract,
|
||||||
datatokensABI: Contract,
|
datatokensABI: Contract,
|
||||||
templateBytecode: string,
|
templateBytecode: string,
|
||||||
factoryBytecode: string
|
factoryBytecode: string,
|
||||||
|
web3: any
|
||||||
) {
|
) {
|
||||||
this.factory = new web3.eth.Contract(factoryABI)
|
this.web3 = web3
|
||||||
this.template = new web3.eth.Contract(datatokensABI)
|
this.factory = new this.web3.eth.Contract(factoryABI)
|
||||||
|
this.template = new this.web3.eth.Contract(datatokensABI)
|
||||||
this.templateBytecode = templateBytecode
|
this.templateBytecode = templateBytecode
|
||||||
this.factoryBytecode = factoryBytecode
|
this.factoryBytecode = factoryBytecode
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getAccounts() {
|
public async getAccounts() {
|
||||||
this.accounts = await web3.eth.getAccounts()
|
this.accounts = await this.web3.eth.getAccounts()
|
||||||
}
|
}
|
||||||
|
|
||||||
public async deployContracts(minter: string) {
|
public async deployContracts(minter: string) {
|
||||||
@ -53,7 +53,7 @@ export class TestContractHandler {
|
|||||||
.send({
|
.send({
|
||||||
from: minter,
|
from: minter,
|
||||||
gas: estGas + 1,
|
gas: estGas + 1,
|
||||||
gasPrice: '12345678'
|
gasPrice: '3000000000'
|
||||||
})
|
})
|
||||||
.then(function (contract) {
|
.then(function (contract) {
|
||||||
return contract.options.address
|
return contract.options.address
|
||||||
@ -77,7 +77,7 @@ export class TestContractHandler {
|
|||||||
.send({
|
.send({
|
||||||
from: minter,
|
from: minter,
|
||||||
gas: estGas + 1,
|
gas: estGas + 1,
|
||||||
gasPrice: '12345678'
|
gasPrice: '3000000000'
|
||||||
})
|
})
|
||||||
.then(function (contract) {
|
.then(function (contract) {
|
||||||
return contract.options.address
|
return contract.options.address
|
||||||
|
115
test/integration/Marketplaceflow.test.ts
Normal file
115
test/integration/Marketplaceflow.test.ts
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
import { TestContractHandler } from '../TestContractHandler'
|
||||||
|
import { DataTokens } from '../../src/datatokens/Datatokens'
|
||||||
|
import { Ocean } from '../../src/ocean/Ocean'
|
||||||
|
import { Config } from '../../src/models/Config'
|
||||||
|
import Accounts from "../../src/ocean/Account" // ??
|
||||||
|
|
||||||
|
const Web3 = require('web3')
|
||||||
|
const web3 = new Web3('http://127.0.0.1:8545')
|
||||||
|
const factory = require('@oceanprotocol/contracts/artifacts/development/Factory.json')
|
||||||
|
const datatokensTemplate = require('@oceanprotocol/contracts/artifacts/development/DataTokenTemplate.json')
|
||||||
|
|
||||||
|
describe('Marketplace flow', () => {
|
||||||
|
let owner
|
||||||
|
let bob
|
||||||
|
let asset
|
||||||
|
let marketplace
|
||||||
|
let marketOcean
|
||||||
|
let contracts
|
||||||
|
let datatoken
|
||||||
|
let tokenAddress
|
||||||
|
let transactionId
|
||||||
|
let service1
|
||||||
|
let service2
|
||||||
|
|
||||||
|
let alice = new Accounts()
|
||||||
|
|
||||||
|
const tokenAmount = 100
|
||||||
|
const transferAmount = 2
|
||||||
|
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
|
||||||
|
)
|
||||||
|
await contracts.getAccounts()
|
||||||
|
owner = contracts.accounts[0]
|
||||||
|
bob = contracts.accounts[2]
|
||||||
|
marketplace = contracts.accounts[3]
|
||||||
|
|
||||||
|
await alice.setId(contracts.accounts[1])
|
||||||
|
await alice.setPassword("0x4a608ef70ce229351d37be7b07ddd7a3ce46709911cf8c8c4bcabd8a6c563711")
|
||||||
|
|
||||||
|
await contracts.deployContracts(owner)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Alice publishes a datatoken contract', async () => {
|
||||||
|
tokenAddress = await datatoken.create(blob, alice.getId())
|
||||||
|
})
|
||||||
|
|
||||||
|
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'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Alice publishes a dataset', async () => {
|
||||||
|
// Alice creates a Datatoken
|
||||||
|
datatoken = new DataTokens(
|
||||||
|
contracts.factoryAddress,
|
||||||
|
factory.abi,
|
||||||
|
datatokensTemplate.abi,
|
||||||
|
web3
|
||||||
|
)
|
||||||
|
|
||||||
|
const config = new Config()
|
||||||
|
const ocean = await Ocean.getInstance(config)
|
||||||
|
|
||||||
|
tokenAddress = await datatoken.create(blob, alice.getId())
|
||||||
|
asset = await ocean.assets.create(asset, alice, [], tokenAddress)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Alice mints 100 tokens', async () => {
|
||||||
|
await datatoken.mint(tokenAddress, alice.getId(), tokenAmount)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Marketplace posts asset for sale', async () => {
|
||||||
|
const config = new Config()
|
||||||
|
marketOcean = await Ocean.getInstance(config)
|
||||||
|
|
||||||
|
service1 = marketOcean.assets.getService('download')
|
||||||
|
service2 = marketOcean.assets.getService('access')
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Bob gets datatokens', async () => {
|
||||||
|
const ts = await datatoken.transfer(tokenAddress, bob, transferAmount, alice)
|
||||||
|
transactionId = ts.transactionHash
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Bob consumes asset 1', async () => {
|
||||||
|
const config = new Config()
|
||||||
|
const ocean = await Ocean.getInstance(config)
|
||||||
|
await ocean.assets.download(asset.did, service1.index, bob, '~/my-datasets')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Bob consumes asset 2', async () => {
|
||||||
|
// TODO
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
50
test/integration/Rinkeby.test.ts
Normal file
50
test/integration/Rinkeby.test.ts
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
import { TestContractHandler } from '../TestContractHandler'
|
||||||
|
import { DataTokens } from '../../src/datatokens/Datatokens'
|
||||||
|
|
||||||
|
const Web3 = require('web3')
|
||||||
|
const web3 = new Web3('wss://rinkeby.infura.io/ws/v3/357f2fe737db4304bd2f7285c5602d0d')
|
||||||
|
const factory = require('@oceanprotocol/contracts/artifacts/development/Factory.json')
|
||||||
|
const datatokensTemplate = require('@oceanprotocol/contracts/artifacts/development/DataTokenTemplate.json')
|
||||||
|
|
||||||
|
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)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
@ -1,4 +1,3 @@
|
|||||||
import { assert } from 'chai'
|
|
||||||
import { TestContractHandler } from '../TestContractHandler'
|
import { TestContractHandler } from '../TestContractHandler'
|
||||||
import { DataTokens } from '../../src/datatokens/Datatokens'
|
import { DataTokens } from '../../src/datatokens/Datatokens'
|
||||||
import { Ocean } from '../../src/ocean/Ocean'
|
import { Ocean } from '../../src/ocean/Ocean'
|
||||||
@ -6,15 +5,13 @@ import { Config } from '../../src/models/Config'
|
|||||||
|
|
||||||
const Web3 = require('web3')
|
const Web3 = require('web3')
|
||||||
const web3 = new Web3('http://127.0.0.1:8545')
|
const web3 = new Web3('http://127.0.0.1:8545')
|
||||||
|
const factory = require('@oceanprotocol/contracts/artifacts/development/Factory.json')
|
||||||
const factoryABI = require('../../src/datatokens/FactoryABI.json')
|
const datatokensTemplate = require('@oceanprotocol/contracts/artifacts/development/DataTokenTemplate.json')
|
||||||
const datatokensABI = require('../../src/datatokens/DatatokensABI.json')
|
|
||||||
|
|
||||||
describe('Simple flow', () => {
|
describe('Simple flow', () => {
|
||||||
let owner
|
let owner
|
||||||
let bob
|
let bob
|
||||||
let alice
|
let alice
|
||||||
let balance
|
|
||||||
let contracts
|
let contracts
|
||||||
let datatoken
|
let datatoken
|
||||||
let tokenAddress
|
let tokenAddress
|
||||||
@ -26,7 +23,13 @@ describe('Simple flow', () => {
|
|||||||
|
|
||||||
describe('#test', () => {
|
describe('#test', () => {
|
||||||
it('Initialize Ocean contracts v3', async () => {
|
it('Initialize Ocean contracts v3', async () => {
|
||||||
contracts = new TestContractHandler(factoryABI, datatokensABI)
|
contracts = new TestContractHandler(
|
||||||
|
factory.abi,
|
||||||
|
datatokensTemplate.abi,
|
||||||
|
datatokensTemplate.bytecode,
|
||||||
|
factory.bytecode,
|
||||||
|
web3
|
||||||
|
)
|
||||||
await contracts.getAccounts()
|
await contracts.getAccounts()
|
||||||
owner = contracts.accounts[0]
|
owner = contracts.accounts[0]
|
||||||
alice = contracts.accounts[1]
|
alice = contracts.accounts[1]
|
||||||
@ -38,8 +41,8 @@ describe('Simple flow', () => {
|
|||||||
// Alice creates a Datatoken
|
// Alice creates a Datatoken
|
||||||
datatoken = new DataTokens(
|
datatoken = new DataTokens(
|
||||||
contracts.factoryAddress,
|
contracts.factoryAddress,
|
||||||
factoryABI,
|
factory.abi,
|
||||||
datatokensABI,
|
datatokensTemplate.abi,
|
||||||
web3
|
web3
|
||||||
)
|
)
|
||||||
tokenAddress = await datatoken.create(blob, alice)
|
tokenAddress = await datatoken.create(blob, alice)
|
||||||
@ -50,7 +53,7 @@ describe('Simple flow', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('Alice transfers 1 token to Bob', async () => {
|
it('Alice transfers 1 token to Bob', async () => {
|
||||||
const ts = await datatoken.transfer(tokenAddress, bob, tokenAmount, alice)
|
const ts = await datatoken.transfer(tokenAddress, bob, transferAmount, alice)
|
||||||
transactionId = ts.transactionHash
|
transactionId = ts.transactionHash
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -24,7 +24,8 @@ describe('DataTokens', () => {
|
|||||||
factory.abi,
|
factory.abi,
|
||||||
datatokensTemplate.abi,
|
datatokensTemplate.abi,
|
||||||
datatokensTemplate.bytecode,
|
datatokensTemplate.bytecode,
|
||||||
factory.bytecode
|
factory.bytecode,
|
||||||
|
web3
|
||||||
)
|
)
|
||||||
await contracts.getAccounts()
|
await contracts.getAccounts()
|
||||||
minter = contracts.accounts[0]
|
minter = contracts.accounts[0]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user