Skip to content

Commit 7b13f49

Browse files
committed
update contribute and vote scripts to make many contributions and votes
1 parent 8e74169 commit 7b13f49

File tree

2 files changed

+54
-11
lines changed

2 files changed

+54
-11
lines changed

Diff for: contracts/scripts/contribute.ts

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
11
import fs from 'fs'
2+
import { Wallet } from 'ethers'
23
import { ethers } from 'hardhat'
34
import { Keypair } from 'maci-domainobjs'
45

56
import { UNIT } from '../utils/constants'
67
import { getEventArg } from '../utils/contracts'
78

89
async function main() {
9-
const [, , , , , , , , , , , , contributor1, contributor2] =
10-
await ethers.getSigners()
10+
// const [, , , , , , , , , , , , contributor1, contributor2, contributor3] =
11+
// await ethers.getSigners()
12+
13+
const contributor1 = new Wallet(
14+
process.env.CONTRIBUTOR_PK_1!,
15+
ethers.provider
16+
)
17+
const contributor2 = new Wallet(
18+
process.env.CONTRIBUTOR_PK_2!,
19+
ethers.provider
20+
)
21+
const contributor3 = new Wallet(
22+
process.env.CONTRIBUTOR_PK_3!,
23+
ethers.provider
24+
)
25+
1126
const state = JSON.parse(fs.readFileSync('state.json').toString())
1227
const fundingRound = await ethers.getContractAt(
1328
'FundingRound',
@@ -21,7 +36,7 @@ async function main() {
2136
const contributionAmount = UNIT.mul(16).div(10)
2237
state.contributors = {}
2338

24-
for (const contributor of [contributor1, contributor2]) {
39+
for (const contributor of [contributor1, contributor2, contributor3]) {
2540
const contributorAddress = await contributor.getAddress()
2641
const contributorKeypair = new Keypair()
2742
const tokenAsContributor = token.connect(contributor)

Diff for: contracts/scripts/vote.ts

+36-8
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
11
import fs from 'fs'
22
import { ethers } from 'hardhat'
3-
import { BigNumber } from 'ethers'
3+
import { BigNumber, Wallet } from 'ethers'
44
import { PrivKey, Keypair } from 'maci-domainobjs'
55

66
import { createMessage } from '../utils/maci'
77

88
async function main() {
9-
const [, , , , , , , , , , , , contributor1, contributor2] =
10-
await ethers.getSigners()
9+
// const [, , , , , , , , , , , , contributor1, contributor2, contributor3] =
10+
// await ethers.getSigners()
11+
12+
const contributor1 = new Wallet(
13+
process.env.CONTRIBUTOR_PK_1!,
14+
ethers.provider
15+
)
16+
const contributor2 = new Wallet(
17+
process.env.CONTRIBUTOR_PK_2!,
18+
ethers.provider
19+
)
20+
const contributor3 = new Wallet(
21+
process.env.CONTRIBUTOR_PK_3!,
22+
ethers.provider
23+
)
24+
1125
const state = JSON.parse(fs.readFileSync('state.json').toString())
1226
const coordinatorKeyPair = new Keypair(
1327
PrivKey.unserialize(state.coordinatorPrivKey)
1428
)
1529

16-
for (const contributor of [contributor1, contributor2]) {
30+
for (const contributor of [contributor1, contributor2, contributor3]) {
1731
const contributorAddress = await contributor.getAddress()
1832
const contributorData = state.contributors[contributorAddress]
1933
const contributorKeyPair = new Keypair(
@@ -37,8 +51,11 @@ async function main() {
3751
encPubKeys.push(encPubKey.asContractParam())
3852
nonce += 1
3953
// Vote
40-
for (const recipientIndex of [1, 2]) {
41-
const votes = BigNumber.from(contributorData.voiceCredits).div(4)
54+
const recipients = [1, 2, 3, 4, 5, 6, 7]
55+
for (const recipientIndex of recipients) {
56+
const votes = BigNumber.from(contributorData.voiceCredits).div(
57+
recipients.length
58+
)
4259
const [message, encPubKey] = createMessage(
4360
contributorData.stateIndex,
4461
newContributorKeypair,
@@ -58,10 +75,21 @@ async function main() {
5875
state.fundingRound,
5976
contributor
6077
)
61-
await fundingRoundAsContributor.submitMessageBatch(
78+
79+
const tx = await fundingRoundAsContributor.submitMessageBatch(
6280
messages.reverse(),
63-
encPubKeys.reverse()
81+
encPubKeys.reverse(),
82+
{
83+
gasLimit: 20000000,
84+
}
6485
)
86+
try {
87+
await tx.wait()
88+
} catch (err) {
89+
console.log('error!', err)
90+
return
91+
}
92+
6593
console.log(`Contributor ${contributorAddress} voted.`)
6694
}
6795
}

0 commit comments

Comments
 (0)