From 9511559b20b4a0be258f05b5bf94875cdd0fe559 Mon Sep 17 00:00:00 2001 From: arsenyjin Date: Thu, 18 Jun 2020 13:56:33 +0200 Subject: [PATCH 1/3] update simpleflow docs --- README_simpleflow.md | 58 +++++++++++++---------------- test/integration/Simpleflow.test.ts | 12 +++--- 2 files changed, 30 insertions(+), 40 deletions(-) diff --git a/README_simpleflow.md b/README_simpleflow.md index 51f44b4a..b17b898a 100644 --- a/README_simpleflow.md +++ b/README_simpleflow.md @@ -36,47 +36,46 @@ Let's go through each of these in detail. For now, you're Alice:) Let's proceed. +Run `ganache-cli` locally: +```bash +ganache-cli +``` ```javascript -const { Ocean, Logger } = require('@oceanprotocol/lib') -const config={ - network: 'rinkeby', - privateKey:'8da4ef21b864d2cc526dbdb2a120bd2874c36c9d0a1fb7f8c63d7f7a8b41de8f', -} -const ocean = Ocean(alice_config) -const account = await ocean.accounts.list()[0] -const myToken = ocean.datatoken.create('localhost:8030',account) -const dt_address=myToken.getAddress() -console.log(dt_address) +const tokenAmount = 100 +const transferAmount = 1 +const blob = 'http://localhost:8030/api/v1/provider/services' + +const alice = await ocean.accounts.list()[0] +const bob = await ocean.accounts.list()[0] +// create datatoken class +const datatoken = new DataTokens(contracts.factoryAddress, factoryABI, datatokensABI, web3) +// deploy datatoken +const tokenAddress = await datatoken.create(blob, alice) + ``` ## 2. Alice hosts the dataset -A locally providerService is required, which will serve just one file for this demo. -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) +Clone [provider-py](https://github.com/oceanprotocol/provider-py) and update your local environment variables: ``` -ENV DT="{'0x1234':'/var/mydata/myFolder1'}" -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 ```javascript -myToken.mint(100) +datatoken.mint(tokenAddress, alice, tokenAmount) ``` ## 4. Alice transfers 1 token to Bob ```javascript -myToken.transfer(1,BobAddress) +const ts = await datatoken.transfer(tokenAddress, bob, transferAmount, alice) +const transactionId = ts['transactionHash'] ``` ## 5. Bob consumes dataset @@ -86,17 +85,10 @@ Now, you are Bob :) ```javascript -const bob_config={ - network: 'rinkeby', - 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) +const config = new Config() +const ocean = await Ocean.getInstance() +await ocean.assets.download(tokenAddress, blob, transactionId, bob) ``` diff --git a/test/integration/Simpleflow.test.ts b/test/integration/Simpleflow.test.ts index 15be5278..dff87162 100644 --- a/test/integration/Simpleflow.test.ts +++ b/test/integration/Simpleflow.test.ts @@ -1,4 +1,3 @@ -import { assert } from 'chai' import { TestContractHandler } from '../TestContractHandler' import { DataTokens } from '../../src/datatokens/Datatokens' import { Ocean } from '../../src/ocean/Ocean' @@ -16,15 +15,14 @@ describe('Simple flow', () => { let owner let bob let alice - let balance let contracts let datatoken let tokenAddress let transactionId - let tokenAmount = 100 - let transferAmount = 1 - let blob = 'http://localhost:8030/api/v1/provider/services' + const tokenAmount = 100 + const transferAmount = 1 + const blob = 'http://localhost:8030/api/v1/provider/services' describe('#test', () => { it('Initialize Ocean contracts v3', async () => { @@ -47,13 +45,13 @@ describe('Simple flow', () => { }) 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'] }) it('Bob consumes dataset', async () => { const config = new Config() - let ocean = await Ocean.getInstance(config) + const ocean = await Ocean.getInstance(config) await ocean.assets.download(tokenAddress, blob, transactionId, bob) }) }) From 07449ed18d82a035ee827439a060fd2a55068967 Mon Sep 17 00:00:00 2001 From: Ahmed Ali Date: Fri, 19 Jun 2020 15:34:45 +0200 Subject: [PATCH 2/3] fix tests --- package.json | 2 +- test/integration/Simpleflow.test.ts | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index aa932f1d..7d81dc0d 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "changelog": "auto-changelog -p", "prepublishOnly": "npm run build", "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" }, "repository": { "type": "git", diff --git a/test/integration/Simpleflow.test.ts b/test/integration/Simpleflow.test.ts index 92e3ab43..6ce2313d 100644 --- a/test/integration/Simpleflow.test.ts +++ b/test/integration/Simpleflow.test.ts @@ -6,9 +6,8 @@ import { Config } from '../../src/models/Config' const Web3 = require('web3') const web3 = new Web3('http://127.0.0.1:8545') - -const factoryABI = require('../../src/datatokens/FactoryABI.json') -const datatokensABI = require('../../src/datatokens/DatatokensABI.json') +const factory = require('@oceanprotocol/contracts/artifacts/development/Factory.json') +const datatokensTemplate = require('@oceanprotocol/contracts/artifacts/development/DataTokenTemplate.json') describe('Simple flow', () => { let owner @@ -26,7 +25,12 @@ describe('Simple flow', () => { describe('#test', () => { it('Initialize Ocean contracts v3', async () => { - contracts = new TestContractHandler(factoryABI, datatokensABI) + contracts = new TestContractHandler( + factory.abi, + datatokensTemplate.abi, + datatokensTemplate.bytecode, + factory.bytecode + ) await contracts.getAccounts() owner = contracts.accounts[0] alice = contracts.accounts[1] @@ -38,8 +42,8 @@ describe('Simple flow', () => { // Alice creates a Datatoken datatoken = new DataTokens( contracts.factoryAddress, - factoryABI, - datatokensABI, + factory.abi, + datatokensTemplate.abi, web3 ) tokenAddress = await datatoken.create(blob, alice) From c9799e271d87f58d3a432f59539fa39989b54818 Mon Sep 17 00:00:00 2001 From: Ahmed Ali Date: Fri, 19 Jun 2020 15:55:34 +0200 Subject: [PATCH 3/3] fix lint --- test/integration/Simpleflow.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/Simpleflow.test.ts b/test/integration/Simpleflow.test.ts index 6ce2313d..1eef5ce6 100644 --- a/test/integration/Simpleflow.test.ts +++ b/test/integration/Simpleflow.test.ts @@ -26,7 +26,7 @@ describe('Simple flow', () => { describe('#test', () => { it('Initialize Ocean contracts v3', async () => { contracts = new TestContractHandler( - factory.abi, + factory.abi, datatokensTemplate.abi, datatokensTemplate.bytecode, factory.bytecode