Skip to content

Commit

Permalink
fixed encryptDDO and setEnvs method
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdanfazakas committed Mar 15, 2024
1 parent fcc2bf6 commit fb94862
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"test": "npm run lint && npm run test:unit:cover && npm run test:integration:cover",
"test:unit": "npm run build-tests && npm run mocha \"./dist/test/unit/**/*.test.js\"",
"test:integration": "npm run build-tests && npm run mocha \"./dist/test/integration/**/*.test.js\"",
"test:integration:encryptFile": "npm run build-tests && npm run mocha ./dist/test/integration/encryptFile.test.js",
"test:integration:encryptDecryptDDO": "npm run build-tests && npm run mocha ./dist/test/integration/encryptDecryptDDO.test.js",
"test:unit:cover": "nyc --report-dir coverage/unit npm run test:unit",
"test:integration:cover": "nyc --report-dir coverage/integration --no-clean npm run test:integration",
"logs": "./scripts/logs.sh"
Expand Down
3 changes: 2 additions & 1 deletion src/components/httpRoutes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export * from './getOceanPeers.js'
export const httpRoutes = express.Router()

// P2P routes related
export const hasP2PInterface = await (await getConfiguration()).hasP2P
export const hasP2PInterface = (await (await getConfiguration())?.hasP2P) || false

export function sendMissingP2PResponse(res: Response) {
res.status(400).send('Invalid or Non Existing P2P configuration')
}
Expand Down
28 changes: 16 additions & 12 deletions src/test/integration/encryptDecryptDDO.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
} from '../utils/utils.js'
import { DecryptDDOCommand } from '../../@types/commands.js'
import { EncryptMethod } from '../../@types/fileObject.js'
import { homedir } from 'os'

describe('Should encrypt and decrypt DDO', () => {
let database: Database
Expand Down Expand Up @@ -63,37 +64,40 @@ describe('Should encrypt and decrypt DDO', () => {
let previousConfiguration: OverrideEnvConfig[]

before(async () => {
let artifactsAddresses = getOceanArtifactsAdressesByChainId(DEVELOPMENT_CHAIN_ID)
if (!artifactsAddresses) {
artifactsAddresses = getOceanArtifactsAdresses().development
}

provider = new JsonRpcProvider('http://127.0.0.1:8545')
publisherAccount = (await provider.getSigner(0)) as Signer
publisherAddress = await publisherAccount.getAddress()
genericAsset = genericDDO
factoryContract = new ethers.Contract(
artifactsAddresses.ERC721Factory,
ERC721Factory.abi,
publisherAccount
)

previousConfiguration = await setupEnvironment(
null,
buildEnvOverrideConfig(
[
ENVIRONMENT_VARIABLES.PRIVATE_KEY,
ENVIRONMENT_VARIABLES.RPCS,
ENVIRONMENT_VARIABLES.AUTHORIZED_DECRYPTERS
ENVIRONMENT_VARIABLES.AUTHORIZED_DECRYPTERS,
ENVIRONMENT_VARIABLES.DB_URL,
ENVIRONMENT_VARIABLES.ADDRESS_FILE
],
[
'0xc594c6e5def4bab63ac29eed19a134c130388f74f019bc74b8f4389df2837a58',
JSON.stringify(mockSupportedNetworks),
JSON.stringify([publisherAddress])
JSON.stringify([publisherAddress]),
'http://localhost:8108/?apiKey=xyz',
`${homedir}/.ocean/ocean-contracts/artifacts/address.json`
]
)
)
let artifactsAddresses = getOceanArtifactsAdressesByChainId(DEVELOPMENT_CHAIN_ID)
if (!artifactsAddresses) {
artifactsAddresses = getOceanArtifactsAdresses().development
}

factoryContract = new ethers.Contract(
artifactsAddresses.ERC721Factory,
ERC721Factory.abi,
publisherAccount
)
const dbConfig = {
url: 'http://localhost:8108/?apiKey=xyz'
}
Expand Down
1 change: 1 addition & 0 deletions src/test/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export async function setupEnvironment(
CONFIG_LOGGER.debug('Overriding environment variable: ' + element.name)
element.originalValue = process.env[element.name] // save original value
process.env[element.name] = element.newValue
ENVIRONMENT_VARIABLES[element.name].value = element.newValue
forceReload = true
}
})
Expand Down

0 comments on commit fb94862

Please sign in to comment.