Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: removed ZeroHashes as private keys #662

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading