| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- // SPDX-License-Identifier: UNLICENSED
- pragma solidity ^0.8.13;
- import {Test, console} from "forge-std/Test.sol";
- import {PythLazer} from "../src/PythLazer.sol";
- contract PythLazerTest is Test {
- PythLazer public pythLazer;
- function setUp() public {
- pythLazer = new PythLazer();
- pythLazer.initialize(address(1));
- }
- function test_update_add_signer() public {
- assert(!pythLazer.isValidSigner(address(2)));
- vm.prank(address(1));
- pythLazer.updateTrustedSigner(address(2), block.timestamp + 1000);
- assert(pythLazer.isValidSigner(address(2)));
- skip(2000);
- assert(!pythLazer.isValidSigner(address(2)));
- }
- function test_update_remove_signer() public {
- assert(!pythLazer.isValidSigner(address(2)));
- vm.prank(address(1));
- pythLazer.updateTrustedSigner(address(2), block.timestamp + 1000);
- assert(pythLazer.isValidSigner(address(2)));
- vm.prank(address(1));
- pythLazer.updateTrustedSigner(address(2), 0);
- assert(!pythLazer.isValidSigner(address(2)));
- }
- function test_verify() public {
- // Prepare dummy update and signer
- address trustedSigner = 0xb8d50f0bAE75BF6E03c104903d7C3aFc4a6596Da;
- vm.prank(address(1));
- pythLazer.updateTrustedSigner(trustedSigner, 3000000000000000);
- bytes
- memory update = hex"2a22999a9ee4e2a3df5affd0ad8c7c46c96d3b5ef197dd653bedd8f44a4b6b69b767fbc66341e80b80acb09ead98c60d169b9a99657ebada101f447378f227bffbc69d3d01003493c7d37500062cf28659c1e801010000000605000000000005f5e10002000000000000000001000000000000000003000104fff8";
- uint256 fee = pythLazer.verification_fee();
- address alice = makeAddr("alice");
- vm.deal(alice, 1 ether);
- address bob = makeAddr("bob");
- vm.deal(bob, 1 ether);
- // Alice provides appropriate fee
- vm.prank(alice);
- pythLazer.verifyUpdate{value: fee}(update);
- assertEq(alice.balance, 1 ether - fee);
- // Alice overpays and is refunded
- vm.prank(alice);
- pythLazer.verifyUpdate{value: 0.5 ether}(update);
- assertEq(alice.balance, 1 ether - fee - fee);
- // Bob does not attach a fee
- vm.prank(bob);
- vm.expectRevert("Insufficient fee provided");
- pythLazer.verifyUpdate(update);
- assertEq(bob.balance, 1 ether);
- }
- }
|