@@ -8,133 +8,134 @@ import {
8
8
getMetadataPointerState ,
9
9
} from '../../src' ;
10
10
11
- describe ( 'SPL Token 2022 Metadata Extension' , ( ) => {
12
- it ( 'can create createInitializeMetadataPointerInstruction' , ( ) => {
13
- const mint = PublicKey . unique ( ) ;
14
- const authority = new PublicKey ( '1111111QLbz7JHiBTspS962RLKV8GndWFwiEaqKM' ) ;
15
- const metadataAddress = new PublicKey ( '1111111ogCyDbaRMvkdsHB3qfdyFYaG1WtRUAfdh' ) ;
11
+ const AUTHORITY_ADDRESS_BYTES = Buffer . alloc ( 32 ) . fill ( 8 ) ;
12
+ const METADATA_ADDRESS_BYTES = Buffer . alloc ( 32 ) . fill ( 5 ) ;
13
+ const NULL_OPTIONAL_NONZERO_PUBKEY_BYTES = Buffer . alloc ( 32 ) . fill ( 0 ) ;
16
14
15
+ describe ( 'SPL Token 2022 MetadataPointer Extension' , ( ) => {
16
+ it ( 'can create InitializeMetadataPointerInstruction' , ( ) => {
17
+ const mint = PublicKey . unique ( ) ;
18
+ const authority = new PublicKey ( AUTHORITY_ADDRESS_BYTES ) ;
19
+ const metadataAddress = new PublicKey ( METADATA_ADDRESS_BYTES ) ;
17
20
const instruction = createInitializeMetadataPointerInstruction (
18
21
mint ,
19
22
authority ,
20
23
metadataAddress ,
21
24
TOKEN_2022_PROGRAM_ID
22
25
) ;
23
-
24
26
expect ( instruction ) . to . deep . equal (
25
27
new TransactionInstruction ( {
26
28
programId : TOKEN_2022_PROGRAM_ID ,
27
29
keys : [ { isSigner : false , isWritable : true , pubkey : mint } ] ,
28
- data : Buffer . from ( [
29
- // Output of rust implementation
30
- 39 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
31
- 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 2 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
30
+ data : Buffer . concat ( [
31
+ Buffer . from ( [
32
+ 39 , // Token instruction discriminator
33
+ 0 , // MetadataPointer instruction discriminator
34
+ ] ) ,
35
+ AUTHORITY_ADDRESS_BYTES ,
36
+ METADATA_ADDRESS_BYTES ,
32
37
] ) ,
33
38
} )
34
39
) ;
35
40
} ) ;
36
-
37
- it ( 'can create createUpdateMetadataPointerInstruction' , ( ) => {
41
+ it ( 'can create UpdateMetadataPointerInstruction' , ( ) => {
38
42
const mint = PublicKey . unique ( ) ;
39
43
const authority = PublicKey . unique ( ) ;
40
- const metadataAddress = new PublicKey ( '11111112cMQwSC9qirWGjZM6gLGwW69X22mqwLLGP' ) ;
41
-
44
+ const metadataAddress = new PublicKey ( METADATA_ADDRESS_BYTES ) ;
42
45
const instruction = createUpdateMetadataPointerInstruction ( mint , authority , metadataAddress ) ;
43
-
44
46
expect ( instruction ) . to . deep . equal (
45
47
new TransactionInstruction ( {
46
48
programId : TOKEN_2022_PROGRAM_ID ,
47
49
keys : [
48
50
{ isSigner : false , isWritable : true , pubkey : mint } ,
49
51
{ isSigner : true , isWritable : false , pubkey : authority } ,
50
52
] ,
51
- data : Buffer . from ( [
52
- // Output of rust implementation
53
- 39 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 4 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
54
- 0 ,
53
+ data : Buffer . concat ( [
54
+ Buffer . from ( [
55
+ 39 , // Token instruction discriminator
56
+ 1 , // MetadataPointer instruction discriminator
57
+ ] ) ,
58
+ METADATA_ADDRESS_BYTES ,
55
59
] ) ,
56
60
} )
57
61
) ;
58
62
} ) ;
59
-
60
- it ( 'can create createUpdateMetadataPointerInstruction to none' , ( ) => {
63
+ it ( 'can create UpdateMetadataPointerInstruction to none' , ( ) => {
61
64
const mint = PublicKey . unique ( ) ;
62
65
const authority = PublicKey . unique ( ) ;
63
66
const metadataAddress = null ;
64
-
65
67
const instruction = createUpdateMetadataPointerInstruction ( mint , authority , metadataAddress ) ;
66
-
67
68
expect ( instruction ) . to . deep . equal (
68
69
new TransactionInstruction ( {
69
70
programId : TOKEN_2022_PROGRAM_ID ,
70
71
keys : [
71
72
{ isSigner : false , isWritable : true , pubkey : mint } ,
72
73
{ isSigner : true , isWritable : false , pubkey : authority } ,
73
74
] ,
74
- data : Buffer . from ( [
75
- // Output of rust implementation
76
- 39 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
77
- 0 ,
75
+ data : Buffer . concat ( [
76
+ Buffer . from ( [
77
+ 39 , // Token instruction discriminator
78
+ 1 , // MetadataPointer instruction discriminator
79
+ ] ) ,
80
+ NULL_OPTIONAL_NONZERO_PUBKEY_BYTES ,
78
81
] ) ,
79
82
} )
80
83
) ;
81
84
} ) ;
82
-
83
85
it ( 'can get state with authority and metadata address' , async ( ) => {
84
86
const mintInfo = {
85
- tlvData : Buffer . from ( [
86
- 18 , 0 , 64 , 0 , 134 , 125 , 9 , 16 , 205 , 223 , 26 , 224 , 220 , 174 , 52 , 213 , 193 , 216 , 9 , 80 , 82 , 181 , 8 , 228 ,
87
- 75 , 112 , 233 , 116 , 2 , 183 , 51 , 228 , 88 , 64 , 179 , 158 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
88
- 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ,
87
+ tlvData : Buffer . concat ( [
88
+ Buffer . from ( [
89
+ // Extension discriminator
90
+ 18 , 0 ,
91
+ // Extension length
92
+ 64 , 0 ,
93
+ ] ) ,
94
+ AUTHORITY_ADDRESS_BYTES ,
95
+ METADATA_ADDRESS_BYTES ,
89
96
] ) ,
90
97
} as Mint ;
91
-
92
98
const metadataPointer = getMetadataPointerState ( mintInfo ) ;
93
-
94
99
expect ( metadataPointer ) . to . deep . equal ( {
95
- authority : new PublicKey ( [
96
- 134 , 125 , 9 , 16 , 205 , 223 , 26 , 224 , 220 , 174 , 52 , 213 , 193 , 216 , 9 , 80 , 82 , 181 , 8 , 228 , 75 , 112 , 233 ,
97
- 116 , 2 , 183 , 51 , 228 , 88 , 64 , 179 , 158 ,
98
- ] ) ,
99
- metadataAddress : new PublicKey ( [
100
- 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ,
101
- ] ) ,
100
+ authority : new PublicKey ( AUTHORITY_ADDRESS_BYTES ) ,
101
+ metadataAddress : new PublicKey ( METADATA_ADDRESS_BYTES ) ,
102
102
} ) ;
103
103
} ) ;
104
104
it ( 'can get state with only metadata address' , async ( ) => {
105
105
const mintInfo = {
106
- tlvData : Buffer . from ( [
107
- 18 , 0 , 64 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
108
- 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ,
106
+ tlvData : Buffer . concat ( [
107
+ Buffer . from ( [
108
+ // Extension discriminator
109
+ 18 , 0 ,
110
+ // Extension length
111
+ 64 , 0 ,
112
+ ] ) ,
113
+ NULL_OPTIONAL_NONZERO_PUBKEY_BYTES ,
114
+ METADATA_ADDRESS_BYTES ,
109
115
] ) ,
110
116
} as Mint ;
111
-
112
117
const metadataPointer = getMetadataPointerState ( mintInfo ) ;
113
-
114
118
expect ( metadataPointer ) . to . deep . equal ( {
115
119
authority : null ,
116
- metadataAddress : new PublicKey ( [
117
- 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ,
118
- ] ) ,
120
+ metadataAddress : new PublicKey ( METADATA_ADDRESS_BYTES ) ,
119
121
} ) ;
120
122
} ) ;
121
-
122
123
it ( 'can get state with only authority address' , async ( ) => {
123
124
const mintInfo = {
124
- tlvData : Buffer . from ( [
125
- 18 , 0 , 64 , 0 , 16 , 218 , 238 , 42 , 17 , 19 , 152 , 173 , 216 , 24 , 229 , 204 , 215 , 108 , 49 , 98 , 233 , 115 , 53 ,
126
- 252 , 9 , 156 , 216 , 23 , 14 , 157 , 139 , 132 , 28 , 182 , 4 , 191 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
127
- 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
125
+ tlvData : Buffer . concat ( [
126
+ Buffer . from ( [
127
+ // Extension discriminator
128
+ 18 , 0 ,
129
+ // Extension length
130
+ 64 , 0 ,
131
+ ] ) ,
132
+ AUTHORITY_ADDRESS_BYTES ,
133
+ NULL_OPTIONAL_NONZERO_PUBKEY_BYTES ,
128
134
] ) ,
129
135
} as Mint ;
130
-
131
136
const metadataPointer = getMetadataPointerState ( mintInfo ) ;
132
-
133
137
expect ( metadataPointer ) . to . deep . equal ( {
134
- authority : new PublicKey ( [
135
- 16 , 218 , 238 , 42 , 17 , 19 , 152 , 173 , 216 , 24 , 229 , 204 , 215 , 108 , 49 , 98 , 233 , 115 , 53 , 252 , 9 , 156 , 216 ,
136
- 23 , 14 , 157 , 139 , 132 , 28 , 182 , 4 , 191 ,
137
- ] ) ,
138
+ authority : new PublicKey ( AUTHORITY_ADDRESS_BYTES ) ,
138
139
metadataAddress : null ,
139
140
} ) ;
140
141
} ) ;
0 commit comments