@@ -139,7 +139,8 @@ contract PythWormholeMerkleAccumulatorTest is Test, PythTestUtils {
139
139
}
140
140
141
141
function createWormholeMerkleUpdateData (
142
- PriceFeedMessage[] memory priceFeedMessages
142
+ PriceFeedMessage[] memory priceFeedMessages ,
143
+ Signer signer
143
144
) internal returns (bytes [] memory updateData , uint updateFee ) {
144
145
updateData = new bytes [](1 );
145
146
@@ -150,11 +151,29 @@ contract PythWormholeMerkleAccumulatorTest is Test, PythTestUtils {
150
151
151
152
depth += getRandUint8 () % 3 ;
152
153
153
- updateData[0 ] = generateWhMerkleUpdate (priceFeedMessages, depth, 1 );
154
+ uint8 numSigners = 1 ;
155
+ if (signer == Signer.Wormhole)
156
+ numSigners = _wormholeTestUtils.getTotalSigners ();
157
+ if (signer == Signer.Verifier)
158
+ numSigners = _verifierTestUtils.getTotalSigners ();
159
+
160
+ updateData[0 ] = generateWhMerkleUpdate (
161
+ priceFeedMessages,
162
+ depth,
163
+ numSigners,
164
+ signer
165
+ );
154
166
155
167
updateFee = pyth.getUpdateFee (updateData);
156
168
}
157
169
170
+ function createWormholeMerkleUpdateData (
171
+ PriceFeedMessage[] memory priceFeedMessages
172
+ ) internal returns (bytes [] memory updateData , uint updateFee ) {
173
+ return
174
+ createWormholeMerkleUpdateData (priceFeedMessages, Signer.Wormhole);
175
+ }
176
+
158
177
/// @notice This method creates a forward compatible wormhole update data by using a newer minor version,
159
178
/// setting a trailing header size and generating additional trailing header data of size `trailingHeaderSize`
160
179
function createFowardCompatibleWormholeMerkleUpdateData (
@@ -1145,4 +1164,59 @@ contract PythWormholeMerkleAccumulatorTest is Test, PythTestUtils {
1145
1164
assertPriceFeedMessageStored (priceFeedMessages[i]);
1146
1165
}
1147
1166
}
1167
+
1168
+ /// Testing update price feeds method using wormhole merkle update type.
1169
+ function testUpdatePriceFeedWithWormholeMerkleAndVerifierSignerWorks (
1170
+ uint seed
1171
+ ) public {
1172
+ setRandSeed (seed);
1173
+ setVerifier (address (pyth), 10 );
1174
+
1175
+ uint numPriceFeeds = (getRandUint () % 10 ) + 1 ;
1176
+ PriceFeedMessage[]
1177
+ memory priceFeedMessages = generateRandomPriceFeedMessage (
1178
+ numPriceFeeds
1179
+ );
1180
+ (
1181
+ bytes [] memory updateData ,
1182
+ uint updateFee
1183
+ ) = createWormholeMerkleUpdateData (priceFeedMessages, Signer.Verifier);
1184
+
1185
+ pyth.updatePriceFeeds {value: updateFee}(updateData);
1186
+
1187
+ for (uint i = 0 ; i < numPriceFeeds; i++ ) {
1188
+ assertPriceFeedMessageStored (priceFeedMessages[i]);
1189
+ }
1190
+
1191
+ // Update the prices again with the same data should work
1192
+ pyth.updatePriceFeeds {value: updateFee}(updateData);
1193
+
1194
+ for (uint i = 0 ; i < numPriceFeeds; i++ ) {
1195
+ assertPriceFeedMessageStored (priceFeedMessages[i]);
1196
+ }
1197
+
1198
+ // Update the prices again with updated data should update the prices
1199
+ for (uint i = 0 ; i < numPriceFeeds; i++ ) {
1200
+ priceFeedMessages[i].price = getRandInt64 ();
1201
+ priceFeedMessages[i].conf = getRandUint64 ();
1202
+ priceFeedMessages[i].expo = getRandInt32 ();
1203
+
1204
+ // Increase the publish time if it is not causing an overflow
1205
+ if (priceFeedMessages[i].publishTime != type (uint64 ).max) {
1206
+ priceFeedMessages[i].publishTime += 1 ;
1207
+ }
1208
+ priceFeedMessages[i].emaPrice = getRandInt64 ();
1209
+ priceFeedMessages[i].emaConf = getRandUint64 ();
1210
+ }
1211
+
1212
+ (updateData, updateFee) = createWormholeMerkleUpdateData (
1213
+ priceFeedMessages
1214
+ );
1215
+
1216
+ pyth.updatePriceFeeds {value: updateFee}(updateData);
1217
+
1218
+ for (uint i = 0 ; i < numPriceFeeds; i++ ) {
1219
+ assertPriceFeedMessageStored (priceFeedMessages[i]);
1220
+ }
1221
+ }
1148
1222
}
0 commit comments