From 2bd5d55198081847e839257fc7ac0710e8453528 Mon Sep 17 00:00:00 2001 From: lacoop6tu Date: Wed, 20 Oct 2021 16:09:18 -0500 Subject: [PATCH] add more NFTFactory test --- src/factories/NFTFactory.ts | 2 +- test/unit/NFTFactory.test.ts | 78 ++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) diff --git a/src/factories/NFTFactory.ts b/src/factories/NFTFactory.ts index dbf376a3..2fe5d04e 100644 --- a/src/factories/NFTFactory.ts +++ b/src/factories/NFTFactory.ts @@ -130,7 +130,7 @@ export class NFTFactory { * @return {Promise} Number of ERC20 Template added to this factory */ public async getCurrentTokenTemplateCount(): Promise { - const count = await this.factory721.methods.getCurrentTokenTemplateCount().call() + const count = await this.factory721.methods.getCurrentTemplateCount().call() return count } diff --git a/test/unit/NFTFactory.test.ts b/test/unit/NFTFactory.test.ts index ab193c72..275a7311 100644 --- a/test/unit/NFTFactory.test.ts +++ b/test/unit/NFTFactory.test.ts @@ -67,8 +67,86 @@ describe('NFT Factory test', () => { it('should initiate NFTFactory instance', async () => { nftFactory = new NFTFactory(contracts.factory721Address, web3, LoggerInstance) + }) + it('#getCurrentNFTCount - should return actual nft count (0)', async () => { const nftCount = await nftFactory.getCurrentNFTCount() assert(nftCount == 0) }) + + it('#getCurrentTokenCount - should return actual token count (0)', async () => { + const tokenCount = await nftFactory.getCurrentTokenCount() + assert(tokenCount == 0) + }) + it('#getOwner - should return actual owner', async () => { + const owner = await nftFactory.getOwner() + assert(owner === contracts.accounts[0]) + }) + it('#getCurrentNFTTemplateCount - should return actual nft template count (1)', async () => { + const nftTemplateCount = await nftFactory.getCurrentNFTTemplateCount() + assert(nftTemplateCount == 1) + }) + it('#getCurrentTokenTemplateCount - should return actual token template count (1)', async () => { + const tokenTemplateCount = await nftFactory.getCurrentTokenTemplateCount() + assert(tokenTemplateCount == 1) + }) + it('#getNFTTemplate - should return NFT template struct', async () => { + const nftTemplate = await nftFactory.getNFTTemplate(1) + assert(nftTemplate.isActive === true) + assert(nftTemplate.templateAddress === contracts.template721Address) + }) + it('#getTokenTemplate - should return Token template struct', async () => { + const tokenTemplate = await nftFactory.getTokenTemplate(1) + assert(tokenTemplate.isActive === true) + assert(tokenTemplate.templateAddress === contracts.template20Address) + }) + it('#addNFTTemplate - should add NFT template if factory owner', async () => { + await nftFactory.addNFTTemplate(contracts.accounts[0], contracts.fixedRateAddress) // contracts.fixedRateAddress it's just a dummy contract in this case + const nftTemplateCount = await nftFactory.getCurrentNFTTemplateCount() + assert(nftTemplateCount == 2) + const nftTemplate = await nftFactory.getNFTTemplate(2) + assert(nftTemplate.isActive === true) + assert(nftTemplate.templateAddress === contracts.fixedRateAddress) + }) + it('#disableNFTTemplate - should disable NFT template if factory owner', async () => { + let nftTemplate = await nftFactory.getNFTTemplate(2) + assert(nftTemplate.isActive === true) + await nftFactory.disableNFTTemplate(contracts.accounts[0], 2) // owner disable template index = 2 + + nftTemplate = await nftFactory.getNFTTemplate(2) + assert(nftTemplate.isActive === false) + }) + it('#reactivateNFTTemplate - should disable NFT template if factory owner', async () => { + let nftTemplate = await nftFactory.getNFTTemplate(2) + assert(nftTemplate.isActive === false) + await nftFactory.reactivateNFTTemplate(contracts.accounts[0], 2) // owner reactivate template index = 2 + + nftTemplate = await nftFactory.getNFTTemplate(2) + assert(nftTemplate.isActive === true) + }) + it('#addTokenTemplate - should add Datatoken template if factory owner', async () => { + await nftFactory.addTokenTemplate(contracts.accounts[0], contracts.fixedRateAddress) // contracts.fixedRateAddress it's just a dummy contract in this case + const tokenTemplateCount = await nftFactory.getCurrentTokenTemplateCount() + assert(tokenTemplateCount == 2) + const nftTemplate = await nftFactory.getTokenTemplate(2) + assert(nftTemplate.isActive === true) + assert(nftTemplate.templateAddress === contracts.fixedRateAddress) + }) + + it('#disableTokenTemplate - should disable Token template if factory owner', async () => { + let tokenTemplate = await nftFactory.getTokenTemplate(2) + assert(tokenTemplate.isActive === true) + await nftFactory.disableTokenTemplate(contracts.accounts[0], 2) // owner disable template index = 2 + + tokenTemplate = await nftFactory.getTokenTemplate(2) + assert(tokenTemplate.isActive === false) + }) + it('#reactivateTokenTemplate - should disable Token template if factory owner', async () => { + let tokenTemplate = await nftFactory.getTokenTemplate(2) + assert(tokenTemplate.isActive === false) + await nftFactory.reactivateTokenTemplate(contracts.accounts[0], 2) // owner reactivate template index = 2 + + tokenTemplate = await nftFactory.getTokenTemplate(2) + assert(tokenTemplate.isActive === true) + }) })