Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix getOwnerAssets response #308

Merged
merged 3 commits into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/datatokens/Datatokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@ export class DataTokens {
* @param {String} toAddress
* @param {string} amount Number of datatokens, as number. Will be converted to wei
* @param {String} address
* @return {Promise<string>} transactionId
* @return {Promise<TransactionReceipt>} transactionId
*/
public async approve(
dataTokenAddress: string,
spender: string,
amount: string,
address: string
): Promise<string> {
): Promise<TransactionReceipt> {
const datatoken = new this.web3.eth.Contract(this.datatokensABI, dataTokenAddress, {
from: address
})
Expand All @@ -142,14 +142,14 @@ export class DataTokens {
* @param {String} address
* @param {String} amount Number of datatokens, as number. Will be converted to wei
* @param {String} toAddress - only if toAddress is different from the minter
* @return {Promise<string>} transactionId
* @return {Promise<TransactionReceipt>} transactionId
*/
public async mint(
dataTokenAddress: string,
address: string,
amount: string,
toAddress?: string
): Promise<string> {
): Promise<TransactionReceipt> {
const destAddress = toAddress || address
const datatoken = new this.web3.eth.Contract(this.datatokensABI, dataTokenAddress, {
from: address
Expand Down Expand Up @@ -178,14 +178,14 @@ export class DataTokens {
* @param {String} toAddress
* @param {String} amount Number of datatokens, as number. Will be converted to wei
* @param {String} address
* @return {Promise<string>} transactionId
* @return {Promise<TransactionReceipt>} transactionId
*/
public async transfer(
dataTokenAddress: string,
toAddress: string,
amount: string,
address: string
): Promise<string> {
): Promise<TransactionReceipt> {
return this.transferToken(dataTokenAddress, toAddress, amount, address)
}

Expand All @@ -195,14 +195,14 @@ export class DataTokens {
* @param {String} toAddress
* @param {String} amount Number of datatokens, as number. Will be converted to wei
* @param {String} address
* @return {Promise<string>} transactionId
* @return {Promise<TransactionReceipt>} transactionId
*/
public async transferToken(
dataTokenAddress: string,
toAddress: string,
amount: string,
address: string
): Promise<string> {
): Promise<TransactionReceipt> {
const weiAmount = this.web3.utils.toWei(amount)
return this.transferWei(dataTokenAddress, toAddress, weiAmount, address)
}
Expand All @@ -213,14 +213,14 @@ export class DataTokens {
* @param {String} toAddress
* @param {String} amount Number of datatokens, as number. Expressed as wei
* @param {String} address
* @return {Promise<string>} transactionId
* @return {Promise<TransactionReceipt>} transactionId
*/
public async transferWei(
dataTokenAddress: string,
toAddress: string,
amount: string,
address: string
): Promise<string> {
): Promise<TransactionReceipt> {
const datatoken = new this.web3.eth.Contract(this.datatokensABI, dataTokenAddress, {
from: address
})
Expand Down
6 changes: 4 additions & 2 deletions src/metadatastore/MetadataStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export class MetadataStore {
return result
}

public async getOwnerAssets(owner: string): Promise<DDO[]> {
public async getOwnerAssets(owner: string): Promise<QueryResult> {
const q = {
offset: 100,
page: 1,
Expand All @@ -266,7 +266,9 @@ export class MetadataStore {
value: 1
}
} as SearchQuery
return (await this.queryMetadata(q)).results

const result = await this.queryMetadata(q)
return result
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/ocean/Assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { EditableMetadata } from '../ddo/interfaces/EditableMetadata'
import Account from './Account'
import DID from './DID'
import { SubscribablePromise, didZeroX } from '../utils'
import { SubscribablePromise } from '../utils'
import { Instantiable, InstantiableConfig } from '../Instantiable.abstract'
import { WebServiceConnector } from './utils/WebServiceConnector'
import BigNumber from 'bignumber.js'
Expand Down Expand Up @@ -205,7 +205,7 @@ export class Assets extends Instantiable {
* @param {string} owner Owner address.
* @return {Promise<string[]>} List of DIDs.
*/
public async ownerAssets(owner: string): Promise<DDO[]> {
public async ownerAssets(owner: string): Promise<QueryResult> {
return this.ocean.metadatastore.getOwnerAssets(owner)
}

Expand Down
10 changes: 5 additions & 5 deletions test/integration/ComputeFlow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Ocean } from '../../src/ocean/Ocean'
import { ConfigHelper } from '../../src/utils/ConfigHelper'

import { assert } from 'chai'
import { ServiceComputePrivacy } from '../../src/ddo/interfaces/Service'
import { ServiceCommon, ServiceComputePrivacy } from '../../src/ddo/interfaces/Service'
import Web3 from 'web3'
import factory from '@oceanprotocol/contracts/artifacts/DTFactory.json'
import datatokensTemplate from '@oceanprotocol/contracts/artifacts/DataTokenTemplate.json'
Expand All @@ -27,14 +27,14 @@ describe('Compute flow', () => {
let datasetWithTrustedAlgo
let algorithmAsset
let contracts
let datatoken
let datatoken: DataTokens
let tokenAddress
let tokenAddressNoRawAlgo
let tokenAddressWithTrustedAlgo
let tokenAddressAlgorithm
let price
let price: string
let ocean
let computeService
let computeService: ServiceCommon
let data
let blob
let jobId
Expand Down Expand Up @@ -77,7 +77,7 @@ describe('Compute flow', () => {
owner = (await ocean.accounts.list())[0]
alice = (await ocean.accounts.list())[1]
bob = (await ocean.accounts.list())[2]
data = { t: 1, url: ocean.config.metadataStoreUri }
data = { t: 1, url: config.metadataStoreUri }
blob = JSON.stringify(data)
await contracts.deployContracts(owner.getId())
})
Expand Down
36 changes: 18 additions & 18 deletions test/integration/Marketplaceflow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import { ConfigHelper } from '../../src/utils/ConfigHelper'
import Web3 from 'web3'
import factory from '@oceanprotocol/contracts/artifacts/DTFactory.json'
import datatokensTemplate from '@oceanprotocol/contracts/artifacts/DataTokenTemplate.json'
import { EditableMetadata } from '../../src/lib'
import { Account, EditableMetadata, ServiceAccess, ServiceCommon } from '../../src/lib'
const web3 = new Web3('http://127.0.0.1:8545')

function sleep(ms) {
function sleep(ms: number) {
return new Promise((resolve) => {
setTimeout(resolve, ms)
})
Expand All @@ -21,19 +21,19 @@ function sleep(ms) {
use(spies)

describe('Marketplace flow', () => {
let owner
let bob
let owner: Account
let bob: Account
let ddo
let alice
let alice: Account
let asset
let marketplace
let contracts
let datatoken
let tokenAddress
let service1
let price
let ocean
let accessService
let marketplace: Account
let contracts: TestContractHandler
let datatoken: DataTokens
let tokenAddress: string
let service1: ServiceAccess
let price: string
let ocean: Ocean
let accessService: ServiceCommon
let data
let blob

Expand All @@ -55,7 +55,7 @@ describe('Marketplace flow', () => {
alice = (await ocean.accounts.list())[1]
bob = (await ocean.accounts.list())[2]
marketplace = (await ocean.accounts.list())[3]
data = { t: 1, url: ocean.config.metadataStoreUri }
data = { t: 1, url: config.metadataStoreUri }
blob = JSON.stringify(data)
await contracts.deployContracts(owner.getId())
})
Expand Down Expand Up @@ -156,8 +156,8 @@ describe('Marketplace flow', () => {

it('Marketplace posts asset for sale', async () => {
accessService = await ocean.assets.getServiceByType(ddo.id, 'access')
price = 20
assert.equal(accessService.attributes.main.cost * price, 200)
price = '20'
assert.equal(accessService.attributes.main.cost * Number(price), 200)
})

it('Bob gets datatokens', async () => {
Expand Down Expand Up @@ -199,9 +199,9 @@ describe('Marketplace flow', () => {
assert(balanceBefore === balanceAfter)
})

it('owner can list there assets', async () => {
it('owner can list their assets', async () => {
const assets = await ocean.assets.ownerAssets(alice.getId())
assert(assets.length > 0)
assert(assets.results.length > 0)
})

it('Alice updates metadata', async () => {
Expand Down
7 changes: 4 additions & 3 deletions test/integration/Provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ import config from './config'
import { assert } from 'console'

describe('Provider tests', () => {
let ocean
let ocean: Ocean

it('Initialize Ocean', async () => {
ocean = await Ocean.getInstance(config)
})
it('Alice tests invalid provider', async () => {
const valid = ocean.provider.isValidProvider('http://example.net')
const valid = await ocean.provider.isValidProvider('http://example.net')
assert(valid === false)
})
it('Alice tests valid provider', async () => {
const valid = ocean.provider.isValidProvider('http://127.0.0.1:8030')
const valid = await ocean.provider.isValidProvider('http://127.0.0.1:8030')
assert(valid === true)
})
})
15 changes: 8 additions & 7 deletions test/integration/Simpleflow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import datatokensTemplate from '@oceanprotocol/contracts/artifacts/DataTokenTemp
const web3 = new Web3('http://127.0.0.1:8545')

describe('Simple flow', () => {
let owner
let bob
let alice
let contracts
let datatoken
let tokenAddress
let transactionId
let owner: string
let bob: string
let alice: string
let contracts: TestContractHandler
let datatoken: DataTokens
let tokenAddress: string
let transactionId: string

const tokenAmount = '100'
const transferAmount = '1'
const blob = 'http://localhost:8030/api/v1/services/consume'
Expand Down