Skip to content

Commit

Permalink
Merge pull request #286 from oceanprotocol/removing-unused-vars
Browse files Browse the repository at this point in the history
Removing unused vars
  • Loading branch information
jamiehewitt15 authored Feb 29, 2024
2 parents 53644c4 + 7ccb16e commit d25ff70
Show file tree
Hide file tree
Showing 15 changed files with 26 additions and 120 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
1 change: 1 addition & 0 deletions src/@types/fileObject.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-unused-vars */
import { Readable } from 'stream'

export interface HeadersObject {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Indexer/index.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
7 changes: 3 additions & 4 deletions src/components/P2P/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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())
Expand Down
3 changes: 1 addition & 2 deletions src/components/core/ddoHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/components/core/utils/feesHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
9 changes: 3 additions & 6 deletions src/test/integration/completeFlow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand Down Expand Up @@ -55,15 +54,13 @@ 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
let nftContract: Contract
let publisherAccount: Signer
let consumerAccount: Signer
let consumerAddress: string
let publisherAddress: string
let dataNftAddress: string
let datatokenAddress: string
let resolvedDDO: Record<string, any>
Expand Down Expand Up @@ -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) {
Expand All @@ -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()

Expand Down
15 changes: 0 additions & 15 deletions src/test/integration/computeFees.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand All @@ -48,9 +44,6 @@ describe('Compute provider fees', async () => {
let assetDID: string
let resolvedDDO: Record<string, any>
let genericAsset: any
let publisherAddress: string
let consumerAccount: Signer
let consumerAddress: string
let datatokenAddress: string
let computeEnvs: Array<any>

Expand All @@ -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,
Expand Down
3 changes: 0 additions & 3 deletions src/test/integration/download.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 1 addition & 4 deletions src/test/integration/encryptDecryptDDO.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/test/integration/encryptFile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
33 changes: 4 additions & 29 deletions src/test/integration/indexer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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()

Expand All @@ -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) {
Expand Down Expand Up @@ -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()
Expand Down
Loading

0 comments on commit d25ff70

Please sign in to comment.