Skip to content

Commit

Permalink
f: added watch mode and fixed all unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jordaniza committed Jun 6, 2024
1 parent cad9f6f commit e82b9d3
Show file tree
Hide file tree
Showing 11 changed files with 616 additions and 405 deletions.
11 changes: 11 additions & 0 deletions packages/contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import '@openzeppelin/hardhat-upgrades';
import '@typechain/hardhat';
import {config as dotenvConfig} from 'dotenv';
import {BigNumber, ethers} from 'ethers';
import {tasks} from 'hardhat';
import 'hardhat-deploy';
import 'hardhat-gas-reporter';
import 'hardhat-watcher';
import {extendEnvironment, HardhatUserConfig} from 'hardhat/config';
import {
HardhatNetworkAccountsUserConfig,
Expand Down Expand Up @@ -183,6 +185,15 @@ const config: HardhatUserConfig = {
outDir: 'typechain',
target: 'ethers-v5',
},
watcher: {
test: {
tasks: [{command: 'test', params: {testFiles: ['{path}']}}],
files: ['./test/**/*'],
verbose: true,
clearOnStart: true,
start: 'echo Running my test task now..',
},
},
};

export default config;
4 changes: 3 additions & 1 deletion packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"lint:sol": "cd ../../ && yarn run lint:contracts:sol",
"lint:ts": "cd ../../ && yarn run lint:contracts:ts",
"test": "hardhat test",
"test:watch": "hardhat watch test",
"typechain": "cross-env TS_NODE_TRANSPILE_ONLY=true hardhat typechain",
"clean": "rimraf ./artifacts ./cache ./coverage ./typechain ./types ./coverage.json && yarn typechain"
},
Expand Down Expand Up @@ -52,7 +53,8 @@
"tmp-promise": "^3.0.3",
"ts-node": "^10.9.1",
"typechain": "^8.3.2",
"typescript": "^5.2.2"
"typescript": "^5.2.2",
"hardhat-watcher": "^2.5.0"
},
"files": [
"/src"
Expand Down
11 changes: 11 additions & 0 deletions packages/contracts/src/ITokenVoting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,15 @@ interface ITokenVoting is IVoteContainer {
/// @param _proposalId The ID of the proposal to be checked.
/// @return True if the proposal can be executed, false otherwise.
function canExecute(uint256 _proposalId) external view returns (bool);

/// @notice Returns the proposal ID for a given proposal.
/// @param _startDate The start date of the proposal vote.
/// @param _endDate The end date of the proposal vote.
/// @param _snapshotBlockTimestamp The block timestamp when the proposal was created.
/// @return proposalId The ID of the proposal encoded as (plugin, startTimestamp, endTimestamp, blockSnapshotTimestamp)

Check failure on line 251 in packages/contracts/src/ITokenVoting.sol

View workflow job for this annotation

GitHub Actions / checks

Line length must be no more than 120 but current length is 123

Check failure on line 251 in packages/contracts/src/ITokenVoting.sol

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

Line length must be no more than 120 but current length is 123

Check failure on line 251 in packages/contracts/src/ITokenVoting.sol

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

Line length must be no more than 120 but current length is 123
function getProposalId(
uint256 _startDate,
uint256 _endDate,
uint256 _snapshotBlockTimestamp
) external view returns (uint256 proposalId);
}
24 changes: 19 additions & 5 deletions packages/contracts/src/TokenVoting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -398,11 +398,10 @@ contract TokenVoting is
_incrementProposalCount();

return
ProposalIdCodec.encode({
_plugin: address(this),
_proposalStartTimestamp: uint(_startDate).toUint32(),
_proposalEndTimestamp: uint(_endDate).toUint32(),
_proposalBlockSnapshotTimestamp: block.timestamp.toUint32()
getProposalId({
_startDate: _startDate,
_endDate: _endDate,
_snapshotBlockTimestamp: block.timestamp
});
}

Expand Down Expand Up @@ -714,6 +713,21 @@ contract TokenVoting is
}
}

/// @inheritdoc ITokenVoting
function getProposalId(
uint256 _startDate,
uint256 _endDate,
uint256 _snapshotBlockTimestamp
) public view returns (uint256 proposalId) {
return
ProposalIdCodec.encode({
_plugin: address(this),
_proposalStartTimestamp: uint(_startDate).toUint32(),
_proposalEndTimestamp: uint(_endDate).toUint32(),
_proposalBlockSnapshotTimestamp: uint(_snapshotBlockTimestamp).toUint32()
});
}

/// @dev This empty reserved space is put in place to allow future versions to add new
/// variables without shifting down storage in the inheritance chain.
/// https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
Expand Down
16 changes: 2 additions & 14 deletions packages/contracts/src/libs/TallyMath.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ library TallyMath {
}

/// @return The difference of two tallies inside a new tally.
/// @dev This can revert ib overflow if the total exceeds the maximum uint.
function sum(IVoteContainer.Tally memory tally) public pure returns (uint) {
/// @dev This can revert if overflow if the total exceeds the maximum uint.
function sum(IVoteContainer.Tally memory tally) internal pure returns (uint256) {
return tally.abstain + tally.yes + tally.no;
}

Expand All @@ -69,15 +69,3 @@ library TallyMath {
return tally.yes == 0 && tally.no == 0 && tally.abstain == 0;
}
}

library OverflowChecker {
function overflows(IVoteContainer.Tally memory tally) internal pure returns (bool) {
try TallyMath.sum(tally) {} catch Error(string memory) {
return true;
} catch (bytes memory) {
return true;
}

return false;
}
}
Loading

0 comments on commit e82b9d3

Please sign in to comment.