Skip to content

Commit 1b759ce

Browse files
committed
Add set verifier to utils
1 parent 7590d39 commit 1b759ce

File tree

5 files changed

+71
-14
lines changed

5 files changed

+71
-14
lines changed

target_chains/ethereum/contracts/forge-test/Pyth.WormholeMerkleAccumulator.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ contract PythWormholeMerkleAccumulatorTest is Test, PythTestUtils {
553553
0,
554554
wormholePayload,
555555
1, // num signers
556-
false
556+
Signer.Wormhole
557557
);
558558

559559
updateData = new bytes[](1);

target_chains/ethereum/contracts/forge-test/PythGovernance.t.sol

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import "./utils/WormholeTestUtils.t.sol";
3333
import "./utils/PythTestUtils.t.sol";
3434
import "./utils/RandTestUtils.t.sol";
3535

36-
contract PythGovernanceTest is Test, PythTestUtils, PythGovernanceInstructions {
36+
contract PythGovernanceTest is Test, PythTestUtils {
3737
using BytesLib for bytes;
3838

3939
IPyth public pyth;
@@ -264,6 +264,9 @@ contract PythGovernanceTest is Test, PythTestUtils, PythGovernanceInstructions {
264264
}
265265

266266
function testSetVerifierAddress() public {
267+
setVerifier(address(pyth), 3);
268+
address oldVerifier = address(PythGetters(address(pyth)).verifier());
269+
267270
// Deploy a new verifier contract
268271
address newVerifier = new WormholeTestUtils(3)
269272
.getWormholeReceiverAddr();
@@ -281,10 +284,10 @@ contract PythGovernanceTest is Test, PythTestUtils, PythGovernanceInstructions {
281284
data,
282285
TEST_GOVERNANCE_CHAIN_ID,
283286
TEST_GOVERNANCE_EMITTER,
284-
1
287+
2
285288
);
286289

287-
address oldVerifier = address(PythGetters(address(pyth)).verifier());
290+
oldVerifier = address(PythGetters(address(pyth)).verifier());
288291
vm.expectEmit(true, true, true, true);
289292
emit VerifierAddressSet(oldVerifier, newVerifier);
290293

@@ -690,7 +693,7 @@ contract PythGovernanceTest is Test, PythTestUtils, PythGovernanceInstructions {
690693
sequence,
691694
data,
692695
numGuardians,
693-
false
696+
Signer.Wormhole
694697
);
695698
}
696699

target_chains/ethereum/contracts/forge-test/VerificationExperiments.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ contract VerificationExperiments is Test, PythTestUtils {
269269
sequence,
270270
bytes.concat(root),
271271
NUM_GUARDIAN_SIGNERS,
272-
false
272+
Signer.Wormhole
273273
);
274274

275275
++sequence;

target_chains/ethereum/contracts/forge-test/utils/PythTestUtils.t.sol

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ pragma solidity ^0.8.0;
55
import "../../contracts/pyth/PythUpgradable.sol";
66
import "../../contracts/pyth/PythInternalStructs.sol";
77
import "../../contracts/pyth/PythAccumulator.sol";
8+
import "../../contracts/pyth/PythGetters.sol";
9+
import "../../contracts/pyth/PythGovernanceInstructions.sol";
810

911
import "../../contracts/libraries/MerkleTree.sol";
1012

@@ -15,10 +17,15 @@ import "@pythnetwork/pyth-sdk-solidity/IPyth.sol";
1517
import "@pythnetwork/pyth-sdk-solidity/PythUtils.sol";
1618

1719
import "forge-std/Test.sol";
20+
import "forge-std/console.sol";
1821
import "./RandTestUtils.t.sol";
1922
import "./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

target_chains/ethereum/contracts/forge-test/utils/WormholeTestUtils.t.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,4 +469,8 @@ contract WormholeTestUtils is AbstractWormholeTestUtils {
469469
constructor(uint8 numGuardians) {
470470
setUpWormholeReceiver(numGuardians);
471471
}
472+
473+
function getTotalSigners() public view returns (uint8) {
474+
return uint8(currentSigners.length);
475+
}
472476
}

0 commit comments

Comments
 (0)