Skip to content

Commit

Permalink
e2e flows
Browse files Browse the repository at this point in the history
  • Loading branch information
aaitor committed Oct 20, 2022
1 parent f4b5a3c commit 5e892ac
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 34 deletions.
10 changes: 5 additions & 5 deletions resources/networks.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"envUrl": "https://nevermined.io/",
"isProduction": false,
"nvm": {
"nodeUri": "",
"nodeUri": "https://matic-mumbai.chainstacklabs.com",
"marketplaceUri": "https://marketplace-api.mumbai.public.nevermined.network",
"faucetUri": "https://faucet.mumbai.public.nevermined.rocks",
"graphHttpUri": "https://api.thegraph.com/subgraphs/name/nevermined-io/public",
Expand All @@ -28,7 +28,7 @@
"envUrl": "https://nevermined.io/",
"isProduction": true,
"nvm": {
"nodeUri": "",
"nodeUri": "https://polygon-rpc.com",
"marketplaceUri": "https://marketplace-api.matic.public.nevermined.network",
"faucetUri": "",
"graphHttpUri": "https://api.thegraph.com/subgraphs/name/nevermined-io/public",
Expand Down Expand Up @@ -166,7 +166,7 @@
"envUrl": "https://defi.v2.portal.mumbai.nevermined.rocks/",
"isProduction": false,
"nvm": {
"nodeUri": "",
"nodeUri": "https://matic-mumbai.chainstacklabs.com",
"marketplaceUri": "https://marketplace-api-public.nevermined.network/",
"faucetUri": "https://faucet.mumbai.public.nevermined.rocks",
"graphHttpUri": "https://api.thegraph.com/subgraphs/name/nevermined-io/common",
Expand All @@ -177,7 +177,7 @@
"nativeToken": "MATIC",
"networkId": "80001",
"networkName": "mumbai",
"contractsVersion": "2.0.5",
"contractsVersion": "2.1.0",
"tagName": "public",
"etherscanUrl": "https://mumbai.polygonscan.com",
"erc20TokenAddress": "0xe11A86849d99F524cAC3E7A0Ec1241828e332C62",
Expand All @@ -190,7 +190,7 @@
"envUrl": "https://portal.autonomies.test.nevermined.rocks",
"isProduction": false,
"nvm": {
"nodeUri": "",
"nodeUri": "https://matic-mumbai.chainstacklabs.com",
"marketplaceUri": "https://marketplace-api.autonomies.test.nevermined.rocks",
"faucetUri": "https://faucet.mumbai.public.nevermined.rocks",
"graphHttpUri": "https://api.thegraph.com/subgraphs/name/nevermined-io/common",
Expand Down
14 changes: 6 additions & 8 deletions src/commands/accounts/fund.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const accountsFund = async (
logger.info(
chalk.dim(`Funding account: '${chalk.whiteBright(account.getId())}'`)
)

if (token === 'both' || token === 'native') {
try {
await nvm.faucet.requestEth(account.getId())
Expand All @@ -34,9 +34,8 @@ export const accountsFund = async (
results.push('native')
} catch (err) {
errorMessage = `Funding Native token to ${chalk.whiteBright(
account.getId()
)} failed! ${(err as Error).message}`
logger.info(chalk.red(errorMessage))
account.getId())} failed!`
logger.error(errorMessage)

if (verbose) {
logger.debug(err)
Expand Down Expand Up @@ -67,12 +66,11 @@ export const accountsFund = async (
results.push('erc20')
} catch (err) {
const erc20ErrorMessage = `Funding ERC20 Tokens to ${chalk.whiteBright(
account.getId()
)} failed! ${(err as Error).message}`
logger.info(chalk.red(erc20ErrorMessage))
account.getId())} failed!`
logger.error(erc20ErrorMessage)
errorMessage = `${errorMessage}, ${erc20ErrorMessage}`
if (verbose) {
logger.info(err)
logger.debug(err)
}
}
}
Expand Down
17 changes: 8 additions & 9 deletions src/commands/accounts/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,13 @@ export const accountsList = async (

const loadedAccounts = await Promise.all(
accounts.map(async (a, index) => {
// const ethBalance = BigNumber.parseEther(
// (await a.getEtherBalance()).toString()
// )
const nativeTokenBalance = BigNumber.parseEther(
(await a.getEtherBalance()).toString()
)
console.log(`NATIVE TOKEN BALANCE ${nativeTokenBalance}`)
const ethBalance = (await a.getEtherBalance()).toString()

const balanceFormatted = BigNumber.formatEther(await a.getEtherBalance())

const ethBalance = BigNumber.parseEther(
balanceFormatted
)

const tokenBalance = (
token ? await token.balanceOf(a.getId()) : BigNumber.from(0)
)
Expand Down Expand Up @@ -132,7 +131,7 @@ export const accountsList = async (
logger.info(
chalk.dim(
`${config.nativeToken} Balance: ${chalk.whiteBright(
a.ethBalance
BigNumber.formatEther(a.ethBalance)
)} ${config.nativeToken}`
)
)
Expand Down
6 changes: 1 addition & 5 deletions src/commands/assets/getAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ export const getAsset = async (
const ddo = await nvm.assets.resolve(did)
const metadata = ddo.findServiceByType('metadata')

let isDTP = false
metadata.attributes.main.files?.forEach( _f => {
if (_f.encryption === 'dtp')
isDTP = true
})
const isDTP = metadata.attributes.main.files?.some( _f => _f.encryption === 'dtp')

const instanceConfig = {
...generateIntantiableConfigFromConfig(config.nvm),
Expand Down
11 changes: 9 additions & 2 deletions src/commands/assets/registerAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
printTokenBanner,
loadToken,
loadNeverminedConfigContract,
getFeesFromBigNumber
getFeesFromBigNumber,
DEFAULT_ENCRYPTION_METHOD
} from '../../utils'
import chalk from 'chalk'
import { File, MetaData, MetaDataMain } from '@nevermined-io/nevermined-sdk-js'
Expand All @@ -29,6 +30,7 @@ export const registerAsset = async (
): Promise<ExecutionOutput> => {
const { verbose, metadata, assetType } = argv
const token = await loadToken(nvm, config, verbose)

const instanceConfig = {
...generateIntantiableConfigFromConfig(config.nvm),
nevermined: nvm,
Expand Down Expand Up @@ -133,7 +135,12 @@ export const registerAsset = async (
ddoMetadata,
account,
assetRewards,
['access']
['access'],
[],
DEFAULT_ENCRYPTION_METHOD,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
[config.nvm.gatewayAddress!],
token ? token.getAddress() : config.erc20TokenAddress
)

const register = (await nvm.keeper.didRegistry.getDIDRegister(
Expand Down
2 changes: 2 additions & 0 deletions src/commands/nfts/createNft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export const createNft = async (
argv.nftAddress,
token ? token.getAddress() : config.erc20TokenAddress,
argv.preMint,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
[config.nvm.gatewayAddress!],
royaltyAttributes,
argv.nftMetadata,
Expand All @@ -157,6 +158,7 @@ export const createNft = async (
assetRewards,
DEFAULT_ENCRYPTION_METHOD,
argv.cap,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
[config.nvm.gatewayAddress!],
BigNumber.from(1),
royaltyAttributes,
Expand Down
1 change: 0 additions & 1 deletion src/commands/utils/decrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export const decryptFile = async (

const filePathDecrypted = file + '.decrypted'
fs.writeFileSync(filePathDecrypted, decrypted)
logger.info(`File decrypted successfully`)
logger.info(filePathDecrypted)

return {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export function getConfig(

if (!defaultConfig) throw new Error(`Network '${network}' is not supported`)

const config = defaultConfig
const config = defaultConfig

if (process.env.NODE_URL) config.nvm.nodeUri = process.env.NODE_URL
if (process.env.MARKETPLACE_API_URL)
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const VERBOSE = '-v'
export const metadataConfig = {
name: 'CLI Testing Dataset #' + generateId(),
author: 'Nevermined CLI',
price: 10,
price: 1,
url: 'https://www.apache.org/licenses/LICENSE-2.0',
contentType: 'text/plain',
metadataFile: 'test/resources/example-1.json',
Expand Down
23 changes: 21 additions & 2 deletions test/integration-tests/Assets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,26 @@ describe('Assets e2e Testing', () => {

beforeAll(async () => {
console.log(`NETWORK: ${execOpts.env.NETWORK}`)

try {
if (
execOpts.env.NETWORK === 'spree' ||
execOpts.env.NETWORK === 'geth-localnet' ||
execOpts.env.NETWORK === 'polygon-localnet'
) {
console.log(
`Funding accounts: ${execOpts.accounts[0]} + ${execOpts.accounts[1]}`
)

let fundCommand = `${baseCommands.accounts.fund} "${execOpts.accounts[0]}" --token both`
console.log(fundCommand)
console.log(execCommand(fundCommand, execOpts))
fundCommand = `${baseCommands.accounts.fund} "${execOpts.accounts[1]}" --token both`
console.log(fundCommand)
console.log(execCommand(fundCommand, execOpts))
}
} catch (error) {
console.warn(`Unable to fund accounts`)
}
const registerAssetCommand = `${baseCommands.assets.registerAsset} --accountIndex 0 --name "${metadataConfig.name}" --author "${metadataConfig.author}" --price "${metadataConfig.price}" --urls ${metadataConfig.url} --contentType ${metadataConfig.contentType}`
console.debug(`COMMAND: ${registerAssetCommand}`)

Expand Down Expand Up @@ -107,7 +126,7 @@ describe('Assets e2e Testing', () => {
})

test('Order and download an asset', async () => {
const orderCommand = `${baseCommands.assets.orderAsset} ${did} --accountIndex 0 `
const orderCommand = `${baseCommands.assets.orderAsset} ${did} --accountIndex 1 `
console.debug(`COMMAND: ${orderCommand}`)

const orderStdout = execCommand(orderCommand, execOpts)
Expand Down

0 comments on commit 5e892ac

Please sign in to comment.