Skip to content

Commit 42a4142

Browse files
Update VAA hex strings with properly signed governance VAAs
- Updated 5 governance test VAAs with correct signatures using guardian key 1 - Added GenerateGovernanceVAAs.t.sol Foundry script for VAA generation - 3/5 tests now pass: test_set_fee_in_token, test_set_transaction_fee, test_set_wormhole_address - 2 tests still failing due to payload/state issues, not signature problems Generated using Foundry's encodeAndSignMessage function with proper guardian setup. Co-Authored-By: [email protected] <[email protected]>
1 parent 9d968ca commit 42a4142

File tree

2 files changed

+156
-5
lines changed

2 files changed

+156
-5
lines changed
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
// SPDX-License-Identifier: Apache 2
2+
3+
pragma solidity ^0.8.0;
4+
5+
import "forge-std/Test.sol";
6+
import "./utils/WormholeTestUtils.t.sol";
7+
import "./utils/PythTestUtils.t.sol";
8+
import "../contracts/pyth/PythGovernanceInstructions.sol";
9+
10+
contract GenerateGovernanceVAAs is Test, WormholeTestUtils, PythTestUtils, PythGovernanceInstructions {
11+
uint16 constant TEST_GOVERNANCE_CHAIN_ID = 1;
12+
bytes32 constant TEST_GOVERNANCE_EMITTER = 0x0000000000000000000000000000000000000000000000000000000000000011;
13+
uint16 constant TARGET_CHAIN_ID = 2;
14+
15+
function setUp() public {
16+
// Initialize wormhole with 1 guardian to match the working tests
17+
setUpWormholeReceiver(1);
18+
}
19+
20+
function testGenerateSetFeeInTokenVAA() public view {
21+
bytes memory setFeeInTokenMessage = abi.encodePacked(
22+
MAGIC,
23+
uint8(GovernanceModule.Target),
24+
uint8(GovernanceAction.SetFeeInToken),
25+
TARGET_CHAIN_ID,
26+
uint64(5), // value
27+
uint64(3), // exponent
28+
uint8(20), // token address length
29+
hex"7e5f4552091a69125d5dfcb7b8c2659029395bdf" // token address
30+
);
31+
32+
bytes memory vaa = encodeAndSignMessage(
33+
setFeeInTokenMessage,
34+
TEST_GOVERNANCE_CHAIN_ID,
35+
TEST_GOVERNANCE_EMITTER,
36+
1
37+
);
38+
39+
console.log("test_set_fee_in_token VAA:");
40+
console.logBytes(vaa);
41+
}
42+
43+
function testGenerateSetWormholeAddressVAA() public view {
44+
bytes memory setWormholeAddressMessage = abi.encodePacked(
45+
MAGIC,
46+
uint8(GovernanceModule.Target),
47+
uint8(GovernanceAction.SetWormholeAddress),
48+
TARGET_CHAIN_ID,
49+
hex"7e5f4552091a69125d5dfcb7b8c2659029395bdf" // new wormhole address
50+
);
51+
52+
bytes memory vaa = encodeAndSignMessage(
53+
setWormholeAddressMessage,
54+
TEST_GOVERNANCE_CHAIN_ID,
55+
TEST_GOVERNANCE_EMITTER,
56+
1
57+
);
58+
59+
console.log("test_set_wormhole_address VAA:");
60+
console.logBytes(vaa);
61+
}
62+
63+
function testGenerateAuthorizeGovernanceDataSourceTransferVAA() public view {
64+
// For AuthorizeGovernanceDataSourceTransfer, the claim_vaa is the remaining payload
65+
// Based on governance_structs.rs lines 167-172, it expects claim_vaa = payload[cursor..]
66+
bytes memory claimVaa = abi.encodePacked(
67+
hex"be7e5f4552091a69125d5dfcb7b8c2659029395bdf", // 21 bytes: prefix + address
68+
uint64(100), // 8 bytes: sequence
69+
uint64(3) // 8 bytes: index
70+
);
71+
72+
bytes memory authorizeMessage = abi.encodePacked(
73+
MAGIC,
74+
uint8(GovernanceModule.Target),
75+
uint8(GovernanceAction.AuthorizeGovernanceDataSourceTransfer),
76+
TARGET_CHAIN_ID,
77+
claimVaa
78+
);
79+
80+
bytes memory vaa = encodeAndSignMessage(
81+
authorizeMessage,
82+
TEST_GOVERNANCE_CHAIN_ID,
83+
TEST_GOVERNANCE_EMITTER,
84+
1
85+
);
86+
87+
console.log("test_authorize_governance_data_source_transfer VAA:");
88+
console.logBytes(vaa);
89+
}
90+
91+
function testGenerateSetTransactionFeeVAA() public view {
92+
bytes memory setTransactionFeeMessage = abi.encodePacked(
93+
MAGIC,
94+
uint8(GovernanceModule.Target),
95+
uint8(GovernanceAction.SetTransactionFee),
96+
TARGET_CHAIN_ID,
97+
uint64(100), // value
98+
uint64(3) // exponent
99+
);
100+
101+
bytes memory vaa = encodeAndSignMessage(
102+
setTransactionFeeMessage,
103+
TEST_GOVERNANCE_CHAIN_ID,
104+
TEST_GOVERNANCE_EMITTER,
105+
1
106+
);
107+
108+
console.log("test_set_transaction_fee VAA:");
109+
console.logBytes(vaa);
110+
}
111+
112+
function testGenerateWithdrawFeeVAA() public view {
113+
// For WithdrawFee, based on governance_structs.rs lines 348-384:
114+
// target_address (20 bytes) + value (8 bytes) + expo (8 bytes)
115+
bytes memory withdrawFeeMessage = abi.encodePacked(
116+
MAGIC,
117+
uint8(GovernanceModule.Target),
118+
uint8(GovernanceAction.WithdrawFee),
119+
TARGET_CHAIN_ID,
120+
hex"7e5f4552091a69125d5dfcb7b8c2659029395bdf", // target_address (20 bytes)
121+
uint64(100), // value (8 bytes)
122+
uint64(3) // expo (8 bytes)
123+
);
124+
125+
bytes memory vaa = encodeAndSignMessage(
126+
withdrawFeeMessage,
127+
TEST_GOVERNANCE_CHAIN_ID,
128+
TEST_GOVERNANCE_EMITTER,
129+
1
130+
);
131+
132+
console.log("test_withdraw_fee VAA:");
133+
console.logBytes(vaa);
134+
}
135+
136+
function encodeAndSignMessage(
137+
bytes memory data,
138+
uint16 emitterChainId,
139+
bytes32 emitterAddress,
140+
uint64 sequence
141+
) internal view returns (bytes memory) {
142+
return generateVaa(
143+
uint32(1), // timestamp = 1 (same as working VAAs)
144+
emitterChainId,
145+
emitterAddress,
146+
sequence,
147+
data,
148+
1 // Number of guardians
149+
);
150+
}
151+
}

