PythLazer.t.sol 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
  6. contract PythLazerTest is Test {
  7. PythLazer public pythLazer;
  8. address owner;
  9. function setUp() public {
  10. owner = address(1);
  11. PythLazer pythLazerImpl = new PythLazer();
  12. TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy(
  13. address(pythLazerImpl),
  14. owner,
  15. abi.encodeWithSelector(PythLazer.initialize.selector, owner)
  16. );
  17. pythLazer = PythLazer(address(proxy));
  18. }
  19. function test_update_add_signer() public {
  20. assert(!pythLazer.isValidSigner(address(2)));
  21. vm.prank(owner);
  22. pythLazer.updateTrustedSigner(address(2), block.timestamp + 1000);
  23. assert(pythLazer.isValidSigner(address(2)));
  24. skip(2000);
  25. assert(!pythLazer.isValidSigner(address(2)));
  26. }
  27. function test_update_remove_signer() public {
  28. assert(!pythLazer.isValidSigner(address(2)));
  29. vm.prank(owner);
  30. pythLazer.updateTrustedSigner(address(2), block.timestamp + 1000);
  31. assert(pythLazer.isValidSigner(address(2)));
  32. vm.prank(owner);
  33. pythLazer.updateTrustedSigner(address(2), 0);
  34. assert(!pythLazer.isValidSigner(address(2)));
  35. }
  36. function test_verify() public {
  37. // Prepare dummy update and signer
  38. address trustedSigner = 0xb8d50f0bAE75BF6E03c104903d7C3aFc4a6596Da;
  39. vm.prank(owner);
  40. pythLazer.updateTrustedSigner(trustedSigner, 3000000000000000);
  41. bytes
  42. memory update = hex"2a22999a9ee4e2a3df5affd0ad8c7c46c96d3b5ef197dd653bedd8f44a4b6b69b767fbc66341e80b80acb09ead98c60d169b9a99657ebada101f447378f227bffbc69d3d01003493c7d37500062cf28659c1e801010000000605000000000005f5e10002000000000000000001000000000000000003000104fff8";
  43. uint256 fee = pythLazer.verification_fee();
  44. address alice = makeAddr("alice");
  45. vm.deal(alice, 1 ether);
  46. address bob = makeAddr("bob");
  47. vm.deal(bob, 1 ether);
  48. // Alice provides appropriate fee
  49. vm.prank(alice);
  50. pythLazer.verifyUpdate{value: fee}(update);
  51. assertEq(alice.balance, 1 ether - fee);
  52. // Alice overpays and is refunded
  53. vm.prank(alice);
  54. pythLazer.verifyUpdate{value: 0.5 ether}(update);
  55. assertEq(alice.balance, 1 ether - fee - fee);
  56. // Bob does not attach a fee
  57. vm.prank(bob);
  58. vm.expectRevert("Insufficient fee provided");
  59. pythLazer.verifyUpdate(update);
  60. assertEq(bob.balance, 1 ether);
  61. }
  62. }