Skip to content

Commit

Permalink
feat: sync bytecode to latest (#584)
Browse files Browse the repository at this point in the history
* feat: sync bytecode to latest

* fix: change foundry version in ci

* chores: add output on ci

* fix: modify ci workflow

* chores: lint contract code for latest foundry fmt

* fix: fix governor test case after governor started on BSC
  • Loading branch information
cosinlink authored Aug 22, 2024
1 parent f11346c commit 7403b72
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 72 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ jobs:
${{ runner.os }}-yarn-
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1.2.0
uses: foundry-rs/foundry-toolchain@v1

- name: Install Project Dependencies
run: |
npm install
forge install --no-git --no-commit foundry-rs/[email protected]
forge --version
- name: Lint Check
run: |
Expand Down
12 changes: 9 additions & 3 deletions contracts/BC_fusion/BSCGovernor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@ contract BSCGovernor is
*@return `true` if the contract implements `interfaceID` and
*`interfaceID` is not 0xffffffff, `false` otherwise
*/
function supportsInterface(bytes4 interfaceId)
function supportsInterface(
bytes4 interfaceId
)
public
view
override(GovernorUpgradeable, IERC165Upgradeable, GovernorTimelockControlUpgradeable)
Expand All @@ -227,7 +229,9 @@ contract BSCGovernor is
* @notice module:core
* @dev Current state of a proposal, following Compound's convention
*/
function state(uint256 proposalId)
function state(
uint256 proposalId
)
public
view
override(GovernorUpgradeable, IGovernorUpgradeable, GovernorTimelockControlUpgradeable)
Expand All @@ -253,7 +257,9 @@ contract BSCGovernor is
* @dev Timepoint at which votes close. If using block number, votes close at the end of this block, so it is
* possible to cast a vote during this block.
*/
function proposalDeadline(uint256 proposalId)
function proposalDeadline(
uint256 proposalId
)
public
view
override(IGovernorUpgradeable, GovernorUpgradeable, GovernorPreventLateQuorumUpgradeable)
Expand Down
70 changes: 24 additions & 46 deletions contracts/BC_fusion/StakeHub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -416,12 +416,9 @@ contract StakeHub is System, Initializable, Protectable {
/**
* @param newConsensusAddress the new consensus address of the validator
*/
function editConsensusAddress(address newConsensusAddress)
external
whenNotPaused
notInBlackList
validatorExist(_bep410MsgSender())
{
function editConsensusAddress(
address newConsensusAddress
) external whenNotPaused notInBlackList validatorExist(_bep410MsgSender()) {
if (newConsensusAddress == address(0)) revert InvalidConsensusAddress();
if (consensusToOperator[newConsensusAddress] != address(0) || _legacyConsensusAddress[newConsensusAddress]) {
revert DuplicateConsensusAddress();
Expand All @@ -442,12 +439,9 @@ contract StakeHub is System, Initializable, Protectable {
/**
* @param commissionRate the new commission rate of the validator
*/
function editCommissionRate(uint64 commissionRate)
external
whenNotPaused
notInBlackList
validatorExist(_bep410MsgSender())
{
function editCommissionRate(
uint64 commissionRate
) external whenNotPaused notInBlackList validatorExist(_bep410MsgSender()) {
address operatorAddress = _bep410MsgSender();
Validator storage valInfo = _validators[operatorAddress];
if (valInfo.updateTime + BREATHE_BLOCK_INTERVAL > block.timestamp) revert UpdateTooFrequently();
Expand All @@ -468,12 +462,9 @@ contract StakeHub is System, Initializable, Protectable {
* @notice the moniker of the validator will be ignored as it is not editable
* @param description the new description of the validator
*/
function editDescription(Description memory description)
external
whenNotPaused
notInBlackList
validatorExist(_bep410MsgSender())
{
function editDescription(
Description memory description
) external whenNotPaused notInBlackList validatorExist(_bep410MsgSender()) {
address operatorAddress = _bep410MsgSender();
Validator storage valInfo = _validators[operatorAddress];
if (valInfo.updateTime + BREATHE_BLOCK_INTERVAL > block.timestamp) revert UpdateTooFrequently();
Expand Down Expand Up @@ -952,11 +943,9 @@ contract StakeHub is System, Initializable, Protectable {
* @return jailed whether the validator is jailed
* @return jailUntil the jail time of the validator
*/
function getValidatorBasicInfo(address operatorAddress)
external
view
returns (uint256 createdTime, bool jailed, uint256 jailUntil)
{
function getValidatorBasicInfo(
address operatorAddress
) external view returns (uint256 createdTime, bool jailed, uint256 jailUntil) {
Validator memory valInfo = _validators[operatorAddress];
createdTime = valInfo.createdTime;
jailed = valInfo.jailed;
Expand All @@ -968,12 +957,9 @@ contract StakeHub is System, Initializable, Protectable {
*
* @return the description of a validator
*/
function getValidatorDescription(address operatorAddress)
external
view
validatorExist(operatorAddress)
returns (Description memory)
{
function getValidatorDescription(
address operatorAddress
) external view validatorExist(operatorAddress) returns (Description memory) {
return _validators[operatorAddress].description;
}

Expand All @@ -982,12 +968,9 @@ contract StakeHub is System, Initializable, Protectable {
*
* @return the commission of a validator
*/
function getValidatorCommission(address operatorAddress)
external
view
validatorExist(operatorAddress)
returns (Commission memory)
{
function getValidatorCommission(
address operatorAddress
) external view validatorExist(operatorAddress) returns (Commission memory) {
return _validators[operatorAddress].commission;
}

Expand All @@ -996,12 +979,9 @@ contract StakeHub is System, Initializable, Protectable {
*
* @return the agent of a validator
*/
function getValidatorAgent(address operatorAddress)
external
view
validatorExist(operatorAddress)
returns (address)
{
function getValidatorAgent(
address operatorAddress
) external view validatorExist(operatorAddress) returns (address) {
return _validators[operatorAddress].agent;
}

Expand Down Expand Up @@ -1051,11 +1031,9 @@ contract StakeHub is System, Initializable, Protectable {
}

/*----------------- internal functions -----------------*/
function _decodeMigrationSynPackage(bytes memory msgBytes)
internal
pure
returns (StakeMigrationPackage memory, bool)
{
function _decodeMigrationSynPackage(
bytes memory msgBytes
) internal pure returns (StakeMigrationPackage memory, bool) {
StakeMigrationPackage memory migrationPackage;

RLPDecode.Iterator memory iter = msgBytes.toRLPItem().iterator();
Expand Down
36 changes: 20 additions & 16 deletions genesis.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions test/Governor.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ contract GovernorTest is Deployer {
address delegator = _getNextUserAddress();
(address validator,, address credit,) = _createValidator(2000 ether);
vm.startPrank(delegator);
assert(!governor.proposeStarted());
assert(governor.proposeStarted());
vm.deal(delegator, 20_000_000 ether);
uint256 bnbAmount = 10_000_000 ether - 2000 ether - 1 ether;
stakeHub.delegate{ value: bnbAmount }(validator, false);
Expand Down Expand Up @@ -94,7 +94,7 @@ contract GovernorTest is Deployer {
"updateParam(string,bytes,address)", "votingDelay", abi.encodePacked(newVotingDelay), GOVERNOR_ADDR
);

assertEq(governor.proposeStarted(), false, "propose should not start");
// assertEq(governor.proposeStarted(), true, "propose should not start");

// mainnet totalSupply is already enough
// // govBNB totalSupply not enough
Expand Down Expand Up @@ -126,7 +126,7 @@ contract GovernorTest is Deployer {
address delegator = _getNextUserAddress();
(address validator,,,) = _createValidator(2000 ether);
vm.startPrank(delegator);
assert(!governor.proposeStarted());
assert(governor.proposeStarted());
vm.deal(delegator, 20_000_000 ether);
uint256 bnbAmount = 10_000_000 ether - 2000 ether;
stakeHub.delegate{ value: bnbAmount }(validator, false);
Expand Down Expand Up @@ -184,7 +184,7 @@ contract GovernorTest is Deployer {
address delegator = _getNextUserAddress();
(address validator,,,) = _createValidator(2000 ether);
vm.startPrank(delegator);
assert(!governor.proposeStarted());
assert(governor.proposeStarted());
vm.deal(delegator, 20_000_000 ether);
uint256 bnbAmount = 10_000_000 ether - 2000 ether;
stakeHub.delegate{ value: bnbAmount }(validator, false);
Expand Down Expand Up @@ -250,7 +250,7 @@ contract GovernorTest is Deployer {
address delegator = _getNextUserAddress();
(address validator,, address credit,) = _createValidator(2000 ether);
vm.startPrank(delegator);
assert(!governor.proposeStarted());
assert(governor.proposeStarted());

vm.deal(delegator, 20_000_000 ether);

Expand Down Expand Up @@ -327,7 +327,7 @@ contract GovernorTest is Deployer {
address delegator = _getNextUserAddress();
(address validator,, address credit,) = _createValidator(2000 ether);
vm.startPrank(delegator);
assert(!governor.proposeStarted());
assert(governor.proposeStarted());

vm.deal(delegator, 20_000_000 ether);

Expand Down

0 comments on commit 7403b72

Please sign in to comment.