mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
Merge pull request #94 from oceanprotocol/fix/integration-test-beta-firstcut
Fix/integration test-beta
This commit is contained in:
commit
087101c34d
@ -36,47 +36,46 @@ 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
|
||||||
|
```
|
||||||
|
|
||||||
```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 PROVIDER_ADDRESS=your_provider_address
|
||||||
docker run @oceanprotocol/provider-py -e CONFIG=DT
|
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 +85,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)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,7 +17,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": {
|
||||||
|
@ -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,12 @@ 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
|
||||||
|
)
|
||||||
await contracts.getAccounts()
|
await contracts.getAccounts()
|
||||||
owner = contracts.accounts[0]
|
owner = contracts.accounts[0]
|
||||||
alice = contracts.accounts[1]
|
alice = contracts.accounts[1]
|
||||||
@ -38,8 +40,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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user