@@ -5,6 +5,8 @@ pragma solidity ^0.8.0;
55import "../../contracts/pyth/PythUpgradable.sol " ;
66import "../../contracts/pyth/PythInternalStructs.sol " ;
77import "../../contracts/pyth/PythAccumulator.sol " ;
8+ import "../../contracts/pyth/PythGetters.sol " ;
9+ import "../../contracts/pyth/PythGovernanceInstructions.sol " ;
810
911import "../../contracts/libraries/MerkleTree.sol " ;
1012
@@ -15,10 +17,15 @@ import "@pythnetwork/pyth-sdk-solidity/IPyth.sol";
1517import "@pythnetwork/pyth-sdk-solidity/PythUtils.sol " ;
1618
1719import "forge-std/Test.sol " ;
20+ import "forge-std/console.sol " ;
1821import "./RandTestUtils.t.sol " ;
1922import "./WormholeTestUtils.t.sol " ;
2023
21- abstract contract PythTestUtils is Test , RandTestUtils {
24+ abstract contract PythTestUtils is
25+ Test ,
26+ RandTestUtils ,
27+ PythGovernanceInstructions
28+ {
2229 uint16 constant SOURCE_EMITTER_CHAIN_ID = 0x1 ;
2330 bytes32 constant SOURCE_EMITTER_ADDRESS =
2431 0x71f8dcb863d176e2c420ad6610cf687359612b6fb392e0642b0ca6b1f186aa3b ;
@@ -28,7 +35,39 @@ abstract contract PythTestUtils is Test, RandTestUtils {
2835 0x0000000000000000000000000000000000000000000000000000000000000011 ;
2936 uint constant SINGLE_UPDATE_FEE_IN_WEI = 1 ;
3037
38+ enum Signer {
39+ Wormhole,
40+ Verifier
41+ }
42+
3143 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+ }
3271
3372 function setUpPyth (
3473 WormholeTestUtils wormholeTestUtils
@@ -58,7 +97,6 @@ abstract contract PythTestUtils is Test, RandTestUtils {
5897 );
5998
6099 _wormholeTestUtils = wormholeTestUtils;
61-
62100 return address (pyth);
63101 }
64102
@@ -69,9 +107,9 @@ abstract contract PythTestUtils is Test, RandTestUtils {
69107 uint64 sequence ,
70108 bytes memory payload ,
71109 uint8 numSigners ,
72- bool verifier
110+ Signer signer
73111 ) internal view returns (bytes memory vaa ) {
74- if (! verifier)
112+ if (signer == Signer.Wormhole) {
75113 return
76114 _wormholeTestUtils.generateVaa (
77115 timestamp,
@@ -81,6 +119,17 @@ abstract contract PythTestUtils is Test, RandTestUtils {
81119 payload,
82120 numSigners
83121 );
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+ }
84133 revert PythErrors.InvalidSigner ();
85134 }
86135
@@ -188,7 +237,7 @@ abstract contract PythTestUtils is Test, RandTestUtils {
188237 0 ,
189238 wormholePayload,
190239 config.numSigners,
191- false
240+ Signer.Wormhole
192241 );
193242
194243 if (config.brokenVaa) {
@@ -204,7 +253,8 @@ abstract contract PythTestUtils is Test, RandTestUtils {
204253 uint32 (0x504e4155 ), // PythAccumulator.ACCUMULATOR_MAGIC
205254 uint8 (1 ), // major version
206255 uint8 (0 ), // minor version
207- uint8 (0 ), // trailing header size
256+ uint8 (1 ), // trailing header size
257+ uint8 (0 ), // Signer
208258 uint8 (PythAccumulator.UpdateType.WormholeMerkle),
209259 uint16 (wormholeMerkleVaa.length ),
210260 wormholeMerkleVaa,
@@ -248,7 +298,7 @@ abstract contract PythTestUtils is Test, RandTestUtils {
248298 0 ,
249299 wormholePayload,
250300 config.numSigners,
251- false
301+ Signer.Wormhole
252302 );
253303
254304 if (config.brokenVaa) {
@@ -374,7 +424,7 @@ abstract contract PythTestUtils is Test, RandTestUtils {
374424 futureData
375425 ),
376426 numSigners,
377- false
427+ Signer.Wormhole
378428 );
379429 }
380430
0 commit comments