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

Feat: Add OpenZeppelin ERC20 tests #7

Merged
merged 10 commits into from
Jun 7, 2024
Merged
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
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Smart Contracts CI

on:
- push

jobs:
tests:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 18.18.0

- name: Install dependencies
run: cd web3 && npm install

- name: Run Hardhat tests
run: cd web3 && npx hardhat test
29 changes: 15 additions & 14 deletions web3/contracts/Token/Game7Token.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,29 @@ contract Game7Token is IERC20 {
totalSupply = _totalSupply;
}

function approve(address spender, uint256 value) external returns (bool) {
allowance[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
function approve(address spender, uint256 amount) external returns (bool) {
allowance[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}

function transfer(address to, uint256 value) external returns (bool) {
return transferFrom(msg.sender, to, value);
function transfer(address to, uint256 amount) external returns (bool) {
return transferFrom(msg.sender, to, amount);
}

function transferFrom(address from, address to, uint256 value) public returns (bool) {
require(balanceOf[from] >= value);
function transferFrom(address from, address to, uint256 amount) public returns (bool) {
require(balanceOf[from] >= amount, 'ERC20: transfer amount exceeds balance');


if (msg.sender != from && allowance[from][msg.sender] != 0) {
require(allowance[from][msg.sender] >= value);
allowance[from][msg.sender] -= value;
}
if (msg.sender != from && allowance[from][msg.sender] != type(uint256).max) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems as though the Openzeppelin contract allows setting an allowance on yourself. Don't have a strong preference on this.

require(allowance[from][msg.sender] >= amount, 'ERC20: insufficient allowance');
allowance[from][msg.sender] -= amount;
}

balanceOf[from] -= value;
balanceOf[to] += value;
balanceOf[from] -= amount;
balanceOf[to] += amount;

emit Transfer(from, to, value);
emit Transfer(from, to, amount);

return true;
}
Expand Down
9 changes: 2 additions & 7 deletions web3/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { ChainId, NetworkExplorer, NetworkName, rpcUrls } from "./constants/netw
dotenv.config()

const {
DEPLOYER_PRIVATE_KEY,
ETHSCAN_API_KEY,
ARB_SCAN_API_KEY,
} = process.env
Expand Down Expand Up @@ -41,22 +40,18 @@ const config: HardhatUserConfig = {
[NetworkName.Ethereum]: {
chainId: ChainId.Ethereum,
url: rpcUrls[ChainId.Ethereum],
accounts: [DEPLOYER_PRIVATE_KEY || ''],
},
[NetworkName.ArbitrumOne]: {
chainId: ChainId.ArbitrumOne,
url: rpcUrls[ChainId.ArbitrumOne],
accounts: [DEPLOYER_PRIVATE_KEY || ''],
},
[NetworkName.Game7OrbitArbSepolia]: {
url: rpcUrls[ChainId.Game7OrbitArbSepolia],
accounts: [DEPLOYER_PRIVATE_KEY || ''],
chainId: ChainId.Game7OrbitArbSepolia,
},
[NetworkName.Game7OrbitBaseSepolia]: {
url: rpcUrls[ChainId.Game7OrbitBaseSepolia],
accounts: [DEPLOYER_PRIVATE_KEY || ''],
chainId: ChainId.Game7OrbitBaseSepolia,
url: rpcUrls[ChainId.Game7OrbitBaseSepolia],
chainId: ChainId.Game7OrbitBaseSepolia,
},
},
};
Expand Down
3 changes: 3 additions & 0 deletions web3/helpers/type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { ethers } from "hardhat";

export type HardhatEthersSigner = Awaited<ReturnType<typeof ethers.getSigner>>;
Loading
Loading