1
0
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:
Ahmed Ali 2020-06-19 10:29:01 +02:00
parent 52260cdf7f
commit 4554f420e3
5 changed files with 98 additions and 102 deletions

View File

@ -40,24 +40,18 @@ 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,
this.factoryAddress,
{
from: account 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)
.send({
from: account, from: account,
gas: estGas+1, gas: estGas + 1,
gasPrice: '3000000000' gasPrice: '3000000000'
}) })
@ -113,15 +107,15 @@ 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)
.estimateGas(function (err, estGas) {
return 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'
}) })

View File

@ -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)
@ -196,5 +195,4 @@ export class Assets extends Instantiable {
return serviceEndpoint return serviceEndpoint
} }
} }

View File

@ -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,7 +17,7 @@ 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
@ -31,49 +31,53 @@ export class TestContractHandler {
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
.deploy({
data: this.templateBytecode, data: this.templateBytecode,
arguments:['Template Contract', 'TEMPLATE', minter, cap, blob] arguments: ['Template Contract', 'TEMPLATE', minter, cap, blob]
}) })
.estimateGas(function(err, estGas){ .estimateGas(function (err, estGas) {
return 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
.deploy({
data: this.templateBytecode, data: this.templateBytecode,
arguments:['Template Contract', 'TEMPLATE', minter, cap, blob] arguments: ['Template Contract', 'TEMPLATE', minter, cap, blob]
}) })
.send({ .send({
from: minter, from: minter,
gas: estGas+1, gas: estGas + 1,
gasPrice: '12345678' gasPrice: '12345678'
}) })
.then(function(contract){ .then(function (contract) {
return contract.options.address return contract.options.address
}) })
estGas = await this.factory.deploy({ estGas = await this.factory
.deploy({
data: this.factoryBytecode, data: this.factoryBytecode,
arguments:[this.templateAddress] arguments: [this.templateAddress]
}) })
.estimateGas(function(err, estGas){ .estimateGas(function (err, estGas) {
return 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
.deploy({
data: this.factoryBytecode, data: this.factoryBytecode,
arguments:[this.templateAddress] arguments: [this.templateAddress]
}) })
.send({ .send({
from: minter, from: minter,
gas: estGas+1, gas: estGas + 1,
gasPrice: '12345678' gasPrice: '12345678'
}) })
.then(function(contract){ .then(function (contract) {
return contract.options.address return contract.options.address
}) })
} }

View File

@ -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,12 +51,12 @@ 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)
}) })
}) })

View File

@ -6,20 +6,17 @@ 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 () => {