mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
fix merge
This commit is contained in:
commit
b1d15163ba
@ -16,7 +16,8 @@
|
||||
"release": "release-it --non-interactive",
|
||||
"changelog": "auto-changelog -p",
|
||||
"prepublishOnly": "npm run build",
|
||||
"test": "mocha --opts test/unit/mocha.opts"
|
||||
"test": "mocha --opts test/unit/mocha.opts",
|
||||
"test:integration": "mocha --opts test/integration/mocha.opts"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
@ -92,8 +92,18 @@ export class DataTokens {
|
||||
dataTokenAddress,
|
||||
{ from: account }
|
||||
)
|
||||
const trxReceipt = null
|
||||
// TODO:
|
||||
const estGas = await datatoken.methods.mint(address, amount)
|
||||
.estimateGas(function(err, estGas){
|
||||
return estGas
|
||||
})
|
||||
|
||||
const trxReceipt = await datatoken.methods.mint(address, amount)
|
||||
.send({
|
||||
from:account,
|
||||
gas: estGas+1,
|
||||
gasPrice: '3000000000'
|
||||
})
|
||||
|
||||
return trxReceipt
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { TransactionReceipt } from 'web3-core'
|
||||
import { SearchQuery } from '../aquarius/Aquarius'
|
||||
import { File, MetaDataAlgorithm } from '../ddo/MetaData'
|
||||
import { DDO } from '../ddo/DDO'
|
||||
import { Metadata } from '../ddo/interfaces/Metadata'
|
||||
import { Service } from '../ddo/interfaces/Service'
|
||||
@ -8,6 +9,7 @@ import DID from './DID'
|
||||
import { SubscribablePromise, didZeroX } from '../utils'
|
||||
import { Instantiable, InstantiableConfig } from '../Instantiable.abstract'
|
||||
|
||||
import { WebServiceConnector } from './utils/WebServiceConnector'
|
||||
import { DataTokens } from '../lib'
|
||||
|
||||
export enum CreateProgressStep {
|
||||
@ -169,4 +171,28 @@ export class Assets extends Instantiable {
|
||||
return storedDdo
|
||||
})
|
||||
}
|
||||
|
||||
public async download(
|
||||
dtAddress: string,
|
||||
serviceEndpoint: string,
|
||||
account: string
|
||||
): Promise<string> {
|
||||
|
||||
let consumeUrl = serviceEndpoint
|
||||
// consumeUrl += `&consumerAddress=${account}`
|
||||
// consumeUrl += `&serviceAgreementId=${dtAddress}`
|
||||
|
||||
let serviceConnector = new WebServiceConnector(this.logger)
|
||||
|
||||
try {
|
||||
await serviceConnector.downloadFile(consumeUrl)
|
||||
} catch (e) {
|
||||
this.logger.error('Error consuming assets')
|
||||
this.logger.error(e)
|
||||
throw e
|
||||
}
|
||||
|
||||
return serviceEndpoint
|
||||
}
|
||||
|
||||
}
|
||||
|
77
test/TestContractHandler.ts
Normal file
77
test/TestContractHandler.ts
Normal file
File diff suppressed because one or more lines are too long
58
test/integration/Simpleflow.test.ts
Normal file
58
test/integration/Simpleflow.test.ts
Normal file
@ -0,0 +1,58 @@
|
||||
import { assert } from 'chai'
|
||||
import { TestContractHandler } from '../TestContractHandler'
|
||||
import { DataTokens } from '../../src/datatokens/Datatokens'
|
||||
import { Ocean } from '../../src/ocean/Ocean'
|
||||
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')
|
||||
|
||||
describe('Simple flow', () => {
|
||||
|
||||
let owner
|
||||
let bob
|
||||
let alice
|
||||
let balance
|
||||
let contracts
|
||||
let datatoken
|
||||
let tokenAddress
|
||||
|
||||
let tokenAmount = 100
|
||||
let transferAmount = 1
|
||||
let blob = 'http://localhost:8030/api/v1/provider/services'
|
||||
|
||||
describe('#test', () => {
|
||||
it('Initialize Ocean contracts v3', async () => {
|
||||
contracts = new TestContractHandler(factoryABI,datatokensABI)
|
||||
await contracts.getAccounts()
|
||||
owner = contracts.accounts[0]
|
||||
alice = contracts.accounts[1]
|
||||
bob = contracts.accounts[2]
|
||||
await contracts.deployContracts(owner)
|
||||
})
|
||||
|
||||
it('Alice publishes a dataset', async () => {
|
||||
// Alice creates a Datatoken
|
||||
datatoken = new DataTokens(contracts.factoryAddress, factoryABI, datatokensABI, web3)
|
||||
tokenAddress = await datatoken.create(config.providerUri, alice)
|
||||
})
|
||||
|
||||
it('Alice mints 100 tokens', async () => {
|
||||
datatoken.mint(tokenAddress, alice, tokenAmount)
|
||||
})
|
||||
|
||||
it('Alice transfers 1 token to Bob', async () => {
|
||||
datatoken.transfer(tokenAddress, bob, tokenAmount, alice)
|
||||
})
|
||||
|
||||
it('Bob consumes dataset', async () => {
|
||||
const config = new Config()
|
||||
let ocean = await Ocean.getInstance(config)
|
||||
ocean.assets.download(tokenAddress, blob, bob)
|
||||
})
|
||||
})
|
||||
})
|
7
test/integration/mocha.opts
Normal file
7
test/integration/mocha.opts
Normal file
@ -0,0 +1,7 @@
|
||||
--require ts-node/register
|
||||
--require source-map-support/register
|
||||
--require mock-local-storage
|
||||
--full-trace
|
||||
--exit
|
||||
--timeout 300000
|
||||
test/integration/**/*.test.ts
|
64
test/unit/Datatokens.test.ts
Normal file
64
test/unit/Datatokens.test.ts
Normal file
@ -0,0 +1,64 @@
|
||||
import { assert } from 'chai'
|
||||
import { TestContractHandler } from '../TestContractHandler'
|
||||
import { DataTokens } from '../../src/datatokens/Datatokens'
|
||||
|
||||
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')
|
||||
|
||||
describe('DataTokens', () => {
|
||||
|
||||
let minter
|
||||
let spender
|
||||
let balance
|
||||
let contracts
|
||||
let datatoken
|
||||
let tokenAddress
|
||||
|
||||
let tokenAmount = 100
|
||||
let blob = 'https://example.com/dataset-1'
|
||||
|
||||
describe('#test', () => {
|
||||
it('should deploy contracts', async () => {
|
||||
contracts = new TestContractHandler(factoryABI,datatokensABI)
|
||||
await contracts.getAccounts()
|
||||
minter = contracts.accounts[0]
|
||||
spender = contracts.accounts[1]
|
||||
await contracts.deployContracts(minter)
|
||||
})
|
||||
|
||||
it('should create Datatoken object', async () => {
|
||||
datatoken = new DataTokens(contracts.factoryAddress, factoryABI, datatokensABI, web3)
|
||||
assert(datatoken !== null)
|
||||
})
|
||||
|
||||
it('should create Datatoken contract', async () => {
|
||||
tokenAddress = await datatoken.create(blob, minter)
|
||||
assert(tokenAddress !== null)
|
||||
})
|
||||
|
||||
it('should mint Datatokens', async () => {
|
||||
await datatoken.mint(tokenAddress, minter, tokenAmount)
|
||||
balance = await datatoken.balance(tokenAddress, minter)
|
||||
assert(balance.toString() === tokenAmount.toString())
|
||||
})
|
||||
|
||||
it('should transfer Datatokens to spender', async () => {
|
||||
await datatoken.transfer(tokenAddress, spender, tokenAmount, minter)
|
||||
balance = await datatoken.balance(tokenAddress, spender)
|
||||
assert(balance.toString() === tokenAmount.toString())
|
||||
})
|
||||
|
||||
it('should approve Datatokens to spend', async () => {
|
||||
await datatoken.approve(tokenAddress, minter, tokenAmount, spender)
|
||||
})
|
||||
|
||||
it('should transferFrom Datatokens back to the minter', async () => {
|
||||
await datatoken.transferFrom(tokenAddress, spender, tokenAmount, minter)
|
||||
minter = await datatoken.balance(tokenAddress, spender)
|
||||
assert(balance.toString() === tokenAmount.toString())
|
||||
})
|
||||
})
|
||||
})
|
Loading…
x
Reference in New Issue
Block a user