Skip to content

Commit

Permalink
wip: still work in progress, refactor in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
paulo-ocean committed Feb 16, 2024
1 parent cd9521f commit 23e891d
Show file tree
Hide file tree
Showing 11 changed files with 370 additions and 200 deletions.
2 changes: 1 addition & 1 deletion .mocharc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"full-trace": true,
"bail": true,
"exit": true,
"timeout": 10000,
"timeout": 20000,
"recursive": true,
"require": ["./dist/test/utils/hooks.js"]
}
2 changes: 1 addition & 1 deletion src/test/.env.test
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ IPFS_GATEWAY=https://ipfs.io/
ARWEAVE_GATEWAY=https://arweave.net/
NODE1_PRIVATE_KEY=0xcb345bd2b11264d523ddaf383094e2675c420a17511c3102a53817f13474a7ff
NODE2_PRIVATE_KEY=0x3634cc4a3d2694a1186a7ce545f149e022eea103cc254d18d08675104bb4b5ac
INDEXER_INTERVAL=15000
INDEXER_INTERVAL=9000
201 changes: 108 additions & 93 deletions src/test/integration/completeFlow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import {
ZeroAddress,
parseUnits
} from 'ethers'
import fs from 'fs'
import { homedir } from 'os'
import ERC721Factory from '@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json' assert { type: 'json' }
import ERC721Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC721Template.sol/ERC721Template.json' assert { type: 'json' }
import ERC20Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20TemplateEnterprise.sol/ERC20TemplateEnterprise.json' assert { type: 'json' }
Expand All @@ -20,10 +18,11 @@ import { OceanIndexer } from '../../components/Indexer/index.js'
import { OceanNode } from '../../OceanNode.js'
import { RPCS } from '../../@types/blockchain.js'
import { getEventFromTx, streamToString, streamToObject } from '../../utils/util.js'
import { delay, waitToIndex } from './testUtils.js'
import { delay, expectedTimeoutFailure, waitToIndex } from './testUtils.js'
import { genericDDO } from '../data/ddo.js'
import {
ENVIRONMENT_VARIABLES,
EVENTS,
PROTOCOL_COMMANDS,
getConfiguration
} from '../../utils/index.js'
Expand All @@ -37,6 +36,7 @@ import { UrlFileObject } from '../../@types/fileObject.js'
import { createFee } from '../../components/core/utils/feesHandler.js'
import { DDO } from '../../@types/DDO/DDO.js'
import {
DEFAULT_TEST_TIMEOUT,
OverrideEnvConfig,
buildEnvOverrideConfig,
getMockSupportedNetworks,
Expand Down Expand Up @@ -163,7 +163,6 @@ describe('Should run a complete node flow.', () => {
})

it('should publish a dataset', async function () {
this.timeout(15000) // Extend default Mocha test timeout
const tx = await factoryContract.createNftWithErc20(
{
name: '72120Bundle',
Expand Down Expand Up @@ -264,11 +263,24 @@ describe('Should run a complete node flow.', () => {
assert(trxReceipt, 'set metada failed')
})

delay(50000)

it('should store the ddo in the database and return it ', async () => {
resolvedDDO = await waitToIndex(assetDID, database)
expect(resolvedDDO.id).to.equal(genericAsset.id)
delay(DEFAULT_TEST_TIMEOUT * 2)

it('should store the ddo in the database and return it', async function () {
const timeout = DEFAULT_TEST_TIMEOUT * 3
this.timeout(timeout)
resolvedDDO = await waitToIndex(
assetDID,
EVENTS.METADATA_CREATED,
(ddo: any, wasTimeOut: boolean) => {
if (ddo != null) {
expect(ddo.id).to.equal(genericAsset.id)
} else expect(expectedTimeoutFailure(this.test.title)).to.be.equal(wasTimeOut)
},
timeout
)
if (resolvedDDO) {
expect(resolvedDDO.id).to.equal(genericAsset.id)
}
})

// it('should be able to decrypt the ddo files ', async () => {
Expand Down Expand Up @@ -305,101 +317,104 @@ describe('Should run a complete node flow.', () => {
})

it('should start an order', async function () {
this.timeout(15000) // Extend default Mocha test timeout
try {
const feeToken = '0x312213d6f6b5FCF9F56B7B8946A6C727Bf4Bc21f'
const serviceIndex = '0'
const consumeMarketFeeAddress = ZeroAddress
const consumeMarketFeeAmount = 0
const consumeMarketFeeToken = feeToken

dataTokenContract = new Contract(
datatokenAddress,
ERC20Template.abi,
publisherAccount
)
const feeToken = '0x312213d6f6b5FCF9F56B7B8946A6C727Bf4Bc21f'
const serviceIndex = '0'
const consumeMarketFeeAddress = ZeroAddress
const consumeMarketFeeAmount = 0
const consumeMarketFeeToken = feeToken

dataTokenContract = new Contract(
datatokenAddress,
ERC20Template.abi,
publisherAccount
)

const feeData = await createFee(
resolvedDDO as DDO,
0,
'null',
resolvedDDO.services[0]
)
const feeData = await createFee(
resolvedDDO as DDO,
0,
'null',
resolvedDDO.services[0]
)

// call the mint function on the dataTokenContract
const mintTx = await dataTokenContract.mint(consumerAddress, parseUnits('1000', 18))
await mintTx.wait()
const consumerBalance = await dataTokenContract.balanceOf(consumerAddress)
assert(consumerBalance === parseUnits('1000', 18), 'consumer balance not correct')
// call the mint function on the dataTokenContract
const mintTx = await dataTokenContract.mint(consumerAddress, parseUnits('1000', 18))
await mintTx.wait()
const consumerBalance = await dataTokenContract.balanceOf(consumerAddress)
assert(consumerBalance === parseUnits('1000', 18), 'consumer balance not correct')

const dataTokenContractWithNewSigner = dataTokenContract.connect(
consumerAccount
) as any
const dataTokenContractWithNewSigner = dataTokenContract.connect(
consumerAccount
) as any

const orderTx = await dataTokenContractWithNewSigner.startOrder(
consumerAddress,
serviceIndex,
{
providerFeeAddress: feeData.providerFeeAddress,
providerFeeToken: feeData.providerFeeToken,
providerFeeAmount: feeData.providerFeeAmount,
v: feeData.v,
r: feeData.r,
s: feeData.s,
providerData: feeData.providerData,
validUntil: feeData.validUntil
},
{
consumeMarketFeeAddress,
consumeMarketFeeToken,
consumeMarketFeeAmount
}
)
const orderTxReceipt = await orderTx.wait()
assert(orderTxReceipt, 'order transaction failed')
orderTxId = orderTxReceipt.hash
assert(orderTxId, 'transaction id not found')
} catch (error) {
console.log(error)
}
const orderTx = await dataTokenContractWithNewSigner.startOrder(
consumerAddress,
serviceIndex,
{
providerFeeAddress: feeData.providerFeeAddress,
providerFeeToken: feeData.providerFeeToken,
providerFeeAmount: feeData.providerFeeAmount,
v: feeData.v,
r: feeData.r,
s: feeData.s,
providerData: feeData.providerData,
validUntil: feeData.validUntil
},
{
consumeMarketFeeAddress,
consumeMarketFeeToken,
consumeMarketFeeAmount
}
)
const orderTxReceipt = await orderTx.wait()
assert(orderTxReceipt, 'order transaction failed')
orderTxId = orderTxReceipt.hash
assert(orderTxId, 'transaction id not found')
})

it('should download triger download file', async function () {
this.timeout(65000)
this.timeout(DEFAULT_TEST_TIMEOUT * 3)

const config = await getConfiguration(true)
database = await new Database(config.dbConfig)
const oceanNode = OceanNode.getInstance(database)
assert(oceanNode, 'Failed to instantiate OceanNode')
const doCheck = async () => {
const config = await getConfiguration(true)
database = await new Database(config.dbConfig)
const oceanNode = OceanNode.getInstance(database)
assert(oceanNode, 'Failed to instantiate OceanNode')

const wallet = new ethers.Wallet(
'0xef4b441145c1d0f3b4bc6d61d29f5c6e502359481152f869247c7a4244d45209'
)
const nonce = Date.now().toString()
const message = String(resolvedDDO.id + nonce)
const consumerMessage = ethers.solidityPackedKeccak256(
['bytes'],
[ethers.hexlify(ethers.toUtf8Bytes(message))]
)
const messageHashBytes = ethers.toBeArray(consumerMessage)
const signature = await wallet.signMessage(messageHashBytes)

const downloadTask = {
fileIndex: 0,
documentId: assetDID,
serviceId,
transferTxId: orderTxId,
nonce,
consumerAddress,
signature,
command: PROTOCOL_COMMANDS.DOWNLOAD
const wallet = new ethers.Wallet(
'0xef4b441145c1d0f3b4bc6d61d29f5c6e502359481152f869247c7a4244d45209'
)
const nonce = Date.now().toString()
const message = String(resolvedDDO.id + nonce)
const consumerMessage = ethers.solidityPackedKeccak256(
['bytes'],
[ethers.hexlify(ethers.toUtf8Bytes(message))]
)
const messageHashBytes = ethers.toBeArray(consumerMessage)
const signature = await wallet.signMessage(messageHashBytes)

const downloadTask = {
fileIndex: 0,
documentId: assetDID,
serviceId,
transferTxId: orderTxId,
nonce,
consumerAddress,
signature,
command: PROTOCOL_COMMANDS.DOWNLOAD
}
const response = await new DownloadHandler(oceanNode).handle(downloadTask)

assert(response)
assert(response.stream, 'stream not present')
assert(response.status.httpStatus === 200, 'http status not 200')
expect(response.stream).to.be.instanceOf(Readable)
}
const response = await new DownloadHandler(oceanNode).handle(downloadTask)

assert(response)
assert(response.stream, 'stream not present')
assert(response.status.httpStatus === 200, 'http status not 200')
expect(response.stream).to.be.instanceOf(Readable)
setTimeout(() => {
expect(expectedTimeoutFailure(this.test.title)).to.be.equal(true)
}, DEFAULT_TEST_TIMEOUT * 3)

doCheck()
})

after(async () => {
Expand Down
31 changes: 24 additions & 7 deletions src/test/integration/download.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,19 @@ import {
import { DownloadHandler } from '../../components/core/downloadHandler.js'
import ERC20Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20TemplateEnterprise.sol/ERC20TemplateEnterprise.json' assert { type: 'json' }
import { getEventFromTx } from '../../utils/util.js'
import { waitToIndex, delay } from './testUtils.js'
import { waitToIndex, delay, expectedTimeoutFailure } from './testUtils.js'
import { getConfiguration } from '../../utils/config.js'
import { ProviderFeeData } from '../../@types/Fees.js'
import { encrypt } from '../../utils/crypt.js'
import { createFee } from '../../components/core/utils/feesHandler.js'
import { ENVIRONMENT_VARIABLES, PROTOCOL_COMMANDS } from '../../utils/constants.js'
import {
ENVIRONMENT_VARIABLES,
EVENTS,
PROTOCOL_COMMANDS
} from '../../utils/constants.js'
import { OceanNode } from '../../OceanNode.js'
import {
DEFAULT_TEST_TIMEOUT,
OverrideEnvConfig,
buildEnvOverrideConfig,
getMockSupportedNetworks,
Expand Down Expand Up @@ -190,11 +195,23 @@ describe('Download Tests', () => {
assert(trxReceipt, 'set metada failed')
})

delay(35000)
it('should store the ddo in the database and return it ', async () => {
resolvedDDO = await waitToIndex(assetDID, database)
console.log('resolvedDDO', resolvedDDO)
expect(resolvedDDO.id).to.equal(genericAsset.id)
delay(DEFAULT_TEST_TIMEOUT)
it('should store the ddo in the database and return it', async function () {
const timeout = DEFAULT_TEST_TIMEOUT * 2
resolvedDDO = await waitToIndex(
assetDID,
EVENTS.METADATA_CREATED,
(ddo: any, wasTimeOut: boolean) => {
if (ddo != null) {
expect(ddo.id).to.equal(genericAsset.id)
} else expect(expectedTimeoutFailure(this.test.title)).to.be.equal(true)
},
timeout
)

if (resolvedDDO) {
expect(resolvedDDO.id).to.equal(genericAsset.id)
}
})

it('should update ddo metadata fields ', async () => {
Expand Down
Loading

0 comments on commit 23e891d

Please sign in to comment.