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

feat: sync genesis.json bytecode to latest and add ci to check #586

Merged
merged 2 commits into from
Aug 22, 2024
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
51 changes: 51 additions & 0 deletions .github/workflows/check-genesis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Check If Genesis Is Latest
on:
push:
branches:
- master
- develop
pull_request:
branches:
- master
- develop
permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read
jobs:
check-genesis:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v1
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Install Poetry
uses: snok/install-poetry@v1

- name: Install Project Dependencies
run: |
npm install ts-node -g
npm install
poetry install
forge install --no-git --no-commit foundry-rs/forge-std@v1.7.3
forge --version

- name: Build
run: |
forge build

- name: Check Genesis Bytecode
run: |
ts-node scripts/check-genesis-bytecode.ts
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/forge-std@v1.7.3
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.

47 changes: 47 additions & 0 deletions scripts/check-genesis-bytecode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import 'dotenv/config';
import {execSync} from 'child_process';
import * as assert from "assert";
import * as fs from "fs";

const log = console.log;

const work = async () => {
log('compare current bytecode with latest mainnet contracts')
let str = (fs.readFileSync(__dirname + '/../genesis.json')).toString();
const currentGenesis = JSON.parse(str);
log('currentGenesis size:', JSON.stringify(currentGenesis, null, 2).length)

const result = execSync('poetry run python -m scripts.generate mainnet')
const resultStr = result.toString()
if (resultStr.indexOf('Generate genesis of mainnet successfully') === -1) {
throw Error(`generate mainnet genesis failed, error result: ${resultStr}`)
}
await sleep(5)
log('generated mainnet genesis')

str = (fs.readFileSync(__dirname + '/../genesis.json')).toString();
const generatedGenesis = JSON.parse(str);
log('generatedGenesis size:', JSON.stringify(generatedGenesis, null, 2).length)

log('try deepStrictEqual(currentGenesis, generatedGenesis)')
assert.deepStrictEqual(currentGenesis, generatedGenesis)

log('Success! genesis bytecode not changed')
};

const sleep = async (seconds: number) => {
console.log('sleep', seconds, 's');
await new Promise((resolve) => setTimeout(resolve, seconds * 1000));
};

const main = async () => {
await work();
};

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});

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
Loading