PythLazer.t.sol 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // SPDX-License-Identifier: UNLICENSED
  2. pragma solidity ^0.8.13;
  3. import {Test, console} from "forge-std/Test.sol";
  4. import {PythLazer} from "../src/PythLazer.sol";
  5. contract PythLazerTest is Test {
  6. PythLazer public pythLazer;
  7. function setUp() public {
  8. pythLazer = new PythLazer();
  9. pythLazer.initialize(address(1));
  10. }
  11. function test_update() public {
  12. assert(!pythLazer.isValidSigner(address(2)));
  13. vm.prank(address(1));
  14. pythLazer.updateTrustedSigner(address(2), block.timestamp + 1000);
  15. assert(pythLazer.isValidSigner(address(2)));
  16. skip(2000);
  17. assert(!pythLazer.isValidSigner(address(2)));
  18. }
  19. function test_verify_with_fee() public {
  20. // Prepare dummy update and signer
  21. address trustedSigner = 0xEfEf56cD66896f6799A90A4e4d512C330c094e44;
  22. vm.prank(address(1));
  23. pythLazer.updateTrustedSigner(trustedSigner, 3000000000000000);
  24. bytes
  25. memory update = hex"2a22999a577d3cc0202197939d736bc0dcf71b9dde7b9470e4d16fa8e2120c0787a1c0d744d0c39cc372af4d1ecf2d09e84160ca905f3f597d20e2eec144a446a0459ad600001c93c7d3750006240af373971c01010000000201000000000005f5e100";
  26. uint256 fee = pythLazer.verification_fee();
  27. address alice = makeAddr("alice");
  28. vm.deal(alice, 1 ether);
  29. address bob = makeAddr("bob");
  30. vm.deal(bob, 1 ether);
  31. // Alice provides appropriate fee
  32. vm.prank(alice);
  33. pythLazer.verifyUpdate{value: fee}(update);
  34. assertEq(alice.balance, 1 ether - fee);
  35. // Alice overpays and is refunded
  36. vm.prank(alice);
  37. pythLazer.verifyUpdate{value: 0.5 ether}(update);
  38. assertEq(alice.balance, 1 ether - fee - fee);
  39. // Bob does not attach a fee
  40. vm.prank(bob);
  41. vm.expectRevert("Insufficient fee provided");
  42. pythLazer.verifyUpdate(update);
  43. assertEq(bob.balance, 1 ether);
  44. // Bob does not attach enough fees
  45. vm.prank(bob);
  46. vm.expectRevert("Insufficient fee provided");
  47. pythLazer.verifyUpdate{value: 1 wei}(update);
  48. assertEq(bob.balance, 1 ether);
  49. }
  50. }