Skip to content

Commit 0bf97bf

Browse files
authored
Merge pull request #231 from AztecProtocol/fix-old-references-to-private-voting
fix old references to private voting
2 parents 357aac6 + 28cfa8e commit 0bf97bf

File tree

12 files changed

+410
-600
lines changed

12 files changed

+410
-600
lines changed

.env.example

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
VOTING_CONTRACT_ADDRESS="0x2320c9938b3e87feb4e475413456d028572f3367e18d61e7d198d342b557f297"
1+
POD_RACING_CONTRACT_ADDRESS="0x2320c9938b3e87feb4e475413456d028572f3367e18d61e7d198d342b557f297"
22
SECRET="0x29aa7f43021f964fe46527ff4df0e9211de94274f54eff12ec81070ee3e16300"
33
SALT="0x23c46f2dd4450fb881f0b0e70c3974f84dfa9d199493001b3fe8eb136dc612cd"
44
AZTEC_ENV=sandbox
5-
VOTING_CONTRACT_ADDRESS="0x0407e827124a8ce742a4e63250f4f508a8b5043746dcedae8312bd32ea24154d"
65
CONTRACT_SALT="0x2d7e8a973f9039f0e2c7771376e131f8ca1c18bd337ee8fa5c6d89db0198645e"
76
CONTRACT_DEPLOYER="0x2e34557bae428d3c489f67e9aa326b41a09faf03f619969b883e413cbec7bc1c"
87
CONTRACT_PK_NULLIFIER="0x01498945581e0eb9f8427ad6021184c700ef091d570892c437d12c7d90364bbd170ae506787c5c43d6ca9255d571c10fa9ffa9d141666e290c347c5c9ab7e344"

.github/workflows/devnet.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,12 @@ jobs:
108108
109109
cat "$TEMP_OUTPUT"
110110
111-
VOTING_CONTRACT_ADDRESS=$(grep -o "Contract address: 0x[a-fA-F0-9]*" "$TEMP_OUTPUT" | head -1 | sed 's/Contract address: //' || echo "")
111+
POD_RACING_CONTRACT_ADDRESS=$(grep -o "Contract address: 0x[a-fA-F0-9]*" "$TEMP_OUTPUT" | head -1 | sed 's/Contract address: //' || echo "")
112112
113113
rm "$TEMP_OUTPUT"
114114
115-
if [ -n "$VOTING_CONTRACT_ADDRESS" ]; then
116-
echo "VOTING_CONTRACT_ADDRESS=\"$VOTING_CONTRACT_ADDRESS\"" >> .env
115+
if [ -n "$POD_RACING_CONTRACT_ADDRESS" ]; then
116+
echo "POD_RACING_CONTRACT_ADDRESS=\"$POD_RACING_CONTRACT_ADDRESS\"" >> .env
117117
echo "📋 Saved contract address to .env file"
118118
else
119119
echo "⚠️ Warning: Could not extract contract address"

.github/workflows/sandbox.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ jobs:
124124
cat "$TEMP_OUTPUT"
125125
126126
# Extract contract address
127-
VOTING_CONTRACT_ADDRESS=$(grep -o "Contract address: 0x[a-fA-F0-9]*" "$TEMP_OUTPUT" | head -1 | sed 's/Contract address: //' || echo "")
127+
POD_RACING_CONTRACT_ADDRESS=$(grep -o "Contract address: 0x[a-fA-F0-9]*" "$TEMP_OUTPUT" | head -1 | sed 's/Contract address: //' || echo "")
128128
129129
# Extract salt
130130
CONTRACT_SALT=$(grep -o "Salt: 0x[a-fA-F0-9]*" "$TEMP_OUTPUT" | head -1 | sed 's/Salt: //' || echo "")
@@ -144,8 +144,8 @@ jobs:
144144
rm "$TEMP_OUTPUT"
145145
146146
# Save all data to .env
147-
if [ -n "$VOTING_CONTRACT_ADDRESS" ]; then
148-
echo "VOTING_CONTRACT_ADDRESS=\"$VOTING_CONTRACT_ADDRESS\"" >> .env
147+
if [ -n "$POD_RACING_CONTRACT_ADDRESS" ]; then
148+
echo "POD_RACING_CONTRACT_ADDRESS=\"$POD_RACING_CONTRACT_ADDRESS\"" >> .env
149149
echo "📋 Saved contract address to .env file"
150150
fi
151151

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010

