From 60c94ed0a9a220b1e19e690610c3226865be1769 Mon Sep 17 00:00:00 2001 From: blockiosaurus Date: Fri, 1 Mar 2024 10:44:39 -0500 Subject: [PATCH] Moving some tests and adding a collection plugin test. --- clients/js/test/addPlugin.test.ts | 70 +++++++++++++++++++ .../js/test/plugins/{ => asset}/burn.test.ts | 4 +- .../test/plugins/{ => asset}/delegate.test.ts | 4 +- .../{ => asset}/delegateTransfer.test.ts | 4 +- .../plugins/{ => asset}/royalties.test.ts | 4 +- .../collectionUpdateDelegate.test.ts | 4 +- 6 files changed, 80 insertions(+), 10 deletions(-) rename clients/js/test/plugins/{ => asset}/burn.test.ts (97%) rename clients/js/test/plugins/{ => asset}/delegate.test.ts (98%) rename clients/js/test/plugins/{ => asset}/delegateTransfer.test.ts (97%) rename clients/js/test/plugins/{ => asset}/royalties.test.ts (99%) rename clients/js/test/plugins/{ => collection}/collectionUpdateDelegate.test.ts (98%) diff --git a/clients/js/test/addPlugin.test.ts b/clients/js/test/addPlugin.test.ts index ecf1c475..77050a04 100644 --- a/clients/js/test/addPlugin.test.ts +++ b/clients/js/test/addPlugin.test.ts @@ -4,11 +4,17 @@ import test from 'ava'; import { Asset, AssetWithPlugins, + CollectionData, + CollectionWithPlugins, DataState, + PluginType, addPlugin, create, + createCollection, fetchAsset, fetchAssetWithPlugins, + fetchCollectionData, + fetchCollectionWithPlugins, updateAuthority, } from '../src'; import { createUmi } from './_setup'; @@ -79,3 +85,67 @@ test('it can add a plugin to an asset', async (t) => { ], }); }); + +test('it can add a plugin to a collection', async (t) => { + // Given a Umi instance and a new signer. + const umi = await createUmi(); + const collectionAddress = generateSigner(umi); + + // When we create a new account. + await createCollection(umi, { + collectionAddress, + name: 'Test Bread', + uri: 'https://example.com/bread', + plugins: [], + }).sendAndConfirm(umi); + + // Then an account was created with the correct data. + const collection = await fetchCollectionData(umi, collectionAddress.publicKey); + // console.log("Account State:", collection); + t.like(collection, { + publicKey: collectionAddress.publicKey, + updateAuthority: umi.identity.publicKey, + name: 'Test Bread', + uri: 'https://example.com/bread', + }); + + await addPlugin(umi, { + assetAddress: collectionAddress.publicKey, + plugin: { + __kind: 'Freeze', + fields: [{ frozen: false }], + }, + }).sendAndConfirm(umi); + + const asset1 = await fetchCollectionWithPlugins(umi, collectionAddress.publicKey); + // console.log(JSON.stringify(asset1, (_, v) => typeof v === 'bigint' ? v.toString() : v, 2)); + t.like(asset1, { + publicKey: collectionAddress.publicKey, + updateAuthority: umi.identity.publicKey, + name: 'Test Bread', + uri: 'https://example.com/bread', + pluginHeader: { + key: 3, + pluginRegistryOffset: BigInt(95), + }, + pluginRegistry: { + key: 4, + registry: [ + { + pluginType: PluginType.Freeze, + offset: BigInt(93), + authorities: [{ __kind: 'Owner' }], + }, + ], + }, + plugins: [ + { + authorities: [{ __kind: 'Owner' }], + plugin: { + __kind: 'Freeze', + fields: [{ frozen: false }], + }, + }, + ], + }); +}); diff --git a/clients/js/test/plugins/burn.test.ts b/clients/js/test/plugins/asset/burn.test.ts similarity index 97% rename from clients/js/test/plugins/burn.test.ts rename to clients/js/test/plugins/asset/burn.test.ts index 5a34c697..90d13df2 100644 --- a/clients/js/test/plugins/burn.test.ts +++ b/clients/js/test/plugins/asset/burn.test.ts @@ -13,8 +13,8 @@ import { burn, Key, updateAuthority, -} from '../../src'; -import { createUmi } from '../_setup'; +} from '../../../src'; +import { createUmi } from '../../_setup'; test('it can burn an asset as the owner', async (t) => { // Given a Umi instance and a new signer. diff --git a/clients/js/test/plugins/delegate.test.ts b/clients/js/test/plugins/asset/delegate.test.ts similarity index 98% rename from clients/js/test/plugins/delegate.test.ts rename to clients/js/test/plugins/asset/delegate.test.ts index 820a91a8..d27f094c 100644 --- a/clients/js/test/plugins/delegate.test.ts +++ b/clients/js/test/plugins/asset/delegate.test.ts @@ -11,8 +11,8 @@ import { fetchAssetWithPlugins, updateAuthority, updatePlugin, -} from '../../src'; -import { createUmi } from '../_setup'; +} from '../../../src'; +import { createUmi } from '../../_setup'; test('it can delegate a new authority', async (t) => { // Given a Umi instance and a new signer. diff --git a/clients/js/test/plugins/delegateTransfer.test.ts b/clients/js/test/plugins/asset/delegateTransfer.test.ts similarity index 97% rename from clients/js/test/plugins/delegateTransfer.test.ts rename to clients/js/test/plugins/asset/delegateTransfer.test.ts index d0f02bc4..6fd2441c 100644 --- a/clients/js/test/plugins/delegateTransfer.test.ts +++ b/clients/js/test/plugins/asset/delegateTransfer.test.ts @@ -10,8 +10,8 @@ import { fetchAssetWithPlugins, transfer, updateAuthority, -} from '../../src'; -import { createUmi } from '../_setup'; +} from '../../../src'; +import { createUmi } from '../../_setup'; test('a delegate can transfer the asset', async (t) => { // Given a Umi instance and a new signer. diff --git a/clients/js/test/plugins/royalties.test.ts b/clients/js/test/plugins/asset/royalties.test.ts similarity index 99% rename from clients/js/test/plugins/royalties.test.ts rename to clients/js/test/plugins/asset/royalties.test.ts index af360094..2e8e3ce9 100644 --- a/clients/js/test/plugins/royalties.test.ts +++ b/clients/js/test/plugins/asset/royalties.test.ts @@ -15,8 +15,8 @@ import { ruleSet, transfer, updateAuthority, -} from '../../src'; -import { createUmi } from '../_setup'; +} from '../../../src'; +import { createUmi } from '../../_setup'; test('it can transfer an asset with royalties', async (t) => { // Given a Umi instance and a new signer. diff --git a/clients/js/test/plugins/collectionUpdateDelegate.test.ts b/clients/js/test/plugins/collection/collectionUpdateDelegate.test.ts similarity index 98% rename from clients/js/test/plugins/collectionUpdateDelegate.test.ts rename to clients/js/test/plugins/collection/collectionUpdateDelegate.test.ts index 937f2e17..acbc049e 100644 --- a/clients/js/test/plugins/collectionUpdateDelegate.test.ts +++ b/clients/js/test/plugins/collection/collectionUpdateDelegate.test.ts @@ -12,8 +12,8 @@ import { fetchAssetWithPlugins, fetchCollectionWithPlugins, updateAuthority, -} from '../../src'; -import { createUmi } from '../_setup'; +} from '../../../src'; +import { createUmi } from '../../_setup'; test('it can create a new asset with a collection if it is the collection update delegate', async (t) => { // Given a Umi instance and a new signer.