refactor(target_chains/ethereum): rename tests and vars in GasBenchmark

This commit is contained in:
Pavel Strakhov 2024-03-27 17:20:13 +00:00
parent f4617b484a
commit d23f6c0d11
1 changed files with 134 additions and 133 deletions

View File

@ -34,19 +34,19 @@ contract GasBenchmark is Test, WormholeTestUtils, PythTestUtils {
PythStructs.Price[] cachedPrices;
uint64[] cachedPricesPublishTimes;
bytes[][] cachedPricesWhMerkleUpdateData; // i th element contains the update data for the first i prices
bytes[] allCachedPricesWhMerkleUpdateData; // the update data for all prices
uint[] cachedPricesWhMerkleUpdateFee; // i th element contains the update fee for the first i prices
uint allCachedPricesWhMerkleUpdateFee; // the update fee for all prices
bytes[][] cachedPricesUpdateData; // i th element contains the update data for the first i prices
bytes[] allCachedPricesUpdateData; // the update data for all prices
uint[] cachedPricesUpdateFee; // i th element contains the update fee for the first i prices
uint allCachedPricesUpdateFee; // the update fee for all prices
// Fresh prices are different prices that can be used
// as a fresh price to update the prices
PythStructs.Price[] freshPrices;
uint64[] freshPricesPublishTimes;
bytes[][] freshPricesWhMerkleUpdateData; // i th element contains the update data for the first i prices
bytes[] allFreshPricesWhMerkleUpdateData; // the update data for all prices
uint[] freshPricesWhMerkleUpdateFee; // i th element contains the update fee for the first i prices
uint allFreshPricesWhMerkleUpdateFee; // the update fee for all prices
bytes[][] freshPricesUpdateData; // i th element contains the update data for the first i prices
bytes[] allFreshPricesUpdateData; // the update data for all prices
uint[] freshPricesUpdateFee; // i th element contains the update fee for the first i prices
uint allFreshPricesUpdateFee; // the update fee for all prices
uint64 sequence;
uint randomSeed;
@ -92,34 +92,24 @@ contract GasBenchmark is Test, WormholeTestUtils, PythTestUtils {
(
bytes[] memory updateData,
uint updateFee
) = generateWhMerkleUpdateDataAndFee(cachedPrices);
) = generateUpdateDataAndFee(cachedPrices);
cachedPricesWhMerkleUpdateData.push(updateData);
cachedPricesWhMerkleUpdateFee.push(updateFee);
cachedPricesUpdateData.push(updateData);
cachedPricesUpdateFee.push(updateFee);
(updateData, updateFee) = generateWhMerkleUpdateDataAndFee(
freshPrices
);
(updateData, updateFee) = generateUpdateDataAndFee(freshPrices);
freshPricesWhMerkleUpdateData.push(updateData);
freshPricesWhMerkleUpdateFee.push(updateFee);
freshPricesUpdateData.push(updateData);
freshPricesUpdateFee.push(updateFee);
}
allCachedPricesWhMerkleUpdateData = cachedPricesWhMerkleUpdateData[
NUM_PRICES - 1
];
allCachedPricesWhMerkleUpdateFee = cachedPricesWhMerkleUpdateFee[
NUM_PRICES - 1
];
allFreshPricesWhMerkleUpdateData = freshPricesWhMerkleUpdateData[
NUM_PRICES - 1
];
allFreshPricesWhMerkleUpdateFee = freshPricesWhMerkleUpdateFee[
NUM_PRICES - 1
];
allCachedPricesUpdateData = cachedPricesUpdateData[NUM_PRICES - 1];
allCachedPricesUpdateFee = cachedPricesUpdateFee[NUM_PRICES - 1];
allFreshPricesUpdateData = freshPricesUpdateData[NUM_PRICES - 1];
allFreshPricesUpdateFee = freshPricesUpdateFee[NUM_PRICES - 1];
// Populate the contract with the initial prices
pyth.updatePriceFeeds{value: allCachedPricesWhMerkleUpdateFee}(
allCachedPricesWhMerkleUpdateData
pyth.updatePriceFeeds{value: allCachedPricesUpdateFee}(
allCachedPricesUpdateData
);
}
@ -128,7 +118,7 @@ contract GasBenchmark is Test, WormholeTestUtils, PythTestUtils {
val = uint(keccak256(abi.encode(randomSeed)));
}
function generateWhMerkleUpdateDataAndFee(
function generateUpdateDataAndFee(
PythStructs.Price[] memory prices
) internal returns (bytes[] memory updateData, uint updateFee) {
updateData = new bytes[](1);
@ -142,83 +132,83 @@ contract GasBenchmark is Test, WormholeTestUtils, PythTestUtils {
updateFee = pyth.getUpdateFee(updateData);
}
function testBenchmarkUpdatePriceFeedsWhMerkle1FeedFresh() public {
pyth.updatePriceFeeds{value: freshPricesWhMerkleUpdateFee[0]}(
freshPricesWhMerkleUpdateData[0]
function testBenchmarkUpdatePriceFeeds1FeedFresh() public {
pyth.updatePriceFeeds{value: freshPricesUpdateFee[0]}(
freshPricesUpdateData[0]
);
}
function testBenchmarkUpdatePriceFeedsWhMerkle2FeedsFresh() public {
pyth.updatePriceFeeds{value: freshPricesWhMerkleUpdateFee[1]}(
freshPricesWhMerkleUpdateData[1]
function testBenchmarkUpdatePriceFeeds2FeedsFresh() public {
pyth.updatePriceFeeds{value: freshPricesUpdateFee[1]}(
freshPricesUpdateData[1]
);
}
function testBenchmarkUpdatePriceFeedsWhMerkle3FeedsFresh() public {
pyth.updatePriceFeeds{value: freshPricesWhMerkleUpdateFee[2]}(
freshPricesWhMerkleUpdateData[2]
function testBenchmarkUpdatePriceFeeds3FeedsFresh() public {
pyth.updatePriceFeeds{value: freshPricesUpdateFee[2]}(
freshPricesUpdateData[2]
);
}
function testBenchmarkUpdatePriceFeedsWhMerkle4FeedsFresh() public {
pyth.updatePriceFeeds{value: freshPricesWhMerkleUpdateFee[3]}(
freshPricesWhMerkleUpdateData[3]
function testBenchmarkUpdatePriceFeeds4FeedsFresh() public {
pyth.updatePriceFeeds{value: freshPricesUpdateFee[3]}(
freshPricesUpdateData[3]
);
}
function testBenchmarkUpdatePriceFeedsWhMerkle5FeedsFresh() public {
pyth.updatePriceFeeds{value: freshPricesWhMerkleUpdateFee[4]}(
freshPricesWhMerkleUpdateData[4]
function testBenchmarkUpdatePriceFeeds5FeedsFresh() public {
pyth.updatePriceFeeds{value: freshPricesUpdateFee[4]}(
freshPricesUpdateData[4]
);
}
function testBenchmarkUpdatePriceFeedsWhMerkle1FeedNotFresh() public {
pyth.updatePriceFeeds{value: cachedPricesWhMerkleUpdateFee[0]}(
cachedPricesWhMerkleUpdateData[0]
function testBenchmarkUpdatePriceFeeds1FeedNotFresh() public {
pyth.updatePriceFeeds{value: cachedPricesUpdateFee[0]}(
cachedPricesUpdateData[0]
);
}
function testBenchmarkUpdatePriceFeedsWhMerkle2FeedsNotFresh() public {
pyth.updatePriceFeeds{value: cachedPricesWhMerkleUpdateFee[1]}(
cachedPricesWhMerkleUpdateData[1]
function testBenchmarkUpdatePriceFeeds2FeedsNotFresh() public {
pyth.updatePriceFeeds{value: cachedPricesUpdateFee[1]}(
cachedPricesUpdateData[1]
);
}
function testBenchmarkUpdatePriceFeedsWhMerkle3FeedsNotFresh() public {
pyth.updatePriceFeeds{value: cachedPricesWhMerkleUpdateFee[2]}(
cachedPricesWhMerkleUpdateData[2]
function testBenchmarkUpdatePriceFeeds3FeedsNotFresh() public {
pyth.updatePriceFeeds{value: cachedPricesUpdateFee[2]}(
cachedPricesUpdateData[2]
);
}
function testBenchmarkUpdatePriceFeedsWhMerkle4FeedsNotFresh() public {
pyth.updatePriceFeeds{value: cachedPricesWhMerkleUpdateFee[3]}(
cachedPricesWhMerkleUpdateData[3]
function testBenchmarkUpdatePriceFeeds4FeedsNotFresh() public {
pyth.updatePriceFeeds{value: cachedPricesUpdateFee[3]}(
cachedPricesUpdateData[3]
);
}
function testBenchmarkUpdatePriceFeedsWhMerkle5FeedsNotFresh() public {
pyth.updatePriceFeeds{value: cachedPricesWhMerkleUpdateFee[4]}(
cachedPricesWhMerkleUpdateData[4]
function testBenchmarkUpdatePriceFeeds5FeedsNotFresh() public {
pyth.updatePriceFeeds{value: cachedPricesUpdateFee[4]}(
cachedPricesUpdateData[4]
);
}
function testBenchmarkUpdatePriceFeedsIfNecessaryWhMerkleFresh() public {
function testBenchmarkUpdatePriceFeedsIfNecessaryFresh() public {
// Since the prices have advanced, the publishTimes are newer than one in
// the contract and hence, the call should succeed.
pyth.updatePriceFeedsIfNecessary{
value: allFreshPricesWhMerkleUpdateFee
}(allFreshPricesWhMerkleUpdateData, priceIds, freshPricesPublishTimes);
pyth.updatePriceFeedsIfNecessary{value: allFreshPricesUpdateFee}(
allFreshPricesUpdateData,
priceIds,
freshPricesPublishTimes
);
}
function testBenchmarkUpdatePriceFeedsIfNecessaryWhMerkleNotFresh() public {
function testBenchmarkUpdatePriceFeedsIfNecessaryNotFresh() public {
// Since the price is not advanced, the publishTimes are the same as the
// ones in the contract.
vm.expectRevert(PythErrors.NoFreshUpdate.selector);
pyth.updatePriceFeedsIfNecessary{
value: allCachedPricesWhMerkleUpdateFee
}(
allCachedPricesWhMerkleUpdateData,
pyth.updatePriceFeedsIfNecessary{value: allCachedPricesUpdateFee}(
allCachedPricesUpdateData,
priceIds,
cachedPricesPublishTimes
);
@ -228,8 +218,8 @@ contract GasBenchmark is Test, WormholeTestUtils, PythTestUtils {
bytes32[] memory ids = new bytes32[](1);
ids[0] = priceIds[0];
pyth.parsePriceFeedUpdates{value: allFreshPricesWhMerkleUpdateFee}(
allFreshPricesWhMerkleUpdateData,
pyth.parsePriceFeedUpdates{value: allFreshPricesUpdateFee}(
allFreshPricesUpdateData,
ids,
0,
50
@ -241,103 +231,114 @@ contract GasBenchmark is Test, WormholeTestUtils, PythTestUtils {
ids[0] = priceIds[0];
ids[1] = priceIds[1];
pyth.parsePriceFeedUpdates{value: allFreshPricesWhMerkleUpdateFee}(
allFreshPricesWhMerkleUpdateData,
pyth.parsePriceFeedUpdates{value: allFreshPricesUpdateFee}(
allFreshPricesUpdateData,
ids,
0,
50
);
}
function testBenchmarkParsePriceFeedUpdatesUniqueForWhMerkle() public {
function testBenchmarkParsePriceFeedUpdatesUniqueFor() public {
bytes32[] memory ids = new bytes32[](1);
ids[0] = priceIds[0];
pyth.parsePriceFeedUpdatesUnique{
value: freshPricesWhMerkleUpdateFee[0]
}(
freshPricesWhMerkleUpdateData[0],
pyth.parsePriceFeedUpdatesUnique{value: freshPricesUpdateFee[0]}(
freshPricesUpdateData[0],
ids,
uint64(freshPrices[0].publishTime),
100
);
}
function testBenchmarkParsePriceFeedUpdatesUniqueWhMerkleForOnePriceFeedNotWithinRange()
function testBenchmarkParsePriceFeedUpdatesUniqueForOnePriceFeedNotWithinRange()
public
{
bytes32[] memory ids = new bytes32[](1);
ids[0] = priceIds[0];
vm.expectRevert(PythErrors.PriceFeedNotFoundWithinRange.selector);
pyth.parsePriceFeedUpdatesUnique{
value: freshPricesWhMerkleUpdateFee[0]
}(
freshPricesWhMerkleUpdateData[0],
pyth.parsePriceFeedUpdatesUnique{value: freshPricesUpdateFee[0]}(
freshPricesUpdateData[0],
ids,
uint64(freshPrices[0].publishTime) - 1,
100
);
}
function testBenchmarkParsePriceFeedUpdatesForWhMerkle1() public {
function testBenchmarkParsePriceFeedUpdates1() public {
uint numIds = 1;
bytes32[] memory ids = new bytes32[](numIds);
for (uint i = 0; i < numIds; i++) {
ids[i] = priceIds[i];
}
pyth.parsePriceFeedUpdates{
value: freshPricesWhMerkleUpdateFee[numIds - 1]
}(freshPricesWhMerkleUpdateData[numIds - 1], ids, 0, 50);
pyth.parsePriceFeedUpdates{value: freshPricesUpdateFee[numIds - 1]}(
freshPricesUpdateData[numIds - 1],
ids,
0,
50
);
}
function testBenchmarkParsePriceFeedUpdatesForWhMerkle2() public {
function testBenchmarkParsePriceFeedUpdates2() public {
uint numIds = 2;
bytes32[] memory ids = new bytes32[](numIds);
for (uint i = 0; i < numIds; i++) {
ids[i] = priceIds[i];
}
pyth.parsePriceFeedUpdates{
value: freshPricesWhMerkleUpdateFee[numIds - 1]
}(freshPricesWhMerkleUpdateData[numIds - 1], ids, 0, 50);
pyth.parsePriceFeedUpdates{value: freshPricesUpdateFee[numIds - 1]}(
freshPricesUpdateData[numIds - 1],
ids,
0,
50
);
}
function testBenchmarkParsePriceFeedUpdatesForWhMerkle3() public {
function testBenchmarkParsePriceFeedUpdates3() public {
uint numIds = 3;
bytes32[] memory ids = new bytes32[](numIds);
for (uint i = 0; i < numIds; i++) {
ids[i] = priceIds[i];
}
pyth.parsePriceFeedUpdates{
value: freshPricesWhMerkleUpdateFee[numIds - 1]
}(freshPricesWhMerkleUpdateData[numIds - 1], ids, 0, 50);
pyth.parsePriceFeedUpdates{value: freshPricesUpdateFee[numIds - 1]}(
freshPricesUpdateData[numIds - 1],
ids,
0,
50
);
}
function testBenchmarkParsePriceFeedUpdatesForWhMerkle4() public {
function testBenchmarkParsePriceFeedUpdates4() public {
uint numIds = 4;
bytes32[] memory ids = new bytes32[](numIds);
for (uint i = 0; i < numIds; i++) {
ids[i] = priceIds[i];
}
pyth.parsePriceFeedUpdates{
value: freshPricesWhMerkleUpdateFee[numIds - 1]
}(freshPricesWhMerkleUpdateData[numIds - 1], ids, 0, 50);
pyth.parsePriceFeedUpdates{value: freshPricesUpdateFee[numIds - 1]}(
freshPricesUpdateData[numIds - 1],
ids,
0,
50
);
}
function testBenchmarkParsePriceFeedUpdatesForWhMerkle5() public {
function testBenchmarkParsePriceFeedUpdates5() public {
uint numIds = 5;
bytes32[] memory ids = new bytes32[](numIds);
for (uint i = 0; i < numIds; i++) {
ids[i] = priceIds[i];
}
pyth.parsePriceFeedUpdates{
value: freshPricesWhMerkleUpdateFee[numIds - 1]
}(freshPricesWhMerkleUpdateData[numIds - 1], ids, 0, 50);
pyth.parsePriceFeedUpdates{value: freshPricesUpdateFee[numIds - 1]}(
freshPricesUpdateData[numIds - 1],
ids,
0,
50
);
}
function testBenchmarkParsePriceFeedUpdatesForAllPriceFeedsShuffledSubsetPriceIds()
@ -348,29 +349,14 @@ contract GasBenchmark is Test, WormholeTestUtils, PythTestUtils {
ids[0] = priceIds[4];
ids[1] = priceIds[2];
ids[2] = priceIds[0];
pyth.parsePriceFeedUpdates{value: freshPricesWhMerkleUpdateFee[4]}( // updateFee based on number of priceFeeds in updateData
freshPricesWhMerkleUpdateData[4],
pyth.parsePriceFeedUpdates{value: freshPricesUpdateFee[4]}( // updateFee based on number of priceFeeds in updateData
freshPricesUpdateData[4],
ids,
0,
50
);
}
function testBenchmarkParsePriceFeedUpdatesWhMerkleForOnePriceFeedNotWithinRange()
public
{
bytes32[] memory ids = new bytes32[](1);
ids[0] = priceIds[0];
vm.expectRevert(PythErrors.PriceFeedNotFoundWithinRange.selector);
pyth.parsePriceFeedUpdates{value: freshPricesWhMerkleUpdateFee[0]}(
freshPricesWhMerkleUpdateData[0],
ids,
50,
100
);
}
function testBenchmarkParsePriceFeedUpdatesForOnePriceFeedNotWithinRange()
public
{
@ -378,8 +364,23 @@ contract GasBenchmark is Test, WormholeTestUtils, PythTestUtils {
ids[0] = priceIds[0];
vm.expectRevert(PythErrors.PriceFeedNotFoundWithinRange.selector);
pyth.parsePriceFeedUpdates{value: allFreshPricesWhMerkleUpdateFee}(
allFreshPricesWhMerkleUpdateData,
pyth.parsePriceFeedUpdates{value: freshPricesUpdateFee[0]}(
freshPricesUpdateData[0],
ids,
50,
100
);
}
function testBenchmarkParsePriceFeedUpdatesForAllPriceFeedsNotWithinRange()
public
{
bytes32[] memory ids = new bytes32[](1);
ids[0] = priceIds[0];
vm.expectRevert(PythErrors.PriceFeedNotFoundWithinRange.selector);
pyth.parsePriceFeedUpdates{value: allFreshPricesUpdateFee}(
allFreshPricesUpdateData,
ids,
50,
100
@ -402,23 +403,23 @@ contract GasBenchmark is Test, WormholeTestUtils, PythTestUtils {
pyth.getEmaPrice(priceIds[0]);
}
function testBenchmarkGetUpdateFeeWhMerkle1() public view {
pyth.getUpdateFee(freshPricesWhMerkleUpdateData[0]);
function testBenchmarkGetUpdateFee1() public view {
pyth.getUpdateFee(freshPricesUpdateData[0]);
}
function testBenchmarkGetUpdateFeeWhMerkle2() public view {
pyth.getUpdateFee(freshPricesWhMerkleUpdateData[1]);
function testBenchmarkGetUpdateFee2() public view {
pyth.getUpdateFee(freshPricesUpdateData[1]);
}
function testBenchmarkGetUpdateFeeWhMerkle3() public view {
pyth.getUpdateFee(freshPricesWhMerkleUpdateData[2]);
function testBenchmarkGetUpdateFee3() public view {
pyth.getUpdateFee(freshPricesUpdateData[2]);
}
function testBenchmarkGetUpdateFeeWhMerkle4() public view {
pyth.getUpdateFee(freshPricesWhMerkleUpdateData[3]);
function testBenchmarkGetUpdateFee4() public view {
pyth.getUpdateFee(freshPricesUpdateData[3]);
}
function testBenchmarkGetUpdateFeeWhMerkle5() public view {
pyth.getUpdateFee(freshPricesWhMerkleUpdateData[4]);
function testBenchmarkGetUpdateFee5() public view {
pyth.getUpdateFee(freshPricesUpdateData[4]);
}
}