1111
This repo is meant to be a starting point for learning to write Aztec contracts and tests on the Aztec sandbox (local development environment). It includes an example contract, useful commands in `package.json` and helpful scripts in `./scripts`.
1212

13-
You can find the **Easy Private Voting contract** in `./src/main.nr`. A simple integration test is in `./src/test/e2e/index.test.ts`.
13+
You can find the **Pod Racing Game contract** in `./src/main.nr`. A simple integration test is in `./src/test/e2e/index.test.ts`.
14+
15+
The Pod Racing contract is a two-player competitive game where players allocate points across 5 tracks over multiple rounds. The game demonstrates Aztec's private state capabilities - round choices remain private until players reveal their final scores.
1416

1517
## Devnet
1618

@@ -176,7 +178,7 @@ You can find a handful of scripts in the `./scripts` folder.
176178
- `./scripts/fees.ts` is an example of how to pay for a contract deployment using various fee payment methods.
177179
- `./scripts/multiple_wallet.ts` is an example of how to deploy a contract from one wallet instance and interact with it from another.
178180
- `./scripts/profile_deploy.ts` shows how to profile a transaction and print the results.
179-
- `./scripts/interaction_existing_contract.ts` demonstrates how to interact with an already deployed voting contract, including casting votes and checking vote counts.
181+
- `./scripts/interaction_existing_contract.ts` demonstrates how to interact with an already deployed pod racing contract, including creating games.
180182
- `./scripts/get_block.ts` is an example of how to retrieve and display block information from the Aztec node.
181183

182184
### Utility Functions

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "pod_racing_codespace",
33
"version": "1.0.0",
44
"main": "index.js",
5-
"repository": "https://github.com/critesjosh/private_voting_codespace.git",
5+
"repository": "https://github.com/AztecProtocol/aztec-starter.git",
66
"author": "Josh Crites <[email protected]>",
77
"license": "MIT",
88
"private": true,

