Skip to content

Commit

Permalink
add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nhanphan committed Mar 1, 2024
1 parent 4e23642 commit 11418fa
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
32 changes: 31 additions & 1 deletion clients/js/test/create.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { generateSigner, publicKey } from '@metaplex-foundation/umi';
import { generateSigner, publicKey, sol } from '@metaplex-foundation/umi';
import test from 'ava';
// import { base58 } from '@metaplex-foundation/umi/serializers';
import { generateSignerWithSol } from '@metaplex-foundation/umi-bundle-tests';
import {
Asset,
AssetWithPlugins,
Expand Down Expand Up @@ -40,6 +41,35 @@ test('it can create a new asset in account state', async (t) => {
});
});

test('it can create a new asset with a different payer', async (t) => {
// Given a Umi instance and a new signer.
const umi = await createUmi();
const payer = await generateSignerWithSol(umi, sol(1));
const assetAddress = generateSigner(umi);

// When we create a new account.
await create(umi, {
owner: umi.identity.publicKey,
payer,
dataState: DataState.AccountState,
assetAddress,
name: 'Test Bread',
uri: 'https://example.com/bread',
plugins: [],
}).sendAndConfirm(umi);

// Then an account was created with the correct data.
const asset = await fetchAsset(umi, assetAddress.publicKey);
// console.log("Account State:", asset);
t.like(asset, <Asset>{
publicKey: assetAddress.publicKey,
updateAuthority: updateAuthority("Address", [payer.publicKey]),
owner: umi.identity.publicKey,
name: 'Test Bread',
uri: 'https://example.com/bread',
});
});

test('it can create a new asset in ledger state', async (t) => {
// Given a Umi instance and a new signer.
const umi = await createUmi();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { generateSigner } from '@metaplex-foundation/umi';
import test from 'ava';
import { generateSignerWithSol } from '@metaplex-foundation/umi-bundle-tests';
import {
AssetWithPlugins,
CollectionWithPlugins,
Expand All @@ -20,7 +21,7 @@ test('it can create a new asset with a collection if it is the collection update
const umi = await createUmi();
const collectionAddress = generateSigner(umi);
const assetAddress = generateSigner(umi);
const updateDelegate = generateSigner(umi);
const updateDelegate = await generateSignerWithSol(umi);

// When we create a new account.
await createCollection(umi, {
Expand Down Expand Up @@ -90,8 +91,12 @@ test('it can create a new asset with a collection if it is the collection update
],
});

umi.identity = updateDelegate;
umi.payer = updateDelegate;
const owner = generateSigner(umi);
// When we create a new account.
await create(umi, {
owner: owner.publicKey,
dataState: DataState.AccountState,
assetAddress,
name: 'Test Bread',
Expand All @@ -107,7 +112,7 @@ test('it can create a new asset with a collection if it is the collection update
updateAuthority: updateAuthority('Collection', [
collectionAddress.publicKey,
]),
owner: umi.identity.publicKey,
owner: owner.publicKey,
name: 'Test Bread',
uri: 'https://example.com/bread',
pluginHeader: {
Expand Down

0 comments on commit 11418fa

Please sign in to comment.