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

Democracy #350

Merged
merged 7 commits into from
Sep 18, 2023
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
1,636 changes: 866 additions & 770 deletions Cargo.lock

Large diffs are not rendered by default.

37 changes: 19 additions & 18 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,25 @@ members = [
#only while debugging

#[patch."https://github.com/encointer/pallets"]
#encointer-balances-tx-payment = { path = "../pallets/balances-tx-payment" }
#encointer-balances-tx-payment-rpc = { path = "../pallets/balances-tx-payment/rpc" }
#encointer-balances-tx-payment-rpc-runtime-api = { path = "../pallets/balances-tx-payment/rpc/runtime-api" }
#encointer-ceremonies-assignment = { path = "../pallets/ceremonies/assignment" }
#encointer-primitives = { path = "../pallets/primitives" }
#pallet-encointer-balances = { path = "../pallets/balances" }
#pallet-encointer-bazaar = { path = "../pallets/bazaar" }
#pallet-encointer-bazaar-rpc = { path = "../pallets/bazaar/rpc" }
#pallet-encointer-bazaar-rpc-runtime-api = { path = "../pallets/bazaar/rpc/runtime-api" }
#pallet-encointer-ceremonies = { path = "../pallets/ceremonies" }
#pallet-encointer-ceremonies-rpc = { path = "../pallets/ceremonies/rpc" }
#pallet-encointer-ceremonies-rpc-runtime-api = { path = "../pallets/ceremonies/rpc/runtime-api" }
#pallet-encointer-communities = { path = "../pallets/communities" }
#pallet-encointer-communities-rpc = { path = "../pallets/communities/rpc" }
#pallet-encointer-communities-rpc-runtime-api = { path = "../pallets/communities/rpc/runtime-api" }
#pallet-encointer-faucet = { path = "../pallets/faucet" }
#pallet-encointer-reputation-commitments = { path = "../pallets/reputation-commitments" }
#pallet-encointer-scheduler = { path = "../pallets/scheduler" }
# encointer-balances-tx-payment = { path = "../encointer-pallets/balances-tx-payment" }
# encointer-balances-tx-payment-rpc = { path = "../encointer-pallets/balances-tx-payment/rpc" }
# encointer-balances-tx-payment-rpc-runtime-api = { path = "../encointer-pallets/balances-tx-payment/rpc/runtime-api" }
# encointer-ceremonies-assignment = { path = "../encointer-pallets/ceremonies/assignment" }
# encointer-primitives = { path = "../encointer-pallets/primitives" }
# pallet-encointer-balances = { path = "../encointer-pallets/balances" }
# pallet-encointer-bazaar = { path = "../encointer-pallets/bazaar" }
# pallet-encointer-bazaar-rpc = { path = "../encointer-pallets/bazaar/rpc" }
# pallet-encointer-bazaar-rpc-runtime-api = { path = "../encointer-pallets/bazaar/rpc/runtime-api" }
# pallet-encointer-ceremonies = { path = "../encointer-pallets/ceremonies" }
# pallet-encointer-ceremonies-rpc = { path = "../encointer-pallets/ceremonies/rpc" }
# pallet-encointer-ceremonies-rpc-runtime-api = { path = "../encointer-pallets/ceremonies/rpc/runtime-api" }
# pallet-encointer-communities = { path = "../encointer-pallets/communities" }
# pallet-encointer-communities-rpc = { path = "../encointer-pallets/communities/rpc" }
# pallet-encointer-communities-rpc-runtime-api = { path = "../encointer-pallets/communities/rpc/runtime-api" }
# pallet-encointer-democracy = { path = "../encointer-pallets/democracy" }
# pallet-encointer-faucet = { path = "../encointer-pallets/faucet" }
# pallet-encointer-reputation-commitments = { path = "../encointer-pallets/reputation-commitments" }
# pallet-encointer-scheduler = { path = "../encointer-pallets/scheduler" }

# [patch."https://github.com/scs/substrate-api-client"]
# substrate-api-client = { path = "../substrate-api-client" }
Expand Down
50 changes: 50 additions & 0 deletions client/bootstrap_demo_community.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,53 @@ def test_faucet(client, cid):
exit(1)
print('Faucet closed', flush=True)


def test_democracy(client, cid):
print('Starting democracy test...')
client.next_phase()
client.next_phase()
client.next_phase()
#phase is 9, registering
print(client.purge_community_ceremony(cid, 1, 8))
register_participants_and_perform_meetup(client, cid, accounts)
cindex = 9
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's brittle. we should not assume the same order of tests forever.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is exactly why i have been saying for a long time that we need to refactor the integration tests :)


# registering of cindex 10
client.next_phase()

claim_rewards(client, cid, "//Alice", pay_fees_in_cc=False)
client.await_block(1)

client.next_phase()
client.next_phase()
client.next_phase()
# cindex is now 11


client.await_block(1)
client.submit_set_inactivity_timeout_proposal("//Alice", 8)
client.await_block(1)
proposals = client.list_proposals()
print(proposals)
if('id: 1' not in proposals):
print(f"Proposal Submission failed")
exit(1)

print('proposal submitted')
# vote with all reputations gathered so far
client.vote("//Alice", 1, "aye", [[cid, cindex]])
client.vote("//Bob", 1, "aye", [[cid, cindex]])
client.vote("//Charlie", 1, "aye", [[cid, cindex]])


client.await_block(21)
client.update_proposal_state("//Alice", 1)
proposals = client.list_proposals()
print(proposals)
if('Approved' not in proposals):
Copy link
Member

@brenzi brenzi Sep 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

within the same testing time we could test 3 parallel proposals to increase test coverage:

  1. 2x Aye, 1x Nay
  2. 1x Aye, 2x Nay
  3. no votes

Moreover, it would be nice to test enactment too, not just approval
(pardon, I know you haven't asked for the review just yet ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure! now in the light of very limited time remaining from my side, where to put the focus? this, or the remaining tasks for the accounting dashboard?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated tracking issue accordningly
encointer/pallets#347

print(f"Proposal Voting and Approval failed")
exit(1)

@click.command()
@click.option('--client', default='../target/release/encointer-client-notee', help='Client binary to communicate with the chain.')
@click.option('-u', '--url', default='ws://127.0.0.1', help='URL of the chain.')
Expand All @@ -331,6 +378,7 @@ def main(ipfs_local, client, url, port, spec_file, test):
client = Client(rust_client=client, node_url=url, port=port)
cid = create_community(client, spec_file, ipfs_local)


newbie = client.create_accounts(1)[0]
faucet(client, cid, [account3, newbie])

Expand Down Expand Up @@ -386,6 +434,8 @@ def main(ipfs_local, client, url, port, spec_file, test):

test_endorsements_by_reputables(client, cid)

test_democracy(client, cid)

print("tests passed")


Expand Down
18 changes: 18 additions & 0 deletions client/py_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,22 @@ def close_faucet(self, account, facuet_account, cid=None, pay_fees_in_cc=False):

def set_faucet_reserve_amount(self, account, amount, cid=None, pay_fees_in_cc=False):
ret = self.run_cli_command(["set-faucet-reserve-amount", "--signer", account, str(amount)], cid, pay_fees_in_cc)
return ret.stdout.decode("utf-8").strip()

def submit_set_inactivity_timeout_proposal(self, account, inactivity_timeout, cid=None, pay_fees_in_cc=False):
ret = self.run_cli_command(["submit-set-inactivity-timeout-proposal", account, str(inactivity_timeout)], cid, pay_fees_in_cc)
return ret.stdout.decode("utf-8").strip()

def vote(self, account, proposal_id, vote, reputations, cid=None, pay_fees_in_cc=False):
reputations = [f'{cid}_{cindex}' for [cid,cindex] in reputations]
reputation_vec = ','.join(reputations)
ret = self.run_cli_command(["vote", account, str(proposal_id), vote, reputation_vec], cid, pay_fees_in_cc)
return ret.stdout.decode("utf-8").strip()

def update_proposal_state(self, account, proposal_id, cid=None, pay_fees_in_cc=False):
ret = self.run_cli_command(["update-proposal-state", account, str(proposal_id)], cid, pay_fees_in_cc)
return ret.stdout.decode("utf-8").strip()

def list_proposals(self):
ret = self.run_cli_command(["list-proposals"])
return ret.stdout.decode("utf-8").strip()
61 changes: 61 additions & 0 deletions client/src/cli_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ const VERBOSE_FLAG: &str = "verbose";
const FAUCET_BALANCE_ARG: &str = "faucet-balance";
const FAUCET_DRIP_AMOUNT_ARG: &str = "faucet-drip-amount";
const FAUCET_RESERVE_AMOUNT_ARG: &str = "faucet-reserve-amount";
const PROPOSAL_ID_ARG: &str = "proposal-id";
const VOTE_ARG: &str = "vote";
const REPUTATION_VEC_ARG: &str = "reputation-vec";
const INACTIVITY_TIMEOUT_ARG: &str = "inactivity-timeout";

pub trait EncointerArgs<'b> {
fn account_arg(self) -> Self;
Expand Down Expand Up @@ -58,6 +62,11 @@ pub trait EncointerArgs<'b> {
fn faucet_balance_arg(self) -> Self;
fn faucet_drip_amount_arg(self) -> Self;
fn faucet_reserve_amount_arg(self) -> Self;

fn proposal_id_arg(self) -> Self;
fn vote_arg(self) -> Self;
fn reputation_vec_arg(self) -> Self;
fn inactivity_timeout_arg(self) -> Self;
}

pub trait EncointerArgsExtractor {
Expand Down Expand Up @@ -89,6 +98,10 @@ pub trait EncointerArgsExtractor {
fn faucet_balance_arg(&self) -> Option<u128>;
fn faucet_drip_amount_arg(&self) -> Option<u128>;
fn faucet_reserve_amount_arg(&self) -> Option<u128>;
fn proposal_id_arg(&self) -> Option<u128>;
fn vote_arg(&self) -> Option<&str>;
fn reputation_vec_arg(&self) -> Option<Vec<&str>>;
fn inactivity_timeout_arg(&self) -> Option<u32>;
}

impl<'a, 'b> EncointerArgs<'b> for App<'a, 'b> {
Expand Down Expand Up @@ -370,6 +383,42 @@ impl<'a, 'b> EncointerArgs<'b> for App<'a, 'b> {
.help("faucet reserve amount"),
)
}
fn proposal_id_arg(self) -> Self {
self.arg(
Arg::with_name(PROPOSAL_ID_ARG)
.takes_value(true)
.required(true)
.value_name("PROPOSAL_ID")
.help("proposal id"),
)
}
fn vote_arg(self) -> Self {
self.arg(
Arg::with_name(VOTE_ARG)
.takes_value(true)
.required(true)
.value_name("VOTE")
.help("vote"),
)
}
fn reputation_vec_arg(self) -> Self {
self.arg(
Arg::with_name(REPUTATION_VEC_ARG)
.takes_value(true)
.required(true)
.value_name("REPUTATION_VEC")
.help("reputation vec"),
)
}
fn inactivity_timeout_arg(self) -> Self {
self.arg(
Arg::with_name(INACTIVITY_TIMEOUT_ARG)
.takes_value(true)
.required(true)
.value_name("INACTIVITY_TIMEOUT")
.help("inactivity timeout"),
)
}
}

impl<'a> EncointerArgsExtractor for ArgMatches<'a> {
Expand Down Expand Up @@ -475,4 +524,16 @@ impl<'a> EncointerArgsExtractor for ArgMatches<'a> {
fn faucet_reserve_amount_arg(&self) -> Option<u128> {
self.value_of(FAUCET_RESERVE_AMOUNT_ARG).map(|v| v.parse().unwrap())
}
fn proposal_id_arg(&self) -> Option<u128> {
self.value_of(PROPOSAL_ID_ARG).map(|v| v.parse().unwrap())
}
fn vote_arg(&self) -> Option<&str> {
self.value_of(VOTE_ARG)
}
fn reputation_vec_arg(&self) -> Option<Vec<&str>> {
self.value_of(REPUTATION_VEC_ARG).map(|s| s.split(",").collect())
}
fn inactivity_timeout_arg(&self) -> Option<u32> {
self.value_of(INACTIVITY_TIMEOUT_ARG).map(|v| v.parse().unwrap())
}
}
Loading
Loading