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

some refactor and commenst

This commit is contained in:
paulo-ocean 2024-09-10 14:57:19 +01:00
parent fb810795d0
commit d9bbaff8e1
2 changed files with 15 additions and 14 deletions

View File

@ -72,12 +72,13 @@ export function getOceanArtifactsAdressesByChainId(chain: number): any {
} }
/** /**
* Use this function if don't need to check if the template if active * Use this function if don't need to check if the template if active
* (not 100% reliable if we need to check at smart contract level)
* @param chainID the chain identifier * @param chainID the chain identifier
* @param template the id or the template address * @param template the id or the template address
* @returns the index of the template from the 'ERC20Template' object * @returns the index of the template from the 'ERC20Template' object
*/ */
export async function calculateTemplateIndex( export async function getTemplateIndexOnList(
chainID: number, chainID: number,
template: string | number template: string | number
): Promise<number> { ): Promise<number> {
@ -111,8 +112,8 @@ export async function calculateTemplateIndex(
* Use this function to accurately calculate the template index, and also checking if the template is active * Use this function to accurately calculate the template index, and also checking if the template is active
* @param owner the signer account * @param owner the signer account
* @param nftContractAddress the nft contract address, usually artifactsAddresses.ERC721Factory * @param nftContractAddress the nft contract address, usually artifactsAddresses.ERC721Factory
* @param template the template ID or template address * @param template the template ID or template address (from smart contract getId() function)
* @returns index of the template * @returns index of the template on the list
*/ */
export async function calculateActiveTemplateIndex( export async function calculateActiveTemplateIndex(
owner: Signer, owner: Signer,

View File

@ -3,7 +3,7 @@ import { KNOWN_CONFIDENTIAL_EVMS } from '../../src/config'
import { provider, getAddresses } from '../config' import { provider, getAddresses } from '../config'
import { import {
calculateActiveTemplateIndex, calculateActiveTemplateIndex,
calculateTemplateIndex, getTemplateIndexOnList,
isConfidentialEVM isConfidentialEVM
} from '../../src/utils' } from '../../src/utils'
import { Signer } from 'ethers/lib/ethers' import { Signer } from 'ethers/lib/ethers'
@ -42,25 +42,25 @@ describe('Asset utils (createAsset)', () => {
}) })
it('should get correct template index from contract artifacts (using SC address as template)', async () => { it('should get correct template index from contract artifacts (using SC address as template)', async () => {
const wrongOne = await calculateTemplateIndex( const wrongOne = await getTemplateIndexOnList(
KNOWN_CONFIDENTIAL_EVMS.networks[1].chainId, // testnet chain KNOWN_CONFIDENTIAL_EVMS.networks[1].chainId, // testnet chain
'12' '12'
) )
assert(wrongOne === -1, 'wrong template index, should be inexistent!') assert(wrongOne === -1, 'wrong template index, should be inexistent!')
const okIndex = await calculateTemplateIndex( const okIndex = await getTemplateIndexOnList(
KNOWN_CONFIDENTIAL_EVMS.networks[0].chainId, // mainnet chain KNOWN_CONFIDENTIAL_EVMS.networks[0].chainId, // mainnet chain
'0x4dD281EB67DED07E76E413Df16176D66ae69e240' '0x4dD281EB67DED07E76E413Df16176D66ae69e240'
) )
assert(okIndex >= 1, 'wrong template index, should exist!') assert(okIndex >= 1, 'wrong template index, should exist!')
const okIndexNonConfidential = await calculateTemplateIndex( const okIndexNonConfidential = await getTemplateIndexOnList(
11155111, // sepolia 11155111, // sepolia
'0xDEfD0018969cd2d4E648209F876ADe184815f038' '0xDEfD0018969cd2d4E648209F876ADe184815f038'
) )
assert(okIndexNonConfidential === 2, 'Should be template 2 for sepolia!') assert(okIndexNonConfidential === 2, 'Should be template 2 for sepolia!')
const notOkIndexNonConfidential = await calculateTemplateIndex( const notOkIndexNonConfidential = await getTemplateIndexOnList(
11155111, // sepolia 11155111, // sepolia
'0xDEfD0018969cd2d4E648209F876ADe184815f022' // wrong template '0xDEfD0018969cd2d4E648209F876ADe184815f022' // wrong template
) )
@ -68,25 +68,25 @@ describe('Asset utils (createAsset)', () => {
}) })
it('should get correct template index from contract artifacts (using template ID as template)', async () => { it('should get correct template index from contract artifacts (using template ID as template)', async () => {
const okTemplate = await calculateTemplateIndex( const okTemplate = await getTemplateIndexOnList(
KNOWN_CONFIDENTIAL_EVMS.networks[1].chainId, // testnet chain KNOWN_CONFIDENTIAL_EVMS.networks[1].chainId, // testnet chain
4 4
) )
assert(okTemplate === 4, 'wrong template index, should be index 4!') assert(okTemplate === 4, 'wrong template index, should be index 4!')
const wrongOne = await calculateTemplateIndex( const wrongOne = await getTemplateIndexOnList(
KNOWN_CONFIDENTIAL_EVMS.networks[0].chainId, // mainnet chain KNOWN_CONFIDENTIAL_EVMS.networks[0].chainId, // mainnet chain
6 6
) )
assert(wrongOne === -1, 'wrong template index, should only exist 5!') assert(wrongOne === -1, 'wrong template index, should only exist 5!')
const okIndexNonConfidential = await calculateTemplateIndex( const okIndexNonConfidential = await getTemplateIndexOnList(
11155111, // sepolia 11155111, // sepolia
2 // ok template 2 // ok template
) )
assert(okIndexNonConfidential === 2, 'Should be template 2 for sepolia!') assert(okIndexNonConfidential === 2, 'Should be template 2 for sepolia!')
const notOkIndexNonConfidential = await calculateTemplateIndex( const notOkIndexNonConfidential = await getTemplateIndexOnList(
11155111, // sepolia 11155111, // sepolia
3 // wrong template 3 // wrong template
) )
@ -94,7 +94,7 @@ describe('Asset utils (createAsset)', () => {
}) })
// checking if active by connecting to the smart contract as well // checking if active by connecting to the smart contract as well
it('V2 - should get correct template index from contract artifacts (using template ID as template)', async () => { it('Calculate index - Should get correct template index from contract getId() (using template ID as template)', async () => {
const okTemplate = await calculateActiveTemplateIndex( const okTemplate = await calculateActiveTemplateIndex(
nftOwner, nftOwner,
addresses.ERC721Factory, addresses.ERC721Factory,