From 876630512942cab1c8e45a924f9524f37b727fdf Mon Sep 17 00:00:00 2001 From: KidSysco Date: Mon, 7 Oct 2024 11:21:33 -0500 Subject: [PATCH] add tests --- .../useEvmNftGallery.history.test.js | 198 ++++++++++++++++++ .../dahDemoV1/useEvmNftGallery.holder.test.js | 151 +++++++++++++ .../dahNftV2/useEvmNftGallery.history.test.js | 112 ++++++++++ .../dahNftV2/useEvmNftGallery.holder.test.js | 153 ++++++++++++++ tests/useEvmNftGallery.test.js | 54 ----- 5 files changed, 614 insertions(+), 54 deletions(-) create mode 100644 tests/dahDemoV1/useEvmNftGallery.history.test.js create mode 100644 tests/dahDemoV1/useEvmNftGallery.holder.test.js create mode 100644 tests/dahNftV2/useEvmNftGallery.history.test.js create mode 100644 tests/dahNftV2/useEvmNftGallery.holder.test.js delete mode 100644 tests/useEvmNftGallery.test.js diff --git a/tests/dahDemoV1/useEvmNftGallery.history.test.js b/tests/dahDemoV1/useEvmNftGallery.history.test.js new file mode 100644 index 0000000..5190784 --- /dev/null +++ b/tests/dahDemoV1/useEvmNftGallery.history.test.js @@ -0,0 +1,198 @@ +import test from 'ava'; +import { mount, flushPromises } from '@vue/test-utils'; +import { createPinia, setActivePinia } from 'pinia'; +import { useEvmNftGallery } from '../../src/composables/useEvmNftGallery'; +import { blockchains } from '../../src/modules/blockchains'; +import { dahDemoV1Abi } from '../../src/modules/dahDemoV1Abi'; + +let contractPublicKey = '0xcbb2a9868d73f24c056893131b97a69ffd36eba9'; // DAH +let contractAddress = '0x33f1cdD52e7ec6F65Ab93dD518c1e2EdB3a8Dd63'; // DAH - Roadmap +let chainId = blockchains.avalanche.chainId; +let itemsPerPage = 5; +let nftStoreCollectionName = 'nftSmartContract1'; +const suspenseTemplate = '
'; + +test.beforeEach(() => { + setActivePinia(createPinia()); +}); + +test('should fetch page 1 of all NFTs on contract', async (t) => { + const wrapper = mount( + { + setup() { + const { nfts } = useEvmNftGallery( + contractPublicKey, + contractAddress, + dahDemoV1Abi, + chainId, + null, + blockchains.avalanche.publicRpc, + itemsPerPage, + nftStoreCollectionName, + true + ); + return { nfts }; + }, + template: suspenseTemplate, + }, + { + global: { + plugins: [createPinia()], + }, + } + ); + + await new Promise((resolve) => setTimeout(resolve, 1000)); + + const nfts = wrapper.vm.nfts; + // console.dir(nfts); + // console.log('NFT list page 1:'); + // console.dir(nfts.map((item) => ({ tokenId: item.tokenId }))); + t.true(nfts.length === itemsPerPage); + t.true(nfts[0].tokenId === 1); + t.true(nfts[1].tokenId === 2); + t.true(nfts[2].tokenId === 3); + t.true(nfts[3].tokenId === 4); + t.true(nfts[4].tokenId === 5); + // +}); + +test('should fetch page 2 of all NFTs on contract', async (t) => { + const wrapper = mount( + { + setup() { + const { nfts, onGetMyNfts } = useEvmNftGallery( + contractPublicKey, + contractAddress, + dahDemoV1Abi, + chainId, + null, + blockchains.avalanche.publicRpc, + itemsPerPage, + nftStoreCollectionName, + true + ); + + return { nfts, onGetMyNfts }; + }, + template: suspenseTemplate, + }, + { + global: { + plugins: [createPinia()], + }, + } + ); + + // Wait for initial data to load completely + await flushPromises(); + await wrapper.vm.$nextTick(); + + // Log the initial data for debugging purposes + + console.log('Initial NFTs:', wrapper.vm.nfts); + + // Simulate changing the page, assuming there's a method or interaction that triggers the change. + // If `onGetMyNfts` is a method to manually trigger page fetching: + await wrapper.vm.onGetMyNfts(2); + + // Wait for the new page data to be fetched and processed + await flushPromises(); + await wrapper.vm.$nextTick(); + + // Log the data after fetching page 2 + const nfts = wrapper.vm.nfts; + // console.log('NFT list after changing to page 2:'); + // console.dir(nfts.map((item) => ({ tokenId: item.tokenId }))); + + // Assert that the NFTs for page 2 have been fetched + t.true(nfts.length === itemsPerPage); + t.true(nfts[0].tokenId === 6); + t.true(nfts[1].tokenId === 7); + t.true(nfts[2].tokenId === 8); + t.true(nfts[3].tokenId === 9); + t.true(nfts[4].tokenId === 10); +}); + +test('should fetch page 1 of all NFTs on contract in desc order', async (t) => { + const wrapper = mount( + { + setup() { + const { nfts } = useEvmNftGallery( + '0x18582f2CA048ac5f22E5a64F92E8a7d7b1F806a4', // Dog plex + '0x9c870E5B8724Db43E58Cd62C424E3071A3FB66E9', // Dog plex - dog show + dahDemoV1Abi, + blockchains.fantom.chainId, + null, + blockchains.fantom.publicRpc, + 24, + 'a1', + false + ); + return { nfts }; + }, + template: suspenseTemplate, + }, + { + global: { + plugins: [createPinia()], + }, + } + ); + + await new Promise((resolve) => setTimeout(resolve, 2000)); + + const nfts = wrapper.vm.nfts; + //console.dir(nfts); + // console.log('NFT list page 1:'); + // console.dir(nfts.map((item) => ({ tokenId: item.tokenId }))); + t.true(nfts.length === 6); + t.true(nfts[0].tokenId === 6); + t.true(nfts[1].tokenId === 5); + t.true(nfts[2].tokenId === 4); + t.true(nfts[3].tokenId === 3); + t.true(nfts[4].tokenId === 2); + t.true(nfts[5].tokenId === 1); +}); + +// This will not be supported. Keeping the test here for debugging and future purposes. +test.only('should fetch page 1 of all NFTs on contract with burned NFTs', async (t) => { + const wrapper = mount( + { + setup() { + const { nfts } = useEvmNftGallery( + '0x5e44cEFFBeCaeCC0D75b3Be756d40726CE310608', // Urbanhomestead + '0x186EE2C8D81183b6bB06368413bc03ed5aa8eF21', // Urbanhomestead - Products + dahDemoV1Abi, + blockchains.avalanche.chainId, + null, + blockchains.avalanche.publicRpc, + 24, + 'a1', + false + ); + return { nfts }; + }, + template: suspenseTemplate, + }, + { + global: { + plugins: [createPinia()], + }, + } + ); + + await new Promise((resolve) => setTimeout(resolve, 2000)); + + const nfts = wrapper.vm.nfts; + //console.dir(nfts); + // console.log('NFT list page 1:'); + // console.dir(nfts.map((item) => ({ tokenId: item.tokenId }))); + t.true(nfts.length > 0); + // t.true(nfts[0].tokenId === 6); + // t.true(nfts[1].tokenId === 5); + // t.true(nfts[2].tokenId === 4); + // t.true(nfts[3].tokenId === 3); + // t.true(nfts[4].tokenId === 2); + // t.true(nfts[5].tokenId === 1); +}); diff --git a/tests/dahDemoV1/useEvmNftGallery.holder.test.js b/tests/dahDemoV1/useEvmNftGallery.holder.test.js new file mode 100644 index 0000000..760228f --- /dev/null +++ b/tests/dahDemoV1/useEvmNftGallery.holder.test.js @@ -0,0 +1,151 @@ +import test from 'ava'; +import { mount, flushPromises } from '@vue/test-utils'; +import { createPinia, setActivePinia } from 'pinia'; +import { useEvmNftGallery } from '../../src/composables/useEvmNftGallery'; +import { blockchains } from '../../src/modules/blockchains'; +import { dahDemoV1Abi } from '../../src/modules/dahDemoV1Abi'; + +let contractPublicKey = '0xcbb2a9868d73f24c056893131b97a69ffd36eba9'; +let contractAddress = '0x33f1cdD52e7ec6F65Ab93dD518c1e2EdB3a8Dd63'; +let chainId = blockchains.avalanche.chainId; +let itemsPerPage = 5; +let nftStoreCollectionName = 'nftSmartContract1'; +const suspenseTemplate = '
'; + +test.beforeEach(() => { + setActivePinia(createPinia()); +}); + +test('should fetch page 1 of NFTs by holder', async (t) => { + const wrapper = mount( + { + setup() { + const { nfts } = useEvmNftGallery( + contractPublicKey, + contractAddress, + dahDemoV1Abi, + chainId, + contractPublicKey, + blockchains.avalanche.publicRpc, + itemsPerPage, + nftStoreCollectionName, + true + ); + return { nfts }; + }, + template: suspenseTemplate, + }, + { + global: { + plugins: [createPinia()], + }, + } + ); + + await flushPromises(); + await wrapper.vm.$nextTick(); + await new Promise((resolve) => setTimeout(resolve, 1000)); + + const nfts = wrapper.vm.nfts; + t.true(nfts.length === itemsPerPage); + t.true(nfts[0].tokenId === 1); + t.true(nfts[1].tokenId === 2); + t.true(nfts[2].tokenId === 3); + t.true(nfts[3].tokenId === 4); + t.true(nfts[4].tokenId === 5); + // console.dir(nfts); +}); + +test('should fetch page 2 of NFTs by holder', async (t) => { + const wrapper = mount( + { + setup() { + const { nfts, onGetMyNfts } = useEvmNftGallery( + contractPublicKey, + contractAddress, + dahDemoV1Abi, + chainId, + contractPublicKey, + blockchains.avalanche.publicRpc, + itemsPerPage, + nftStoreCollectionName, + true + ); + + return { nfts, onGetMyNfts }; + }, + template: suspenseTemplate, + }, + { + global: { + plugins: [createPinia()], + }, + } + ); + + // Wait for initial data to load completely + await flushPromises(); + await wrapper.vm.$nextTick(); + + // Simulate changing the page, assuming there's a method or interaction that triggers the change. + // If `onGetMyNfts` is a method to manually trigger page fetching: + await wrapper.vm.onGetMyNfts(2); + + // Wait for the new page data to be fetched and processed + await flushPromises(); + await wrapper.vm.$nextTick(); + + // Log the data after fetching page 2 + const nfts = wrapper.vm.nfts; + // console.log('NFT list after changing to page 2:'); + // console.dir(nfts.map((item) => ({ tokenId: item.tokenId }))); + + // Assert that the NFTs for page 2 have been fetched + t.true(nfts.length === itemsPerPage); + t.true(nfts[0].tokenId === 6); + t.true(nfts[1].tokenId === 7); + t.true(nfts[2].tokenId === 8); + t.true(nfts[3].tokenId === 9); + t.true(nfts[4].tokenId === 10); +}); + +test('should fetch page 1 of all NFTs on contract in desc order', async (t) => { + const wrapper = mount( + { + setup() { + const { nfts } = useEvmNftGallery( + '0x18582f2CA048ac5f22E5a64F92E8a7d7b1F806a4', + '0x9c870E5B8724Db43E58Cd62C424E3071A3FB66E9', + dahDemoV1Abi, + blockchains.fantom.chainId, + '0x18582f2CA048ac5f22E5a64F92E8a7d7b1F806a4', + blockchains.fantom.publicRpc, + 24, + 'a1', + false + ); + return { nfts }; + }, + template: suspenseTemplate, + }, + { + global: { + plugins: [createPinia()], + }, + } + ); + + await new Promise((resolve) => setTimeout(resolve, 2000)); + + const nfts = wrapper.vm.nfts; + //console.dir(nfts); + // console.log('NFT list page 1:'); + // console.dir(nfts.map((item) => ({ tokenId: item.tokenId }))); + t.true(nfts.length === 6); + t.true(nfts[0].tokenId === 6); + t.true(nfts[1].tokenId === 5); + t.true(nfts[2].tokenId === 4); + t.true(nfts[3].tokenId === 3); + t.true(nfts[4].tokenId === 2); + t.true(nfts[5].tokenId === 1); +}); diff --git a/tests/dahNftV2/useEvmNftGallery.history.test.js b/tests/dahNftV2/useEvmNftGallery.history.test.js new file mode 100644 index 0000000..049f173 --- /dev/null +++ b/tests/dahNftV2/useEvmNftGallery.history.test.js @@ -0,0 +1,112 @@ +import test from 'ava'; +import { mount, flushPromises } from '@vue/test-utils'; +import { createPinia, setActivePinia } from 'pinia'; +import { useEvmNftGallery } from '../../src/composables/useEvmNftGallery'; +import { blockchains } from '../../src/modules/blockchains'; +import { dahNftV2Abi } from '../../src/modules/dahNftV2Abi'; + +let contractPublicKey = '0x18582f2CA048ac5f22E5a64F92E8a7d7b1F806a4'; +let contractAddress = '0x9c870E5B8724Db43E58Cd62C424E3071A3FB66E9'; +let chainId = blockchains.polygon.chainId; +let itemsPerPage = 5; +let nftStoreCollectionName = 'nftSmartContract1'; +const suspenseTemplate = '
'; + +test.beforeEach(() => { + setActivePinia(createPinia()); +}); + +test('should fetch page 1 of all NFTs on contract', async (t) => { + const wrapper = mount( + { + setup() { + const { nfts } = useEvmNftGallery( + contractPublicKey, + contractAddress, + dahNftV2Abi, + chainId, + null, + blockchains.polygon.publicRpc, + itemsPerPage, + nftStoreCollectionName, + true + ); + return { nfts }; + }, + template: suspenseTemplate, + }, + { + global: { + plugins: [createPinia()], + }, + } + ); + + await new Promise((resolve) => setTimeout(resolve, 1000)); + + const nfts = wrapper.vm.nfts; + // console.dir(nfts); + // console.log('NFT list page 1:'); + // console.dir(nfts.map((item) => ({ tokenId: item.tokenId }))); + t.true(nfts.length === itemsPerPage); + t.true(nfts[0].tokenId === 0); + t.true(nfts[1].tokenId === 1); + t.true(nfts[2].tokenId === 2); + t.true(nfts[3].tokenId === 3); + t.true(nfts[4].tokenId === 4); + // +}); + +test('should fetch page 2 of all NFTs on contract', async (t) => { + itemsPerPage = 5; + const wrapper = mount( + { + setup() { + const { nfts, onGetMyNfts } = useEvmNftGallery( + contractPublicKey, + contractAddress, + dahNftV2Abi, + chainId, + null, + blockchains.polygon.publicRpc, // otherwise batch too large + itemsPerPage, + nftStoreCollectionName, + true + ); + + return { nfts, onGetMyNfts }; + }, + template: suspenseTemplate, + }, + { + global: { + plugins: [createPinia()], + }, + } + ); + + // Wait for initial data to load completely + await flushPromises(); + await wrapper.vm.$nextTick(); + + // Simulate changing the page, assuming there's a method or interaction that triggers the change. + // If `onGetMyNfts` is a method to manually trigger page fetching: + await wrapper.vm.onGetMyNfts(2); + + // Wait for the new page data to be fetched and processed + await flushPromises(); + await wrapper.vm.$nextTick(); + + // Log the data after fetching page 2 + const nfts = wrapper.vm.nfts; + // console.log('NFT list after changing to page 2:'); + // console.dir(nfts.map((item) => ({ tokenId: item.tokenId }))); + + // Assert that the NFTs for page 2 have been fetched + t.true(nfts.length === itemsPerPage); + // t.true(nfts[0].tokenId === 5); + // t.true(nfts[1].tokenId === 6); + // t.true(nfts[2].tokenId === 7); + // t.true(nfts[3].tokenId === 8); + // t.true(nfts[4].tokenId === 9); +}); diff --git a/tests/dahNftV2/useEvmNftGallery.holder.test.js b/tests/dahNftV2/useEvmNftGallery.holder.test.js new file mode 100644 index 0000000..48de108 --- /dev/null +++ b/tests/dahNftV2/useEvmNftGallery.holder.test.js @@ -0,0 +1,153 @@ +import test from 'ava'; +import { mount, flushPromises } from '@vue/test-utils'; +import { createPinia, setActivePinia } from 'pinia'; +import { useEvmNftGallery } from '../../src/composables/useEvmNftGallery'; +import { blockchains } from '../../src/modules/blockchains'; +import { dahNftV2Abi } from '../../src/modules/dahNftV2Abi'; + +let contractPublicKey = '0x18582f2CA048ac5f22E5a64F92E8a7d7b1F806a4'; +let contractAddress = '0x9c870E5B8724Db43E58Cd62C424E3071A3FB66E9'; +let chainId = blockchains.polygon.chainId; +let itemsPerPage = 5; +let nftStoreCollectionName = 'nftSmartContract1'; +const suspenseTemplate = '
'; + +test.beforeEach(() => { + setActivePinia(createPinia()); +}); + +test('should fetch page 1 of NFTs by holder', async (t) => { + const wrapper = mount( + { + setup() { + const { nfts } = useEvmNftGallery( + contractPublicKey, + contractAddress, + dahNftV2Abi, + chainId, + contractPublicKey, + blockchains.polygon.publicRpc, + itemsPerPage, + nftStoreCollectionName, + true + ); + return { nfts }; + }, + template: suspenseTemplate, + }, + { + global: { + plugins: [createPinia()], + }, + } + ); + + await flushPromises(); + await wrapper.vm.$nextTick(); + await new Promise((resolve) => setTimeout(resolve, 1000)); + + const nfts = wrapper.vm.nfts; + // console.dir(nfts); + t.true(nfts.length === itemsPerPage); + t.true(nfts[0].tokenId === 0); + t.true(nfts[1].tokenId === 1); + t.true(nfts[2].tokenId === 2); + t.true(nfts[3].tokenId === 3); + t.true(nfts[4].tokenId === 4); +}); + +test('should fetch page 2 of NFTs by holder', async (t) => { + const wrapper = mount( + { + setup() { + const { nfts, onGetMyNfts } = useEvmNftGallery( + contractPublicKey, + contractAddress, + dahNftV2Abi, + chainId, + contractPublicKey, + blockchains.polygon.publicRpc, // otherwise batch too large + itemsPerPage, + nftStoreCollectionName, + true + ); + + return { nfts, onGetMyNfts }; + }, + template: suspenseTemplate, + }, + { + global: { + plugins: [createPinia()], + }, + } + ); + + // Wait for initial data to load completely + await flushPromises(); + await wrapper.vm.$nextTick(); + + // Log the initial data for debugging purposes + + // Simulate changing the page, assuming there's a method or interaction that triggers the change. + // If `onGetMyNfts` is a method to manually trigger page fetching: + await wrapper.vm.onGetMyNfts(2); + + // Wait for the new page data to be fetched and processed + await flushPromises(); + await wrapper.vm.$nextTick(); + + // Log the data after fetching page 2 + const nfts = wrapper.vm.nfts; + // console.log('NFT list after changing to page 2:'); + // console.dir(nfts.map((item) => ({ tokenId: item.tokenId }))); + + // Assert that the NFTs for page 2 have been fetched + t.true(nfts.length === itemsPerPage); + t.true(nfts[0].tokenId === 5); + t.true(nfts[1].tokenId === 6); + t.true(nfts[2].tokenId === 7); + t.true(nfts[3].tokenId === 8); + t.true(nfts[4].tokenId === 9); +}); + +test('should fetch page 1 of all NFTs by holder in desc order', async (t) => { + const wrapper = mount( + { + setup() { + const { nfts } = useEvmNftGallery( + contractPublicKey, + contractAddress, + dahNftV2Abi, + blockchains.polygon.chainId, + contractPublicKey, + blockchains.polygon.publicRpc, + 6, + 'a1', + false + ); + return { nfts }; + }, + template: suspenseTemplate, + }, + { + global: { + plugins: [createPinia()], + }, + } + ); + + await new Promise((resolve) => setTimeout(resolve, 2000)); + + const nfts = wrapper.vm.nfts; + //console.dir(nfts); + // console.log('NFT list page 1:'); + // console.dir(nfts.map((item) => ({ tokenId: item.tokenId }))); + t.true(nfts.length === 6); + t.true(nfts[0].tokenId === 34); + t.true(nfts[1].tokenId === 33); + t.true(nfts[2].tokenId === 32); + t.true(nfts[3].tokenId === 31); + t.true(nfts[4].tokenId === 30); + t.true(nfts[5].tokenId === 29); +}); diff --git a/tests/useEvmNftGallery.test.js b/tests/useEvmNftGallery.test.js deleted file mode 100644 index 3e51dd9..0000000 --- a/tests/useEvmNftGallery.test.js +++ /dev/null @@ -1,54 +0,0 @@ -import test from 'ava'; -import { mount, flushPromises } from '@vue/test-utils'; -import { createPinia, setActivePinia } from 'pinia'; -import { useEvmNftGallery } from '../src/composables/useEvmNftGallery'; -import { blockchains } from '../src/modules/blockchains'; -import { dahDemoV1Abi } from '../src/modules/dahDemoV1Abi'; - -let walletPublicKey = '0x5e44ceffbecaecc0d75b3be756d40726ce310608'; -let contractAddress = '0x186EE2C8D81183b6bB06368413bc03ed5aa8eF21'; -let chainId = blockchains.avalanche.chainId; -let itemsPerPage = 24; -let nftStoreCollectionName = 'nftSmartContract1'; - -test.beforeEach(() => { - setActivePinia(createPinia()); -}); - -test('useEvmNftGallery fetches NFT Meta Data', async (t) => { - const wrapper = mount( - { - setup() { - const { nfts } = useEvmNftGallery( - walletPublicKey, - contractAddress, - dahDemoV1Abi, - chainId, - walletPublicKey, - blockchains.avalanche.publicRpc, - itemsPerPage, - nftStoreCollectionName, - true - ); - return { nfts }; - }, - template: '
', // Wrap in Suspense - }, - { - global: { - plugins: [createPinia()], - }, - } - ); - - // Wait for promises to resolve - await flushPromises(); - await wrapper.vm.$nextTick(); // Ensure Vue's reactivity system is updated - await new Promise((resolve) => setTimeout(resolve, 2000)); // Delay to wait for network requests - - // Ensure Vue has processed all changes - await wrapper.vm.$nextTick(); // Trigger another reactivity update if needed - - // Assert that the NFTs are now populated - t.true(wrapper.vm.nfts.length > 0); -});