From 04cdf30f40e619fed49efe778a45b8ae07407083 Mon Sep 17 00:00:00 2001 From: mariacarmina Date: Fri, 20 Dec 2024 15:52:59 +0200 Subject: [PATCH] Added tests for dispenser, index dispenser activated. --- src/test/integration/pricing.test.ts | 59 +++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/src/test/integration/pricing.test.ts b/src/test/integration/pricing.test.ts index 4a2dd4f20..be6135656 100644 --- a/src/test/integration/pricing.test.ts +++ b/src/test/integration/pricing.test.ts @@ -11,7 +11,8 @@ import { } from 'ethers' import ERC721Factory from '@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json' assert { type: 'json' } import ERC721Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC721Template.sol/ERC721Template.json' assert { type: 'json' } -// import ERC20Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20TemplateEnterprise.sol/ERC20TemplateEnterprise.json' assert { type: 'json' } +import ERC20Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20TemplateEnterprise.sol/ERC20TemplateEnterprise.json' assert { type: 'json' } +import Dispenser from '@oceanprotocol/contracts/artifacts/contracts/pools/dispenser/Dispenser.sol/Dispenser.json' assert { type: 'json' } import { Database } from '../../components/database/index.js' import { OceanIndexer } from '../../components/Indexer/index.js' import { RPCS } from '../../@types/blockchain.js' @@ -45,6 +46,7 @@ describe('Publish pricing scehmas and assert ddo stats', () => { let provider: JsonRpcProvider let factoryContract: Contract let nftContract: Contract + let datatokenContract: Contract let publisherAccount: Signer let nftAddress: string let datatokenAddress: string @@ -145,6 +147,11 @@ describe('Publish pricing scehmas and assert ddo stats', () => { const datatokenEvent = getEventFromTx(txReceipt, 'TokenCreated') datatokenAddress = datatokenEvent.args[0] assert(datatokenAddress, 'find datatoken created failed') + datatokenContract = new ethers.Contract( + datatokenAddress, + ERC20Template.abi, + publisherAccount + ) }) it('should set metadata and save ', async () => { @@ -285,6 +292,56 @@ describe('Publish pricing scehmas and assert ddo stats', () => { } else expect(expectedTimeoutFailure(this.test.title)).to.be.equal(wasTimeout) }) + it('should attach a dispenser', async () => { + const dispenserParams: any = { + maxTokens: '1', + maxBalance: '1', + withMint: true + } + const tx = await datatokenContract.createDispenser( + datatokenAddress, + await publisherAccount.getAddress(), + artifactsAddresses.Dispenser, + dispenserParams + ) + assert(tx, 'Cannot create dispenser') + const txReceipt = await tx.wait() + const dispenserEvent = getEventFromTx(txReceipt, 'DispenserCreated') + assert( + dispenserEvent.args[0] === datatokenAddress, + 'Datatoken addresses do not match for dispenser event' + ) + const dispenserContract = new ethers.Contract( + artifactsAddresses.Dispenser, + Dispenser.abi, + publisherAccount + ) + const activationTx = await dispenserContract.activate( + datatokenAddress, + ethers.parseUnits('1', 'ether'), + ethers.parseUnits('1', 'ether') + ) + assert(tx, 'Cannot activate dispenser') + const activationReceipt = await activationTx.wait() + const activationEvent = getEventFromTx(activationReceipt, 'DispenserActivated') + assert( + activationEvent.args[0] === datatokenAddress, + 'Datatoken addresses do not match for dispenser event' + ) + assert( + (await dispenserContract.status(datatokenAddress))[0] === true, + 'dispenser not active' + ) + const { ddo } = await waitToIndex( + assetDID, + EVENTS.DISPENSER_ACTIVATED, + DEFAULT_TEST_TIMEOUT, + true + ) + console.log(`JSON stringified ddo w dispenser: ${JSON.stringify(ddo)}`) + assert(ddo.indexedMetadata.stats) + }) + after(async () => { await tearDownEnvironment(previousConfiguration) indexer.stopAllThreads()