Skip to content

Commit

Permalink
Merge pull request #462 from unchain-tech/feature/polygon-whitelist-n…
Browse files Browse the repository at this point in the history
…ft/update-openzeppelin

Feature/Polygon Whitelist NFT/update openzeppelin
  • Loading branch information
yk-saito authored Oct 12, 2023
2 parents 86117b3 + 2239fdb commit bacb032
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ In `Whitelist.sol`, let's start with a simple block of code.
```solidity
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.4;
pragma solidity ^0.8.20;
contract Whitelist {
constructor() {
Expand All @@ -33,10 +33,10 @@ Let's talk about the code line by line.
This line is referred to `SPDX license identifier`, which addresses the copyright issues of the code that follows. Generally speaking, `UNLICENSED` and `MIT` are the most common suffixes, indicating that the following code is permitted for anyone to use. In other words, you all can freely copy and paste it. You can find more information [here](https://spdx.org/licenses/).

```solidity
pragma solidity ^0.8.4;
pragma solidity ^0.8.20;
```

This specifies the version of the Solidity compiler that we want the contract to use. It means that only a Solidity compiler with a version between `0.8.4` and `0.9.0` can be used to compile the code.
This specifies the version of the Solidity compiler that we want the contract to use. It means that only a Solidity compiler with a version between `0.8.20` and `0.9.0` can be used to compile the code.

```solidity
contract Whitelist {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The basic knowledge about smart contracts is ready. Let's update the `Whitelist.

```solidity
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.4;
pragma solidity ^0.8.20;
contract Whitelist {
// The address that can operate addAddressToWhitelist function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ We'll insert the following code into the `IWhitelist.sol`.

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
pragma solidity ^0.8.20;
interface IWhitelist {
function whitelistedAddresses(address) external view returns (bool);
Expand All @@ -64,7 +64,7 @@ We insert the code below in `Shield.sol`.

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
Expand Down Expand Up @@ -103,7 +103,7 @@ contract Shield is ERC721Enumerable, Ownable {
* Constructor for Shields takes in the baseURI to set _baseTokenURI for the collection.
* It also initializes an instance of whitelist interface.
*/
constructor (string memory baseURI, address whitelistContract) ERC721("ChainIDE Shields", "CS") {
constructor (string memory baseURI, address whitelistContract) ERC721("ChainIDE Shields", "CS") Ownable(msg.sender) {
_baseTokenURI = baseURI;
_whitelist = IWhitelist(whitelistContract);
}
Expand Down Expand Up @@ -154,7 +154,7 @@ Don't worry, lets talk about this contract step by step.

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Verify that hardhat has been added to packages/contract/package.json. If the ins
Next, install the necessary tools. As before, run the following command in the root of the project.

```
yarn workspace contract add @openzeppelin/contracts@^4.8.2 && yarn workspace contract add --dev @nomicfoundation/hardhat-chai-matchers@^1.0.0 @nomicfoundation/hardhat-network-helpers@^1.0.8 @nomicfoundation/hardhat-toolbox@^2.0.1 @nomiclabs/hardhat-ethers@^2.0.0 @nomiclabs/hardhat-etherscan@^3.0.0 @typechain/ethers-v5@^10.1.0 @typechain/hardhat@^6.1.2 @types/chai@^4.2.0 @types/mocha@^9.1.0 chai@^4.3.7 hardhat-gas-reporter@^1.0.8 solidity-coverage@^0.8.1 ts-node@^8.0.0 typechain@^8.1.0 typescript@^4.5.0
yarn workspace contract add @openzeppelin/contracts@^5.0.0 && yarn workspace contract add --dev @nomicfoundation/hardhat-chai-matchers@^1.0.0 @nomicfoundation/hardhat-network-helpers@^1.0.8 @nomicfoundation/hardhat-toolbox@^2.0.1 @nomiclabs/hardhat-ethers@^2.0.0 @nomiclabs/hardhat-etherscan@^3.0.0 @typechain/ethers-v5@^10.1.0 @typechain/hardhat@^6.1.2 @types/chai@^4.2.0 @types/mocha@^9.1.0 chai@^4.3.7 hardhat-gas-reporter@^1.0.8 solidity-coverage@^0.8.1 ts-node@^8.0.0 typechain@^8.1.0 typescript@^4.5.0
```

At this point, packages/contract/package.json should look like the following.
Expand Down Expand Up @@ -151,7 +151,7 @@ import { HardhatUserConfig } from 'hardhat/config';
import '@nomicfoundation/hardhat-toolbox';

const config: HardhatUserConfig = {
solidity: '0.8.4',
solidity: '0.8.20',
paths: {
artifacts: '../client/artifacts',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ describe('Shield', function () {
const { shield, alice } = await loadFixture(deployWhitelistFixture);

// Verify that an account that is not the owner of the contract will get an error if it tries to execute the setPaused function.
await expect(shield.connect(alice).setPaused(true)).to.be.revertedWith(
'Ownable: caller is not the owner',
);
await expect(shield.connect(alice).setPaused(true))
.to.be.revertedWithCustomError(shield, 'OwnableUnauthorizedAccount')
.withArgs(alice.address);
});
});
context('when set to true', function () {
Expand Down Expand Up @@ -280,9 +280,9 @@ describe('Shield', function () {
const { shield, alice } = await loadFixture(deployWhitelistFixture);

// Verify that an error occurs when an account that is not the owner of the contract tries to execute the withdraw function.
await expect(shield.connect(alice).withdraw()).to.be.revertedWith(
'Ownable: caller is not the owner',
);
await expect(shield.connect(alice).withdraw())
.to.be.revertedWithCustomError(shield, 'OwnableUnauthorizedAccount')
.withArgs(alice.address);
});
});
context('when owner executes', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
```solidity
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.4;
pragma solidity ^0.8.20;
contract Whitelist {
constructor() {
Expand All @@ -34,10 +34,10 @@ contract Whitelist {
この行は`SPDXライセンス識別子`と呼ばれ、その後に続くコードの著作権の問題に対処します。一般的には、`UNLICENSED``MIT`が最もよく使われる接尾辞で、これは以下のコードが誰でも使ってよいことを示します。言い換えれば、皆さんは自由にコピー&ペーストすることができます。詳細は[こちら](https://spdx.org/licenses/)で確認できます。

```solidity
pragma solidity ^0.8.4;
pragma solidity ^0.8.20;
```

これは、コントラクトに使用するSolidityコンパイラのバージョンを指定します。`0.8.4`から`0.9.0`の間のバージョンのSolidityコンパイラのみが使用できることを意味します。
これは、コントラクトに使用するSolidityコンパイラのバージョンを指定します。`0.8.20`から`0.9.0`の間のバージョンのSolidityコンパイラのみが使用できることを意味します。

```solidity
contract Whitelist {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

```solidity
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.4;
pragma solidity ^0.8.20;
contract Whitelist {
// The address that can operate addAddressToWhitelist function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Whitelistコントラクトでは、オーナーアドレスを設定し、`requ

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
pragma solidity ^0.8.20;
interface IWhitelist {
function whitelistedAddresses(address) external view returns (bool);
Expand All @@ -64,7 +64,7 @@ interface IWhitelist {

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
Expand Down Expand Up @@ -103,7 +103,7 @@ contract Shield is ERC721Enumerable, Ownable {
* Constructor for Shields takes in the baseURI to set _baseTokenURI for the collection.
* It also initializes an instance of whitelist interface.
*/
constructor (string memory baseURI, address whitelistContract) ERC721("ChainIDE Shields", "CS") {
constructor (string memory baseURI, address whitelistContract) ERC721("ChainIDE Shields", "CS") Ownable(msg.sender) {
_baseTokenURI = baseURI;
_whitelist = IWhitelist(whitelistContract);
}
Expand Down Expand Up @@ -155,7 +155,7 @@ contract Shield is ERC721Enumerable, Ownable {

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ packages/contract/package.jsonにhardhatが追加されていることを確認
次に必要なツールをインストールします。先ほどと同様に、プロジェクトのルートで下記のコマンドを実行してください。

```
yarn workspace contract add @openzeppelin/contracts@^4.8.2 && yarn workspace contract add --dev @nomicfoundation/hardhat-chai-matchers@^1.0.0 @nomicfoundation/hardhat-network-helpers@^1.0.8 @nomicfoundation/hardhat-toolbox@^2.0.1 @nomiclabs/hardhat-ethers@^2.0.0 @nomiclabs/hardhat-etherscan@^3.0.0 @typechain/ethers-v5@^10.1.0 @typechain/hardhat@^6.1.2 @types/chai@^4.2.0 @types/mocha@^9.1.0 chai@^4.3.7 hardhat-gas-reporter@^1.0.8 solidity-coverage@^0.8.1 ts-node@^8.0.0 typechain@^8.1.0 typescript@^4.5.0
yarn workspace contract add @openzeppelin/contracts@^5.0.0 && yarn workspace contract add --dev @nomicfoundation/hardhat-chai-matchers@^1.0.0 @nomicfoundation/hardhat-network-helpers@^1.0.8 @nomicfoundation/hardhat-toolbox@^2.0.1 @nomiclabs/hardhat-ethers@^2.0.0 @nomiclabs/hardhat-etherscan@^3.0.0 @typechain/ethers-v5@^10.1.0 @typechain/hardhat@^6.1.2 @types/chai@^4.2.0 @types/mocha@^9.1.0 chai@^4.3.7 hardhat-gas-reporter@^1.0.8 solidity-coverage@^0.8.1 ts-node@^8.0.0 typechain@^8.1.0 typescript@^4.5.0
```

ここまでで、packages/contract/package.jsonは下記のようになっているはずです。
Expand Down Expand Up @@ -151,7 +151,7 @@ import { HardhatUserConfig } from 'hardhat/config';
import '@nomicfoundation/hardhat-toolbox';

const config: HardhatUserConfig = {
solidity: '0.8.4',
solidity: '0.8.20',
paths: {
artifacts: '../client/artifacts',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ describe('Shield', function () {
const { shield, alice } = await loadFixture(deployWhitelistFixture);

// コントラクトのオーナーではないアカウントが、setPaused関数を実行しようとするとエラーとなることを確認します。
await expect(shield.connect(alice).setPaused(true)).to.be.revertedWith(
'Ownable: caller is not the owner',
);
await expect(shield.connect(alice).setPaused(true))
.to.be.revertedWithCustomError(shield, 'OwnableUnauthorizedAccount')
.withArgs(alice.address);
});
});
context('when set to true', function () {
Expand Down Expand Up @@ -280,9 +280,9 @@ describe('Shield', function () {
const { shield, alice } = await loadFixture(deployWhitelistFixture);

// コントラクトのオーナーではないアカウントが、withdraw関数を実行しようとするとエラーとなることを確認します。
await expect(shield.connect(alice).withdraw()).to.be.revertedWith(
'Ownable: caller is not the owner',
);
await expect(shield.connect(alice).withdraw())
.to.be.revertedWithCustomError(shield, 'OwnableUnauthorizedAccount')
.withArgs(alice.address);
});
});
context('when owner executes', function () {
Expand Down

0 comments on commit bacb032

Please sign in to comment.