Skip to content

Commit

Permalink
fix: removed ZeroHashes as private keys (#662)
Browse files Browse the repository at this point in the history
* fix: removed ZeroHashes as private keys

Signed-off-by: Logan Nguyen <[email protected]>

* chore(docs): added a prerequisite comment for ballot test suite

Signed-off-by: Logan Nguyen <[email protected]>

* fix: added awaiting receipt to make sure the transactions properly finalized

Signed-off-by: Logan Nguyen <[email protected]>

---------

Signed-off-by: Logan Nguyen <[email protected]>
  • Loading branch information
quiet-node authored Feb 5, 2024
1 parent 98583b3 commit 5d91fb0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 33 deletions.
27 changes: 3 additions & 24 deletions hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,7 @@ module.exports = {
networks: {
local: {
url: NETWORKS.local.url,
accounts: [
PRIVATE_KEYS[0],
PRIVATE_KEYS[1],
PRIVATE_KEYS[2],
PRIVATE_KEYS[3],
PRIVATE_KEYS[4],
PRIVATE_KEYS[5],
],
accounts: PRIVATE_KEYS,
chainId: NETWORKS.local.chainId,
gas: 10000000,
sdkClient: {
Expand All @@ -79,14 +72,7 @@ module.exports = {
},
testnet: {
url: NETWORKS.testnet.url,
accounts: [
PRIVATE_KEYS[0],
PRIVATE_KEYS[1],
PRIVATE_KEYS[2],
PRIVATE_KEYS[3],
PRIVATE_KEYS[4],
PRIVATE_KEYS[5],
],
accounts: PRIVATE_KEYS,
chainId: NETWORKS.testnet.chainId,
sdkClient: {
operatorId: OPERATOR_ID_A,
Expand All @@ -98,14 +84,7 @@ module.exports = {
},
previewnet: {
url: NETWORKS.previewnet.url,
accounts: [
PRIVATE_KEYS[0],
PRIVATE_KEYS[1],
PRIVATE_KEYS[2],
PRIVATE_KEYS[3],
PRIVATE_KEYS[4],
PRIVATE_KEYS[5],
],
accounts: PRIVATE_KEYS,
chainId: NETWORKS.previewnet.chainId,
sdkClient: {
operatorId: OPERATOR_ID_A,
Expand Down
30 changes: 25 additions & 5 deletions test/solidity/voting/Ballot.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ const { expect } = require('chai');
const { ethers } = require('hardhat');
const Constants = require('../../constants');

/**
* @notice This specific test suite necessitates the presence of 6 accounts for completion.
* @notice Ensure that you include 6 private keys in the .env file under the `PRIVATE_KEYS` variable.
*/

describe('@solidityequiv3 Ballot Units Test Suite', function () {
let ballotContract, owner, addressB, addressC, addressD, addressE, addrs;

Expand All @@ -40,21 +45,36 @@ describe('@solidityequiv3 Ballot Units Test Suite', function () {
});

it('Should give voting rights', async function () {
await ballotContract.giveRightToVote(addressB.address);
const tx = await ballotContract.giveRightToVote(addressB.address);
await tx.wait();
const voter = await ballotContract.voters(addressB.address);
expect(voter.weight).to.equal(1);
});

it('Should allow a voter to delegate their vote', async function () {
await ballotContract.giveRightToVote(addressB.address);
await ballotContract.connect(addressB).delegate(owner.address);
const giveRightToVoteTx = await ballotContract.giveRightToVote(
addressB.address
);
await giveRightToVoteTx.wait();

const delegateTx = await ballotContract
.connect(addressB)
.delegate(owner.address);
await delegateTx.wait();

const ownerVoter = await ballotContract.voters(owner.address);
expect(ownerVoter.weight).to.equal(2); // 1 (original) + 1 (delegated)
});

it('Should allow voting for a proposal', async function () {
await ballotContract.giveRightToVote(addressB.address);
await ballotContract.connect(addressB).vote(1); // voting for proposal2
const giveRightToVoteTx = await ballotContract.giveRightToVote(
addressB.address
);
await giveRightToVoteTx.wait();

const voteTx = await ballotContract.connect(addressB).vote(1); // voting for proposal2
await voteTx.wait();

const proposal = await ballotContract.proposals(1);
expect(proposal.voteCount).to.equal(1);
});
Expand Down
5 changes: 1 addition & 4 deletions utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const { ethers } = require('ethers');
const OPERATOR_ID_A = process.env.OPERATOR_ID_A
? process.env.OPERATOR_ID_A
: '0.0.0';

/** @type string */
const OPERATOR_KEY_A = process.env.OPERATOR_KEY_A
? process.env.OPERATOR_KEY_A
Expand All @@ -14,10 +15,6 @@ const PRIVATE_KEYS = process.env.PRIVATE_KEYS
? process.env.PRIVATE_KEYS.split(',').map((key) => key.trim())
: [];

while (PRIVATE_KEYS.length < 6) {
PRIVATE_KEYS.push(ethers.ZeroHash);
}

const NETWORKS = {
local: {
name: 'local',
Expand Down

0 comments on commit 5d91fb0

Please sign in to comment.