mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
fix more linting errors
This commit is contained in:
parent
52260cdf7f
commit
4554f420e3
@ -40,26 +40,20 @@ export class DataTokens {
|
|||||||
*/
|
*/
|
||||||
public async create(metaDataStoreURI: string, account: Account): Promise<string> {
|
public async create(metaDataStoreURI: string, account: Account): Promise<string> {
|
||||||
// Create factory contract object
|
// Create factory contract object
|
||||||
const factory = new this.web3.eth.Contract(
|
const factory = new this.web3.eth.Contract(this.factoryABI, this.factoryAddress, {
|
||||||
this.factoryABI,
|
from: account
|
||||||
this.factoryAddress,
|
})
|
||||||
{
|
|
||||||
from: account
|
|
||||||
}
|
|
||||||
)
|
|
||||||
const estGas = await factory.methods
|
const estGas = await factory.methods
|
||||||
.createToken(metaDataStoreURI)
|
.createToken(metaDataStoreURI)
|
||||||
.estimateGas(function(err, estGas){
|
.estimateGas(function (err, estGas) {
|
||||||
return estGas
|
return estGas
|
||||||
})
|
})
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
const trxReceipt = await factory.methods
|
const trxReceipt = await factory.methods.createToken(metaDataStoreURI).send({
|
||||||
.createToken(metaDataStoreURI)
|
from: account,
|
||||||
.send({
|
gas: estGas + 1,
|
||||||
from: account,
|
gasPrice: '3000000000'
|
||||||
gas: estGas+1,
|
})
|
||||||
gasPrice: '3000000000'
|
|
||||||
})
|
|
||||||
|
|
||||||
let tokenAddress = null
|
let tokenAddress = null
|
||||||
try {
|
try {
|
||||||
@ -113,17 +107,17 @@ export class DataTokens {
|
|||||||
dataTokenAddress,
|
dataTokenAddress,
|
||||||
{ from: account }
|
{ from: account }
|
||||||
)
|
)
|
||||||
const estGas = await datatoken.methods.mint(address, amount)
|
const estGas = await datatoken.methods
|
||||||
.estimateGas(function(err, estGas){
|
.mint(address, amount)
|
||||||
return estGas
|
.estimateGas(function (err, estGas) {
|
||||||
})
|
return estGas
|
||||||
|
})
|
||||||
|
|
||||||
const trxReceipt = await datatoken.methods.mint(address, amount)
|
const trxReceipt = await datatoken.methods.mint(address, amount).send({
|
||||||
.send({
|
from: account,
|
||||||
from:account,
|
gas: estGas + 1,
|
||||||
gas: estGas+1,
|
gasPrice: '3000000000'
|
||||||
gasPrice: '3000000000'
|
})
|
||||||
})
|
|
||||||
|
|
||||||
return trxReceipt
|
return trxReceipt
|
||||||
}
|
}
|
||||||
|
@ -178,13 +178,12 @@ export class Assets extends Instantiable {
|
|||||||
txId: string,
|
txId: string,
|
||||||
account: string
|
account: string
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
|
|
||||||
let consumeUrl = serviceEndpoint
|
let consumeUrl = serviceEndpoint
|
||||||
consumeUrl += `?consumerAddress=${account}`
|
consumeUrl += `?consumerAddress=${account}`
|
||||||
consumeUrl += `&tokenAddress=${dtAddress}`
|
consumeUrl += `&tokenAddress=${dtAddress}`
|
||||||
consumeUrl += `&transferTxId=${txId}`
|
consumeUrl += `&transferTxId=${txId}`
|
||||||
|
|
||||||
let serviceConnector = new WebServiceConnector(this.logger)
|
const serviceConnector = new WebServiceConnector(this.logger)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await serviceConnector.downloadFile(consumeUrl)
|
await serviceConnector.downloadFile(consumeUrl)
|
||||||
@ -193,8 +192,7 @@ export class Assets extends Instantiable {
|
|||||||
this.logger.error(e)
|
this.logger.error(e)
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
|
|
||||||
return serviceEndpoint
|
return serviceEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { Contract } from 'web3-eth-contract'
|
import { Contract } from 'web3-eth-contract'
|
||||||
|
|
||||||
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')
|
||||||
|
|
||||||
export class TestContractHandler {
|
export class TestContractHandler {
|
||||||
public factory: Contract
|
public factory: Contract
|
||||||
@ -17,8 +17,8 @@ export class TestContractHandler {
|
|||||||
datatokensABI: Contract,
|
datatokensABI: Contract,
|
||||||
templateBytecode: string,
|
templateBytecode: string,
|
||||||
factoryBytecode: string
|
factoryBytecode: string
|
||||||
){
|
) {
|
||||||
this.factory = new web3.eth.Contract(factoryABI)
|
this.factory = new web3.eth.Contract(factoryABI)
|
||||||
this.template = new web3.eth.Contract(datatokensABI)
|
this.template = new web3.eth.Contract(datatokensABI)
|
||||||
this.templateBytecode = templateBytecode
|
this.templateBytecode = templateBytecode
|
||||||
this.factoryBytecode = factoryBytecode
|
this.factoryBytecode = factoryBytecode
|
||||||
@ -27,54 +27,58 @@ export class TestContractHandler {
|
|||||||
public async getAccounts() {
|
public async getAccounts() {
|
||||||
this.accounts = await web3.eth.getAccounts()
|
this.accounts = await web3.eth.getAccounts()
|
||||||
}
|
}
|
||||||
|
|
||||||
public async deployContracts(minter: string) {
|
public async deployContracts(minter: string) {
|
||||||
let estGas
|
let estGas
|
||||||
|
|
||||||
let blob = 'https://example.com/dataset-1'
|
const blob = 'https://example.com/dataset-1'
|
||||||
let cap = 1400000000
|
const cap = 1400000000
|
||||||
|
|
||||||
// get est gascost
|
// get est gascost
|
||||||
estGas = await this.template.deploy({
|
estGas = await this.template
|
||||||
data: this.templateBytecode,
|
.deploy({
|
||||||
arguments:['Template Contract', 'TEMPLATE', minter, cap, blob]
|
data: this.templateBytecode,
|
||||||
})
|
arguments: ['Template Contract', 'TEMPLATE', minter, cap, blob]
|
||||||
.estimateGas(function(err, estGas){
|
})
|
||||||
return estGas
|
.estimateGas(function (err, estGas) {
|
||||||
})
|
return estGas
|
||||||
|
})
|
||||||
// deploy the contract and get it's address
|
// deploy the contract and get it's address
|
||||||
this.templateAddress = await this.template.deploy({
|
this.templateAddress = await this.template
|
||||||
data: this.templateBytecode,
|
.deploy({
|
||||||
arguments:['Template Contract', 'TEMPLATE', minter, cap, blob]
|
data: this.templateBytecode,
|
||||||
})
|
arguments: ['Template Contract', 'TEMPLATE', minter, cap, blob]
|
||||||
.send({
|
})
|
||||||
from: minter,
|
.send({
|
||||||
gas: estGas+1,
|
from: minter,
|
||||||
gasPrice: '12345678'
|
gas: estGas + 1,
|
||||||
})
|
gasPrice: '12345678'
|
||||||
.then(function(contract){
|
})
|
||||||
return contract.options.address
|
.then(function (contract) {
|
||||||
})
|
return contract.options.address
|
||||||
|
})
|
||||||
estGas = await this.factory.deploy({
|
|
||||||
data: this.factoryBytecode,
|
estGas = await this.factory
|
||||||
arguments:[this.templateAddress]
|
.deploy({
|
||||||
})
|
data: this.factoryBytecode,
|
||||||
.estimateGas(function(err, estGas){
|
arguments: [this.templateAddress]
|
||||||
return estGas
|
})
|
||||||
})
|
.estimateGas(function (err, estGas) {
|
||||||
|
return estGas
|
||||||
|
})
|
||||||
// deploy the contract and get it's address
|
// deploy the contract and get it's address
|
||||||
this.factoryAddress = await this.factory.deploy({
|
this.factoryAddress = await this.factory
|
||||||
data: this.factoryBytecode,
|
.deploy({
|
||||||
arguments:[this.templateAddress]
|
data: this.factoryBytecode,
|
||||||
})
|
arguments: [this.templateAddress]
|
||||||
.send({
|
})
|
||||||
from: minter,
|
.send({
|
||||||
gas: estGas+1,
|
from: minter,
|
||||||
gasPrice: '12345678'
|
gas: estGas + 1,
|
||||||
})
|
gasPrice: '12345678'
|
||||||
.then(function(contract){
|
})
|
||||||
return contract.options.address
|
.then(function (contract) {
|
||||||
})
|
return contract.options.address
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,15 +4,13 @@ import { DataTokens } from '../../src/datatokens/Datatokens'
|
|||||||
import { Ocean } from '../../src/ocean/Ocean'
|
import { Ocean } from '../../src/ocean/Ocean'
|
||||||
import { Config } from '../../src/models/Config'
|
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 factoryABI = require('../../src/datatokens/FactoryABI.json')
|
const factoryABI = require('../../src/datatokens/FactoryABI.json')
|
||||||
const datatokensABI = require('../../src/datatokens/DatatokensABI.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
|
||||||
@ -22,13 +20,13 @@ describe('Simple flow', () => {
|
|||||||
let tokenAddress
|
let tokenAddress
|
||||||
let transactionId
|
let transactionId
|
||||||
|
|
||||||
let tokenAmount = 100
|
const tokenAmount = 100
|
||||||
let transferAmount = 1
|
const transferAmount = 1
|
||||||
let blob = 'http://localhost:8030/api/v1/provider/services'
|
const blob = 'http://localhost:8030/api/v1/provider/services'
|
||||||
|
|
||||||
describe('#test', () => {
|
describe('#test', () => {
|
||||||
it('Initialize Ocean contracts v3', async () => {
|
it('Initialize Ocean contracts v3', async () => {
|
||||||
contracts = new TestContractHandler(factoryABI,datatokensABI)
|
contracts = new TestContractHandler(factoryABI, datatokensABI)
|
||||||
await contracts.getAccounts()
|
await contracts.getAccounts()
|
||||||
owner = contracts.accounts[0]
|
owner = contracts.accounts[0]
|
||||||
alice = contracts.accounts[1]
|
alice = contracts.accounts[1]
|
||||||
@ -38,7 +36,12 @@ describe('Simple flow', () => {
|
|||||||
|
|
||||||
it('Alice publishes a dataset', async () => {
|
it('Alice publishes a dataset', async () => {
|
||||||
// Alice creates a Datatoken
|
// Alice creates a Datatoken
|
||||||
datatoken = new DataTokens(contracts.factoryAddress, factoryABI, datatokensABI, web3)
|
datatoken = new DataTokens(
|
||||||
|
contracts.factoryAddress,
|
||||||
|
factoryABI,
|
||||||
|
datatokensABI,
|
||||||
|
web3
|
||||||
|
)
|
||||||
tokenAddress = await datatoken.create(blob, alice)
|
tokenAddress = await datatoken.create(blob, alice)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -48,13 +51,13 @@ 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, tokenAmount, alice)
|
||||||
transactionId = ts['transactionHash']
|
transactionId = ts.transactionHash
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Bob consumes dataset', async () => {
|
it('Bob consumes dataset', async () => {
|
||||||
const config = new Config()
|
const config = new Config()
|
||||||
let ocean = await Ocean.getInstance(config)
|
const ocean = await Ocean.getInstance(config)
|
||||||
await ocean.assets.download(tokenAddress, blob, transactionId, bob)
|
await ocean.assets.download(tokenAddress, blob, transactionId, bob)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -6,25 +6,22 @@ import Web3 from 'web3'
|
|||||||
const factory = require('@oceanprotocol/contracts/artifacts/development/Factory.json')
|
const factory = require('@oceanprotocol/contracts/artifacts/development/Factory.json')
|
||||||
const datatokensTemplate = require('@oceanprotocol/contracts/artifacts/development/DataTokenTemplate.json')
|
const datatokensTemplate = require('@oceanprotocol/contracts/artifacts/development/DataTokenTemplate.json')
|
||||||
|
|
||||||
|
const web3 = new Web3('http://127.0.0.1:8545')
|
||||||
const web3 = new Web3("http://127.0.0.1:8545")
|
|
||||||
|
|
||||||
|
|
||||||
describe('DataTokens', () => {
|
describe('DataTokens', () => {
|
||||||
|
|
||||||
let minter
|
let minter
|
||||||
let spender
|
let spender
|
||||||
let balance
|
let balance
|
||||||
let contracts
|
let contracts
|
||||||
let datatoken
|
let datatoken
|
||||||
let tokenAddress
|
let tokenAddress
|
||||||
let tokenAmount = 100
|
const tokenAmount = 100
|
||||||
let blob = 'https://example.com/dataset-1'
|
const blob = 'https://example.com/dataset-1'
|
||||||
|
|
||||||
describe('#test', () => {
|
describe('#test', () => {
|
||||||
it('#deploy', async () => {
|
it('#deploy', async () => {
|
||||||
contracts = new TestContractHandler(
|
contracts = new TestContractHandler(
|
||||||
factory.abi,
|
factory.abi,
|
||||||
datatokensTemplate.abi,
|
datatokensTemplate.abi,
|
||||||
datatokensTemplate.bytecode,
|
datatokensTemplate.bytecode,
|
||||||
factory.bytecode
|
factory.bytecode
|
||||||
@ -37,9 +34,9 @@ describe('DataTokens', () => {
|
|||||||
|
|
||||||
it('#init', async () => {
|
it('#init', async () => {
|
||||||
datatoken = new DataTokens(
|
datatoken = new DataTokens(
|
||||||
contracts.factoryAddress,
|
contracts.factoryAddress,
|
||||||
factory.abi,
|
factory.abi,
|
||||||
datatokensTemplate.abi,
|
datatokensTemplate.abi,
|
||||||
web3
|
web3
|
||||||
)
|
)
|
||||||
assert(datatoken !== null)
|
assert(datatoken !== null)
|
||||||
@ -72,4 +69,4 @@ describe('DataTokens', () => {
|
|||||||
assert(balance.toString() === tokenAmount.toString())
|
assert(balance.toString() === tokenAmount.toString())
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user