From 5e892acde60a64f46606650854ee5c03a94d792a Mon Sep 17 00:00:00 2001 From: Aitor <1726644+aaitor@users.noreply.github.com> Date: Thu, 20 Oct 2022 19:07:26 +0200 Subject: [PATCH] e2e flows --- resources/networks.json | 10 +++++----- src/commands/accounts/fund.ts | 14 ++++++-------- src/commands/accounts/list.ts | 17 ++++++++--------- src/commands/assets/getAsset.ts | 6 +----- src/commands/assets/registerAsset.ts | 11 +++++++++-- src/commands/nfts/createNft.ts | 2 ++ src/commands/utils/decrypt.ts | 1 - src/utils/config.ts | 2 +- test/helpers/Config.ts | 2 +- test/integration-tests/Assets.test.ts | 23 +++++++++++++++++++++-- 10 files changed, 54 insertions(+), 34 deletions(-) diff --git a/resources/networks.json b/resources/networks.json index e06ee74..47c0276 100644 --- a/resources/networks.json +++ b/resources/networks.json @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", diff --git a/src/commands/accounts/fund.ts b/src/commands/accounts/fund.ts index 7337e20..a0a4f10 100644 --- a/src/commands/accounts/fund.ts +++ b/src/commands/accounts/fund.ts @@ -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()) @@ -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) @@ -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) } } } diff --git a/src/commands/accounts/list.ts b/src/commands/accounts/list.ts index 3941095..8565793 100644 --- a/src/commands/accounts/list.ts +++ b/src/commands/accounts/list.ts @@ -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) ) @@ -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}` ) ) diff --git a/src/commands/assets/getAsset.ts b/src/commands/assets/getAsset.ts index 9b606ca..5834ef2 100644 --- a/src/commands/assets/getAsset.ts +++ b/src/commands/assets/getAsset.ts @@ -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), diff --git a/src/commands/assets/registerAsset.ts b/src/commands/assets/registerAsset.ts index daf40e9..e79921a 100644 --- a/src/commands/assets/registerAsset.ts +++ b/src/commands/assets/registerAsset.ts @@ -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' @@ -29,6 +30,7 @@ export const registerAsset = async ( ): Promise => { const { verbose, metadata, assetType } = argv const token = await loadToken(nvm, config, verbose) + const instanceConfig = { ...generateIntantiableConfigFromConfig(config.nvm), nevermined: nvm, @@ -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( diff --git a/src/commands/nfts/createNft.ts b/src/commands/nfts/createNft.ts index c90a46b..bebce76 100644 --- a/src/commands/nfts/createNft.ts +++ b/src/commands/nfts/createNft.ts @@ -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, @@ -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, diff --git a/src/commands/utils/decrypt.ts b/src/commands/utils/decrypt.ts index 726145c..b85829b 100644 --- a/src/commands/utils/decrypt.ts +++ b/src/commands/utils/decrypt.ts @@ -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 { diff --git a/src/utils/config.ts b/src/utils/config.ts index 5d19d82..770575a 100644 --- a/src/utils/config.ts +++ b/src/utils/config.ts @@ -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) diff --git a/test/helpers/Config.ts b/test/helpers/Config.ts index 68bdf67..3a7f88b 100644 --- a/test/helpers/Config.ts +++ b/test/helpers/Config.ts @@ -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', diff --git a/test/integration-tests/Assets.test.ts b/test/integration-tests/Assets.test.ts index 8364304..9aeaadd 100644 --- a/test/integration-tests/Assets.test.ts +++ b/test/integration-tests/Assets.test.ts @@ -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}`) @@ -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)