etape3testavantdeploementok
This commit is contained in:
@@ -4,7 +4,13 @@ Sources du token **FGC42Forge** (symbole **FG42**), standard **BEP-20**, déploi
|
||||
|
||||
Stack : **Solidity**, **Hardhat 3**, **OpenZeppelin**, tests **Mocha + ethers** et tests Solidity (`.t.sol`).
|
||||
|
||||
> Le contrat `FGC42Forge.sol` sera ajouté à l’étape 3. Le dossier contient encore l’exemple **Counter** généré par `npx hardhat --init`.
|
||||
### BEP-20 vs `ERC20` dans le code
|
||||
|
||||
- **Rendu / soutenance :** token **BEP-20** sur **BNB Smart Chain Testnet** (chainId 97).
|
||||
- **Code :** héritage **OpenZeppelin `ERC20`** — norme EVM identique en pratique ; pas de bibliothèque `BEP20` séparée.
|
||||
- **Après deploy :** BscScan classera le contrat en **BEP-20** ; le source reste `import {ERC20} from "@openzeppelin/contracts/..."`.
|
||||
|
||||
> Le dossier peut encore contenir l’exemple **Counter** (template Hardhat) en attendant nettoyage.
|
||||
|
||||
## Prérequis
|
||||
|
||||
|
||||
17
tokenizerRendu/code/contracts/FGC42Forge.sol
Normal file
17
tokenizerRendu/code/contracts/FGC42Forge.sol
Normal file
@@ -0,0 +1,17 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.34;
|
||||
|
||||
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
||||
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
|
||||
|
||||
/// @title FGC42Forge — jeton fongible pour BNB Smart Chain Testnet
|
||||
/// @notice Standard **BEP-20** (exigé sur BSC) : même interface que l’ERC-20 sur l’EVM.
|
||||
/// On importe OpenZeppelin `ERC20` ; après déploiement sur BSC, BscScan affiche un token BEP-20.
|
||||
/// Phrase soutenance : « BEP-20 sur la chaîne, implémenté via ERC20 OpenZeppelin. »
|
||||
contract FGC42Forge is ERC20, Ownable {
|
||||
uint256 private constant INITIAL_SUPPLY = 1_000_000 * (10 ** 18);
|
||||
|
||||
constructor() ERC20("FGC42Forge", "FG42") Ownable(msg.sender) {
|
||||
_mint(msg.sender, INITIAL_SUPPLY);
|
||||
}
|
||||
}
|
||||
35
tokenizerRendu/code/test/FGC42Forge.ts
Normal file
35
tokenizerRendu/code/test/FGC42Forge.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { expect } from "chai";
|
||||
import { network } from "hardhat";
|
||||
|
||||
const { ethers } = await network.create();
|
||||
|
||||
const INITIAL_SUPPLY = 1_000_000n * 10n ** 18n;
|
||||
|
||||
describe("FGC42Forge", function () {
|
||||
it("expose le nom, le symbole et la supply fixe au déployeur", async function () {
|
||||
const [deployer] = await ethers.getSigners();
|
||||
const token = await ethers.deployContract("FGC42Forge");
|
||||
|
||||
expect(await token.name()).to.equal("FGC42Forge");
|
||||
expect(await token.symbol()).to.equal("FG42");
|
||||
expect(await token.decimals()).to.equal(18n);
|
||||
expect(await token.totalSupply()).to.equal(INITIAL_SUPPLY);
|
||||
expect(await token.balanceOf(deployer.address)).to.equal(INITIAL_SUPPLY);
|
||||
expect(await token.owner()).to.equal(deployer.address);
|
||||
});
|
||||
|
||||
it("permet un transfer ERC-20 classique", async function () {
|
||||
const [deployer, recipient] = await ethers.getSigners();
|
||||
const token = await ethers.deployContract("FGC42Forge");
|
||||
|
||||
const amount = 1_000n * 10n ** 18n;
|
||||
await expect(token.transfer(recipient.address, amount))
|
||||
.to.emit(token, "Transfer")
|
||||
.withArgs(deployer.address, recipient.address, amount);
|
||||
|
||||
expect(await token.balanceOf(recipient.address)).to.equal(amount);
|
||||
expect(await token.balanceOf(deployer.address)).to.equal(
|
||||
INITIAL_SUPPLY - amount,
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user