Skip to content

Commit

Permalink
feat: merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
phenix3443 committed Mar 20, 2024
2 parents 31949c2 + 9c31b3e commit 08a3a8a
Show file tree
Hide file tree
Showing 41 changed files with 1,788 additions and 1,773 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/lint-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Lint PR

on:
pull_request_target:
types:
- opened
- edited
- synchronize

jobs:
main:
name: Validate PR title
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
scopes: |
ci
DeFi
NFT
DAO
CRYPTO
requireScope: true
2 changes: 1 addition & 1 deletion BTC/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ crypto 不到一年的时间。如果其中有任何错误的话,可以尽情

在 crypto 中,有了 private key,才能打开 crypto 的大
门。所以对于自己的 private key,一定不要大意,失去了这
个 key,就会被 crypo 拒之门外。这里推荐看一下
个 key,就会被 crypto 拒之门外。这里推荐看一下
[区块链黑暗深林自救手册](https://github.com/slowmist/Blockchain-dark-forest-selfguard-handbook)
不求完全理解或者按照其中的每一个步骤去做,但是在 crypto
这种新兴的产业中,你心中需要有这么一根弦。不要觉得安全事小,
Expand Down
32 changes: 14 additions & 18 deletions basic/07-hardhat/test/erc20-all.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { expect } = require("chai");
const { expect } = require('chai');

// `describe` is a Mocha function that allows you to organize your tests. It's
// not actually needed, but having your tests organized makes debugging them
Expand All @@ -7,8 +7,8 @@ const { expect } = require("chai");
// `describe` receives the name of a section of your test suite, and a callback.
// The callback must define the tests of that section. This callback can't be
// an async function.
describe("Token contract", function () {
// Mocha has four functions that let you hook into the the test runner's
describe('Token contract', function () {
// Mocha has four functions that let you hook into the test runner's
// lifecyle. These are: `before`, `beforeEach`, `after`, `afterEach`.

// They're very useful to setup the environment for tests, and to clean it
Expand All @@ -28,28 +28,28 @@ describe("Token contract", function () {
// time. It receives a callback, which can be async.
beforeEach(async function () {
// Get the ContractFactory and Signers here.
Token = await ethers.getContractFactory("SimpleToken");
Token = await ethers.getContractFactory('SimpleToken');
[owner, addr1, addr2, ...addrs] = await ethers.getSigners();

// To deploy our contract, we just have to call Token.deploy() and await
// for it to be deployed(), which happens onces its transaction has been
// mined.
hardhatToken = await Token.deploy("HEHE", "HH", 1, 100000000);
hardhatToken = await Token.deploy('HEHE', 'HH', 1, 100000000);
});

// You can nest describe calls to create subsections.
describe("Deployment", function () {
describe('Deployment', function () {
// `it` is another Mocha function. This is the one you use to define your
// tests. It receives the test name, and a callback function.

it("Should assign the total supply of tokens to the owner", async function () {
it('Should assign the total supply of tokens to the owner', async function () {
const ownerBalance = await hardhatToken.balanceOf(owner.address);
expect(await hardhatToken.totalSupply()).to.equal(ownerBalance);
});
});

describe("Transactions", function () {
it("Should transfer tokens between accounts", async function () {
describe('Transactions', function () {
it('Should transfer tokens between accounts', async function () {
// Transfer 50 tokens from owner to addr1
await hardhatToken.transfer(addr1.address, 50);
const addr1Balance = await hardhatToken.balanceOf(addr1.address);
Expand All @@ -62,22 +62,18 @@ describe("Token contract", function () {
expect(addr2Balance).to.equal(50);
});

it("Should fail if sender doesn’t have enough tokens", async function () {
it('Should fail if sender doesn’t have enough tokens', async function () {
const initialOwnerBalance = await hardhatToken.balanceOf(owner.address);

// Try to send 1 token from addr1 (0 tokens) to owner (1000 tokens).
// `require` will evaluate false and revert the transaction.
await expect(
hardhatToken.connect(addr1).transfer(owner.address, 1)
).to.be.revertedWith("ERC20: transfer amount exceeds balance");
await expect(hardhatToken.connect(addr1).transfer(owner.address, 1)).to.be.revertedWith('ERC20: transfer amount exceeds balance');

// Owner balance shouldn't have changed.
expect(await hardhatToken.balanceOf(owner.address)).to.equal(
initialOwnerBalance
);
expect(await hardhatToken.balanceOf(owner.address)).to.equal(initialOwnerBalance);
});

it("Should update balances after transfers", async function () {
it('Should update balances after transfers', async function () {
const initialOwnerBalance = await hardhatToken.balanceOf(owner.address);

// Transfer 100 tokens from owner to addr1.
Expand All @@ -97,4 +93,4 @@ describe("Token contract", function () {
expect(addr2Balance).to.equal(50);
});
});
});
});
32 changes: 14 additions & 18 deletions basic/08-hardhat-graph/test/erc20-all-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { expect } = require("chai");
const { expect } = require('chai');

// `describe` is a Mocha function that allows you to organize your tests. It's
// not actually needed, but having your tests organized makes debugging them
Expand All @@ -7,8 +7,8 @@ const { expect } = require("chai");
// `describe` receives the name of a section of your test suite, and a callback.
// The callback must define the tests of that section. This callback can't be
// an async function.
describe("Token contract", function () {
// Mocha has four functions that let you hook into the the test runner's
describe('Token contract', function () {
// Mocha has four functions that let you hook into the test runner's
// lifecyle. These are: `before`, `beforeEach`, `after`, `afterEach`.

// They're very useful to setup the environment for tests, and to clean it
Expand All @@ -28,28 +28,28 @@ describe("Token contract", function () {
// time. It receives a callback, which can be async.
beforeEach(async function () {
// Get the ContractFactory and Signers here.
Token = await ethers.getContractFactory("SimpleToken");
Token = await ethers.getContractFactory('SimpleToken');
[owner, addr1, addr2, ...addrs] = await ethers.getSigners();

// To deploy our contract, we just have to call Token.deploy() and await
// for it to be deployed(), which happens onces its transaction has been
// mined.
hardhatToken = await Token.deploy("HEHE", "HH", 1, 100000000);
hardhatToken = await Token.deploy('HEHE', 'HH', 1, 100000000);
});

// You can nest describe calls to create subsections.
describe("Deployment", function () {
describe('Deployment', function () {
// `it` is another Mocha function. This is the one you use to define your
// tests. It receives the test name, and a callback function.

it("Should assign the total supply of tokens to the owner", async function () {
it('Should assign the total supply of tokens to the owner', async function () {
const ownerBalance = await hardhatToken.balanceOf(owner.address);
expect(await hardhatToken.totalSupply()).to.equal(ownerBalance);
});
});

describe("Transactions", function () {
it("Should transfer tokens between accounts", async function () {
describe('Transactions', function () {
it('Should transfer tokens between accounts', async function () {
// Transfer 50 tokens from owner to addr1
await hardhatToken.transfer(addr1.address, 50);
const addr1Balance = await hardhatToken.balanceOf(addr1.address);
Expand All @@ -62,22 +62,18 @@ describe("Token contract", function () {
expect(addr2Balance).to.equal(50);
});

it("Should fail if sender doesn’t have enough tokens", async function () {
it('Should fail if sender doesn’t have enough tokens', async function () {
const initialOwnerBalance = await hardhatToken.balanceOf(owner.address);

// Try to send 1 token from addr1 (0 tokens) to owner (1000 tokens).
// `require` will evaluate false and revert the transaction.
await expect(
hardhatToken.connect(addr1).transfer(owner.address, 1)
).to.be.revertedWith("revert SafeMath: subtraction overflow");
await expect(hardhatToken.connect(addr1).transfer(owner.address, 1)).to.be.revertedWith('revert SafeMath: subtraction overflow');

// Owner balance shouldn't have changed.
expect(await hardhatToken.balanceOf(owner.address)).to.equal(
initialOwnerBalance
);
expect(await hardhatToken.balanceOf(owner.address)).to.equal(initialOwnerBalance);
});

it("Should update balances after transfers", async function () {
it('Should update balances after transfers', async function () {
const initialOwnerBalance = await hardhatToken.balanceOf(owner.address);

// Transfer 100 tokens from owner to addr1.
Expand All @@ -97,4 +93,4 @@ describe("Token contract", function () {
expect(addr2Balance).to.equal(50);
});
});
});
});
99 changes: 42 additions & 57 deletions basic/09-hardhat-react/test/SimpleToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Hardhat tests are normally written with Mocha and Chai.

// We import Chai to use its asserting functions here.
const { expect } = require('chai')
const { expect } = require('chai');

// `describe` is a Mocha function that allows you to organize your tests. It's
// not actually needed, but having your tests organized makes debugging them
Expand All @@ -14,7 +14,7 @@ const { expect } = require('chai')
// The callback must define the tests of that section. This callback can't be
// an async function.
describe('SimpleToken contract', function () {
// Mocha has four functions that let you hook into the the test runner's
// Mocha has four functions that let you hook into the test runner's
// lifecyle. These are: `before`, `beforeEach`, `after`, `afterEach`.

// They're very useful to setup the environment for tests, and to clean it
Expand All @@ -23,96 +23,81 @@ describe('SimpleToken contract', function () {
// A common pattern is to declare some variables, and assign them in the
// `before` and `beforeEach` callbacks.

let simpleToken
let hardhatSimpleToken
let owner
let addr1
let addr2
let addrs
let simpleToken;
let hardhatSimpleToken;
let owner;
let addr1;
let addr2;
let addrs;

// `beforeEach` will run before each test, re-deploying the contract every
// time. It receives a callback, which can be async.
beforeEach(async function () {
// Get the ContractFactory and Signers here.
simpleToken = await ethers.getContractFactory('SimpleToken')
;[owner, addr1, addr2, ...addrs] = await ethers.getSigners()
simpleToken = await ethers.getContractFactory('SimpleToken');
[owner, addr1, addr2, ...addrs] = await ethers.getSigners();

// To deploy our contract, we just have to call Token.deploy() and await
// for it to be deployed(), which happens onces its transaction has been
// mined.
hardhatSimpleToken = await simpleToken.deploy(
'SimpleToken Test',
'SimpleToken Test',
1,
1000000
)
await hardhatSimpleToken.deployed()
})
hardhatSimpleToken = await simpleToken.deploy('SimpleToken Test', 'SimpleToken Test', 1, 1000000);
await hardhatSimpleToken.deployed();
});

// You can nest describe calls to create subsections.
describe('Deployment', function () {
// `it` is another Mocha function. This is the one you use to define your
// tests. It receives the test name, and a callback function.

it('Should assign the total supply of tokens to the owner', async function () {
const ownerBalance = await hardhatSimpleToken.balanceOf(owner.address)
expect(await hardhatSimpleToken.totalSupply()).to.equal(ownerBalance)
})
})
const ownerBalance = await hardhatSimpleToken.balanceOf(owner.address);
expect(await hardhatSimpleToken.totalSupply()).to.equal(ownerBalance);
});
});

describe('Transactions', function () {
it('Should transfer tokens between accounts', async function () {
// Transfer 50 tokens from owner to addr1
await hardhatSimpleToken.transfer(addr1.address, 50)
const addr1Balance = await hardhatSimpleToken.balanceOf(addr1.address)
expect(addr1Balance).to.equal(50)
await hardhatSimpleToken.transfer(addr1.address, 50);
const addr1Balance = await hardhatSimpleToken.balanceOf(addr1.address);
expect(addr1Balance).to.equal(50);

// Transfer 50 tokens from addr1 to addr2
// We use .connect(signer) to send a transaction from another account
await hardhatSimpleToken.connect(addr1).transfer(addr2.address, 50)
const addr2Balance = await hardhatSimpleToken.balanceOf(addr2.address)
expect(addr2Balance).to.equal(50)
})
await hardhatSimpleToken.connect(addr1).transfer(addr2.address, 50);
const addr2Balance = await hardhatSimpleToken.balanceOf(addr2.address);
expect(addr2Balance).to.equal(50);
});

it('Should fail if sender doesn’t have enough tokens', async function () {
const initialOwnerBalance = await hardhatSimpleToken.balanceOf(
owner.address
)
const initialOwnerBalance = await hardhatSimpleToken.balanceOf(owner.address);

// Try to send 1 token from addr1 (0 tokens) to owner (1000 tokens).
// `require` will evaluate false and revert the transaction.
await expect(
hardhatSimpleToken.connect(addr1).transfer(owner.address, 10000)
).to.be.revertedWith('transfer amount exceeds balance')
await expect(hardhatSimpleToken.connect(addr1).transfer(owner.address, 10000)).to.be.revertedWith('transfer amount exceeds balance');

// Owner balance shouldn't have changed.
expect(await hardhatSimpleToken.balanceOf(owner.address)).to.equal(
initialOwnerBalance
)
})
expect(await hardhatSimpleToken.balanceOf(owner.address)).to.equal(initialOwnerBalance);
});

it('Should update balances after transfers', async function () {
const initialOwnerBalance = await hardhatSimpleToken.balanceOf(
owner.address
)
const initialOwnerBalance = await hardhatSimpleToken.balanceOf(owner.address);

// Transfer 100 tokens from owner to addr1.
await hardhatSimpleToken.transfer(addr1.address, 100)
await hardhatSimpleToken.transfer(addr1.address, 100);

// Transfer another 50 tokens from owner to addr2.
await hardhatSimpleToken.transfer(addr2.address, 50)
await hardhatSimpleToken.transfer(addr2.address, 50);

// Check balances.
const finalOwnerBalance = await hardhatSimpleToken.balanceOf(
owner.address
)
expect(finalOwnerBalance).to.equal(initialOwnerBalance - 150)

const addr1Balance = await hardhatSimpleToken.balanceOf(addr1.address)
expect(addr1Balance).to.equal(100)

const addr2Balance = await hardhatSimpleToken.balanceOf(addr2.address)
expect(addr2Balance).to.equal(50)
})
})
})
const finalOwnerBalance = await hardhatSimpleToken.balanceOf(owner.address);
expect(finalOwnerBalance).to.equal(initialOwnerBalance - 150);

const addr1Balance = await hardhatSimpleToken.balanceOf(addr1.address);
expect(addr1Balance).to.equal(100);

const addr2Balance = await hardhatSimpleToken.balanceOf(addr2.address);
expect(addr2Balance).to.equal(50);
});
});
});
Loading

0 comments on commit 08a3a8a

Please sign in to comment.