Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kremalicious committed Sep 23, 2020
1 parent 19e4e58 commit 905fd99
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 43 deletions.
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
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

0 comments on commit 905fd99

Please sign in to comment.