1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00

test tweaks

This commit is contained in:
Matthias Kretschmann 2019-10-31 11:23:41 +01:00
parent c772324b34
commit 354149d2d4
Signed by: m
GPG Key ID: 606EEEF3C479A91F
6 changed files with 22 additions and 18 deletions

View File

@ -26,7 +26,7 @@ before_script:
- export KEEPER_VERSION=v0.12.6 - export KEEPER_VERSION=v0.12.6
- export EVENTS_HANDLER_VERSION=v0.1.2 - export EVENTS_HANDLER_VERSION=v0.1.2
- export KEEPER_OWNER_ROLE_ADDRESS="0xe2DD09d719Da89e5a3D0F2549c7E24566e947260" - export KEEPER_OWNER_ROLE_ADDRESS="0xe2DD09d719Da89e5a3D0F2549c7E24566e947260"
- bash -x start_ocean.sh --no-commons --local-spree-node 2>&1 > start_ocean.log & - bash -x start_ocean.sh --no-commons --no-dashboard 2>&1 > start_ocean.log &
- cd .. - cd ..
script: script:

View File

@ -1,9 +1,6 @@
import { assert } from 'chai' import { assert } from 'chai'
import { config } from '../config' import { config } from '../config'
import { getMetadata } from '../utils' import { getMetadata } from '../utils'
import { Ocean, Account } from '../../src' // @oceanprotocol/squid import { Ocean, Account } from '../../src' // @oceanprotocol/squid
describe('Asset Owners', () => { describe('Asset Owners', () => {
@ -25,15 +22,14 @@ describe('Asset Owners', () => {
} }
}) })
it('should be set correctly the owner of an asset', async () => { it('should set the owner of an asset', async () => {
const ddo = await ocean.assets.create(metadata as any, account1) const ddo = await ocean.assets.create(metadata as any, account1)
const owner = await ocean.assets.owner(ddo.id) const owner = await ocean.assets.owner(ddo.id)
assert.equal(owner, account1.getId()) assert.equal(owner, account1.getId())
}) })
it('should be set correctly the provider of an asset', async () => { it('should set the provider of an asset', async () => {
const ddo = await ocean.assets.create(metadata as any, account1) const ddo = await ocean.assets.create(metadata as any, account1)
const isProvider = await ocean.keeper.didRegistry.isDIDProvider( const isProvider = await ocean.keeper.didRegistry.isDIDProvider(
@ -61,7 +57,7 @@ describe('Asset Owners', () => {
assert.equal(finalLength - initialLength, 1) assert.equal(finalLength - initialLength, 1)
}) })
it('should get the assets that can be consumer by a user', async () => { it('should get the assets that can be consumed by a user', async () => {
const { length: initialLength } = await ocean.assets.consumerAssets( const { length: initialLength } = await ocean.assets.consumerAssets(
account2.getId() account2.getId()
) )

View File

@ -20,7 +20,7 @@ export class ContractEvent {
public subscribe( public subscribe(
callback: (events: any[]) => void callback: (events: any[]) => void
): ContractEventSubscription { ): ContractEventSubscription {
const onEvent = async blockNumber => { const onEvent = async (blockNumber: number) => {
const events = await this.contract.getEventData(this.eventName, { const events = await this.contract.getEventData(this.eventName, {
filter: this.filter, filter: this.filter,
fromBlock: blockNumber, fromBlock: blockNumber,

View File

@ -5,7 +5,7 @@ LoggerInstance.setLevel(LogLevel.Error)
export default { export default {
aquariusUri: 'http://localhost:5000', aquariusUri: 'http://localhost:5000',
brizoUri: 'http://localhost:3000', brizoUri: 'http://localhost:8030',
nodeUri: `http://localhost:${process.env.ETH_PORT || 8545}`, nodeUri: `http://localhost:${process.env.ETH_PORT || 8545}`,
parityUri: 'http://localhost:9545', parityUri: 'http://localhost:9545',
secretStoreUri: 'http://localhost:12001', secretStoreUri: 'http://localhost:12001',

View File

@ -22,7 +22,7 @@ describe('ContractEvent', () => {
}) })
describe('#subscribe()', () => { describe('#subscribe()', () => {
it('should listen the events', async () => { it('should be able to listen to events', async () => {
const event = eventHandler.getEvent( const event = eventHandler.getEvent(
ocean.keeper.token, ocean.keeper.token,
'Transfer', 'Transfer',
@ -55,7 +55,7 @@ describe('ContractEvent', () => {
}) })
describe('#once()', () => { describe('#once()', () => {
it('should listen only once', async () => { it('should listen to event only once', async () => {
const to = account const to = account
const event = eventHandler.getEvent( const event = eventHandler.getEvent(
ocean.keeper.token, ocean.keeper.token,
@ -65,7 +65,7 @@ describe('ContractEvent', () => {
let canBeRejected = false let canBeRejected = false
const waitUntilEvent = new Promise((resolve, reject) => { const waitUntilEvent = new Promise((resolve, reject) => {
event.once(events => { event.once(() => {
if (canBeRejected) { if (canBeRejected) {
reject(new Error('')) reject(new Error(''))
} }

View File

@ -4,6 +4,11 @@ import Web3Provider from '../../src/keeper/Web3Provider'
import Logger from '../../src/utils/Logger' import Logger from '../../src/utils/Logger'
import config from '../config' import config from '../config'
interface TestContract extends Contract {
testContract?: boolean
$initialized?: boolean
}
export default class TestContractHandler extends ContractHandler { export default class TestContractHandler extends ContractHandler {
public static async prepareContracts() { public static async prepareContracts() {
const web3 = Web3Provider.getWeb3(config) const web3 = Web3Provider.getWeb3(config)
@ -134,20 +139,23 @@ export default class TestContractHandler extends ContractHandler {
from: string, from: string,
args: any[] = [], args: any[] = [],
tokens: { [name: string]: string } = {} tokens: { [name: string]: string } = {}
): Promise<any & { $initialized: boolean }> { ): Promise<any> {
const where = this.networkId const where = this.networkId
// dont redeploy if there is already something loaded // dont redeploy if there is already something loaded
if (TestContractHandler.hasContract(name, where)) { if (TestContractHandler.hasContract(name, where)) {
const contract = await ContractHandler.getContract(name, where) const contract: TestContract = ContractHandler.getContract(
if ((contract as any).testContract) { name,
where
)
if (contract.testContract) {
return { ...contract, $initialized: true } return { ...contract, $initialized: true }
} }
} }
const web3 = Web3Provider.getWeb3(config) const web3 = Web3Provider.getWeb3(config)
let contractInstance: Contract let contractInstance: TestContract
try { try {
Logger.log('Deploying', name) Logger.log('Deploying', name)
const sendConfig = { const sendConfig = {
@ -188,7 +196,7 @@ export default class TestContractHandler extends ContractHandler {
.initialize(...args) .initialize(...args)
.send(sendConfig) .send(sendConfig)
} }
;(contractInstance as any).testContract = true contractInstance.testContract = true
ContractHandler.setContract(name, where, contractInstance) ContractHandler.setContract(name, where, contractInstance)
// Logger.log("Deployed", name, "at", contractInstance.options.address); // Logger.log("Deployed", name, "at", contractInstance.options.address);
} catch (err) { } catch (err) {