Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(XPToken): upgrade to Ownable2Step #51

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions .gas-report
Original file line number Diff line number Diff line change
Expand Up @@ -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 | | | | | |
Expand All @@ -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 |



Expand Down
14 changes: 8 additions & 6 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions src/XPToken.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// 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";

Check warning on line 8 in src/XPToken.sol

View workflow job for this annotation

GitHub Actions / lint

Constant name must be in capitalized SNAKE_CASE
string public constant symbol = "XP";

Check warning on line 9 in src/XPToken.sol

View workflow job for this annotation

GitHub Actions / lint

Constant name must be in capitalized SNAKE_CASE
uint256 public constant decimals = 18;

Check warning on line 10 in src/XPToken.sol

View workflow job for this annotation

GitHub Actions / lint

Constant name must be in capitalized SNAKE_CASE

uint256 public totalSupply;

Expand Down
33 changes: 30 additions & 3 deletions test/XPToken.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Loading