Skip to content

Commit

Permalink
chore(tests): Add counter and private voting tests (#4592)
Browse files Browse the repository at this point in the history
The Counter contract and the EasyPrivateVoting contracts did not have
e2e tests. Now they do.

closes #4585

---------

Co-authored-by: Rahul Kothari <[email protected]>
  • Loading branch information
critesjosh and rahul-kothari authored Feb 14, 2024
1 parent 730e73a commit d3be5cc
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,28 @@ jobs:
name: "Test"
command: cond_spot_run_compose end-to-end 4 ./scripts/docker-compose.yml TEST=e2e_note_getter.test.ts

e2e-counter:
docker:
- image: aztecprotocol/alpine-build-image
resource_class: small
steps:
- *checkout
- *setup_env
- run:
name: "Test"
command: cond_spot_run_compose end-to-end 4 ./scripts/docker-compose.yml TEST=e2e_counter_contract.test.ts

e2e-private-voting:
docker:
- image: aztecprotocol/alpine-build-image
resource_class: small
steps:
- *checkout
- *setup_env
- run:
name: "Test"
command: cond_spot_run_compose end-to-end 4 ./scripts/docker-compose.yml TEST=e2e_private_voting_contract.test.ts

e2e-multiple-accounts-1-enc-key:
docker:
- image: aztecprotocol/alpine-build-image
Expand Down Expand Up @@ -1297,6 +1319,8 @@ workflows:
- e2e-inclusion-proofs-contract: *e2e_test
- e2e-pending-commitments-contract: *e2e_test
- e2e-ordering: *e2e_test
- e2e-counter: *e2e_test
- e2e-private-voting: *e2e_test
- uniswap-trade-on-l1-from-l2: *e2e_test
- integration-l1-publisher: *e2e_test
- integration-archiver-l1-to-l2: *e2e_test
Expand Down Expand Up @@ -1336,6 +1360,8 @@ workflows:
- e2e-inclusion-proofs-contract
- e2e-pending-commitments-contract
- e2e-ordering
- e2e-counter
- e2e-private-voting
- uniswap-trade-on-l1-from-l2
- integration-l1-publisher
- integration-archiver-l1-to-l2
Expand Down
39 changes: 39 additions & 0 deletions yarn-project/end-to-end/src/e2e_counter_contract.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { AccountWallet, AztecAddress, CompleteAddress, DebugLogger, TxStatus } from '@aztec/aztec.js';
import { CounterContract } from '@aztec/noir-contracts.js/Counter';

import { setup } from './fixtures/utils.js';

describe('e2e_counter_contract', () => {
let wallet: AccountWallet;
let accounts: CompleteAddress[];
let logger: DebugLogger;
let teardown: () => Promise<void>;

let counterContract: CounterContract;
let owner: AztecAddress;

beforeAll(async () => {
// Setup environment
({
teardown,
accounts,
wallets: [wallet],
logger,
} = await setup(1));
owner = accounts[0].address;

counterContract = await CounterContract.deploy(wallet, 0, owner).send().deployed();

logger(`Counter contract deployed at ${counterContract.address}`);
}, 25_000);

afterAll(() => teardown());

describe('increments', () => {
it('counts', async () => {
const receipt = await counterContract.methods.increment(owner).send().wait();
expect(receipt.status).toBe(TxStatus.MINED);
expect(await counterContract.methods.get_counter(owner).view()).toBe(1n);
});
});
});
41 changes: 41 additions & 0 deletions yarn-project/end-to-end/src/e2e_private_voting_contract.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { AccountWallet, AztecAddress, CompleteAddress, DebugLogger, Fr, TxStatus } from '@aztec/aztec.js';
import { EasyPrivateVotingContract } from '@aztec/noir-contracts.js/EasyPrivateVoting';

import { setup } from './fixtures/utils.js';

describe('e2e_voting_contract', () => {
let wallet: AccountWallet;
let accounts: CompleteAddress[];
let logger: DebugLogger;
let teardown: () => Promise<void>;

let votingContract: EasyPrivateVotingContract;
let owner: AztecAddress;

beforeAll(async () => {
// Setup environment
({
teardown,
accounts,
wallets: [wallet],
logger,
} = await setup(1));
owner = accounts[0].address;

votingContract = await EasyPrivateVotingContract.deploy(wallet, owner).send().deployed();

logger(`Counter contract deployed at ${votingContract.address}`);
}, 25_000);

afterAll(() => teardown());

describe('votes', () => {
it('votes', async () => {
const candidate = new Fr(1);
const tx = votingContract.methods.cast_vote(candidate).send();
const receipt = await tx.wait();
expect(receipt.status).toBe(TxStatus.MINED);
expect(await votingContract.methods.get_vote(candidate).view()).toBe(1n);
});
});
});

0 comments on commit d3be5cc

Please sign in to comment.