@@ -401,64 +401,64 @@ contract PythUtilsTest is Test, WormholeTestUtils, PythTestUtils, IPythEvents {
401401 }
402402
403403 function testCombinePrices () public {
404- // Test case 1: Basic price combination (ETH/USD / BTC /USD = ETH/BTC)
405- PythStructs.Price memory ethUsd = PythStructs.Price ({
404+ // Test case 1: Basic price combination (StEth/Eth / Eth /USD = ETH/BTC)
405+ PythStructs.Price memory stEthEth = PythStructs.Price ({
406406 price: 206487956502 ,
407407 conf: 10 ,
408408 expo: - 8 ,
409409 publishTime: block .timestamp
410410 });
411411
412- PythStructs.Price memory btcUsd = PythStructs.Price ({
412+ PythStructs.Price memory ethUsd = PythStructs.Price ({
413413 price: 206741615681 ,
414414 conf: 100 ,
415415 expo: - 8 ,
416416 publishTime: block .timestamp
417417 });
418418
419- (int64 price , int32 expo ) = PythUtils.combinePrices (ethUsd .price, ethUsd .expo, btcUsd .price, btcUsd .expo);
420- assertApproxEqRel (price, 99875203 , 9e17 );
419+ (int64 price , int32 expo ) = PythUtils.combinePrices (stEthEth .price, stEthEth .expo, ethUsd .price, ethUsd .expo);
420+ assertApproxEqRel (price, 100000000 , 9e17 ); // $1
421421 assertEq (expo, - 8 );
422422
423- // // Test case 2: Different exponents
424- // PythStructs.Price memory smallPrice = PythStructs.Price({
425- // price: 100, // $0.01
426- // conf: 1,
427- // expo: -4, // 4 decimals
428- // publishTime: block.timestamp
429- // });
430-
431- // PythStructs.Price memory largePrice = PythStructs.Price({
432- // price: 1000, // $10
433- // conf: 10,
434- // expo: -2, // 2 decimals
435- // publishTime: block.timestamp
436- // });
437-
438- // (price, expo) = PythUtils.combinePrices(smallPrice, largePrice, -2 );
439- // assertEq(price, 1 ); // 0.01
440- // assertEq(expo, -2 );
441-
442- // // Test case 3: Revert on negative prices
443- // PythStructs.Price memory negativePrice = PythStructs.Price({
444- // price: -100,
445- // conf: 10,
446- // expo: -2,
447- // publishTime: block.timestamp
448- // });
449-
450- // vm.expectRevert();
451- // PythUtils.combinePrices(negativePrice, btcUsd, -2 );
452-
453- // // Test case 4: Revert on positive exponents
454- // PythStructs.Price memory invalidExpo = PythStructs.Price({
455- // price: 100,
456- // conf: 10,
457- // expo: 2,
458- // publishTime: block.timestamp
459- // });
460-
461- // vm.expectRevert();
462- // PythUtils.combinePrices(ethUsd, invalidExpo, -2 );
423+ // Test case 2: Different exponents
424+ PythStructs.Price memory smallPrice = PythStructs.Price ({
425+ price: 100 , // $0.01
426+ conf: 1 ,
427+ expo: - 4 , // 4 decimals
428+ publishTime: block .timestamp
429+ });
430+
431+ PythStructs.Price memory largePrice = PythStructs.Price ({
432+ price: 1000 , // $10
433+ conf: 10 ,
434+ expo: - 2 , // 2 decimals
435+ publishTime: block .timestamp
436+ });
437+
438+ (price, expo) = PythUtils.combinePrices (smallPrice.price, smallPrice.expo, largePrice.price, largePrice.expo );
439+ assertEq (price, 10 ); // 0.001
440+ assertEq (expo, - 4 );
441+
442+ // Test case 3: Revert on negative prices
443+ PythStructs.Price memory negativePrice = PythStructs.Price ({
444+ price: - 100 ,
445+ conf: 10 ,
446+ expo: - 2 ,
447+ publishTime: block .timestamp
448+ });
449+
450+ vm.expectRevert ();
451+ PythUtils.combinePrices (negativePrice.price, negativePrice.expo, ethUsd.price, ethUsd.expo );
452+
453+ // Test case 4: Revert on positive exponents
454+ PythStructs.Price memory invalidExpo = PythStructs.Price ({
455+ price: 100 ,
456+ conf: 10 ,
457+ expo: 2 ,
458+ publishTime: block .timestamp
459+ });
460+
461+ vm.expectRevert ();
462+ PythUtils.combinePrices (ethUsd.price, ethUsd.expo, invalidExpo.price, invalidExpo.expo );
463463 }
464464}
0 commit comments