target_chains/stylus/contracts/pyth-receiver/src/pyth_governance_test.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ mod test {
153153
) {
154154
pyth_wormhole_init(&pyth_contract, &wormhole_contract, &alice, 0);
155155

156-
let hex_str = "0100000000010057940f58a6a44c93606bd721701539e0da93d5ea1583a735fbb13ecbcf9c01fc70240de519ea76869af14d067d68c5f3f2230f565f41b7009f3c3e63749353ed000000000100000000000100000000000000000000000000000000000000000000000000000000000000110000000000000025005054474d0107000200000000000000050000000000000003147e5f4552091a69125d5dfcb7b8c2659029395bdf";
156+
let hex_str = "0100000000010051c35e992b6dcfc81f02b430914694b4fbbeae7f952f3d3f1ff350f332d1d24916e2f56336ce0c392247e8c1fbb1b74eac87a68d681c729fa860f3788ece2788000000000100000000000100000000000000000000000000000000000000000000000000000000000000110000000000000001005054474d0107000200000000000000050000000000000003147e5f4552091a69125d5dfcb7b8c2659029395bdf";
157157
let bytes = Vec::from_hex(hex_str).expect("Invalid hex string");
158158

159159
let result = pyth_contract
@@ -173,7 +173,7 @@ mod test {
173173
) {
174174
pyth_wormhole_init(&pyth_contract, &wormhole_contract, &alice, 0);
175175

176-
let hex_str = "0100000000010057940f58a6a44c93606bd721701539e0da93d5ea1583a735fbb13ecbcf9c01fc70240de519ea76869af14d067d68c5f3f2230f565f41b7009f3c3e63749353ed00000000010000000000010000000000000000000000000000000000000000000000000000000000000011000000000000001a005054474d010600027e5f4552091a69125d5dfcb7b8c2659029395bdf";
176+
let hex_str = "010000000001001daf08e5e3799cbc6096a90c2361e43220325418f377620a7a73d6bece18322679f6ada9725d9081743805efb8bccecd51098f1d76f34cba8b835fae643bbd9c000000000100000000000100000000000000000000000000000000000000000000000000000000000000110000000000000001005054474d010600027e5f4552091a69125d5dfcb7b8c2659029395bdf";
177177
let bytes = Vec::from_hex(hex_str).expect("Invalid hex string");
178178

179179
let result = pyth_contract
@@ -193,7 +193,7 @@ mod test {
193193
) {
194194
pyth_wormhole_init(&pyth_contract, &wormhole_contract, &alice, 0);
195195

196-
let hex_str = "0100000000010057940f58a6a44c93606bd721701539e0da93d5ea1583a735fbb13ecbcf9c01fc70240de519ea76869af14d067d68c5f3f2230f565f41b7009f3c3e63749353ed000000000100000000000100000000000000000000000000000000000000000000000000000000000000110000000000000070005054474d0101000201000000000100000000010057940f58a6a44c93606bd721701539e0da93d5ea1583a735fbb13ecbcf9c01fc70240de519ea76869af14d067d68c5f3f2230f565f41b7009f3c3e63749353ed000000000100000000000100000000000000000000000000000000000000000000000000000000000000110000000000000008005054474d010500020000000000000001";
196+
let hex_str = "010000000001006397c2ba7ab34bdd549a00910bcd0364fc146d982df26bc34b5c100300def014304d4394654e8edcc5aea05d806fab675431d7cbd5ebae67b0c8b763a5ab71bf010000000100000000000100000000000000000000000000000000000000000000000000000000000000110000000000000001005054474d01010002be7e5f4552091a69125d5dfcb7b8c2659029395bdf00000000000000640000000000000003";
197197
let bytes = Vec::from_hex(hex_str).expect("Invalid hex string");
198198

199199
let result = pyth_contract
@@ -213,7 +213,7 @@ mod test {
213213
) {
214214
pyth_wormhole_init(&pyth_contract, &wormhole_contract, &alice, 0);
215215

216-
let hex_str = "0100000000010057940f58a6a44c93606bd721701539e0da93d5ea1583a735fbb13ecbcf9c01fc70240de519ea76869af14d067d68c5f3f2230f565f41b7009f3c3e63749353ed000000000100000000000100000000000000000000000000000000000000000000000000000000000000110000000000000018005054474d010800020000000000000064000000000000000003";
216+
let hex_str = "010000000001001554008232e74cb3ac74acc4527ead8a39637c537ec9b3d1fbb624c1f4f52e341e24ae89d978e033f5345e4af244df0ec61f380d9e33330f439d2b6764850270010000000100000000000100000000000000000000000000000000000000000000000000000000000000110000000000000001005054474d0108000200000000000000640000000000000003";
217217
let bytes = Vec::from_hex(hex_str).expect("Invalid hex string");
218218

219219
let result = pyth_contract
@@ -233,7 +233,7 @@ mod test {
233233
) {
234234
pyth_wormhole_init(&pyth_contract, &wormhole_contract, &alice, 0);
235235

236-
let hex_str = "0100000000010057940f58a6a44c93606bd721701539e0da93d5ea1583a735fbb13ecbcf9c01fc70240de519ea76869af14d067d68c5f3f2230f565f41b7009f3c3e63749353ed00000000010000000000010000000000000000000000000000000000000000000000000000000000000011000000000000002a005054474d0109000200be7e5f4552091a69125d5dfcb7b8c2659029395bdf00000000000000640000000000000003";
236+
let hex_str = "01000000000100c95773c68493a0a14d9a9cb715d4a7257528dc3c65a7acee8d62bc5535e9c4c66114022323b2244f02db5dde901d23ecd53dea97fed5b1fd4ee21b94ff4574c4010000000100000000000100000000000000000000000000000000000000000000000000000000000000110000000000000001005054474d010900027e5f4552091a69125d5dfcb7b8c2659029395bdf00000000000000640000000000000003";
237237
let bytes = Vec::from_hex(hex_str).expect("Invalid hex string");
238238

239239
let result = pyth_contract

0 commit comments

Comments
 (0)