Skip to content

Commit

Permalink
fix checkpoints, add check for hex in _is_valid_description
Browse files Browse the repository at this point in the history
  • Loading branch information
Artemka374 committed Aug 15, 2023
1 parent 8b92fad commit a06db05
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 19 deletions.
7 changes: 7 additions & 0 deletions contracts/src/governance/governor/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,13 @@ pub trait GovernorInternal:
return Ok(true)
}

let pos = description.find("proposer=0x").unwrap();
let address = &description[pos..];

if hex::decode(address).is_err() {
return Ok(true)
}

let proposer_str = hex::encode(proposer);
let result = String::from("#proposer=0x".to_owned() + &proposer_str);

Expand Down
21 changes: 4 additions & 17 deletions contracts/src/utils/checkpoint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,7 @@ impl Checkpoints {

match pos == 0 {
true => None,
false => {
Some(
self.checkpoints
.get(pos - 1)
.unwrap_or_else(|| panic!("wrong checkpoint position"))// todo: remove panic
.value,
)
}
false => Some(self.checkpoints[pos - 1].value),
}
}

Expand Down Expand Up @@ -165,14 +158,8 @@ impl Checkpoints {

fn _upper_binary_lookup(&self, key: u64, mut low: usize, mut high: usize) -> usize {
while low < high {
let mid = low / 2 + high / 2;
if key
< self
.checkpoints
.get(mid)
.unwrap_or_else(|| panic!("wrong checkpoint position"))// todo: remove panic
.key
{
let mid = (low + high) / 2;
if key < self.checkpoints[mid].key {
high = mid;
} else {
low = mid + 1;
Expand All @@ -183,7 +170,7 @@ impl Checkpoints {

fn _lower_binary_lookup(&self, key: u64, mut low: usize, mut high: usize) -> usize {
while low < high {
let mid = low / 2 + high / 2;
let mid = (low + high) / 2;
if key > self.checkpoints[mid].key {
low = mid + 1;
} else {
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/governance/governor.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ describe('Governor', function () {
contractReceiver.address,
getSelectorByName(contractReceiver.abi.messages, 'mock_function'),
[],
'<description>#proposer=' + '0x1234'
'<description>#proposer=' + '0x3C44CdDdB6a900fa2b585dd299e03d12FA429XYZ'
)

await expect(helper.propose(deployer)).to.eventually.be.fulfilled
Expand All @@ -681,7 +681,7 @@ describe('Governor', function () {
contractReceiver.address,
getSelectorByName(contractReceiver.abi.messages, 'mock_function'),
[],
'<description>#proposer=' + '0x1234'
'<description>#proposer=' + '0x3C44CdDdB6a900fa2b585dd299e03d12FA429XYZ'
)

await expect(helper.propose(alice)).to.eventually.be.fulfilled
Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/governance/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export class GovernorHelper {

console.log('Proposal ID: ', await this.calculateProposalId())

console.log((await this.governor?.query.propose([this.proposal!], this.description!))?.value.ok?.err)

if(proposer) {
await this.governor?.withSigner(proposer).tx.propose([this.proposal!], this.description!)
}
Expand Down

0 comments on commit a06db05

Please sign in to comment.