1
0
mirror of https://github.com/oceanprotocol/ocean.js.git synced 2024-11-26 20:39:05 +01:00

test/unit/AssetUtils.test.ts

This commit is contained in:
paulo-ocean 2024-09-09 12:46:47 +01:00
parent df2d5dd054
commit 13827001e8

View File

@ -17,19 +17,9 @@ import { DispenserCreationParams } from '../@types/Dispenser'
import { FreCreationParams } from '../@types/FixedPrice' import { FreCreationParams } from '../@types/FixedPrice'
import { getEventFromTx } from './ContractUtils' import { getEventFromTx } from './ContractUtils'
import { ProviderInstance } from '../services/Provider' import { ProviderInstance } from '../services/Provider'
import { HardhatEthersHelpers } from '@nomiclabs/hardhat-ethers/types'
import { HardhatRuntimeEnvironment } from 'hardhat/types'
import hre from 'hardhat'
// eslint-disable-next-line import/no-named-default // eslint-disable-next-line import/no-named-default
import ERC20Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json' import ERC20Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json'
console.log('ABI', ERC20Template.abi)
const hardhatEthers = hre as HardhatRuntimeEnvironment & { ethers: any } & {
ethers: typeof ethers & HardhatEthersHelpers
}
// import * as hre from 'hardhat' // import * as hre from 'hardhat'
export const DEVELOPMENT_CHAIN_ID = 8996 export const DEVELOPMENT_CHAIN_ID = 8996
@ -128,7 +118,7 @@ export async function calculateTemplateIndex(
``` ```
*/ */
export async function calculateTemplateIndexV2( export async function calculateActiveTemplateIndex(
owner: Signer, owner: Signer,
nftContractAddress: string, // addresses.ERC721Factory, nftContractAddress: string, // addresses.ERC721Factory,
template: string | number template: string | number
@ -142,7 +132,6 @@ export async function calculateTemplateIndexV2(
const tokenTemplate = await factoryERC721.getTokenTemplate(i) const tokenTemplate = await factoryERC721.getTokenTemplate(i)
console.log('\n\n------------\ntemplateIndex:' + i) console.log('\n\n------------\ntemplateIndex:' + i)
console.log(tokenTemplate) console.log(tokenTemplate)
console.log('hardhatEthers', hardhatEthers)
// const artifact = await hre.artifacts.readArtifact('ERC20Template') // const artifact = await hre.artifacts.readArtifact('ERC20Template')
const erc20Template = new ethers.Contract( const erc20Template = new ethers.Contract(
@ -150,18 +139,8 @@ export async function calculateTemplateIndexV2(
ERC20Template.abi, ERC20Template.abi,
owner owner
) )
// const erc20Template = await getContractAtFromArtifact(
// hre,
// artifact,
// tokenTemplate.templateAddress,
// owner
// )
console.log('erc20Template: ', erc20Template) console.log('erc20Template: ', erc20Template)
// hardhatEthers.ethers.getContractAt(
// 'ERC20Template',
// tokenTemplate.templateAddress
// )
// check for ID // check for ID
if (isTemplateID) { if (isTemplateID) {
const id = await erc20Template.connect(owner).getId() const id = await erc20Template.connect(owner).getId()
@ -220,15 +199,15 @@ export async function createAsset(
const config = new ConfigHelper().getConfig(parseInt(String(chainID))) const config = new ConfigHelper().getConfig(parseInt(String(chainID)))
let templateIndex = await calculateTemplateIndex(chainID, template) // let templateIndex = await calculateTemplateIndexOld(chainID, template)
const templateIndexV2 = await calculateTemplateIndexV2( let templateIndex = await calculateActiveTemplateIndex(
owner, owner,
nftContractAddress, nftContractAddress,
template template
) )
console.log('first template index:', templateIndex) console.log('first template index:', templateIndex)
console.log('last template index:', templateIndexV2) // console.log('last template index:', templateIndexV2)
if (templateIndex < 1) { if (templateIndex < 1) {
// for testing purposes only // for testing purposes only
if (chainID === DEVELOPMENT_CHAIN_ID) { if (chainID === DEVELOPMENT_CHAIN_ID) {