PythLazer.t.sol 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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_add_signer() 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_update_remove_signer() public {
  20. assert(!pythLazer.isValidSigner(address(2)));
  21. vm.prank(address(1));
  22. pythLazer.updateTrustedSigner(address(2), block.timestamp + 1000);
  23. assert(pythLazer.isValidSigner(address(2)));
  24. vm.prank(address(1));
  25. pythLazer.updateTrustedSigner(address(2), 0);
  26. assert(!pythLazer.isValidSigner(address(2)));
  27. }
  28. function test_verify() public {
  29. // Prepare dummy update and signer
  30. address trustedSigner = 0xb8d50f0bAE75BF6E03c104903d7C3aFc4a6596Da;
  31. vm.prank(address(1));
  32. pythLazer.updateTrustedSigner(trustedSigner, 3000000000000000);
  33. bytes
  34. memory update = hex"2a22999a9ee4e2a3df5affd0ad8c7c46c96d3b5ef197dd653bedd8f44a4b6b69b767fbc66341e80b80acb09ead98c60d169b9a99657ebada101f447378f227bffbc69d3d01003493c7d37500062cf28659c1e801010000000605000000000005f5e10002000000000000000001000000000000000003000104fff8";
  35. uint256 fee = pythLazer.verification_fee();
  36. address alice = makeAddr("alice");
  37. vm.deal(alice, 1 ether);
  38. address bob = makeAddr("bob");
  39. vm.deal(bob, 1 ether);
  40. // Alice provides appropriate fee
  41. vm.prank(alice);
  42. pythLazer.verifyUpdate{value: fee}(update);
  43. assertEq(alice.balance, 1 ether - fee);
  44. // Alice overpays and is refunded
  45. vm.prank(alice);
  46. pythLazer.verifyUpdate{value: 0.5 ether}(update);
  47. assertEq(alice.balance, 1 ether - fee - fee);
  48. // Bob does not attach a fee
  49. vm.prank(bob);
  50. vm.expectRevert("Insufficient fee provided");
  51. pythLazer.verifyUpdate(update);
  52. assertEq(bob.balance, 1 ether);
  53. }
  54. }