Skip to content

Commit

Permalink
Merge pull request #763 from privacy-scaling-explorations/fix/voice-c…
Browse files Browse the repository at this point in the history
…redits-cli

fix(cli) - fix wrong condition check in contracts deployment
  • Loading branch information
baumstern authored Nov 1, 2023
2 parents 2dc220d + 08da813 commit ac04d42
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 28 deletions.
34 changes: 18 additions & 16 deletions cli/ts/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,23 @@ const create = async (args: any) => {
return
}

const TopupCreditContract = await deployTopupCreditContract()
console.log('TopupCredit:', TopupCreditContract.address)

// Initial voice credits
const initialVoiceCredits = args.initial_voice_credits ? args.initial_voice_credits : DEFAULT_INITIAL_VOICE_CREDITS
const topupCreditContract = await deployTopupCreditContract()
console.log('TopupCredit:', topupCreditContract.address)

// Initial voice credit proxy contract
const initialVoiceCreditProxy = args.initial_vc_proxy

// Whether we should deploy a ConstantInitialVoiceCreditProxy
if (initialVoiceCreditProxy != undefined && initialVoiceCredits != undefined) {
if (initialVoiceCreditProxy && args.initial_voice_credits) {
console.error('Error: only one of the following can be specified: the initial voice credit proxy or the amount of initial voice credits.')
return
}

let initialVoiceCreditProxyContractAddress
if (initialVoiceCreditProxy == undefined) {
let initialVoiceCreditProxyContractAddress: string
if (!initialVoiceCreditProxy) {
// check if we have the amount of credits to set, or use the default
const initialVoiceCredits = args.initial_voice_credits ? args.initial_voice_credits : DEFAULT_INITIAL_VOICE_CREDITS

// Deploy a ConstantInitialVoiceCreditProxy contract
const c = await deployConstantInitialVoiceCreditProxy(
initialVoiceCredits,
Expand All @@ -91,23 +91,25 @@ const create = async (args: any) => {
initialVoiceCreditProxyContractAddress = initialVoiceCreditProxy
}

console.log("Initial voice credit proxy", initialVoiceCreditProxyContractAddress)
// Signup gatekeeper contract
const signupGatekeeper = args.signup_gatekeeper

let signUpGatekeeperAddress
if (signupGatekeeper == undefined) {
let signUpGatekeeperAddress: string
if (!signupGatekeeper) {
// Deploy a FreeForAllGatekeeper contract
const c = await deployFreeForAllSignUpGatekeeper(true)
signUpGatekeeperAddress = c.address
} else {
signUpGatekeeperAddress = signupGatekeeper
}


console.log("Signup gatekeeper", signUpGatekeeperAddress)
const verifierContract = await deployVerifier(true)
console.log("Verifier", verifierContract.address)

const vkRegistryContractAddress = args.vk_registry ? args.vk_registry: contractAddrs["VkRegistry"]

console.log("VkRegistry", vkRegistryContractAddress)
const {
maciContract,
stateAqContract,
Expand All @@ -118,18 +120,18 @@ const create = async (args: any) => {
initialVoiceCreditProxyContractAddress,
verifierContract.address,
vkRegistryContractAddress,
TopupCreditContract.address
topupCreditContract.address
)

console.log('MACI:', maciContract.address)

contractAddrs['InitialVoiceCreditProxy'] = initialVoiceCreditProxyContractAddress
contractAddrs['SignUpGatekeeper'] = signUpGatekeeperAddress
contractAddrs['Verifier'] = verifierContract.address
contractAddrs['MACI'] = maciContract.address
contractAddrs['StateAq'] = stateAqContract.address
contractAddrs['PollFactory'] = pollFactoryContract.address
contractAddrs['TopupCredit'] = TopupCreditContract.address
contractAddrs['TopupCredit'] = topupCreditContract.address
contractAddrs['PoseidonT3'] = poseidonAddrs[0]
contractAddrs['PoseidonT4'] = poseidonAddrs[1]
contractAddrs['PoseidonT5'] = poseidonAddrs[2]
Expand Down
15 changes: 3 additions & 12 deletions integrationTests/ts/__tests__/suites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,15 @@ const executeSuite = async (data: any, expect: any) => {
const config = loadYaml()
const coordinatorKeypair = new Keypair()

const maciState = new MaciState(
coordinatorKeypair,
config.constants.maci.stateTreeDepth,
config.constants.maci.messageTreeDepth,
config.constants.maci.voteOptionTreeDepth,
config.constants.maci.maxVoteOptions,
)
const maciState = new MaciState()

const deployVkRegistryCommand = `node build/index.js deployVkRegistry`
const vkDeployOutput = exec(deployVkRegistryCommand)
const vkAddressMatch = vkDeployOutput.stdout.trim().match(/(0x[a-fA-F0-9]{40})/)
if (!vkAddressMatch) {
console.log(vkDeployOutput)
return false
}
const vkAddress = vkAddressMatch[1]
console.log(vkAddress)

let subsidyZkeyFilePath
let subsidyWitnessCalculatorPath
Expand Down Expand Up @@ -122,13 +114,12 @@ const executeSuite = async (data: any, expect: any) => {
treeDepths.voteOptionTreeDepth = config.constants.maci.voteOptionTreeDepth

const maxValues = {} as MaxValues
maxValues.maxUsers = config.constants.maci.maxUsers
maxValues.maxMessages = config.constants.maci.maxMessages
maxValues.maxVoteOptions = config.constants.maci.maxVoteOptions
const messageBatchSize = 5 ** config.constants.poll.messageBatchDepth
maciState.deployPoll(
config.constants.poll.duration,
(Date.now() + (config.constants.poll.duration * 60000)),
BigInt((Date.now() + (config.constants.poll.duration * 60000))),
maxValues,
treeDepths,
messageBatchSize,
Expand Down Expand Up @@ -160,7 +151,7 @@ const executeSuite = async (data: any, expect: any) => {
maciState.signUp(
userKeypair.pubKey,
BigInt(config.constants.maci.initialVoiceCredits),
Date.now()
BigInt(Date.now())
)
}

Expand Down

0 comments on commit ac04d42

Please sign in to comment.