scripts/deploy_contract.ts

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PrivateVotingContract } from "../src/artifacts/PrivateVoting.js"
1+
import { PodRacingContract } from "../src/artifacts/PodRacing.js"
22
import { Logger, createLogger } from "@aztec/aztec.js/log";
33
import { SponsoredFeePaymentMethod } from "@aztec/aztec.js/fee/testing";
44
import { Fr } from "@aztec/aztec.js/fields";
@@ -38,38 +38,28 @@ async function main() {
3838
const address = accountManager.address;
3939
logger.info(`✅ Account deployed successfully at: ${address}`);
4040

41-
// Deploy voting contract
42-
logger.info('🗳️ Starting voting contract deployment...');
43-
logger.info(`📋 Admin address for voting contract: ${address}`);
41+
// Deploy pod racing contract
42+
logger.info('🏎️ Starting pod racing contract deployment...');
43+
logger.info(`📋 Admin address for pod racing contract: ${address}`);
4444

45-
const deployTx = PrivateVotingContract.deploy(wallet, address).send({
45+
const deployTx = PodRacingContract.deploy(wallet, address).send({
4646
from: address,
4747
fee: { paymentMethod: sponsoredPaymentMethod }
4848
});
4949

5050
logger.info('⏳ Waiting for deployment transaction to be mined...');
51-
const votingContract = await deployTx.deployed({ timeout: timeouts.deployTimeout });
51+
const podRacingContract = await deployTx.deployed({ timeout: timeouts.deployTimeout });
5252

53-
logger.info(`🎉 Voting Contract deployed successfully!`);
54-
logger.info(`📍 Contract address: ${votingContract.address}`);
53+
logger.info(`🎉 Pod Racing Contract deployed successfully!`);
54+
logger.info(`📍 Contract address: ${podRacingContract.address}`);
5555
logger.info(`👤 Admin address: ${address}`);
5656

5757
// Verify deployment
5858
logger.info('🔍 Verifying contract deployment...');
59-
try {
60-
// Test a read operation
61-
logger.info('🧪 Testing contract read operation...');
62-
const initialVoteCount = await votingContract.methods.get_vote(Fr.fromString("1")).simulate({
63-
from: address
64-
});
65-
logger.info(`📊 Initial vote count for candidate 1: ${initialVoteCount}`);
66-
67-
} catch (error) {
68-
logger.error(`❌ Contract verification failed: ${error}`);
69-
}
59+
logger.info('✅ Contract deployed and ready for game creation');
7060

7161
// Get contract instance for instantiation data
72-
const instance = votingContract.instance;
62+
const instance = podRacingContract.instance;
7363
if (instance) {
7464
logger.info('📦 Contract instantiation data:');
7565
logger.info(`Salt: ${instance.salt}`);
@@ -85,7 +75,7 @@ async function main() {
8575

8676
logger.info('🏁 Deployment process completed successfully!');
8777
logger.info(`📋 Summary:`);
88-
logger.info(` - Contract Address: ${votingContract.address}`);
78+
logger.info(` - Contract Address: ${podRacingContract.address}`);
8979
logger.info(` - Admin Address: ${address}`);
9080
logger.info(` - Sponsored FPC: ${sponsoredFPC.address}`);
9181
}

scripts/fees.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { foundry } from 'viem/chains'
66
import { mnemonicToAccount } from 'viem/accounts';
77
import { FeeJuiceContract } from "@aztec/noir-contracts.js/FeeJuice";
88
import { FPCContract } from "@aztec/noir-contracts.js/FPC";
9-
import { PrivateVotingContract } from "../src/artifacts/PrivateVoting.js"
9+
import { PodRacingContract } from "../src/artifacts/PodRacing.js"
1010
import { TokenContract } from "@aztec/noir-contracts.js/Token";
1111
import { SponsoredFeePaymentMethod } from '@aztec/aztec.js/fee/testing'
1212
import { getSponsoredFPCInstance } from "../src/utils/sponsored_fpc.js";
@@ -69,7 +69,7 @@ async function main() {
6969
const paymentMethod = new SponsoredFeePaymentMethod(sponsoredFPC.address);
7070

7171
// Two arbitrary txs to make the L1 message available on L2
72-
const votingContract = await PrivateVotingContract.deploy(wallet, account1.address).send({
72+
const podRacingContract = await PodRacingContract.deploy(wallet, account1.address).send({
7373
from: account1.address,
7474
fee: { paymentMethod }
7575
}).deployed();
@@ -86,11 +86,12 @@ async function main() {
8686

8787
// Pay fees yourself
8888

89-
// Create a new voting contract instance, interacting from the newWallet
90-
await votingContract.methods.cast_vote(account1.address).send({
89+
// Create a new game on the pod racing contract, interacting from the newWallet
90+
const gameId = Fr.random();
91+
await podRacingContract.methods.create_game(gameId).send({
9192
from: account2.address,
9293
}).wait()
93-
logger.info(`Vote cast from new account, paying fees via newWallet.`)
94+
logger.info(`Game created from new account, paying fees via newWallet.`)
9495

9596
// Private Fee Payments via FPC
9697

scripts/interaction_existing_contract.ts

Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Logger, createLogger } from "@aztec/aztec.js/log";
22
import { SponsoredFeePaymentMethod } from "@aztec/aztec.js/fee/testing";
33
import { Fr } from "@aztec/aztec.js/fields";
44
import { AztecAddress } from "@aztec/stdlib/aztec-address";
5-
import { PrivateVotingContract } from "../src/artifacts/PrivateVoting.js";
5+
import { PodRacingContract } from "../src/artifacts/PodRacing.js";
66
import { SponsoredFPCContract } from "@aztec/noir-contracts.js/SponsoredFPC";
77
import { setupWallet } from "../src/utils/setup_wallet.js";
88
import { getSponsoredFPCInstance } from "../src/utils/sponsored_fpc.js";
@@ -12,7 +12,7 @@ import { getContractInstanceFromInstantiationParams } from "@aztec/aztec.js/cont
1212

1313
async function main() {
1414
let logger: Logger;
15-
logger = createLogger('aztec:voting-operations-existing');
15+
logger = createLogger('aztec:pod-racing-operations-existing');
1616

1717
const timeouts = getTimeouts();
1818

@@ -28,14 +28,14 @@ async function main() {
2828
const accountManager = await getAccountFromEnv(wallet);
2929
const address = accountManager.address;
3030

31-
// Connect to existing voting contract (replace with your deployed contract address)
32-
const contractAddress = process.env.VOTING_CONTRACT_ADDRESS;
31+
// Connect to existing pod racing contract (replace with your deployed contract address)
32+
const contractAddress = process.env.POD_RACING_CONTRACT_ADDRESS;
3333
if (!contractAddress) {
34-
logger.error("Please set VOTING_CONTRACT_ADDRESS environment variable with your deployed contract address");
34+
logger.error("Please set POD_RACING_CONTRACT_ADDRESS environment variable with your deployed contract address");
3535
return;
3636
}
3737

38-
logger.info(`Connecting to voting contract at: ${contractAddress}`);
38+
logger.info(`Connecting to pod racing contract at: ${contractAddress}`);
3939
// Get instantiation parameters from environment variables
4040
const contractSalt = process.env.CONTRACT_SALT;
4141
const contractDeployer = process.env.CONTRACT_DEPLOYER;
@@ -47,7 +47,7 @@ async function main() {
4747
return;
4848
}
4949

50-
logger.info("📦 Reconstructing contract instance from environment variables...");
50+
logger.info("Reconstructing contract instance from environment variables...");
5151

5252
// Parse constructor args
5353
let constructorArgs;
@@ -65,9 +65,9 @@ async function main() {
6565
}
6666

6767
// Reconstruct contract instance
68-
const votingContractAddress = AztecAddress.fromString(contractAddress);
68+
const podRacingContractAddress = AztecAddress.fromString(contractAddress);
6969

70-
const instance = await getContractInstanceFromInstantiationParams(PrivateVotingContract.artifact, {
70+
const instance = await getContractInstanceFromInstantiationParams(PodRacingContract.artifact, {
7171
constructorArgs,
7272
salt: Fr.fromString(contractSalt),
7373
deployer: AztecAddress.fromString(contractDeployer)
@@ -76,47 +76,31 @@ async function main() {
7676
logger.info("✅ Contract instance reconstructed successfully");
7777

7878
// Register the contract with the wallet
79-
await wallet.registerContract({ instance, artifact: PrivateVotingContract.artifact });
80-
79+
await wallet.registerContract({ instance, artifact: PodRacingContract.artifact });
8180

8281
// Get the contract instance from the PXE
83-
const votingContract = await PrivateVotingContract.at(
84-
votingContractAddress,
82+
const podRacingContract = await PodRacingContract.at(
83+
podRacingContractAddress,
8584
wallet
8685
);
8786

87+
// Create a new game
88+
const gameId = Fr.random();
89+
logger.info(`Creating new game with ID: ${gameId}`);
8890

89-
// Define a candidate to vote for (using a Field value)
90-
const candidate = Fr.fromString("1"); // Voting for candidate "1"
91-
92-
// First get_vote call - check initial vote count
93-
logger.info("Getting initial vote count...");
94-
const initialVoteCount = await votingContract.methods.get_vote(candidate).simulate({
95-
from: address
96-
});
97-
logger.info(`Initial vote count for candidate ${candidate}: ${initialVoteCount}`);
98-
99-
// Cast a vote
100-
logger.info("Casting vote...");
101-
await votingContract.methods.cast_vote(candidate)
91+
await podRacingContract.methods.create_game(gameId)
10292
.send({
10393
from: address,
10494
fee: { paymentMethod: sponsoredPaymentMethod }
10595
})
10696
.wait({ timeout: timeouts.txTimeout });
107-
logger.info("Vote cast successfully!");
108-
109-
// Second get_vote call - check updated vote count
110-
logger.info("Getting updated vote count...");
111-
const updatedVoteCount = await votingContract.methods.get_vote(candidate).simulate({
112-
from: address
113-
});
114-
logger.info(`Updated vote count for candidate ${candidate}: ${updatedVoteCount}`);
97+
logger.info("Game created successfully!");
11598

116-
logger.info(`Vote count increased from ${initialVoteCount} to ${updatedVoteCount}`);
99+
logger.info(`Game ${gameId} is now waiting for a second player to join.`);
100+
logger.info("To join this game, another player would call join_game with the same game ID.");
117101
}
118102

119103
main().catch((error) => {
120104
console.error("Error:", error);
121105
process.exit(1);
122-
});
106+
});

scripts/profile_deploy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PrivateVotingContract } from "../src/artifacts/PrivateVoting.js"
1+
import { PodRacingContract } from "../src/artifacts/PodRacing.js"
22
import { Logger, createLogger } from "@aztec/aztec.js/log";
33
import { setupWallet } from "../src/utils/setup_wallet.js";
44
import { getSponsoredFPCInstance } from "../src/utils/sponsored_fpc.js";
@@ -19,7 +19,7 @@ async function main() {
1919
let accountManager = await deploySchnorrAccount(wallet);
2020
const address = accountManager.address;
2121

22-
const profileTx = await PrivateVotingContract.deploy(wallet, address).profile({ profileMode: "full", from: address });
22+
const profileTx = await PodRacingContract.deploy(wallet, address).profile({ profileMode: "full", from: address });
2323
console.dir(profileTx, { depth: 2 });
2424
}
2525

src/test/e2e/accounts.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PrivateVotingContractArtifact, PrivateVotingContract } from "../../artifacts/PrivateVoting.js"
1+
import { PodRacingContractArtifact, PodRacingContract } from "../../artifacts/PodRacing.js"
22
import { generateSchnorrAccounts } from "@aztec/accounts/testing"
33
import { SponsoredFeePaymentMethod } from '@aztec/aztec.js/fee/testing'
44
import { createEthereumChain, createExtendedL1Client } from '@aztec/ethereum';
@@ -112,19 +112,19 @@ describe("Accounts", () => {
112112
console.log(`Total claims created: ${claims.length}`);
113113

114114
// arbitrary transactions to progress 2 blocks, and have fee juice on Aztec ready to claim
115-
console.log('Deploying first PrivateVotingContract to progress blocks...');
116-
await PrivateVotingContract.deploy(wallet, ownerAccount.address).send({
115+
console.log('Deploying first PodRacingContract to progress blocks...');
116+
await PodRacingContract.deploy(wallet, ownerAccount.address).send({
117117
from: ownerAccount.address,
118118
fee: { paymentMethod: sponsoredPaymentMethod }
119119
}).deployed({ timeout: getTimeouts().deployTimeout }); // deploy contract with first funded wallet
120-
console.log('First PrivateVotingContract deployed');
120+
console.log('First PodRacingContract deployed');
121121

122-
console.log('Deploying second PrivateVotingContract to progress blocks...');
123-
await PrivateVotingContract.deploy(wallet, ownerAccount.address).send({
122+
console.log('Deploying second PodRacingContract to progress blocks...');
123+
await PodRacingContract.deploy(wallet, ownerAccount.address).send({
124124
from: ownerAccount.address,
125125
fee: { paymentMethod: sponsoredPaymentMethod }
126126
}).deployed({ timeout: getTimeouts().deployTimeout }); // deploy contract with first funded wallet
127-
console.log('Second PrivateVotingContract deployed');
127+
console.log('Second PodRacingContract deployed');
128128

129129
// Now deploy random accounts using FeeJuicePaymentMethodWithClaim (which claims and pays in one tx)
130130
console.log('Starting account deployments with FeeJuicePaymentMethodWithClaim...');
@@ -154,7 +154,7 @@ describe("Accounts", () => {
154154
logger.info('Starting "Sponsored contract deployment" test');
155155
const salt = Fr.random();
156156
logger.info(`Using salt: ${salt.toString()}`);
157-
const VotingContractArtifact = PrivateVotingContractArtifact
157+
const PodRacingArtifact = PodRacingContractArtifact
158158

159159
logger.info('Generating 2 Schnorr accounts...');
160160
const accounts = await Promise.all(
@@ -177,13 +177,13 @@ describe("Accounts", () => {
177177
logger.info(`Deployer address: ${deployerAddress.toString()}`);
178178
logger.info(`Admin address: ${adminAddress.toString()}`);
179179

180-
const deploymentData = await getContractInstanceFromInstantiationParams(VotingContractArtifact,
180+
const deploymentData = await getContractInstanceFromInstantiationParams(PodRacingArtifact,
181181
{
182182
constructorArgs: [adminAddress],
183183
salt,
184184
deployer: deployerAccount.getAddress()
185185
});
186-
const deployer = new ContractDeployer(VotingContractArtifact, wallet);
186+
const deployer = new ContractDeployer(PodRacingArtifact, wallet);
187187
const tx = deployer.deploy(adminAddress).send({
188188
from: deployerAddress,
189189
contractAddressSalt: salt,

0 commit comments

Comments
 (0)