Skip to content

Commit 86d4e2a

Browse files
committed
keep naming style uniform
1 parent 3496d52 commit 86d4e2a

File tree

6 files changed

+104
-137
lines changed

6 files changed

+104
-137
lines changed

Diff for: basic/25-multi-sig-wallet/hardhat.config.js

+18-18
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,23 @@ module.exports = {
4646
(you can put in a mnemonic here to set the deployer locally)
4747
*/
4848
},
49-
goerli: {
50-
url: "https://goerli.infura.io/v3/" + process.env.INFURA_ID, //<---- YOUR INFURA ID! (or it won't work)
51-
accounts: [
52-
mnemonic()
53-
],
54-
},
55-
mainnet: {
56-
url: "https://mainnet.infura.io/v3/" + process.env.INFURA_ID, //<---- YOUR INFURA ID! (or it won't work)
57-
accounts: [
58-
mnemonic()
59-
],
60-
},
61-
ropsten: {
62-
url: "https://ropsten.infura.io/v3/" + process.env.INFURA_ID, //<---- YOUR INFURA ID! (or it won't work)
63-
accounts: [
64-
mnemonic()
65-
],
66-
},
49+
// goerli: {
50+
// url: "https://goerli.infura.io/v3/" + process.env.INFURA_ID, //<---- YOUR INFURA ID! (or it won't work)
51+
// accounts: [
52+
// mnemonic()
53+
// ],
54+
// },
55+
// mainnet: {
56+
// url: "https://mainnet.infura.io/v3/" + process.env.INFURA_ID, //<---- YOUR INFURA ID! (or it won't work)
57+
// accounts: [
58+
// mnemonic()
59+
// ],
60+
// },
61+
// ropsten: {
62+
// url: "https://ropsten.infura.io/v3/" + process.env.INFURA_ID, //<---- YOUR INFURA ID! (or it won't work)
63+
// accounts: [
64+
// mnemonic()
65+
// ],
66+
// },
6767
}
6868
};

Diff for: basic/25-multi-sig-wallet/scripts/deploy.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ async function main () {
1111

1212
//部署MyToken.sol
1313
const MultiSigWalletContractFactory = await ethers.getContractFactory("MultiSigWallet");
14-
const multiSigWalletReceipt = await MultiSigWalletContractFactory.deploy([Alice.address], 1);
15-
await multiSigWalletReceipt.deployed();
14+
const multiSigWallet = await MultiSigWalletContractFactory.deploy([Alice.address], 1);
15+
await multiSigWallet.deployed();
1616

17-
console.log("MultiSigWallet Contract address:", multiSigWalletReceipt.address);
17+
console.log("MultiSigWallet Contract address:", multiSigWallet.address);
1818

1919
// Deploy Verify sol
2020
const verifyContractFactory = await ethers.getContractFactory("Verifier");
21-
const verifyReceipt = await verifyContractFactory.deploy();
22-
await verifyReceipt.deployed();
21+
const verify = await verifyContractFactory.deploy();
22+
await verify.deployed();
2323

24-
console.log("Verifier Contract address: ", verifyReceipt.address)
24+
console.log("Verifier Contract address: ", verify.address)
2525
}
2626

2727
main()

Diff for: basic/25-multi-sig-wallet/test/Hello.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
describe("Hello test",function(){
2+
it("test function of Hello.sol",async function(){
3+
//测试账号数组
4+
const HelloContractFactory = await ethers.getContractFactory("Hello");
5+
const hello = await HelloContractFactory.deploy();
6+
await hello.deployed();
7+
console.log("address of hello:",hello.address);
8+
9+
//在多签钱包添加一笔交易
10+
const tokenArtifact = await hre.artifacts.readArtifact("Hello");
11+
console.log("abi of hello:",tokenArtifact.abi);
12+
});
13+
});
14+

Diff for: basic/25-multi-sig-wallet/test/MultiSigWallet.js

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
const { expect } = require("chai");
2+
3+
4+
5+
function getPayLoad(contractABI,functionName,param){
6+
for(let i=0;i<contractABI.length;i++){
7+
const functionABI = contractABI[i];
8+
if (functionName !== functionABI.name) {
9+
continue;
10+
}
11+
12+
//get sigHash of function
13+
const contractInterface = new ethers.utils.Interface(contractABI);
14+
const functionSigHash = contractInterface.getSighash(functionName);
15+
console.log("sign of method:%s is %s",functionName,functionSigHash);
16+
17+
//encode param
18+
const abiCoder =new ethers.utils.AbiCoder()
19+
const codeOfParam = abiCoder.encode(['uint256'],[param])
20+
console.log("codeOfParam:",codeOfParam);
21+
22+
23+
//payload
24+
const payload = functionSigHash + codeOfParam.substring(2,codeOfParam.length);
25+
console.log("payload:",functionName,payload);
26+
return payload;
27+
}
28+
}
29+
30+
describe("MultiSigWallet test",function(){
31+
it("test function of MultiSigWallet.sol",async function(){
32+
//测试账号数组
33+
const [Alice,Bob,David] = await ethers.getSigners();
34+
35+
//部署多签合约`MultiSigWallet.sol`
36+
const MultiSigWalletContractFactory = await ethers.getContractFactory("MultiSigWallet");
37+
const multiSigWallet = await MultiSigWalletContractFactory.deploy([Alice.address,Bob.address,David.address],2);
38+
await multiSigWallet.deployed();
39+
console.log("address of multiSigWallet:",multiSigWallet.address);
40+
41+
//部署交易合约`Hello.sol`,该合约的交易只能由上面的那个合约触发
42+
const HelloContractFactory = await ethers.getContractFactory("Hello");
43+
const hello = await HelloContractFactory.deploy();
44+
await hello.deployed();
45+
console.log("address of hello:",hello.address);
46+
47+
//在多签钱包添加一笔交易
48+
const tokenArtifact = await hre.artifacts.readArtifact("Hello");
49+
const payload = getPayLoad(tokenArtifact.abi,"set",233);
50+
const submitTransaction = await multiSigWallet.submitTransaction(hello.address, 0, payload);
51+
const transactionReceipt = await submitTransaction.wait();
52+
53+
// 检查结果(不通过)
54+
expect((await hello.balance()).toString()).not.to.equal("233");
55+
56+
//其他参与者同意
57+
const transactionCount = await multiSigWallet.transactionCount();
58+
console.debug("transaction count:",transactionCount);
59+
60+
await multiSigWallet.connect(Bob).confirmTransaction(transactionReceipt.events[0].args.transactionId);
61+
62+
// 再次检查结果
63+
expect((await hello.balance()).toString()).to.equal("233");
64+
});
65+
});
66+

Diff for: basic/25-multi-sig-wallet/test/test.js

-113
This file was deleted.

0 commit comments

Comments
 (0)