Skip to content

Commit

Permalink
Fix JS tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danenbm committed Mar 8, 2024
1 parent e1b3a1a commit 05765a7
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 31 deletions.
7 changes: 4 additions & 3 deletions clients/js/test/compress.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { generateSigner } from '@metaplex-foundation/umi';
import { generateSigner, publicKey } from '@metaplex-foundation/umi';
import test from 'ava';
import {
Asset,
Expand Down Expand Up @@ -44,7 +44,8 @@ test('it can compress an asset without any plugins as the owner', async (t) => {
// And when we compress the asset.
await compress(umi, {
asset: assetAddress.publicKey,
owner: umi.identity,
authority: umi.identity,
logWrapper: publicKey('noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV'),
}).sendAndConfirm(umi);
// console.log('Compress signature: ', bs58.encode(tx.signature));

Expand Down Expand Up @@ -92,7 +93,7 @@ test('it cannot compress an asset if not the owner', async (t) => {

const result = compress(umi, {
asset: assetAddress.publicKey,
owner: attacker,
authority: attacker,
}).sendAndConfirm(umi);

await t.throwsAsync(result, { name: 'InvalidAuthority' });
Expand Down
44 changes: 22 additions & 22 deletions clients/js/test/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import {
create,
fetchAsset,
fetchAssetWithPlugins,
fetchHashedAsset,
getAssetAccountDataSerializer,
updateAuthority,
} from '../src';
import { createUmi } from './_setup';
Expand Down Expand Up @@ -76,7 +74,7 @@ test('it can create a new asset in ledger state', async (t) => {
const assetAddress = generateSigner(umi);

// When we create a new account.
const txResult = await create(umi, {
const result = create(umi, {
dataState: DataState.LedgerState,
asset: assetAddress,
name: 'Test Bread',
Expand All @@ -85,27 +83,29 @@ test('it can create a new asset in ledger state', async (t) => {
plugins: [],
}).sendAndConfirm(umi);

await t.throwsAsync(result, { name: 'NotImplemented' });

// Then an account was created with the correct data.
const asset = await fetchHashedAsset(umi, assetAddress.publicKey);
//const asset = await fetchHashedAsset(umi, assetAddress.publicKey);
// console.log(asset);
t.like(asset, <Asset>{
publicKey: assetAddress.publicKey,
});

const tx = await umi.rpc.getTransaction(txResult.signature);
if (tx && tx.meta.innerInstructions) {
// console.log(tx.meta.innerInstructions[0].instructions);
const { data } = tx.meta.innerInstructions[0].instructions[0];
// console.log(base58.deserialize(data));
const parsed = getAssetAccountDataSerializer().deserialize(data)[0];
// console.log("Ledger State:", parsed);
t.like(parsed, <Asset>{
updateAuthority: updateAuthority('Address', [umi.identity.publicKey]),
owner: umi.identity.publicKey,
name: 'Test Bread',
uri: 'https://example.com/bread',
});
}
// t.like(asset, <Asset>{
// publicKey: assetAddress.publicKey,
// });

// const tx = await umi.rpc.getTransaction(txResult.signature);
// if (tx && tx.meta.innerInstructions) {
// // console.log(tx.meta.innerInstructions[0].instructions);
// const { data } = tx.meta.innerInstructions[0].instructions[0];
// // console.log(base58.deserialize(data));
// const parsed = getAssetAccountDataSerializer().deserialize(data)[0];
// // console.log("Ledger State:", parsed);
// t.like(parsed, <Asset>{
// updateAuthority: updateAuthority('Address', [umi.identity.publicKey]),
// owner: umi.identity.publicKey,
// name: 'Test Bread',
// uri: 'https://example.com/bread',
// });
// }
});

test('it can create a new asset in account state with plugins', async (t) => {
Expand Down
7 changes: 4 additions & 3 deletions clients/js/test/decompress.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { generateSigner } from '@metaplex-foundation/umi';
import { generateSigner, publicKey } from '@metaplex-foundation/umi';
import test from 'ava';
import {
Asset,
Expand Down Expand Up @@ -44,7 +44,8 @@ test('it can decompress a previously compressed asset as the owner', async (t) =
// And when we compress the asset.
await compress(umi, {
asset: assetAddress.publicKey,
owner: umi.identity,
authority: umi.identity,
logWrapper: publicKey('noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV'),
}).sendAndConfirm(umi);

// And the asset is now compressed as a hashed asset.
Expand All @@ -67,7 +68,7 @@ test('it can decompress a previously compressed asset as the owner', async (t) =
// And when we decompress the asset.
await decompress(umi, {
asset: assetAddress.publicKey,
owner: umi.identity,
authority: umi.identity,
compressionProof: {
updateAuthority: updateAuthority('Address', [umi.identity.publicKey]),
owner: umi.identity.publicKey,
Expand Down
12 changes: 9 additions & 3 deletions clients/js/test/info.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { generateSigner, publicKey } from '@metaplex-foundation/umi';
import test from 'ava';
import { DataState, create /* fetchAsset, fetchHashedAsset */ } from '../src';
import { DataState, create, compress /* fetchAsset, fetchHashedAsset */ } from '../src';
import { createUmi } from './_setup';

test('fetch account info for account state', async (t) => {
Expand Down Expand Up @@ -30,21 +30,27 @@ test('fetch account info for account state', async (t) => {
t.pass();
});

test('fetch account info for ledger state', async (t) => {
test('HELLO EHLO HLEOOO fetch account info for ledger state', async (t) => {
// Given a Umi instance and a new signer.
const umi = await createUmi();
const assetAddress = generateSigner(umi);

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

// And when we compress the asset.
await compress(umi, {
asset: assetAddress.publicKey,
logWrapper: publicKey('noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV'),
}).sendAndConfirm(umi);

// Print the size of the account.
const account = await umi.rpc.getAccount(assetAddress.publicKey);
if (account.exists) {
Expand Down

0 comments on commit 05765a7

Please sign in to comment.