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" ;
5
4
6
- import wallet from "../../../wallet.json"
7
5
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 ) ) ;
13
6
// Works
14
7
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 ) ;
52
42
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 ) ;
55
45
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 ) ;
57
47
} ;
58
48
59
49
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 ( ) ;
65
51
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 ( ) ;
72
53
73
54
const assetSigner = generateSigner ( umi ) ;
74
55
const assetAddress = assetSigner . publicKey ;
@@ -99,7 +80,6 @@ const test2 = async() => {
99
80
100
81
await updateV2 ( umi , {
101
82
asset : assetAddress ,
102
- authority : assetOwner ,
103
83
newCollection : collectionAddress ,
104
84
newUpdateAuthority : updateAuthority ( 'Collection' , [ collectionAddress ] ) ,
105
85
} ) . sendAndConfirm ( umi ) ;
@@ -114,18 +94,9 @@ const test2 = async() => {
114
94
}
115
95
116
96
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 ( ) ;
122
98
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 ( ) ;
129
100
const collectionOwner = collectionUmi . identity ;
130
101
131
102
const assetSigner = generateSigner ( umi ) ;
@@ -179,4 +150,3 @@ test2().then(() => {
179
150
test3 ( ) . then ( ( ) => {
180
151
console . log ( "\nTest 3 completed!" )
181
152
} )
182
-
0 commit comments