diff --git a/.eslintrc b/.eslintrc index 3f4e014fe..ce57dcef9 100644 --- a/.eslintrc +++ b/.eslintrc @@ -13,7 +13,7 @@ "prefer-destructuring": ["warn", { "object": true, "array": false }], "no-dupe-class-members": ["warn"], "no-useless-constructor": ["warn"], - "no-unused-vars": ["warn"], + "no-unused-vars": ["error"], "constructor-super": ["warn"] }, "env": { diff --git a/src/@types/fileObject.ts b/src/@types/fileObject.ts index 13489a276..40e07678f 100644 --- a/src/@types/fileObject.ts +++ b/src/@types/fileObject.ts @@ -1,3 +1,4 @@ +/* eslint-disable no-unused-vars */ import { Readable } from 'stream' export interface HeadersObject { diff --git a/src/components/Indexer/index.ts b/src/components/Indexer/index.ts index 16cf6844d..335a6bf6d 100644 --- a/src/components/Indexer/index.ts +++ b/src/components/Indexer/index.ts @@ -1,5 +1,5 @@ import EventEmitter from 'node:events' -import { Worker, workerData } from 'node:worker_threads' +import { Worker } from 'node:worker_threads' import { Database } from '../database/index.js' import { RPCS, SupportedNetwork } from '../../@types/blockchain.js' import { ReindexTask } from './crawlerThread.js' diff --git a/src/components/P2P/handlers.ts b/src/components/P2P/handlers.ts index b975baab6..551560777 100644 --- a/src/components/P2P/handlers.ts +++ b/src/components/P2P/handlers.ts @@ -3,7 +3,7 @@ export * from './handleProtocolCommands.js' export function handlePeerConnect(details: any) { if (details) { - const peerId = details.detail + // const peerId = details.detail // console.log('Connection established to:', peerId.toString()) // Emitted when a peer has been found /* try{ @@ -21,15 +21,14 @@ export function handlePeerConnect(details: any) { } export function handlePeerDisconnect(details: any) { - const peerId = details.detail + // const peerId = details.detail // console.log('Connection closed to:', peerId.toString()) // Emitted when a peer has been found } export function handlePeerDiscovery(details: any) { - const peerInfo = details.detail + // const peerInfo = details.detail // console.log('Discovered new peer:', peerInfo.id.toString()) // console.log(details.detail) - /* try{ //this._libp2p.services.pubsub.connect(peerInfo.id.toString()) diff --git a/src/components/core/ddoHandler.ts b/src/components/core/ddoHandler.ts index 2ac7e2150..556f8bfa9 100644 --- a/src/components/core/ddoHandler.ts +++ b/src/components/core/ddoHandler.ts @@ -17,7 +17,7 @@ import { CORE_LOGGER } from '../../utils/logging/common.js' import { Blockchain } from '../../utils/blockchain.js' import ERC721Factory from '@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json' assert { type: 'json' } import { getOceanArtifactsAdressesByChainId } from '../../utils/address.js' -import { ethers, hexlify } from 'ethers' +import { ethers } from 'ethers' import ERC721Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC721Template.sol/ERC721Template.json' assert { type: 'json' } import { decrypt, create256Hash } from '../../utils/crypt.js' import lzma from 'lzma-native' @@ -30,7 +30,6 @@ import { ValidateDDOCommand } from '../../@types/commands.js' import { hasP2PInterface } from '../httpRoutes/index.js' -import { getProviderWallet } from './utils/feesHandler' import { EncryptMethod } from '../../@types/fileObject.js' const MAX_NUM_PROVIDERS = 5 diff --git a/src/components/core/utils/feesHandler.ts b/src/components/core/utils/feesHandler.ts index be8cbe57a..6557d0f26 100644 --- a/src/components/core/utils/feesHandler.ts +++ b/src/components/core/utils/feesHandler.ts @@ -294,13 +294,13 @@ export async function createFee( // ethers.toBeArray(messageHash).length // ) - const signableHash = ethers.solidityPackedKeccak256( - ['bytes'], - [ethers.toUtf8Bytes(messageHash)] + // const signableHash = ethers.solidityPackedKeccak256( + // ['bytes'], + // [ethers.toUtf8Bytes(messageHash)] - // OR ethers.utils.hashMessage(ethers.utils.concat([ hash, string, address ]) - // https://github.com/ethers-io/ethers.js/issues/468 - ) + // // OR ethers.utils.hashMessage(ethers.utils.concat([ hash, string, address ]) + // // https://github.com/ethers-io/ethers.js/issues/468 + // ) // *** NOTE: provider.py *** // pk = keys.PrivateKey(provider_wallet.key) diff --git a/src/index.ts b/src/index.ts index 3dfe7cf6c..d028a165b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,7 +16,9 @@ const app: Express = express() // const port = getRandomInt(6000,6500) declare global { + // eslint-disable-next-line no-unused-vars namespace Express { + // eslint-disable-next-line no-unused-vars interface Request { oceanNode: OceanNode } diff --git a/src/test/integration/completeFlow.test.ts b/src/test/integration/completeFlow.test.ts index 4b00c96b2..3c9af6b60 100644 --- a/src/test/integration/completeFlow.test.ts +++ b/src/test/integration/completeFlow.test.ts @@ -8,8 +8,7 @@ import { getAddress, hexlify, ZeroAddress, - parseUnits, - MaxUint256 + parseUnits } from 'ethers' 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' } @@ -55,7 +54,6 @@ describe('Should run a complete node flow.', () => { let config: OceanNodeConfig let database: Database let oceanNode: OceanNode - let indexer: OceanIndexer let provider: JsonRpcProvider let factoryContract: Contract let dataTokenContract: Contract @@ -63,7 +61,6 @@ describe('Should run a complete node flow.', () => { let publisherAccount: Signer let consumerAccount: Signer let consumerAddress: string - let publisherAddress: string let dataNftAddress: string let datatokenAddress: string let resolvedDDO: Record @@ -100,7 +97,8 @@ describe('Should run a complete node flow.', () => { database = await new Database(config.dbConfig) oceanNode = await OceanNode.getInstance(database) - indexer = new OceanIndexer(database, mockSupportedNetworks) + // eslint-disable-next-line no-unused-vars + const indexer = new OceanIndexer(database, mockSupportedNetworks) let network = getOceanArtifactsAdressesByChainId(DEVELOPMENT_CHAIN_ID) if (!network) { @@ -110,7 +108,6 @@ describe('Should run a complete node flow.', () => { provider = new JsonRpcProvider('http://127.0.0.1:8545') publisherAccount = (await provider.getSigner(0)) as Signer - publisherAddress = await publisherAccount.getAddress() consumerAccount = (await provider.getSigner(1)) as Signer consumerAddress = await consumerAccount.getAddress() diff --git a/src/test/integration/computeFees.test.ts b/src/test/integration/computeFees.test.ts index 0dc50dd2b..3c76b849e 100644 --- a/src/test/integration/computeFees.test.ts +++ b/src/test/integration/computeFees.test.ts @@ -11,8 +11,6 @@ import { } from 'ethers' 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 { Database } from '../../components/database/index.js' -import { OceanIndexer } from '../../components/Indexer/index.js' import { RPCS } from '../../@types/blockchain.js' import { genericDDO } from '../data/ddo.js' import { getOceanArtifactsAdresses } from '../../utils/address.js' @@ -37,8 +35,6 @@ import { DDO } from '../../@types/DDO/DDO.js' import { EncryptMethod } from '../../@types/fileObject.js' describe('Compute provider fees', async () => { - let database: Database - let indexer: OceanIndexer let provider: JsonRpcProvider let factoryContract: Contract let nftContract: Contract @@ -48,9 +44,6 @@ describe('Compute provider fees', async () => { let assetDID: string let resolvedDDO: Record let genericAsset: any - let publisherAddress: string - let consumerAccount: Signer - let consumerAddress: string let datatokenAddress: string let computeEnvs: Array @@ -68,17 +61,9 @@ describe('Compute provider fees', async () => { [JSON.stringify(mockSupportedNetworks), JSON.stringify({ 8996: oceanToken })] ) ) - const dbConfig = { - url: 'http://localhost:8108/?apiKey=xyz' - } - database = await new Database(dbConfig) - indexer = new OceanIndexer(database, mockSupportedNetworks) provider = new JsonRpcProvider('http://127.0.0.1:8545') - consumerAccount = (await provider.getSigner(1)) as Signer publisherAccount = (await provider.getSigner(0)) as Signer - publisherAddress = await publisherAccount.getAddress() - consumerAddress = await consumerAccount.getAddress() genericAsset = genericDDO factoryContract = new ethers.Contract( data.development.ERC721Factory, diff --git a/src/test/integration/download.test.ts b/src/test/integration/download.test.ts index a1addc459..40e2923b6 100644 --- a/src/test/integration/download.test.ts +++ b/src/test/integration/download.test.ts @@ -14,7 +14,6 @@ import { 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 { Database } from '../../components/database/index.js' -import { OceanIndexer } from '../../components/Indexer/index.js' import { RPCS } from '../../@types/blockchain.js' import { genericDDO } from '../data/ddo.js' import { @@ -48,7 +47,6 @@ import { EncryptMethod } from '../../@types/fileObject.js' describe('Download Tests', () => { let database: Database - let indexer: OceanIndexer let provider: JsonRpcProvider let factoryContract: Contract let nftContract: Contract @@ -82,7 +80,6 @@ describe('Download Tests', () => { url: 'http://localhost:8108/?apiKey=xyz' } database = await new Database(dbConfig) - indexer = new OceanIndexer(database, mockSupportedNetworks) let network = getOceanArtifactsAdressesByChainId(DEVELOPMENT_CHAIN_ID) if (!network) { diff --git a/src/test/integration/encryptDecryptDDO.test.ts b/src/test/integration/encryptDecryptDDO.test.ts index 189203581..0d5d33960 100644 --- a/src/test/integration/encryptDecryptDDO.test.ts +++ b/src/test/integration/encryptDecryptDDO.test.ts @@ -22,8 +22,7 @@ import { createHash } from 'crypto' import { encrypt } from '../../utils/crypt.js' import { Database } from '../../components/database/index.js' import { DecryptDdoHandler } from '../../components/core/ddoHandler.js' -import { ENVIRONMENT_VARIABLES, getConfiguration } from '../../utils/index.js' -import { OceanNodeConfig } from '../../@types/OceanNode.js' +import { ENVIRONMENT_VARIABLES } from '../../utils/index.js' import { Readable } from 'stream' import { OceanNode } from '../../OceanNode.js' import { @@ -36,7 +35,6 @@ import { DecryptDDOCommand } from '../../@types/commands.js' import { EncryptMethod } from '../../@types/fileObject.js' describe('Should encrypt and decrypt DDO', () => { - let config: OceanNodeConfig let database: Database let oceanNode: OceanNode let provider: JsonRpcProvider @@ -99,7 +97,6 @@ describe('Should encrypt and decrypt DDO', () => { const dbConfig = { url: 'http://localhost:8108/?apiKey=xyz' } - config = await getConfiguration(true) database = await new Database(dbConfig) oceanNode = OceanNode.getInstance(database) // will be used later diff --git a/src/test/integration/encryptFile.test.ts b/src/test/integration/encryptFile.test.ts index 9c1c47042..676888524 100644 --- a/src/test/integration/encryptFile.test.ts +++ b/src/test/integration/encryptFile.test.ts @@ -5,7 +5,6 @@ import { OceanNode } from '../../OceanNode.js' import { PROTOCOL_COMMANDS } from '../../utils/constants.js' import { OceanNodeConfig } from '../../@types/OceanNode.js' import { Readable } from 'stream' -import { streamToString } from '../../utils/util.js' import { EncryptFileHandler } from '../../components/core/encryptHandler.js' import { EncryptFileCommand } from '../../@types/commands' import { EncryptMethod, FileObjectType } from '../../@types/fileObject.js' diff --git a/src/test/integration/indexer.test.ts b/src/test/integration/indexer.test.ts index cf26a47be..249e56d86 100644 --- a/src/test/integration/indexer.test.ts +++ b/src/test/integration/indexer.test.ts @@ -8,8 +8,6 @@ import { getAddress, hexlify, ZeroAddress, - toUtf8Bytes, - solidityPackedKeccak256, parseUnits } from 'ethers' import ERC721Factory from '@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json' assert { type: 'json' } @@ -19,7 +17,7 @@ import { Database } from '../../components/database/index.js' import { OceanIndexer } from '../../components/Indexer/index.js' import { RPCS } from '../../@types/blockchain.js' import { getEventFromTx } from '../../utils/util.js' -import { waitToIndex, signMessage, expectedTimeoutFailure } from './testUtils.js' +import { waitToIndex, expectedTimeoutFailure } from './testUtils.js' import { genericDDO } from '../data/ddo.js' import { DEVELOPMENT_CHAIN_ID, @@ -33,11 +31,9 @@ import { EVENTS } from '../../utils/constants.js' describe('Indexer stores a new metadata events and orders.', () => { let database: Database - let indexer: OceanIndexer let provider: JsonRpcProvider let factoryContract: Contract let nftContract: Contract - let datatokenContract: Contract let publisherAccount: Signer let consumerAccount: Signer let nftAddress: string @@ -50,22 +46,14 @@ describe('Indexer stores a new metadata events and orders.', () => { let orderTxId: string let reuseOrderTxId: string let dataTokenContractWithNewSigner: any - let signedMessage: { v: string; r: string; s: string } - let message: string - let providerData: string let orderEvent: any let reusedOrderEvent: any let initialOrderCount: number - const timeout = 0 const feeToken = '0x312213d6f6b5FCF9F56B7B8946A6C727Bf4Bc21f' - const providerFeeAddress = ZeroAddress // publisherAddress - const providerFeeToken = feeToken const serviceIndex = 0 // dummy index - const providerFeeAmount = 0 // fee to be collected on top, requires approval const consumeMarketFeeAddress = ZeroAddress // marketplace fee Collector const consumeMarketFeeAmount = 0 // fee to be collected on top, requires approval - const consumeMarketFeeToken = feeToken // token address for the feeAmount, - const providerValidUntil = 0 + const consumeMarketFeeToken = feeToken // token address for the feeAmount const mockSupportedNetworks: RPCS = getMockSupportedNetworks() @@ -74,7 +62,8 @@ describe('Indexer stores a new metadata events and orders.', () => { url: 'http://localhost:8108/?apiKey=xyz' } database = await new Database(dbConfig) - indexer = new OceanIndexer(database, mockSupportedNetworks) + // eslint-disable-next-line no-unused-vars + const indexer = new OceanIndexer(database, mockSupportedNetworks) let artifactsAddresses = getOceanArtifactsAdressesByChainId(DEVELOPMENT_CHAIN_ID) if (!artifactsAddresses) { @@ -279,20 +268,6 @@ describe('Indexer stores a new metadata events and orders.', () => { resolvedDDO.services[0] ) - // sign provider data - providerData = JSON.stringify({ timeout }) - message = solidityPackedKeccak256( - ['bytes', 'address', 'address', 'uint256', 'uint256'], - [ - hexlify(toUtf8Bytes(providerData)), - providerFeeAddress, - providerFeeToken, - providerFeeAmount, - providerValidUntil - ] - ) - signedMessage = await signMessage(message, publisherAddress, provider) - // call the mint function on the dataTokenContract const mintTx = await dataTokenContract.mint(consumerAddress, parseUnits('1000', 18)) await mintTx.wait() diff --git a/src/test/integration/transactionValidation.test.ts b/src/test/integration/transactionValidation.test.ts index bfbad2a99..dd02fbc9d 100644 --- a/src/test/integration/transactionValidation.test.ts +++ b/src/test/integration/transactionValidation.test.ts @@ -6,8 +6,6 @@ import { ethers, getAddress, hexlify, - toUtf8Bytes, - solidityPackedKeccak256, parseUnits, ZeroAddress } from 'ethers' @@ -17,7 +15,7 @@ import ERC721Factory from '@oceanprotocol/contracts/artifacts/contracts/ERC721Fa 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' } import { getEventFromTx } from '../../utils/util.js' -import { expectedTimeoutFailure, signMessage, waitToIndex } from './testUtils.js' +import { expectedTimeoutFailure, waitToIndex } from './testUtils.js' import { genericDDO } from '../data/ddo.js' import { Database } from '../../components/database/index.js' import { @@ -27,13 +25,11 @@ import { } from '../../utils/address.js' import { createFee } from '../../components/core/utils/feesHandler.js' import { DDO } from '../../@types/DDO/DDO.js' -import { DEFAULT_TEST_TIMEOUT, getMockSupportedNetworks } from '../utils/utils.js' +import { DEFAULT_TEST_TIMEOUT } from '../utils/utils.js' import { EVENTS } from '../../utils/constants.js' -import { OceanIndexer } from '../../components/Indexer/index.js' describe('validateOrderTransaction Function with Orders', () => { let database: Database - let indexer: OceanIndexer let provider: JsonRpcProvider let factoryContract: Contract let nftContract: Contract @@ -45,26 +41,15 @@ describe('validateOrderTransaction Function with Orders', () => { let consumerAddress: string let dataNftAddress: string let datatokenAddress: string - let message: string - let providerData: string let orderTxId: string let dataTokenContractWithNewSigner: any - let signedMessage: { - v: string - r: string - s: string - } let resolvedDDO: any const feeToken = '0x312213d6f6b5FCF9F56B7B8946A6C727Bf4Bc21f' - const providerFeeAddress = ZeroAddress // publisherAddress - const providerFeeToken = feeToken const serviceId = '0' // dummy index - const providerFeeAmount = 0 // fee to be collected on top, requires approval const consumeMarketFeeAddress = ZeroAddress // marketplace fee Collector const consumeMarketFeeAmount = 0 // fee to be collected on top, requires approval const consumeMarketFeeToken = feeToken // token address for the feeAmount, - const providerValidUntil = 0 const timeout = 0 before(async () => { @@ -84,9 +69,6 @@ describe('validateOrderTransaction Function with Orders', () => { } database = await new Database(dbConfig) - // need to make sure there is an indexer running on the test suite - indexer = new OceanIndexer(database, getMockSupportedNetworks()) - // Initialize the factory contract factoryContract = new ethers.Contract( artifactsAddresses.ERC721Factory, @@ -195,20 +177,6 @@ describe('validateOrderTransaction Function with Orders', () => { resolvedDDO.services[0] ) - // sign provider data - providerData = JSON.stringify({ timeout }) - message = solidityPackedKeccak256( - ['bytes', 'address', 'address', 'uint256', 'uint256'], - [ - hexlify(toUtf8Bytes(providerData)), - feeData.providerFeeAddress, - feeData.providerFeeToken, - feeData.providerFeeAmount, - feeData.validUntil - ] - ) - signedMessage = await signMessage(message, publisherAddress, provider) - // call the mint function on the dataTokenContract const mintTx = await dataTokenContract.mint(consumerAddress, parseUnits('1000', 18)) await mintTx.wait() @@ -270,20 +238,6 @@ describe('validateOrderTransaction Function with Orders', () => { // git status dataTokenContractWithNewSigner = dataTokenContract.connect(consumerAccount) as any - // sign provider data - providerData = JSON.stringify({ timeout }) - message = solidityPackedKeccak256( - ['bytes', 'address', 'address', 'uint256', 'uint256'], - [ - hexlify(toUtf8Bytes(providerData)), - feeData.providerFeeAddress, - feeData.providerFeeToken, - feeData.providerFeeAmount, - feeData.validUntil - ] - ) - signedMessage = await signMessage(message, publisherAddress, provider) - const orderTx = await dataTokenContractWithNewSigner.reuseOrder( orderTxId, { diff --git a/src/test/unit/logging.test.ts b/src/test/unit/logging.test.ts index e5359ebad..8b1534d9a 100644 --- a/src/test/unit/logging.test.ts +++ b/src/test/unit/logging.test.ts @@ -49,6 +49,7 @@ describe('Logger instances and transports tests', async () => { expect(process.env.NODE_ENV).to.be.equal('production') // will build the DB transport layer const config = await getConfiguration(true) + // eslint-disable-next-line no-unused-vars const DB = new Database(config.dbConfig) // Could generate Typesene error if DB is not running, but does not matter for this test OCEAN_NODE_LOGGER.logMessage('Should build DB transport layer')