diff --git a/.gas-report b/.gas-report index 673a871..fe04109 100644 --- a/.gas-report +++ b/.gas-report @@ -37,18 +37,21 @@ | src/XPToken.sol:XPToken contract | | | | | | |----------------------------------|-----------------|-------|--------|-------|---------| | Deployment Cost | Deployment Size | | | | | -| 725645 | 3153 | | | | | +| 799398 | 3520 | | | | | | Function Name | min | avg | median | max | # calls | -| addXPProvider | 23968 | 57184 | 51091 | 68191 | 18 | -| allowance | 488 | 488 | 488 | 488 | 1 | +| acceptOwnership | 28247 | 28247 | 28247 | 28247 | 1 | +| addXPProvider | 23991 | 57207 | 51114 | 68214 | 18 | +| allowance | 511 | 511 | 511 | 511 | 1 | | approve | 390 | 390 | 390 | 390 | 1 | -| balanceOf | 8808 | 14560 | 11066 | 23808 | 3 | -| getXPProviders | 1033 | 3286 | 3286 | 5539 | 2 | -| removeXPProvider | 23665 | 28074 | 25780 | 34777 | 3 | +| balanceOf | 8786 | 14538 | 11044 | 23786 | 3 | +| getXPProviders | 1011 | 3264 | 3264 | 5517 | 2 | +| owner | 374 | 1040 | 374 | 2374 | 3 | +| removeXPProvider | 23666 | 28075 | 25781 | 34778 | 3 | | setTotalSupply | 23792 | 26266 | 26266 | 28740 | 2 | | totalSupply | 363 | 1863 | 2363 | 2363 | 4 | -| transfer | 411 | 411 | 411 | 411 | 1 | +| transfer | 389 | 389 | 389 | 389 | 1 | | transferFrom | 521 | 521 | 521 | 521 | 1 | +| transferOwnership | 47732 | 47732 | 47732 | 47732 | 1 | | test/mocks/MockToken.sol:MockToken contract | | | | | | @@ -70,7 +73,7 @@ | getTotalXPShares | 302 | 968 | 302 | 2302 | 6 | | getUserXPShare | 504 | 1837 | 2504 | 2504 | 6 | | setTotalXPShares | 43632 | 43632 | 43632 | 43632 | 2 | -| setUserXPShare | 43900 | 43900 | 43900 | 43900 | 2 | +| setUserXPShare | 44128 | 44128 | 44128 | 44128 | 2 | diff --git a/.gas-snapshot b/.gas-snapshot index ca08778..1133dc4 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -28,11 +28,13 @@ UnstakeTest:test_UnstakeMultipleAccounts() (gas: 616281) UnstakeTest:test_UnstakeMultipleAccountsAndRewards() (gas: 937677) UnstakeTest:test_UnstakeOneAccount() (gas: 446369) UnstakeTest:test_UnstakeOneAccountAndRewards() (gas: 557220) -XPTokenTest:testAddXPProviderOnlyOwner() (gas: 285732) -XPTokenTest:testBalanceOf() (gas: 210530) -XPTokenTest:testBalanceOfWithNoSystemTotalXP() (gas: 45808) -XPTokenTest:testRemoveXPProviderIndexOutOfBounds() (gas: 36277) -XPTokenTest:testRemoveXPProviderOnlyOwner() (gas: 72074) +XPTokenOwnershipTest:testInitialOwner() (gas: 12649) +XPTokenOwnershipTest:testOwnershipTransfer() (gas: 87234) +XPTokenTest:testAddXPProviderOnlyOwner() (gas: 285756) +XPTokenTest:testBalanceOf() (gas: 210964) +XPTokenTest:testBalanceOfWithNoSystemTotalXP() (gas: 45764) +XPTokenTest:testRemoveXPProviderIndexOutOfBounds() (gas: 36278) +XPTokenTest:testRemoveXPProviderOnlyOwner() (gas: 72054) XPTokenTest:testSetTotalSupplyOnlyOwner() (gas: 70544) XPTokenTest:testTotalSupply() (gas: 10507) -XPTokenTest:testTransfersNotAllowed() (gas: 20634) +XPTokenTest:testTransfersNotAllowed() (gas: 20635) \ No newline at end of file diff --git a/src/XPToken.sol b/src/XPToken.sol index 853a975..83d8f6e 100644 --- a/src/XPToken.sol +++ b/src/XPToken.sol @@ -1,10 +1,10 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.26; -import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; +import { Ownable, Ownable2Step } from "@openzeppelin/contracts/access/Ownable2Step.sol"; import { IXPProvider } from "./interfaces/IXPProvider.sol"; -contract XPToken is Ownable { +contract XPToken is Ownable2Step { string public constant name = "XP Token"; string public constant symbol = "XP"; uint256 public constant decimals = 18; diff --git a/test/XPToken.t.sol b/test/XPToken.t.sol index a7c42e6..ecc1f38 100644 --- a/test/XPToken.t.sol +++ b/test/XPToken.t.sol @@ -9,9 +9,10 @@ import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; contract XPTokenTest is Test { XPToken xpToken; - address owner = address(0x1); - address alice = address(0x2); - address bob = address(0x3); + + address owner = makeAddr("owner"); + address alice = makeAddr("alice"); + address bob = makeAddr("bob"); XPProviderMock provider1; XPProviderMock provider2; @@ -124,3 +125,29 @@ contract XPTokenTest is Test { assertEq(allowance, 0); } } + +contract XPTokenOwnershipTest is Test { + XPToken xpToken; + + address owner = makeAddr("owner"); + address alice = makeAddr("alice"); + + function setUp() public { + vm.prank(owner); + xpToken = new XPToken(1000e18); + } + + function testInitialOwner() public view { + assertEq(xpToken.owner(), owner); + } + + function testOwnershipTransfer() public { + vm.prank(owner); + xpToken.transferOwnership(alice); + assertEq(xpToken.owner(), owner); + + vm.prank(alice); + xpToken.acceptOwnership(); + assertEq(xpToken.owner(), alice); + } +}