Skip to content

Commit

Permalink
Added tests for dispenser, index dispenser activated.
Browse files Browse the repository at this point in the history
  • Loading branch information
mariacarmina committed Dec 20, 2024
1 parent d5d8b4f commit 04cdf30
Showing 1 changed file with 58 additions and 1 deletion.
59 changes: 58 additions & 1 deletion src/test/integration/pricing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 04cdf30

Please sign in to comment.