Skip to content

Commit

Permalink
fix: remappings, library unused, _disableInitializers, test
Browse files Browse the repository at this point in the history
  • Loading branch information
gpylypchuk committed Feb 7, 2024
1 parent a40bb50 commit 3a87e51
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 13 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "lib/openzeppelin-foundry-upgrades"]
path = lib/openzeppelin-foundry-upgrades
url = https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades
[submodule "lib/openzeppelin-contracts-upgradeable"]
path = lib/openzeppelin-contracts-upgradeable
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable
1 change: 0 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ out = "out"
libs = ["lib"]
build_info = true
extra_output = ["storageLayout"]
remappings = ["@openzeppelin/contracts=lib/openzeppelin-contracts/contracts","@openzeppelin/contracts-upgradeable=lib/openzeppelin-contracts-upgradeable/contracts"]

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options

1 change: 0 additions & 1 deletion lib/openzeppelin-foundry-upgrades
Submodule openzeppelin-foundry-upgrades deleted from 1daeea
2 changes: 2 additions & 0 deletions remappings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ ds-test/=lib/forge-std/lib/ds-test/src/
erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/
forge-std/=lib/forge-std/src/
openzeppelin-contracts/=lib/openzeppelin-contracts/
@openzeppelin/contracts/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/
@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/
9 changes: 9 additions & 0 deletions src/NftReward.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ contract NftReward is Initializable, ERC721Upgradeable, OwnableUpgradeable, Paus
string[] values;
}

/**
* @notice _disableInitializers in the constructor,
* this prevents initialization of the implementation contract itself,
* as extra protection to prevent an attacker from initializing it.
*/
constructor() {
_disableInitializers();
}

/**
* @notice Contract initializer (replaces constructor)
* @param _tokenName NFT token name
Expand Down
25 changes: 17 additions & 8 deletions test/NftReward.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.13;

import {Test, console} from "forge-std/Test.sol";
import {NftReward} from "../src/NftReward.sol";
import {Upgrades} from "openzeppelin-foundry-upgrades/Upgrades.sol";
import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";

contract NftRewardTest is Test {
NftReward nftReward;
Expand All @@ -15,15 +15,23 @@ contract NftRewardTest is Test {
address user2 = address(3);
address minter = vm.addr(minterPrivateKey);

bytes public data;

function setUp() public {
vm.prank(owner);
nftReward = new NftReward();
nftReward.initialize(
"NFT reward", // token name
"RWD", // token symbol
owner, // initial owner
minter // minter (off-chain signer)

data = abi.encodeWithSignature(
"initialize(string,string,address,address)",
"NFT reward",
"RWD",
owner,
minter
);

nftReward = new NftReward();
ERC1967Proxy proxy = new ERC1967Proxy(address(nftReward), data);

nftReward = NftReward(address(proxy));
}

//==================
Expand All @@ -49,7 +57,8 @@ contract NftRewardTest is Test {
// get mint request digest which should be signed
bytes32 digest = nftReward.getMintRequestDigest(mintRequest);

assertEq(digest, 0x2c680706f2350ed5622f229af6736cd20626f7b9b4569b2fd5abb7e086886dc3);
// expected digest: 0x2c680706f2350ed5622f229af6736cd20626f7b9b4569b2fd5abb7e086886dc3
assertEq(digest, 0xf85127466b4ea4a97ec0c1b445b54622c8c3760b720bf9136b491d50f122b043);
}

function testGetTokenDataKeys_ReturnAllTokenDataKeys() public {
Expand Down

0 comments on commit 3a87e51

Please sign in to comment.