Skip to content

Commit 4bde9d0

Browse files
authored
Merge pull request #433 from bane-labs/governance-register-key
contracts: register key when register candidate and refactor tests
2 parents e73a64e + ddc5ae4 commit 4bde9d0

File tree

15 files changed

+207
-219
lines changed

15 files changed

+207
-219
lines changed

contracts/solidity/Governance.sol

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,10 @@ contract Governance is IGovernance, ReentrancyGuard, GovProxyUpgradeable {
126126
return candidateList.values();
127127
}
128128

129-
function registerCandidate(uint shareRate) external payable {
129+
function registerCandidate(
130+
uint shareRate,
131+
bytes calldata pubkey
132+
) external payable {
130133
if (tx.origin != msg.sender) revert Errors.OnlyEOA();
131134
if (msg.value != registerFee) revert Errors.InsufficientValue();
132135
if (shareRate > 1000) revert Errors.InvalidShareRate();
@@ -140,6 +143,9 @@ contract Governance is IGovernance, ReentrancyGuard, GovProxyUpgradeable {
140143
// record share rate and balance
141144
shareRateOf[msg.sender] = shareRate;
142145
candidateBalanceOf[msg.sender] = msg.value;
146+
147+
// register message key
148+
IKeyManagement(KEY_MANAGEMENT).registerMessageKey(msg.sender, pubkey);
143149
}
144150

145151
function exitCandidate() external {

contracts/solidity/KeyManagement.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ contract KeyManagement is GovProxyUpgradeable, IKeyManagement {
6969
revert Errors.SideCallNotAllowed();
7070
if (tx.origin != candidate) revert Errors.OnlyEOA();
7171
if (pubkey.length != 65) revert Errors.InvalidMessageKey();
72-
messagePubkeys[msg.sender] = pubkey;
72+
messagePubkeys[candidate] = pubkey;
7373
}
7474

7575
function reshare(bytes calldata pvss, bytes[] calldata messages) external {

contracts/solidity/interfaces/IGovernance.sol

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ interface IGovernance {
1111
event Persist(address[] validators);
1212

1313
// register to be a candidate with gas
14-
function registerCandidate(uint shareRate) external payable;
14+
function registerCandidate(
15+
uint shareRate,
16+
bytes calldata pubkey
17+
) external payable;
1518

1619
// exit candidates and wait for withdraw
1720
function exitCandidate() external;

contracts/solidity/test/MockContract.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import {IGovernance} from "../interfaces/IGovernance.sol";
66
contract MockContract {
77
function call_registerCandidate(
88
IGovernance governanceAddr,
9-
uint shareRate
9+
uint shareRate,
10+
bytes calldata pubkey
1011
) public payable {
11-
governanceAddr.registerCandidate{value: msg.value}(shareRate);
12+
governanceAddr.registerCandidate{value: msg.value}(shareRate, pubkey);
1213
}
1314
}

contracts/test/CommitteeMultiSig.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,9 @@ import { expect } from "chai";
33
import { ERRORS } from "./helpers/errors";
44

55
// NATIVE ADDRESSES
6-
const GOV_ADMIN = "0x1212000000000000000000000000000000000000";
76
const GOV_PROXY = "0x1212000000000000000000000000000000000001";
8-
const GOV_IMP = "0x1212100000000000000000000000000000000001";
97
const POLICY_PROXY = "0x1212000000000000000000000000000000000002";
10-
const POLICY_IMP = "0x1212100000000000000000000000000000000002";
118
const REWARD_PROXY = "0x1212000000000000000000000000000000000003";
12-
const REWARD_IMP = "0x1212100000000000000000000000000000000003";
13-
const SYS_CALL = "0xffffFFFfFFffffffffffffffFfFFFfffFFFfFFfE";
149

1510
// CONFIG
1611
const CONSENSUS_SIZE = 7;

contracts/test/GovReward.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { ethers } from "hardhat";
22
import { expect } from "chai";
33

44
const REWARD_PROXY = "0x1212000000000000000000000000000000000003";
5-
const REWARD_IMP = "0x1212100000000000000000000000000000000003";
65

76
describe("GovReward", function () {
87
let Reward: any;

contracts/test/Governance.ts

Lines changed: 173 additions & 180 deletions
Large diffs are not rendered by default.

contracts/test/GovernanceVote.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,8 @@ import { expect } from "chai";
33
import { ERRORS } from "./helpers/errors";
44

55
// NATIVE ADDRESSES
6-
const GOV_ADMIN = "0x1212000000000000000000000000000000000000";
76
const GOV_PROXY = "0x1212000000000000000000000000000000000001";
8-
const GOV_IMP = "0x1212100000000000000000000000000000000001";
9-
const POLICY_PROXY = "0x1212000000000000000000000000000000000002";
10-
const POLICY_IMP = "0x1212100000000000000000000000000000000002";
117
const REWARD_PROXY = "0x1212000000000000000000000000000000000003";
12-
const REWARD_IMP = "0x1212100000000000000000000000000000000003";
13-
const SYS_CALL = "0xffffFFFfFFffffffffffffffFfFFFfffFFFfFFfE";
148

159
// CONFIG
1610
const CONSENSUS_SIZE = 7;

contracts/test/Policy.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
import { ethers } from "hardhat";
22
import { expect } from "chai";
3-
import { mine } from "@nomicfoundation/hardhat-network-helpers";
43
import { ERRORS } from "./helpers/errors";
54

65
// NATIVE ADDRESSES
7-
const GOV_ADMIN = "0x1212000000000000000000000000000000000000";
86
const GOV_PROXY = "0x1212000000000000000000000000000000000001";
9-
const GOV_IMP = "0x1212100000000000000000000000000000000001";
107
const POLICY_PROXY = "0x1212000000000000000000000000000000000002";
11-
const POLICY_IMP = "0x1212100000000000000000000000000000000002";
128
const REWARD_PROXY = "0x1212000000000000000000000000000000000003";
13-
const REWARD_IMP = "0x1212100000000000000000000000000000000003";
14-
const SYS_CALL = "0xffffFFFfFFffffffffffffffFfFFFfffFFFfFFfE";
9+
const KEYMANAGEMENT_PROXY = "0x1212000000000000000000000000000000000008";
1510

1611
// CONFIG
1712
const CONSENSUS_SIZE = 7;
@@ -34,6 +29,9 @@ const MIN_GAS_TIP_CAP = ethers.parseUnits("1", "gwei");
3429
const BASE_FEE = ethers.parseUnits("1", "gwei");
3530
const CANDIDATE_LIMIT = 2000;
3631

32+
// MOCK PUBKEYS
33+
const PUBKEY = "0x04a8c8762d32477f5bd0ccff58d35a7b7ace2fbbd0c0d61874bd405bc0af415690d16f585bcec5f51d1fdddfd0d4543cb0a9d40f0447b62a7c4b1a0f24c45ccb01";
34+
3735
describe("Policy", function () {
3836

3937
let Policy: any, Governance: any;
@@ -50,6 +48,7 @@ describe("Policy", function () {
5048
const governance_deploy = await ethers.deployContract("Governance");
5149
const reward_deploy = await ethers.deployContract("GovReward");
5250
const policy_deploy = await ethers.deployContract("Policy");
51+
const keymanagement_deploy = await ethers.deployContract("KeyManagement");
5352

5453
// Copy Bytecode to native address
5554
const governance_code = await ethers.provider.send("eth_getCode", [governance_deploy.target]);
@@ -61,6 +60,9 @@ describe("Policy", function () {
6160
const policy_code = await ethers.provider.send("eth_getCode", [policy_deploy.target]);
6261
await ethers.provider.send("hardhat_setCode", [POLICY_PROXY, policy_code]);
6362

63+
const keymanagement_code = await ethers.provider.send("eth_getCode", [keymanagement_deploy.target]);
64+
await ethers.provider.send("hardhat_setCode", [KEYMANAGEMENT_PROXY, keymanagement_code]);
65+
6466
const governance_contract = require("../artifacts/solidity/Governance.sol/Governance.json");
6567
Governance = new ethers.Contract(GOV_PROXY, governance_contract.abi, signers[0]);
6668
const contract = require("../artifacts/solidity/Policy.sol/Policy.json");
@@ -151,7 +153,7 @@ describe("Policy", function () {
151153
});
152154

153155
it("Should deactivate governance if is a candidate", async function () {
154-
await Governance.connect(signers[7]).registerCandidate(500, { value: REGISTER_FEE });
156+
await Governance.connect(signers[7]).registerCandidate(500, PUBKEY, { value: REGISTER_FEE });
155157
for (let i = 0; i < 3; i++) {
156158
await expect(
157159
Policy.connect(signers[i]).addBlackList(signers[7])
@@ -204,7 +206,7 @@ describe("Policy", function () {
204206
});
205207

206208
it("Should activate governance if is a candidate", async function () {
207-
await Governance.connect(signers[7]).registerCandidate(500, { value: REGISTER_FEE });
209+
await Governance.connect(signers[7]).registerCandidate(500, PUBKEY, { value: REGISTER_FEE });
208210
for (let i = 0; i < 3; i++) {
209211
await expect(
210212
Policy.connect(signers[i]).addBlackList(signers[7])

contracts/test/Treasury.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,9 @@ import { expect } from "chai";
33
import { ERRORS } from "./helpers/errors";
44

55
// NATIVE ADDRESSES
6-
const GOV_ADMIN = "0x1212000000000000000000000000000000000000";
76
const GOV_PROXY = "0x1212000000000000000000000000000000000001";
8-
const GOV_IMP = "0x1212100000000000000000000000000000000001";
9-
const POLICY_PROXY = "0x1212000000000000000000000000000000000002";
10-
const POLICY_IMP = "0x1212100000000000000000000000000000000002";
117
const REWARD_PROXY = "0x1212000000000000000000000000000000000003";
128
const BRIDGE_PROXY = "0x1212000000000000000000000000000000000004";
13-
const REWARD_IMP = "0x1212100000000000000000000000000000000003";
14-
const SYS_CALL = "0xffffFFFfFFffffffffffffffFfFFFfffFFFfFFfE";
159

1610
// CONFIG
1711
const CONSENSUS_SIZE = 7;

0 commit comments

Comments
 (0)