@@ -5,6 +5,8 @@ pragma solidity ^0.8.0;
5
5
import "../../contracts/pyth/PythUpgradable.sol " ;
6
6
import "../../contracts/pyth/PythInternalStructs.sol " ;
7
7
import "../../contracts/pyth/PythAccumulator.sol " ;
8
+ import "../../contracts/pyth/PythGetters.sol " ;
9
+ import "../../contracts/pyth/PythGovernanceInstructions.sol " ;
8
10
9
11
import "../../contracts/libraries/MerkleTree.sol " ;
10
12
@@ -15,10 +17,15 @@ import "@pythnetwork/pyth-sdk-solidity/IPyth.sol";
15
17
import "@pythnetwork/pyth-sdk-solidity/PythUtils.sol " ;
16
18
17
19
import "forge-std/Test.sol " ;
20
+ import "forge-std/console.sol " ;
18
21
import "./RandTestUtils.t.sol " ;
19
22
import "./WormholeTestUtils.t.sol " ;
20
23
21
- abstract contract PythTestUtils is Test , RandTestUtils {
24
+ abstract contract PythTestUtils is
25
+ Test ,
26
+ RandTestUtils ,
27
+ PythGovernanceInstructions
28
+ {
22
29
uint16 constant SOURCE_EMITTER_CHAIN_ID = 0x1 ;
23
30
bytes32 constant SOURCE_EMITTER_ADDRESS =
24
31
0x71f8dcb863d176e2c420ad6610cf687359612b6fb392e0642b0ca6b1f186aa3b ;
@@ -28,7 +35,39 @@ abstract contract PythTestUtils is Test, RandTestUtils {
28
35
0x0000000000000000000000000000000000000000000000000000000000000011 ;
29
36
uint constant SINGLE_UPDATE_FEE_IN_WEI = 1 ;
30
37
38
+ enum Signer {
39
+ Wormhole,
40
+ Verifier
41
+ }
42
+
31
43
WormholeTestUtils _wormholeTestUtils;
44
+ WormholeTestUtils _verifierTestUtils;
45
+
46
+ function setVerifier (address pyth , uint8 numSigners ) internal {
47
+ _verifierTestUtils = new WormholeTestUtils (numSigners);
48
+ uint64 sequence = PythGetters (pyth).lastExecutedGovernanceSequence ();
49
+
50
+ // Create governance VAA to set new verifier address
51
+ bytes memory payload = abi.encodePacked (
52
+ MAGIC,
53
+ uint8 (GovernanceModule.Target),
54
+ uint8 (GovernanceAction.SetVerifierAddress),
55
+ uint16 (2 ),
56
+ _verifierTestUtils.getWormholeReceiverAddr ()
57
+ );
58
+
59
+ bytes memory vaa = generateVaa (
60
+ uint32 (block .timestamp ),
61
+ GOVERNANCE_EMITTER_CHAIN_ID,
62
+ GOVERNANCE_EMITTER_ADDRESS,
63
+ sequence + 1 ,
64
+ payload,
65
+ _wormholeTestUtils.getTotalSigners (),
66
+ Signer.Wormhole
67
+ );
68
+
69
+ PythGovernance (pyth).executeGovernanceInstruction (vaa);
70
+ }
32
71
33
72
function setUpPyth (
34
73
WormholeTestUtils wormholeTestUtils
@@ -58,7 +97,6 @@ abstract contract PythTestUtils is Test, RandTestUtils {
58
97
);
59
98
60
99
_wormholeTestUtils = wormholeTestUtils;
61
-
62
100
return address (pyth);
63
101
}
64
102
@@ -69,9 +107,9 @@ abstract contract PythTestUtils is Test, RandTestUtils {
69
107
uint64 sequence ,
70
108
bytes memory payload ,
71
109
uint8 numSigners ,
72
- bool verifier
110
+ Signer signer
73
111
) internal view returns (bytes memory vaa ) {
74
- if (! verifier)
112
+ if (signer == Signer.Wormhole) {
75
113
return
76
114
_wormholeTestUtils.generateVaa (
77
115
timestamp,
@@ -81,6 +119,17 @@ abstract contract PythTestUtils is Test, RandTestUtils {
81
119
payload,
82
120
numSigners
83
121
);
122
+ } else if (signer == Signer.Verifier) {
123
+ return
124
+ _verifierTestUtils.generateVaa (
125
+ timestamp,
126
+ emitterChainId,
127
+ emitterAddress,
128
+ sequence,
129
+ payload,
130
+ numSigners
131
+ );
132
+ }
84
133
revert PythErrors.InvalidSigner ();
85
134
}
86
135
@@ -188,7 +237,7 @@ abstract contract PythTestUtils is Test, RandTestUtils {
188
237
0 ,
189
238
wormholePayload,
190
239
config.numSigners,
191
- false
240
+ Signer.Wormhole
192
241
);
193
242
194
243
if (config.brokenVaa) {
@@ -204,7 +253,8 @@ abstract contract PythTestUtils is Test, RandTestUtils {
204
253
uint32 (0x504e4155 ), // PythAccumulator.ACCUMULATOR_MAGIC
205
254
uint8 (1 ), // major version
206
255
uint8 (0 ), // minor version
207
- uint8 (0 ), // trailing header size
256
+ uint8 (1 ), // trailing header size
257
+ uint8 (0 ), // Signer
208
258
uint8 (PythAccumulator.UpdateType.WormholeMerkle),
209
259
uint16 (wormholeMerkleVaa.length ),
210
260
wormholeMerkleVaa,
@@ -248,7 +298,7 @@ abstract contract PythTestUtils is Test, RandTestUtils {
248
298
0 ,
249
299
wormholePayload,
250
300
config.numSigners,
251
- false
301
+ Signer.Wormhole
252
302
);
253
303
254
304
if (config.brokenVaa) {
@@ -374,7 +424,7 @@ abstract contract PythTestUtils is Test, RandTestUtils {
374
424
futureData
375
425
),
376
426
numSigners,
377
- false
427
+ Signer.Wormhole
378
428
);
379
429
}
380
430
0 commit comments