2
2
pragma solidity >= 0.8.8 < 0.9.0 ;
3
3
4
4
import "../../src/wormhole/Governance.sol " ;
5
+ import "forge-std/console.sol " ;
5
6
import "forge-std/Test.sol " ;
6
7
import "openzeppelin-contracts/contracts/access/Ownable.sol " ;
7
8
import "wormhole-solidity-sdk/testing/helpers/WormholeSimulator.sol " ;
@@ -41,7 +42,6 @@ contract GovernanceTest is Test {
41
42
}
42
43
43
44
function buildGovernanceVaa (
44
- bytes32 module ,
45
45
uint8 action ,
46
46
uint16 chainId ,
47
47
address governanceContract ,
@@ -50,55 +50,51 @@ contract GovernanceTest is Test {
50
50
) public view returns (bytes memory ) {
51
51
Governance.GeneralPurposeGovernanceMessage memory message = Governance
52
52
.GeneralPurposeGovernanceMessage ({
53
- module: module,
54
53
action: action,
55
54
chain: chainId,
56
55
governanceContract: governanceContract,
57
56
governedContract: governedContract,
58
57
callData: callData
59
58
});
60
59
61
- IWormhole.VM memory vaa = IWormhole.VM ({
60
+ IWormhole.VM memory vaa =
61
+ buildVaa (governance.encodeGeneralPurposeGovernanceMessage (message));
62
+
63
+ return guardian.encodeAndSignMessage (vaa);
64
+ }
65
+
66
+ function buildVaa (bytes memory payload ) public view returns (IWormhole.VM memory ) {
67
+ return IWormhole.VM ({
62
68
version: 1 ,
63
69
timestamp: uint32 (block .timestamp ),
64
70
nonce: 0 ,
65
71
emitterChainId: wormhole.governanceChainId (),
66
72
emitterAddress: wormhole.governanceContract (),
67
73
sequence: 0 ,
68
74
consistencyLevel: 200 ,
69
- payload: governance. encodeGeneralPurposeGovernanceMessage (message) ,
75
+ payload: payload ,
70
76
guardianSetIndex: 0 ,
71
77
signatures: new IWormhole.Signature [](0 ),
72
78
hash: bytes32 ("" )
73
79
});
74
-
75
- return guardian.encodeAndSignMessage (vaa);
76
80
}
77
81
78
82
function test_invalidModule () public {
79
- uint16 thisChain = wormhole.chainId ();
80
83
bytes32 coreBridgeModule =
81
84
0x00000000000000000000000000000000000000000000000000000000436f7265 ;
82
-
83
- bytes memory signed = buildGovernanceVaa (
84
- coreBridgeModule,
85
- uint8 (Governance.GovernanceAction.EVM_CALL),
86
- thisChain,
87
- address (governance),
88
- address (myContract),
89
- abi.encodeWithSignature ("governanceStuff() " )
90
- );
85
+ bytes memory restOfPayload =
86
+ "0x0100022e234dae75c793f67a35089c9d99245e1c58470bf62849f9a0b5bf2913b396098f7c7019b51a820a000471cd25f9 " ;
87
+ bytes memory badModulePayload = abi.encodePacked (coreBridgeModule, restOfPayload);
91
88
92
89
vm.expectRevert (abi.encodeWithSignature ("InvalidModule(bytes32) " , coreBridgeModule));
93
- governance.performGovernance (signed );
90
+ governance.parseGeneralPurposeGovernanceMessage (badModulePayload );
94
91
}
95
92
96
93
// TODO: this should ideally test all actions that != 1
97
94
function test_invalidAction () public {
98
95
uint16 thisChain = wormhole.chainId ();
99
96
100
97
bytes memory signed = buildGovernanceVaa (
101
- governance.MODULE (),
102
98
uint8 (Governance.GovernanceAction.UNDEFINED),
103
99
thisChain,
104
100
address (governance),
@@ -113,7 +109,6 @@ contract GovernanceTest is Test {
113
109
// TODO: this should ideally test all chainIds that != wormhole.chainId()
114
110
function test_invalidChain () public {
115
111
bytes memory signed = buildGovernanceVaa (
116
- governance.MODULE (),
117
112
uint8 (Governance.GovernanceAction.EVM_CALL),
118
113
0 ,
119
114
address (governance),
@@ -131,7 +126,6 @@ contract GovernanceTest is Test {
131
126
address random = address (0x1234 );
132
127
133
128
bytes memory signed = buildGovernanceVaa (
134
- governance.MODULE (),
135
129
uint8 (Governance.GovernanceAction.EVM_CALL),
136
130
thisChain,
137
131
random,
@@ -147,7 +141,6 @@ contract GovernanceTest is Test {
147
141
uint16 thisChain = wormhole.chainId ();
148
142
149
143
bytes memory signed = buildGovernanceVaa (
150
- governance.MODULE (),
151
144
uint8 (Governance.GovernanceAction.EVM_CALL),
152
145
thisChain,
153
146
address (governance),
@@ -163,7 +156,6 @@ contract GovernanceTest is Test {
163
156
uint16 thisChain = wormhole.chainId ();
164
157
165
158
bytes memory signed = buildGovernanceVaa (
166
- governance.MODULE (),
167
159
uint8 (Governance.GovernanceAction.EVM_CALL),
168
160
thisChain,
169
161
address (governance),
@@ -181,7 +173,6 @@ contract GovernanceTest is Test {
181
173
uint16 thisChain = wormhole.chainId ();
182
174
183
175
bytes memory signed = buildGovernanceVaa (
184
- governance.MODULE (),
185
176
uint8 (Governance.GovernanceAction.EVM_CALL),
186
177
thisChain,
187
178
address (governance),
0 commit comments