1- import { PublicKey , SystemProgram } from "@solana/web3.js" ;
2- import { decodeExecutePostedVaa , decodeHeader } from ".." ;
1+ import { ChainName } from "@certusone/wormhole-sdk" ;
2+ import {
3+ PACKET_DATA_SIZE ,
4+ PublicKey ,
5+ SystemProgram ,
6+ TransactionInstruction ,
7+ } from "@solana/web3.js" ;
8+ import {
9+ ActionName ,
10+ decodeExecutePostedVaa ,
11+ decodeHeader ,
12+ encodeHeader ,
13+ } from ".." ;
14+ import { encodeExecutePostedVaa } from "../governance_payload/ExecutePostedVaa" ;
315
4- test ( "GovernancePayload" , ( done ) => {
16+ test ( "GovernancePayload ser/de " , ( done ) => {
517 jest . setTimeout ( 60000 ) ;
618
7- let governanceHeader = decodeHeader (
8- Buffer . from ( [ 80 , 84 , 71 , 77 , 0 , 0 , 0 , 26 , 0 , 0 , 0 , 0 ] )
9- ) ;
19+ // Valid header 1
20+ let expectedGovernanceHeader = {
21+ targetChainId : "pythnet" as ChainName ,
22+ action : "ExecutePostedVaa" as ActionName ,
23+ } ;
24+ let buffer = Buffer . alloc ( PACKET_DATA_SIZE ) ;
25+ let span = encodeHeader ( expectedGovernanceHeader , buffer ) ;
26+ expect (
27+ buffer . subarray ( 0 , span ) . equals ( Buffer . from ( [ 80 , 84 , 71 , 77 , 0 , 0 , 0 , 26 ] ) )
28+ ) . toBeTruthy ( ) ;
29+
30+ let governanceHeader = decodeHeader ( buffer . subarray ( 0 , span ) ) ;
1031 expect ( governanceHeader ?. targetChainId ) . toBe ( "pythnet" ) ;
1132 expect ( governanceHeader ?. action ) . toBe ( "ExecutePostedVaa" ) ;
1233
13- governanceHeader = decodeHeader (
14- Buffer . from ( [ 80 , 84 , 71 , 77 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] )
15- ) ;
34+ // Valid header 2
35+ expectedGovernanceHeader = {
36+ targetChainId : "unset" as ChainName ,
37+ action : "ExecutePostedVaa" as ActionName ,
38+ } ;
39+ buffer = Buffer . alloc ( PACKET_DATA_SIZE ) ;
40+ span = encodeHeader ( expectedGovernanceHeader , buffer ) ;
41+ expect (
42+ buffer . subarray ( 0 , span ) . equals ( Buffer . from ( [ 80 , 84 , 71 , 77 , 0 , 0 , 0 , 0 ] ) )
43+ ) . toBeTruthy ( ) ;
44+ governanceHeader = decodeHeader ( buffer . subarray ( 0 , span ) ) ;
1645 expect ( governanceHeader ?. targetChainId ) . toBe ( "unset" ) ;
1746 expect ( governanceHeader ?. action ) . toBe ( "ExecutePostedVaa" ) ;
1847
19- governanceHeader = decodeHeader (
20- Buffer . from ( [ 80 , 84 , 71 , 77 , 1 , 3 , 0 , 1 , 0 , 0 , 0 , 0 ] )
21- ) ;
48+ // Valid header 3
49+ expectedGovernanceHeader = {
50+ targetChainId : "solana" as ChainName ,
51+ action : "SetFee" as ActionName ,
52+ } ;
53+ buffer = Buffer . alloc ( PACKET_DATA_SIZE ) ;
54+ span = encodeHeader ( expectedGovernanceHeader , buffer ) ;
55+ expect (
56+ buffer . subarray ( 0 , span ) . equals ( Buffer . from ( [ 80 , 84 , 71 , 77 , 1 , 3 , 0 , 1 ] ) )
57+ ) . toBeTruthy ( ) ;
58+ governanceHeader = decodeHeader ( buffer . subarray ( 0 , span ) ) ;
2259 expect ( governanceHeader ?. targetChainId ) . toBe ( "solana" ) ;
2360 expect ( governanceHeader ?. action ) . toBe ( "SetFee" ) ;
2461
@@ -40,27 +77,49 @@ test("GovernancePayload", (done) => {
4077 ) ;
4178 expect ( governanceHeader ) . toBeUndefined ( ) ;
4279
43- // Decode executePostVaa
44- let executePostedVaaArgs = decodeExecutePostedVaa (
45- Buffer . from ( [ 80 , 84 , 71 , 77 , 0 , 0 , 0 , 26 , 0 , 0 , 0 , 0 ] )
46- ) ;
47- expect ( executePostedVaaArgs ?. header . targetChainId ) . toBe ( "pythnet" ) ;
48- expect ( executePostedVaaArgs ?. header . action ) . toBe ( "ExecutePostedVaa" ) ;
80+ // Decode executePostVaa with empty instructions
81+ let expectedExecuteVaaArgs = {
82+ targetChainId : "pythnet" as ChainName ,
83+ instructions : [ ] as TransactionInstruction [ ] ,
84+ } ;
85+ buffer = encodeExecutePostedVaa ( expectedExecuteVaaArgs ) ;
86+ expect (
87+ buffer . equals ( Buffer . from ( [ 80 , 84 , 71 , 77 , 0 , 0 , 0 , 26 , 0 , 0 , 0 , 0 ] ) )
88+ ) . toBeTruthy ( ) ;
89+ let executePostedVaaArgs = decodeExecutePostedVaa ( buffer ) ;
90+ expect ( executePostedVaaArgs ?. targetChainId ) . toBe ( "pythnet" ) ;
4991 expect ( executePostedVaaArgs ?. instructions . length ) . toBe ( 0 ) ;
5092
51- executePostedVaaArgs = decodeExecutePostedVaa (
52- Buffer . from ( [
53- 80 , 84 , 71 , 77 , 0 , 0 , 0 , 26 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
54- 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 2 , 0 , 0 , 0 ,
55- 141 , 65 , 8 , 219 , 216 , 57 , 229 , 94 , 74 , 17 , 138 , 50 , 121 , 176 , 38 , 178 , 50 ,
56- 229 , 210 , 103 , 232 , 253 , 133 , 66 , 14 , 47 , 228 , 224 , 162 , 147 , 232 , 251 , 1 ,
57- 1 , 252 , 221 , 21 , 33 , 156 , 1 , 72 , 252 , 246 , 229 , 150 , 218 , 109 , 165 , 127 ,
58- 11 , 165 , 252 , 140 , 6 , 121 , 57 , 204 , 91 , 119 , 165 , 106 , 241 , 234 , 131 , 75 ,
59- 180 , 0 , 1 , 12 , 0 , 0 , 0 , 2 , 0 , 0 , 0 , 0 , 152 , 13 , 0 , 0 , 0 , 0 , 0 ,
60- ] )
61- ) ;
62- expect ( executePostedVaaArgs ?. header . targetChainId ) . toBe ( "pythnet" ) ;
63- expect ( executePostedVaaArgs ?. header . action ) . toBe ( "ExecutePostedVaa" ) ;
93+ // Decode executePostVaa with one system instruction
94+ expectedExecuteVaaArgs = {
95+ targetChainId : "pythnet" as ChainName ,
96+ instructions : [
97+ SystemProgram . transfer ( {
98+ fromPubkey : new PublicKey (
99+ "AWQ18oKzd187aM2oMB4YirBcdgX1FgWfukmqEX91BRES"
100+ ) ,
101+ toPubkey : new PublicKey ( "J25GT2knN8V2Wvg9jNrYBuj9SZdsLnU6bK7WCGrL7daj" ) ,
102+ lamports : 890880 ,
103+ } ) ,
104+ ] as TransactionInstruction [ ] ,
105+ } ;
106+ buffer = encodeExecutePostedVaa ( expectedExecuteVaaArgs ) ;
107+ expect (
108+ buffer . equals (
109+ Buffer . from ( [
110+ 80 , 84 , 71 , 77 , 0 , 0 , 0 , 26 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
111+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 2 , 0 ,
112+ 0 , 0 , 141 , 65 , 8 , 219 , 216 , 57 , 229 , 94 , 74 , 17 , 138 , 50 , 121 , 176 , 38 ,
113+ 178 , 50 , 229 , 210 , 103 , 232 , 253 , 133 , 66 , 14 , 47 , 228 , 224 , 162 , 147 ,
114+ 232 , 251 , 1 , 1 , 252 , 221 , 21 , 33 , 156 , 1 , 72 , 252 , 246 , 229 , 150 , 218 ,
115+ 109 , 165 , 127 , 11 , 165 , 252 , 140 , 6 , 121 , 57 , 204 , 91 , 119 , 165 , 106 ,
116+ 241 , 234 , 131 , 75 , 180 , 0 , 1 , 12 , 0 , 0 , 0 , 2 , 0 , 0 , 0 , 0 , 152 , 13 , 0 , 0 ,
117+ 0 , 0 , 0 ,
118+ ] )
119+ )
120+ ) . toBeTruthy ( ) ;
121+ executePostedVaaArgs = decodeExecutePostedVaa ( buffer ) ;
122+ expect ( executePostedVaaArgs ?. targetChainId ) . toBe ( "pythnet" ) ;
64123 expect ( executePostedVaaArgs ?. instructions . length ) . toBe ( 1 ) ;
65124 expect (
66125 executePostedVaaArgs ?. instructions [ 0 ] . programId . equals (
0 commit comments