Skip to content

Commit 569fe3c

Browse files
authored
Update tests.ts
1 parent 367ccdd commit 569fe3c

File tree

1 file changed

+44
-74
lines changed

1 file changed

+44
-74
lines changed

clients/js/src/tests.ts

+44-74
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,55 @@
1-
import { createUmi } from "@metaplex-foundation/umi-bundle-defaults";
2-
import { createV2, createCollection, fetchAssetV1, mplCore, addCollectionPlugin, updateV2, updateAuthority, addPlugin } from "@metaplex-foundation/mpl-core";
3-
import { createSignerFromKeypair, generateSigner, signerIdentity, sol } from "@metaplex-foundation/umi";
4-
//import { Keypair, PublicKey } from "@solana/web3.js";
1+
import { createUmi } from '@metaplex-foundation/umi-bundle-tests';
2+
import { createV2, createCollection, fetchAssetV1, addCollectionPlugin, updateV2, updateAuthority, addPlugin } from "@metaplex-foundation/mpl-core";
3+
import { generateSigner } from "@metaplex-foundation/umi";
54

6-
import wallet from "../../../wallet.json"
75

8-
const umi = createUmi("http://127.0.0.1:8899").use(mplCore());
9-
10-
let keypair = umi.eddsa.createKeypairFromSecretKey(new Uint8Array(wallet));
11-
const signer = createSignerFromKeypair(umi, keypair);
12-
umi.use(signerIdentity(signer));
136
// Works
147
const test1 = async () => {
15-
//const umi = await createUmi();
16-
const assetOwner = umi.identity;
17-
//const collectionUmi = await createUmi();
18-
19-
const assetSigner = generateSigner(umi);
20-
await umi.rpc.airdrop(keypair.publicKey, sol(10));
21-
//await umi.rpc.airdrop(assetSigner.publicKey, sol(10));
22-
const assetAddress = assetSigner.publicKey;
23-
await createV2(umi, {
24-
asset: assetSigner,
25-
name: 'My Asset',
26-
uri: 'https://example.com/my-asset.json',
27-
}).sendAndConfirm(umi);
28-
29-
const collectionSigner = generateSigner(umi);
30-
const collectionAddress = collectionSigner.publicKey;
31-
//expect(false).toBeTruthy()
32-
await createCollection(umi, {
33-
collection: collectionSigner,
34-
name: 'My Collection',
35-
uri: 'https://example.com/my-collection.json',
36-
}).sendAndConfirm(umi);
37-
38-
await addCollectionPlugin(umi, {
39-
collection: collectionAddress,
40-
plugin: {
41-
type: 'UpdateDelegate',
42-
authority: { type: 'Address', address: assetOwner.publicKey },
43-
additionalDelegates: [],
44-
},
45-
}).sendAndConfirm(umi);
46-
47-
await updateV2(umi, {
48-
asset: assetAddress,
49-
newCollection: collectionAddress,
50-
newUpdateAuthority: updateAuthority('Collection', [collectionAddress]),
51-
}).sendAndConfirm(umi);
8+
const umi = await createUmi();
9+
const assetOwner = umi.identity;
10+
const collectionUmi = await createUmi();
11+
12+
const assetSigner = generateSigner(umi);
13+
const assetAddress = assetSigner.publicKey;
14+
await createV2(umi, {
15+
asset: assetSigner,
16+
name: 'My Asset',
17+
uri: 'https://example.com/my-asset.json',
18+
}).sendAndConfirm(umi);
19+
20+
const collectionSigner = generateSigner(collectionUmi);
21+
const collectionAddress = collectionSigner.publicKey;
22+
await createCollection(collectionUmi, {
23+
collection: collectionSigner,
24+
name: 'My Collection',
25+
uri: 'https://example.com/my-collection.json',
26+
}).sendAndConfirm(collectionUmi);
27+
28+
await addCollectionPlugin(collectionUmi, {
29+
collection: collectionAddress,
30+
plugin: {
31+
type: 'UpdateDelegate',
32+
authority: { type: 'Address', address: assetOwner.publicKey },
33+
additionalDelegates: [],
34+
},
35+
}).sendAndConfirm(collectionUmi);
36+
37+
await updateV2(umi, {
38+
asset: assetAddress,
39+
newCollection: collectionAddress,
40+
newUpdateAuthority: updateAuthority('Collection', [collectionAddress]),
41+
}).sendAndConfirm(umi);
5242

53-
const asset = await fetchAssetV1(umi, assetAddress);
54-
console.log("\n\n\nTest 1 -> Asset Owner matches? ", asset.owner === assetOwner.publicKey);
43+
const asset = await fetchAssetV1(umi, assetAddress);
44+
console.log("\n\n\nTest 1 -> Asset Owner matches? ", asset.owner === assetOwner.publicKey);
5545

56-
console.log("Test 1 -> Update Authority matches? ", asset.updateAuthority.type === 'Collection' && asset.updateAuthority.address === collectionAddress);
46+
console.log("Test 1 -> Update Authority matches? ", asset.updateAuthority.type === 'Collection' && asset.updateAuthority.address === collectionAddress);
5747
};
5848

