Skip to content

Commit

Permalink
Merge pull request #136 from informalsystems/dusan/prepare-v1.0.2-rel…
Browse files Browse the repository at this point in the history
…ease

Bring changes from main to release/v1.x
  • Loading branch information
dusan-maksimovic authored Oct 8, 2024
2 parents 384b9bd + a0a4de0 commit 26bf652
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- fix: do not insert proposal into PROPS_BY_SCORE on proposal creation.
([\#135](https://github.com/informalsystems/hydro/pull/135))
2 changes: 1 addition & 1 deletion artifacts/checksums.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
42675f222ce57123a53125584f18220e18566bc16aabaa75deb8043ea95c9bda hydro.wasm
8291920f2b3b1c9916886b4bd97119fa7783cff0240a1612a217acadfe1239e2 hydro.wasm
b522862cb198bbfa2cab046110b4d26a590dea315fe838af3cf1455cad41f9b7 tribute.wasm
Binary file modified artifacts/hydro.wasm
Binary file not shown.
6 changes: 0 additions & 6 deletions contracts/hydro/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,12 +558,6 @@ fn create_proposal(
PROP_ID.save(deps.storage, &(proposal_id + 1))?;
PROPOSAL_MAP.save(deps.storage, (round_id, tranche_id, proposal_id), &proposal)?;

PROPS_BY_SCORE.save(
deps.storage,
((round_id, tranche_id), proposal.power.into(), proposal_id),
&proposal_id,
)?;

Ok(Response::new()
.add_attribute("action", "create_proposal")
.add_attribute("sender", info.sender)
Expand Down
11 changes: 5 additions & 6 deletions contracts/hydro/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,20 +333,19 @@ fn create_proposal_basic_test() {

let proposal = &res.proposals[0];
assert_eq!(expected_round_id, proposal.round_id);
assert_eq!(0, proposal.power.u128());

let proposal = &res.proposals[1];
assert_eq!(expected_round_id, proposal.round_id);
assert_eq!(0, proposal.power.u128());

// assert that the proposals are not added to top N proposals
// immediately upon creation, as their voting power is 0
let res = query_top_n_proposals(deps.as_ref(), expected_round_id, 1, 2);
assert!(res.is_ok(), "error: {:?}", res);

let res = res.unwrap();
assert_eq!(2, res.proposals.len());

// check that both proposals have power 0
for proposal in res.proposals.iter() {
assert_eq!(0, proposal.power.u128());
}
assert_eq!(0, res.proposals.len());
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions contracts/hydro/src/testing_lsm_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use neutron_sdk::{
use neutron_std::types::ibc::applications::transfer::v1::QueryDenomTraceResponse;

use crate::{
contract::{execute, instantiate, query_top_n_proposals, sudo},
contract::{execute, instantiate, query_round_tranche_proposals, query_top_n_proposals, sudo},
lsm_integration::{
get_total_power_for_round, get_validator_power_ratio_for_round,
update_scores_due_to_power_ratio_change, validate_denom,
Expand Down Expand Up @@ -699,7 +699,7 @@ fn lock_tokens_multiple_validators_and_vote() {
// check proposals
{
// Check the proposal scores
let proposals = query_top_n_proposals(deps.as_ref(), 0, 1, 2);
let proposals = query_round_tranche_proposals(deps.as_ref(), 0, 1, 0, 100);

// unwrap the proposals
let proposals = proposals.unwrap();
Expand Down
29 changes: 13 additions & 16 deletions test/interchain/hydro_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,9 @@ func (s *HydroSuite) TestActiveValidatorChange() {
err = s.LockTokens(0, 3*86400000000000, "10", dstIbcDenom2, contractAddr)
s.Require().NoError(err)

votingPowerVal1Val1 := "10"
votingPowerVal1Val2 := "25"
votingPowerVal1Val3 := "30"
votingPowerVal1Denom := "10"
votingPowerVal1Val2Denoms := "25"
votingPowerVal1Val3Denoms := "30"

// create hydro proposals
log.Println("==== Creating proposals")
Expand All @@ -253,7 +253,7 @@ func (s *HydroSuite) TestActiveValidatorChange() {
s.Require().NoError(err)
proposal, err = s.GetProposalByTitle(contractAddr, "tranche 1 prop 1", 1)
s.Require().NoError(err)
s.Require().Equal(votingPowerVal1Val2, proposal.Power)
s.Require().Equal(votingPowerVal1Val2Denoms, proposal.Power)

// increase stake for val3 on hub, so that val2 drops from active valset and val3 enters
log.Println("==== Increasing stake for val3 to drop val2 from active valset")
Expand All @@ -263,23 +263,20 @@ func (s *HydroSuite) TestActiveValidatorChange() {
log.Println("==== Registering interchain query for val3")
s.RegisterInterchainQueries([]string{s.HubChain.ValidatorWallets[2].ValoperAddress}, contractAddr, s.NeutronChain.ValidatorWallets[0].Moniker)

// lock token for val3
log.Println("==== Locking tokens for val3")
err = s.LockTokens(0, 6*86400000000000, "10", dstIbcDenom3, contractAddr)
s.Require().NoError(err)

// check that voting power is equal to voting power of val1 because val2 is not among active vals anymore
proposal, err = s.GetProposalByTitle(contractAddr, "tranche 1 prop 1", 1)
s.Require().NoError(err)
s.Require().Equal(votingPowerVal1Val1, proposal.Power)
s.Require().Equal(votingPowerVal1Denom, proposal.Power)

// vote again so that val3 power is taken into account
log.Println("==== Voting for proposal with val3 shares")
err = s.VoteForHydroProposal(0, contractAddr, proposal.ProposalID, 1)
// lock token for val3
log.Println("==== Locking tokens for val3")
err = s.LockTokens(0, 6*86400000000000, "10", dstIbcDenom3, contractAddr)
s.Require().NoError(err)

// proposal power is increased with val3 shares right after the locking
proposal, err = s.GetProposalByTitle(contractAddr, "tranche 1 prop 1", 1)
s.Require().NoError(err)
s.Require().Equal(votingPowerVal1Val3, proposal.Power)
s.Require().Equal(votingPowerVal1Val3Denoms, proposal.Power)
}

// TestValidatorSlashing tests that voting power of user, proposal, round is changed after validator is slashed
Expand Down Expand Up @@ -507,8 +504,8 @@ func (s *HydroSuite) TestTributeContract() {

// proposal power after voting: proposal_1=800, proposal_2: 400, proposal_3: 200, proposal_4: 0
// proposal 1 and 2 are in top N proposals(N=2), which means that only those voters got the tribute reward and tribute from the other proposals can be refunded
s.Require().True(newBalanceVal2.Sub(oldBalanceVal2).Equal(math.NewInt(9000))) // reward is tribute for proposal1 - communityTax = 10000-10%=9000
s.Require().True(newBalanceVal3.Sub(oldBalanceVal3).Equal(math.NewInt(18000))) // reward is tribute for proposal2 - communityTax = 20000-10%=18000
s.Require().True(newBalanceVal2.Sub(oldBalanceVal2).Equal(math.NewInt(10000))) // reward is tribute for proposal1 = 10000
s.Require().True(newBalanceVal3.Sub(oldBalanceVal3).Equal(math.NewInt(20000))) // reward is tribute for proposal2 = 20000
s.Require().True(newBalanceVal1.GT(oldBalanceVal1)) // refunded proposal3
s.Require().True(newBalanceVal4.GT(oldBalanceVal4)) // refunded proposal4
}

0 comments on commit 26bf652

Please sign in to comment.