Skip to content

Commit a606f40

Browse files
authored
Merge pull request #759 from yingjingyang/main
fix test script
2 parents 5e53c25 + fd0ff9b commit a606f40

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

basic/42-merkle-distributor-airdrop/hardhat.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module.exports = {
2828
],
2929
},
3030
etherscan: {
31-
apiKey: "939NEFMUQ7F3TJ7BR343RKQDU3UX8Y9AEZ"
31+
apiKey: process.env.API_KEY
3232
},
3333
networks: {
3434
localhost: {
@@ -56,7 +56,7 @@ module.exports = {
5656
accounts: mnemonic(),
5757
},
5858
matic: {
59-
url: 'https://polygon-mainnet.infura.io/v3/' + process.env.PROJECT_ID,
59+
url: 'https://polygon-mainnet.infura.io/v3/' + process.env.INFURA_ID,
6060
accounts: mnemonic()
6161
},
6262
},

basic/42-merkle-distributor-airdrop/scripts/redpacket/3-createRedPacket.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ require('dotenv').config();
88
const { MerkleTree } = require('merkletreejs');
99
const keccak256 = require('keccak256');
1010
const { readRedpacketDeployment, saveRedpacketDeployment } = require('../../utils');
11+
const claimerList = require('./claimerList.json');
1112

1213
function hashToken(account) {
1314
return Buffer.from(ethers.utils.solidityKeccak256(['address'], [account]).slice(2), 'hex');
@@ -28,7 +29,7 @@ async function sleep() {
2829
}
2930

3031
async function main() {
31-
const [deployer, user1, user2] = await ethers.getSigners();
32+
const [deployer] = await ethers.getSigners();
3233
const deployment = readRedpacketDeployment();
3334

3435
const HappyRedPacketAddress = deployment.redPacketAddress;
@@ -37,13 +38,13 @@ async function main() {
3738
const redPacket = await ethers.getContractAt('HappyRedPacket', HappyRedPacketAddress, deployer);
3839
const simpleToken = await ethers.getContractAt('SimpleToken', SimpleTokenAddress, deployer);
3940

40-
let tx = await simpleToken.approve(redPacket.address, ethers.utils.parseEther('100'));
41-
await tx.wait();
41+
// let tx = await simpleToken.approve(redPacket.address, ethers.utils.parseEther('100'));
42+
// await tx.wait();
4243

43-
console.log('Approve Successfully');
44+
// console.log('Approve Successfully');
4445

4546
merkleTree = new MerkleTree(
46-
[deployer, user1, user2].map((user) => hashToken(user.address)),
47+
claimerList.map((user) => hashToken(user)),
4748
keccak256,
4849
{ sortPairs: true }
4950
);
@@ -53,15 +54,16 @@ async function main() {
5354
// create_red_packet
5455
let creationParams = {
5556
merkleroot: merkleTreeRoot,
56-
number: 3,
57+
number: 93,
5758
ifrandom: true,
58-
duration: 2 ** 30,
59+
duration: 259200,
5960
seed: ethers.utils.formatBytes32String('lajsdklfjaskldfhaikl'),
6061
message: 'Hi',
6162
name: 'cache',
6263
token_type: 1,
6364
token_addr: SimpleTokenAddress,
64-
total_tokens: ethers.utils.parseEther('100'),
65+
// total_tokens: ethers.utils.parseEther('100'),
66+
total_tokens: 438000000
6567
};
6668

6769
redPacket.once('CreationSuccess', (total, id, name, message, creator, creation_time, token_address, number, ifrandom, duration) => {

basic/42-merkle-distributor-airdrop/scripts/redpacket/4-claimRedpacket.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ require('dotenv').config();
88
const { MerkleTree } = require('merkletreejs');
99
const keccak256 = require('keccak256');
1010
const { readRedpacketDeployment } = require('../../utils');
11+
const claimerList = require('./claimerList.json');
1112

1213
function hashToken(account) {
1314
return Buffer.from(ethers.utils.solidityKeccak256(['address'], [account]).slice(2), 'hex');
@@ -23,18 +24,18 @@ async function main() {
2324
const redPacket = await ethers.getContractAt('HappyRedPacket', HappyRedPacketAddress, deployer);
2425

2526
merkleTree = new MerkleTree(
26-
[deployer, user1, user2].map((user) => hashToken(user.address)),
27+
claimerList.map((user) => hashToken(user)),
2728
keccak256,
2829
{ sortPairs: true }
2930
);
3031

3132
async function cliamRedPacket(user) {
3233
let proof = merkleTree.getHexProof(hashToken(user.address));
33-
// console.log('merkleTree proof: ', proof);
34+
console.log('merkleTree proof: ', proof);
3435

3536
const balanceBefore = await simpleToken.balanceOf(user.address);
3637

37-
let createRedPacketRecipt = await redPacket.connect(user).claim(redpacketID, proof, user.address);
38+
let createRedPacketRecipt = await redPacket.connect(user).claim(redpacketID, proof);
3839
await createRedPacketRecipt.wait();
3940

4041
const balanceAfter = await simpleToken.balanceOf(user.address);
@@ -44,8 +45,6 @@ async function main() {
4445
console.log("\n=========Begin to claim Red Packet=========\n")
4546

4647
await cliamRedPacket(deployer);
47-
await cliamRedPacket(user1);
48-
await cliamRedPacket(user2);
4948

5049
console.log('\n=========Claim Red Packet successfully=========\n');
5150
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[
2+
"0x1111",
3+
"0x222"
4+
]

0 commit comments

Comments
 (0)