5949
const test2 = async() => {
60-
const umi = createUmi("http://127.0.0.1:8899").use(mplCore());
61-
let keypair = umi.eddsa.createKeypairFromSecretKey(new Uint8Array(wallet));
62-
const signer = createSignerFromKeypair(umi, keypair);
63-
umi.use(signerIdentity(signer));
64-
50+
const umi = await createUmi();
6551
const assetOwner = umi.identity;
66-
67-
const collectionUmi = createUmi("http://127.0.0.1:8899").use(mplCore());
68-
let collectionUmiKeypair = umi.eddsa.generateKeypair();
69-
await umi.rpc.airdrop(collectionUmiKeypair.publicKey, sol(10));
70-
const collectionUmiSigner = createSignerFromKeypair(umi, collectionUmiKeypair);
71-
collectionUmi.use(signerIdentity(collectionUmiSigner));
52+
const collectionUmi = await createUmi();
7253

7354
const assetSigner = generateSigner(umi);
7455
const assetAddress = assetSigner.publicKey;
@@ -99,7 +80,6 @@ const test2 = async() => {
9980

10081
await updateV2(umi, {
10182
asset: assetAddress,
102-
authority: assetOwner,
10383
newCollection: collectionAddress,
10484
newUpdateAuthority: updateAuthority('Collection', [collectionAddress]),
10585
}).sendAndConfirm(umi);
@@ -114,18 +94,9 @@ const test2 = async() => {
11494
}
11595

11696
const test3 = async() => {
117-
const umi = createUmi("http://127.0.0.1:8899").use(mplCore());
118-
let keypair = umi.eddsa.createKeypairFromSecretKey(new Uint8Array(wallet));
119-
const signer = createSignerFromKeypair(umi, keypair);
120-
umi.use(signerIdentity(signer));
121-
97+
const umi = await createUmi();
12298
const assetOwner = umi.identity;
123-
124-
const collectionUmi = createUmi("http://127.0.0.1:8899").use(mplCore());
125-
let collectionUmiKeypair = umi.eddsa.generateKeypair();
126-
await umi.rpc.airdrop(collectionUmiKeypair.publicKey, sol(10));
127-
const collectionUmiSigner = createSignerFromKeypair(umi, collectionUmiKeypair);
128-
collectionUmi.use(signerIdentity(collectionUmiSigner));
99+
const collectionUmi = await createUmi();
129100
const collectionOwner = collectionUmi.identity;
130101

131102
const assetSigner = generateSigner(umi);
@@ -179,4 +150,3 @@ test2().then(() => {
179150
test3().then(() => {
180151
console.log("\nTest 3 completed!")
181152
})
182-

0 commit comments

Comments
 (0)