|
3 | 3 | import bittensor
|
4 | 4 | from bittensor.core.chain_data.chain_identity import ChainIdentity
|
5 | 5 | from bittensor.core.chain_data.delegate_info import DelegatedInfo, DelegateInfo
|
| 6 | +from bittensor.core.chain_data.proposal_vote_data import ProposalVoteData |
6 | 7 | from bittensor.utils.balance import Balance
|
7 | 8 | from tests.e2e_tests.utils.chain_interactions import (
|
| 9 | + propose, |
8 | 10 | set_identity,
|
9 | 11 | sudo_set_admin_utils,
|
| 12 | + vote, |
10 | 13 | )
|
| 14 | +from tests.helpers.helpers import CLOSE_IN_VALUE |
11 | 15 |
|
12 | 16 | DEFAULT_DELEGATE_TAKE = 0.179995422293431
|
13 | 17 |
|
@@ -321,3 +325,105 @@ def test_nominator_min_required_stake(local_chain, subtensor, alice_wallet, bob_
|
321 | 325 | )
|
322 | 326 |
|
323 | 327 | assert stake == Balance(0)
|
| 328 | + |
| 329 | + |
| 330 | +def test_get_vote_data(subtensor, alice_wallet): |
| 331 | + """ |
| 332 | + Tests: |
| 333 | + - Sends Propose |
| 334 | + - Checks existing Proposals |
| 335 | + - Votes |
| 336 | + - Checks Proposal is updated |
| 337 | + """ |
| 338 | + |
| 339 | + subtensor.root_register(alice_wallet) |
| 340 | + |
| 341 | + proposals = subtensor.query_map( |
| 342 | + "Triumvirate", |
| 343 | + "ProposalOf", |
| 344 | + params=[], |
| 345 | + ) |
| 346 | + |
| 347 | + assert proposals.records == [] |
| 348 | + |
| 349 | + success, error = propose( |
| 350 | + subtensor, |
| 351 | + alice_wallet, |
| 352 | + proposal=subtensor.substrate.compose_call( |
| 353 | + call_module="Triumvirate", |
| 354 | + call_function="set_members", |
| 355 | + call_params={ |
| 356 | + "new_members": [], |
| 357 | + "prime": None, |
| 358 | + "old_count": 0, |
| 359 | + }, |
| 360 | + ), |
| 361 | + duration=1_000_000, |
| 362 | + ) |
| 363 | + |
| 364 | + assert error == "" |
| 365 | + assert success is True |
| 366 | + |
| 367 | + proposals = subtensor.query_map( |
| 368 | + "Triumvirate", |
| 369 | + "ProposalOf", |
| 370 | + params=[], |
| 371 | + ) |
| 372 | + proposals = { |
| 373 | + bytes(proposal_hash[0]): proposal.value for proposal_hash, proposal in proposals |
| 374 | + } |
| 375 | + |
| 376 | + assert list(proposals.values()) == [ |
| 377 | + { |
| 378 | + "Triumvirate": ( |
| 379 | + { |
| 380 | + "set_members": { |
| 381 | + "new_members": (), |
| 382 | + "prime": None, |
| 383 | + "old_count": 0, |
| 384 | + }, |
| 385 | + }, |
| 386 | + ), |
| 387 | + }, |
| 388 | + ] |
| 389 | + |
| 390 | + proposal_hash = list(proposals.keys())[0] |
| 391 | + proposal_hash = f"0x{proposal_hash.hex()}" |
| 392 | + |
| 393 | + proposal = subtensor.get_vote_data( |
| 394 | + proposal_hash, |
| 395 | + ) |
| 396 | + |
| 397 | + assert proposal == ProposalVoteData( |
| 398 | + ayes=[], |
| 399 | + end=CLOSE_IN_VALUE(1_000_000, subtensor.block), |
| 400 | + index=0, |
| 401 | + nays=[], |
| 402 | + threshold=3, |
| 403 | + ) |
| 404 | + |
| 405 | + success, error = vote( |
| 406 | + subtensor, |
| 407 | + alice_wallet, |
| 408 | + alice_wallet.hotkey.ss58_address, |
| 409 | + proposal_hash, |
| 410 | + index=0, |
| 411 | + approve=True, |
| 412 | + ) |
| 413 | + |
| 414 | + assert error == "" |
| 415 | + assert success is True |
| 416 | + |
| 417 | + proposal = subtensor.get_vote_data( |
| 418 | + proposal_hash, |
| 419 | + ) |
| 420 | + |
| 421 | + assert proposal == ProposalVoteData( |
| 422 | + ayes=[ |
| 423 | + alice_wallet.hotkey.ss58_address, |
| 424 | + ], |
| 425 | + end=CLOSE_IN_VALUE(1_000_000, subtensor.block), |
| 426 | + index=0, |
| 427 | + nays=[], |
| 428 | + threshold=3, |
| 429 | + ) |
0 commit comments