mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
update tests
This commit is contained in:
parent
19e4e584a8
commit
905fd99496
@ -119,14 +119,14 @@ export class DataTokens {
|
|||||||
* @param {String} toAddress
|
* @param {String} toAddress
|
||||||
* @param {string} amount Number of datatokens, as number. Will be converted to wei
|
* @param {string} amount Number of datatokens, as number. Will be converted to wei
|
||||||
* @param {String} address
|
* @param {String} address
|
||||||
* @return {Promise<string>} transactionId
|
* @return {Promise<TransactionReceipt>} transactionId
|
||||||
*/
|
*/
|
||||||
public async approve(
|
public async approve(
|
||||||
dataTokenAddress: string,
|
dataTokenAddress: string,
|
||||||
spender: string,
|
spender: string,
|
||||||
amount: string,
|
amount: string,
|
||||||
address: string
|
address: string
|
||||||
): Promise<string> {
|
): Promise<TransactionReceipt> {
|
||||||
const datatoken = new this.web3.eth.Contract(this.datatokensABI, dataTokenAddress, {
|
const datatoken = new this.web3.eth.Contract(this.datatokensABI, dataTokenAddress, {
|
||||||
from: address
|
from: address
|
||||||
})
|
})
|
||||||
@ -142,14 +142,14 @@ export class DataTokens {
|
|||||||
* @param {String} address
|
* @param {String} address
|
||||||
* @param {String} amount Number of datatokens, as number. Will be converted to wei
|
* @param {String} amount Number of datatokens, as number. Will be converted to wei
|
||||||
* @param {String} toAddress - only if toAddress is different from the minter
|
* @param {String} toAddress - only if toAddress is different from the minter
|
||||||
* @return {Promise<string>} transactionId
|
* @return {Promise<TransactionReceipt>} transactionId
|
||||||
*/
|
*/
|
||||||
public async mint(
|
public async mint(
|
||||||
dataTokenAddress: string,
|
dataTokenAddress: string,
|
||||||
address: string,
|
address: string,
|
||||||
amount: string,
|
amount: string,
|
||||||
toAddress?: string
|
toAddress?: string
|
||||||
): Promise<string> {
|
): Promise<TransactionReceipt> {
|
||||||
const destAddress = toAddress || address
|
const destAddress = toAddress || address
|
||||||
const datatoken = new this.web3.eth.Contract(this.datatokensABI, dataTokenAddress, {
|
const datatoken = new this.web3.eth.Contract(this.datatokensABI, dataTokenAddress, {
|
||||||
from: address
|
from: address
|
||||||
@ -178,14 +178,14 @@ export class DataTokens {
|
|||||||
* @param {String} toAddress
|
* @param {String} toAddress
|
||||||
* @param {String} amount Number of datatokens, as number. Will be converted to wei
|
* @param {String} amount Number of datatokens, as number. Will be converted to wei
|
||||||
* @param {String} address
|
* @param {String} address
|
||||||
* @return {Promise<string>} transactionId
|
* @return {Promise<TransactionReceipt>} transactionId
|
||||||
*/
|
*/
|
||||||
public async transfer(
|
public async transfer(
|
||||||
dataTokenAddress: string,
|
dataTokenAddress: string,
|
||||||
toAddress: string,
|
toAddress: string,
|
||||||
amount: string,
|
amount: string,
|
||||||
address: string
|
address: string
|
||||||
): Promise<string> {
|
): Promise<TransactionReceipt> {
|
||||||
return this.transferToken(dataTokenAddress, toAddress, amount, address)
|
return this.transferToken(dataTokenAddress, toAddress, amount, address)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,14 +195,14 @@ export class DataTokens {
|
|||||||
* @param {String} toAddress
|
* @param {String} toAddress
|
||||||
* @param {String} amount Number of datatokens, as number. Will be converted to wei
|
* @param {String} amount Number of datatokens, as number. Will be converted to wei
|
||||||
* @param {String} address
|
* @param {String} address
|
||||||
* @return {Promise<string>} transactionId
|
* @return {Promise<TransactionReceipt>} transactionId
|
||||||
*/
|
*/
|
||||||
public async transferToken(
|
public async transferToken(
|
||||||
dataTokenAddress: string,
|
dataTokenAddress: string,
|
||||||
toAddress: string,
|
toAddress: string,
|
||||||
amount: string,
|
amount: string,
|
||||||
address: string
|
address: string
|
||||||
): Promise<string> {
|
): Promise<TransactionReceipt> {
|
||||||
const weiAmount = this.web3.utils.toWei(amount)
|
const weiAmount = this.web3.utils.toWei(amount)
|
||||||
return this.transferWei(dataTokenAddress, toAddress, weiAmount, address)
|
return this.transferWei(dataTokenAddress, toAddress, weiAmount, address)
|
||||||
}
|
}
|
||||||
@ -213,14 +213,14 @@ export class DataTokens {
|
|||||||
* @param {String} toAddress
|
* @param {String} toAddress
|
||||||
* @param {String} amount Number of datatokens, as number. Expressed as wei
|
* @param {String} amount Number of datatokens, as number. Expressed as wei
|
||||||
* @param {String} address
|
* @param {String} address
|
||||||
* @return {Promise<string>} transactionId
|
* @return {Promise<TransactionReceipt>} transactionId
|
||||||
*/
|
*/
|
||||||
public async transferWei(
|
public async transferWei(
|
||||||
dataTokenAddress: string,
|
dataTokenAddress: string,
|
||||||
toAddress: string,
|
toAddress: string,
|
||||||
amount: string,
|
amount: string,
|
||||||
address: string
|
address: string
|
||||||
): Promise<string> {
|
): Promise<TransactionReceipt> {
|
||||||
const datatoken = new this.web3.eth.Contract(this.datatokensABI, dataTokenAddress, {
|
const datatoken = new this.web3.eth.Contract(this.datatokensABI, dataTokenAddress, {
|
||||||
from: address
|
from: address
|
||||||
})
|
})
|
||||||
|
@ -5,7 +5,7 @@ import { Ocean } from '../../src/ocean/Ocean'
|
|||||||
import { ConfigHelper } from '../../src/utils/ConfigHelper'
|
import { ConfigHelper } from '../../src/utils/ConfigHelper'
|
||||||
|
|
||||||
import { assert } from 'chai'
|
import { assert } from 'chai'
|
||||||
import { ServiceComputePrivacy } from '../../src/ddo/interfaces/Service'
|
import { ServiceCommon, ServiceComputePrivacy } from '../../src/ddo/interfaces/Service'
|
||||||
import Web3 from 'web3'
|
import Web3 from 'web3'
|
||||||
import factory from '@oceanprotocol/contracts/artifacts/DTFactory.json'
|
import factory from '@oceanprotocol/contracts/artifacts/DTFactory.json'
|
||||||
import datatokensTemplate from '@oceanprotocol/contracts/artifacts/DataTokenTemplate.json'
|
import datatokensTemplate from '@oceanprotocol/contracts/artifacts/DataTokenTemplate.json'
|
||||||
@ -27,14 +27,14 @@ describe('Compute flow', () => {
|
|||||||
let datasetWithTrustedAlgo
|
let datasetWithTrustedAlgo
|
||||||
let algorithmAsset
|
let algorithmAsset
|
||||||
let contracts
|
let contracts
|
||||||
let datatoken
|
let datatoken: DataTokens
|
||||||
let tokenAddress
|
let tokenAddress
|
||||||
let tokenAddressNoRawAlgo
|
let tokenAddressNoRawAlgo
|
||||||
let tokenAddressWithTrustedAlgo
|
let tokenAddressWithTrustedAlgo
|
||||||
let tokenAddressAlgorithm
|
let tokenAddressAlgorithm
|
||||||
let price
|
let price: string
|
||||||
let ocean
|
let ocean
|
||||||
let computeService
|
let computeService: ServiceCommon
|
||||||
let data
|
let data
|
||||||
let blob
|
let blob
|
||||||
let jobId
|
let jobId
|
||||||
@ -77,7 +77,7 @@ describe('Compute flow', () => {
|
|||||||
owner = (await ocean.accounts.list())[0]
|
owner = (await ocean.accounts.list())[0]
|
||||||
alice = (await ocean.accounts.list())[1]
|
alice = (await ocean.accounts.list())[1]
|
||||||
bob = (await ocean.accounts.list())[2]
|
bob = (await ocean.accounts.list())[2]
|
||||||
data = { t: 1, url: ocean.config.metadataStoreUri }
|
data = { t: 1, url: config.metadataStoreUri }
|
||||||
blob = JSON.stringify(data)
|
blob = JSON.stringify(data)
|
||||||
await contracts.deployContracts(owner.getId())
|
await contracts.deployContracts(owner.getId())
|
||||||
})
|
})
|
||||||
|
@ -9,10 +9,10 @@ import { ConfigHelper } from '../../src/utils/ConfigHelper'
|
|||||||
import Web3 from 'web3'
|
import Web3 from 'web3'
|
||||||
import factory from '@oceanprotocol/contracts/artifacts/DTFactory.json'
|
import factory from '@oceanprotocol/contracts/artifacts/DTFactory.json'
|
||||||
import datatokensTemplate from '@oceanprotocol/contracts/artifacts/DataTokenTemplate.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')
|
const web3 = new Web3('http://127.0.0.1:8545')
|
||||||
|
|
||||||
function sleep(ms) {
|
function sleep(ms: number) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
setTimeout(resolve, ms)
|
setTimeout(resolve, ms)
|
||||||
})
|
})
|
||||||
@ -21,19 +21,19 @@ function sleep(ms) {
|
|||||||
use(spies)
|
use(spies)
|
||||||
|
|
||||||
describe('Marketplace flow', () => {
|
describe('Marketplace flow', () => {
|
||||||
let owner
|
let owner: Account
|
||||||
let bob
|
let bob: Account
|
||||||
let ddo
|
let ddo
|
||||||
let alice
|
let alice: Account
|
||||||
let asset
|
let asset
|
||||||
let marketplace
|
let marketplace: Account
|
||||||
let contracts
|
let contracts: TestContractHandler
|
||||||
let datatoken
|
let datatoken: DataTokens
|
||||||
let tokenAddress
|
let tokenAddress: string
|
||||||
let service1
|
let service1: ServiceAccess
|
||||||
let price
|
let price: string
|
||||||
let ocean
|
let ocean: Ocean
|
||||||
let accessService
|
let accessService: ServiceCommon
|
||||||
let data
|
let data
|
||||||
let blob
|
let blob
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ describe('Marketplace flow', () => {
|
|||||||
alice = (await ocean.accounts.list())[1]
|
alice = (await ocean.accounts.list())[1]
|
||||||
bob = (await ocean.accounts.list())[2]
|
bob = (await ocean.accounts.list())[2]
|
||||||
marketplace = (await ocean.accounts.list())[3]
|
marketplace = (await ocean.accounts.list())[3]
|
||||||
data = { t: 1, url: ocean.config.metadataStoreUri }
|
data = { t: 1, url: config.metadataStoreUri }
|
||||||
blob = JSON.stringify(data)
|
blob = JSON.stringify(data)
|
||||||
await contracts.deployContracts(owner.getId())
|
await contracts.deployContracts(owner.getId())
|
||||||
})
|
})
|
||||||
@ -156,8 +156,8 @@ describe('Marketplace flow', () => {
|
|||||||
|
|
||||||
it('Marketplace posts asset for sale', async () => {
|
it('Marketplace posts asset for sale', async () => {
|
||||||
accessService = await ocean.assets.getServiceByType(ddo.id, 'access')
|
accessService = await ocean.assets.getServiceByType(ddo.id, 'access')
|
||||||
price = 20
|
price = '20'
|
||||||
assert.equal(accessService.attributes.main.cost * price, 200)
|
assert.equal(accessService.attributes.main.cost * Number(price), 200)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Bob gets datatokens', async () => {
|
it('Bob gets datatokens', async () => {
|
||||||
@ -199,9 +199,9 @@ describe('Marketplace flow', () => {
|
|||||||
assert(balanceBefore === balanceAfter)
|
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())
|
const assets = await ocean.assets.ownerAssets(alice.getId())
|
||||||
assert(assets.length > 0)
|
assert(assets.results.length > 0)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Alice updates metadata', async () => {
|
it('Alice updates metadata', async () => {
|
||||||
|
@ -3,16 +3,17 @@ import config from './config'
|
|||||||
import { assert } from 'console'
|
import { assert } from 'console'
|
||||||
|
|
||||||
describe('Provider tests', () => {
|
describe('Provider tests', () => {
|
||||||
let ocean
|
let ocean: Ocean
|
||||||
|
|
||||||
it('Initialize Ocean', async () => {
|
it('Initialize Ocean', async () => {
|
||||||
ocean = await Ocean.getInstance(config)
|
ocean = await Ocean.getInstance(config)
|
||||||
})
|
})
|
||||||
it('Alice tests invalid provider', async () => {
|
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)
|
assert(valid === false)
|
||||||
})
|
})
|
||||||
it('Alice tests valid provider', async () => {
|
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)
|
assert(valid === true)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -8,13 +8,14 @@ import datatokensTemplate from '@oceanprotocol/contracts/artifacts/DataTokenTemp
|
|||||||
const web3 = new Web3('http://127.0.0.1:8545')
|
const web3 = new Web3('http://127.0.0.1:8545')
|
||||||
|
|
||||||
describe('Simple flow', () => {
|
describe('Simple flow', () => {
|
||||||
let owner
|
let owner: string
|
||||||
let bob
|
let bob: string
|
||||||
let alice
|
let alice: string
|
||||||
let contracts
|
let contracts: TestContractHandler
|
||||||
let datatoken
|
let datatoken: DataTokens
|
||||||
let tokenAddress
|
let tokenAddress: string
|
||||||
let transactionId
|
let transactionId: string
|
||||||
|
|
||||||
const tokenAmount = '100'
|
const tokenAmount = '100'
|
||||||
const transferAmount = '1'
|
const transferAmount = '1'
|
||||||
const blob = 'http://localhost:8030/api/v1/services/consume'
|
const blob = 'http://localhost:8030/api/v1/services/consume'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user