mirror of
https://github.com/semaphore-protocol/semaphore.git
synced 2026-04-28 03:00:41 -04:00
chore(contracts): create script to add mock data on testnets
Former-commit-id: 76aba71eba
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
"compile": "hardhat compile",
|
||||
"deploy": "hardhat deploy",
|
||||
"verify": "hardhat run scripts/verify-contracts.ts",
|
||||
"mock": "hardhat run scripts/create-mock-groups.ts",
|
||||
"test": "hardhat test",
|
||||
"test:report-gas": "REPORT_GAS=true hardhat test",
|
||||
"test:coverage": "hardhat coverage",
|
||||
|
||||
62
packages/contracts/scripts/create-mock-groups.ts
Normal file
62
packages/contracts/scripts/create-mock-groups.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import { Group } from "@semaphore-protocol/group"
|
||||
import { Identity } from "@semaphore-protocol/identity"
|
||||
import { generateProof } from "@semaphore-protocol/proof"
|
||||
import { ethers, hardhatArguments } from "hardhat"
|
||||
import { getDeployedContracts } from "./utils"
|
||||
|
||||
async function main() {
|
||||
const deployedContracts = getDeployedContracts(hardhatArguments.network)
|
||||
|
||||
if (deployedContracts) {
|
||||
const semaphoreContract = await ethers.getContractAt("Semaphore", deployedContracts.Semaphore)
|
||||
|
||||
const [admin] = await ethers.getSigners()
|
||||
const adminAddress = await admin.getAddress()
|
||||
|
||||
const identity = new Identity(0)
|
||||
const members = Array.from({ length: 3 }, (_, i) => new Identity(i)).map(({ commitment }) => commitment)
|
||||
const group = new Group(members)
|
||||
|
||||
const groupId = 42
|
||||
|
||||
console.info(`Creating group '${groupId}' with ${members.length} members...`)
|
||||
|
||||
// Create a group and add 3 members.
|
||||
await semaphoreContract["createGroup(uint256,address)"](groupId, adminAddress)
|
||||
await semaphoreContract.addMembers(groupId, members)
|
||||
|
||||
console.info(`Removing third member from group '${groupId}'...`)
|
||||
|
||||
// Remove the third member.
|
||||
{
|
||||
group.removeMember(2)
|
||||
const { siblings } = group.generateMerkleProof(2)
|
||||
|
||||
await semaphoreContract.removeMember(groupId, members[2], siblings)
|
||||
}
|
||||
|
||||
console.info(`Updating second member from group '${groupId}'...`)
|
||||
|
||||
// Update the second member.
|
||||
{
|
||||
group.updateMember(1, members[2])
|
||||
const { siblings } = group.generateMerkleProof(1)
|
||||
|
||||
await semaphoreContract.updateMember(groupId, members[1], members[2], siblings)
|
||||
}
|
||||
|
||||
console.info(`Validating a proof generated by the first member of group '${groupId}'...`)
|
||||
|
||||
// Validate a proof.
|
||||
const proof = await generateProof(identity, group, 42, 9, 10)
|
||||
|
||||
await semaphoreContract.validateProof(groupId, proof)
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
||||
.then(() => process.exit(0))
|
||||
.catch((error) => {
|
||||
console.error(error)
|
||||
process.exit(1)
|
||||
})
|
||||
15
packages/contracts/scripts/utils.ts
Normal file
15
packages/contracts/scripts/utils.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { readFileSync } from "fs"
|
||||
|
||||
export type DeployedContracts = {
|
||||
Poseidon: string
|
||||
Semaphore: string
|
||||
Verifier: string
|
||||
}
|
||||
|
||||
export function getDeployedContracts(network: string | undefined): DeployedContracts | null {
|
||||
try {
|
||||
return JSON.parse(readFileSync(`./deployed-contracts/${network}.json`, "utf8"))
|
||||
} catch (error) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,5 @@
|
||||
import { hardhatArguments, run } from "hardhat"
|
||||
import { readFileSync } from "fs"
|
||||
|
||||
type DeployedContracts = {
|
||||
Poseidon: string
|
||||
Semaphore: string
|
||||
Verifier: string
|
||||
}
|
||||
|
||||
export function getDeployedContracts(network: string | undefined): DeployedContracts | null {
|
||||
try {
|
||||
return JSON.parse(readFileSync(`./deployed-contracts/${network}.json`, "utf8"))
|
||||
} catch (error) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
import { getDeployedContracts } from "./utils"
|
||||
|
||||
async function verify(address: string, constructorArguments?: any[]): Promise<void> {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user