| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  | import os | 
					
						
							| 
									
										
										
										
											2023-11-30 07:55:51 -08:00
										 |  |  | from unittest import SkipTest | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | import boto3 | 
					
						
							| 
									
										
										
										
											2021-05-13 10:36:56 +01:00
										 |  |  | import pytest | 
					
						
							|  |  |  | from botocore.exceptions import ClientError | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  | from freezegun import freeze_time | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-18 19:44:29 +00:00
										 |  |  | from moto import mock_managedblockchain | 
					
						
							| 
									
										
										
										
											2023-11-30 07:55:51 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  | from . import helpers | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_managedblockchain | 
					
						
							|  |  |  | def test_vote_on_proposal_one_member_total_yes(): | 
					
						
							|  |  |  |     conn = boto3.client("managedblockchain", region_name="us-east-1") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Create network | 
					
						
							|  |  |  |     response = conn.create_network( | 
					
						
							|  |  |  |         Name="testnetwork1", | 
					
						
							|  |  |  |         Framework="HYPERLEDGER_FABRIC", | 
					
						
							|  |  |  |         FrameworkVersion="1.2", | 
					
						
							|  |  |  |         FrameworkConfiguration=helpers.default_frameworkconfiguration, | 
					
						
							|  |  |  |         VotingPolicy=helpers.default_votingpolicy, | 
					
						
							|  |  |  |         MemberConfiguration=helpers.default_memberconfiguration, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     network_id = response["NetworkId"] | 
					
						
							|  |  |  |     member_id = response["MemberId"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Create proposal | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     proposal_id = conn.create_proposal( | 
					
						
							| 
									
										
										
										
											2022-03-10 13:39:59 -01:00
										 |  |  |         NetworkId=network_id, MemberId=member_id, Actions=helpers.default_policy_actions | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     )["ProposalId"] | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Get proposal details | 
					
						
							|  |  |  |     response = conn.get_proposal(NetworkId=network_id, ProposalId=proposal_id) | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     assert response["Proposal"]["NetworkId"] == network_id | 
					
						
							|  |  |  |     assert response["Proposal"]["Status"] == "IN_PROGRESS" | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Vote yes | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     conn.vote_on_proposal( | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  |         NetworkId=network_id, | 
					
						
							|  |  |  |         ProposalId=proposal_id, | 
					
						
							|  |  |  |         VoterMemberId=member_id, | 
					
						
							|  |  |  |         Vote="YES", | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # List proposal votes | 
					
						
							|  |  |  |     response = conn.list_proposal_votes(NetworkId=network_id, ProposalId=proposal_id) | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     assert response["ProposalVotes"][0]["MemberId"] == member_id | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Get proposal details - should be APPROVED | 
					
						
							|  |  |  |     response = conn.get_proposal(NetworkId=network_id, ProposalId=proposal_id) | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     assert response["Proposal"]["Status"] == "APPROVED" | 
					
						
							|  |  |  |     assert response["Proposal"]["YesVoteCount"] == 1 | 
					
						
							|  |  |  |     assert response["Proposal"]["NoVoteCount"] == 0 | 
					
						
							|  |  |  |     assert response["Proposal"]["OutstandingVoteCount"] == 0 | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_managedblockchain | 
					
						
							|  |  |  | def test_vote_on_proposal_one_member_total_no(): | 
					
						
							|  |  |  |     conn = boto3.client("managedblockchain", region_name="us-east-1") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Create network | 
					
						
							|  |  |  |     response = conn.create_network( | 
					
						
							|  |  |  |         Name="testnetwork1", | 
					
						
							|  |  |  |         Framework="HYPERLEDGER_FABRIC", | 
					
						
							|  |  |  |         FrameworkVersion="1.2", | 
					
						
							|  |  |  |         FrameworkConfiguration=helpers.default_frameworkconfiguration, | 
					
						
							|  |  |  |         VotingPolicy=helpers.default_votingpolicy, | 
					
						
							|  |  |  |         MemberConfiguration=helpers.default_memberconfiguration, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     network_id = response["NetworkId"] | 
					
						
							|  |  |  |     member_id = response["MemberId"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Create proposal | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     proposal_id = conn.create_proposal( | 
					
						
							| 
									
										
										
										
											2022-03-10 13:39:59 -01:00
										 |  |  |         NetworkId=network_id, MemberId=member_id, Actions=helpers.default_policy_actions | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     )["ProposalId"] | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Get proposal details | 
					
						
							|  |  |  |     response = conn.get_proposal(NetworkId=network_id, ProposalId=proposal_id) | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     assert response["Proposal"]["NetworkId"] == network_id | 
					
						
							|  |  |  |     assert response["Proposal"]["Status"] == "IN_PROGRESS" | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Vote no | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     conn.vote_on_proposal( | 
					
						
							| 
									
										
										
										
											2022-03-10 13:39:59 -01:00
										 |  |  |         NetworkId=network_id, ProposalId=proposal_id, VoterMemberId=member_id, Vote="NO" | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # List proposal votes | 
					
						
							|  |  |  |     response = conn.list_proposal_votes(NetworkId=network_id, ProposalId=proposal_id) | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     assert response["ProposalVotes"][0]["MemberId"] == member_id | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Get proposal details - should be REJECTED | 
					
						
							|  |  |  |     response = conn.get_proposal(NetworkId=network_id, ProposalId=proposal_id) | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     assert response["Proposal"]["Status"] == "REJECTED" | 
					
						
							|  |  |  |     assert response["Proposal"]["YesVoteCount"] == 0 | 
					
						
							|  |  |  |     assert response["Proposal"]["NoVoteCount"] == 1 | 
					
						
							|  |  |  |     assert response["Proposal"]["OutstandingVoteCount"] == 0 | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_managedblockchain | 
					
						
							|  |  |  | def test_vote_on_proposal_yes_greater_than(): | 
					
						
							|  |  |  |     conn = boto3.client("managedblockchain", region_name="us-east-1") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     votingpolicy = { | 
					
						
							|  |  |  |         "ApprovalThresholdPolicy": { | 
					
						
							|  |  |  |             "ThresholdPercentage": 50, | 
					
						
							|  |  |  |             "ProposalDurationInHours": 24, | 
					
						
							|  |  |  |             "ThresholdComparator": "GREATER_THAN", | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Create network | 
					
						
							|  |  |  |     response = conn.create_network( | 
					
						
							|  |  |  |         Name="testnetwork1", | 
					
						
							|  |  |  |         Framework="HYPERLEDGER_FABRIC", | 
					
						
							|  |  |  |         FrameworkVersion="1.2", | 
					
						
							|  |  |  |         FrameworkConfiguration=helpers.default_frameworkconfiguration, | 
					
						
							|  |  |  |         VotingPolicy=votingpolicy, | 
					
						
							|  |  |  |         MemberConfiguration=helpers.default_memberconfiguration, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     network_id = response["NetworkId"] | 
					
						
							|  |  |  |     member_id = response["MemberId"] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     proposal_id = conn.create_proposal( | 
					
						
							| 
									
										
										
										
											2022-03-10 13:39:59 -01:00
										 |  |  |         NetworkId=network_id, MemberId=member_id, Actions=helpers.default_policy_actions | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     )["ProposalId"] | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Vote yes | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     conn.vote_on_proposal( | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  |         NetworkId=network_id, | 
					
						
							|  |  |  |         ProposalId=proposal_id, | 
					
						
							|  |  |  |         VoterMemberId=member_id, | 
					
						
							|  |  |  |         Vote="YES", | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Get the invitation | 
					
						
							|  |  |  |     response = conn.list_invitations() | 
					
						
							|  |  |  |     invitation_id = response["Invitations"][0]["InvitationId"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Create the member | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     member_id2 = conn.create_member( | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  |         InvitationId=invitation_id, | 
					
						
							|  |  |  |         NetworkId=network_id, | 
					
						
							|  |  |  |         MemberConfiguration=helpers.create_member_configuration( | 
					
						
							|  |  |  |             "testmember2", "admin", "Admin12345", False, "Test Member 2" | 
					
						
							|  |  |  |         ), | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     )["MemberId"] | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Create another proposal | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     proposal_id = conn.create_proposal( | 
					
						
							| 
									
										
										
										
											2022-03-10 13:39:59 -01:00
										 |  |  |         NetworkId=network_id, MemberId=member_id, Actions=helpers.default_policy_actions | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     )["ProposalId"] | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Vote yes with member 1 | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     conn.vote_on_proposal( | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  |         NetworkId=network_id, | 
					
						
							|  |  |  |         ProposalId=proposal_id, | 
					
						
							|  |  |  |         VoterMemberId=member_id, | 
					
						
							|  |  |  |         Vote="YES", | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Get proposal details | 
					
						
							|  |  |  |     response = conn.get_proposal(NetworkId=network_id, ProposalId=proposal_id) | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     assert response["Proposal"]["NetworkId"] == network_id | 
					
						
							|  |  |  |     assert response["Proposal"]["Status"] == "IN_PROGRESS" | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-15 19:38:19 -05:00
										 |  |  |     # Vote no with member 2 | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     conn.vote_on_proposal( | 
					
						
							| 
									
										
										
										
											2020-05-15 19:38:19 -05:00
										 |  |  |         NetworkId=network_id, | 
					
						
							|  |  |  |         ProposalId=proposal_id, | 
					
						
							|  |  |  |         VoterMemberId=member_id2, | 
					
						
							|  |  |  |         Vote="NO", | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Get proposal details | 
					
						
							|  |  |  |     response = conn.get_proposal(NetworkId=network_id, ProposalId=proposal_id) | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     assert response["Proposal"]["Status"] == "REJECTED" | 
					
						
							| 
									
										
										
										
											2020-05-15 19:38:19 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | @mock_managedblockchain | 
					
						
							|  |  |  | def test_vote_on_proposal_no_greater_than(): | 
					
						
							|  |  |  |     conn = boto3.client("managedblockchain", region_name="us-east-1") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     votingpolicy = { | 
					
						
							|  |  |  |         "ApprovalThresholdPolicy": { | 
					
						
							|  |  |  |             "ThresholdPercentage": 50, | 
					
						
							|  |  |  |             "ProposalDurationInHours": 24, | 
					
						
							|  |  |  |             "ThresholdComparator": "GREATER_THAN", | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Create network | 
					
						
							|  |  |  |     response = conn.create_network( | 
					
						
							|  |  |  |         Name="testnetwork1", | 
					
						
							|  |  |  |         Framework="HYPERLEDGER_FABRIC", | 
					
						
							|  |  |  |         FrameworkVersion="1.2", | 
					
						
							|  |  |  |         FrameworkConfiguration=helpers.default_frameworkconfiguration, | 
					
						
							|  |  |  |         VotingPolicy=votingpolicy, | 
					
						
							|  |  |  |         MemberConfiguration=helpers.default_memberconfiguration, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     network_id = response["NetworkId"] | 
					
						
							|  |  |  |     member_id = response["MemberId"] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     proposal_id = conn.create_proposal( | 
					
						
							| 
									
										
										
										
											2022-03-10 13:39:59 -01:00
										 |  |  |         NetworkId=network_id, MemberId=member_id, Actions=helpers.default_policy_actions | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     )["ProposalId"] | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Vote yes | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     conn.vote_on_proposal( | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  |         NetworkId=network_id, | 
					
						
							|  |  |  |         ProposalId=proposal_id, | 
					
						
							|  |  |  |         VoterMemberId=member_id, | 
					
						
							|  |  |  |         Vote="YES", | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Get the invitation | 
					
						
							|  |  |  |     response = conn.list_invitations() | 
					
						
							|  |  |  |     invitation_id = response["Invitations"][0]["InvitationId"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Create the member | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     member_id2 = conn.create_member( | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  |         InvitationId=invitation_id, | 
					
						
							|  |  |  |         NetworkId=network_id, | 
					
						
							|  |  |  |         MemberConfiguration=helpers.create_member_configuration( | 
					
						
							|  |  |  |             "testmember2", "admin", "Admin12345", False, "Test Member 2" | 
					
						
							|  |  |  |         ), | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     )["MemberId"] | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Create another proposal | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     proposal_id = conn.create_proposal( | 
					
						
							| 
									
										
										
										
											2022-03-10 13:39:59 -01:00
										 |  |  |         NetworkId=network_id, MemberId=member_id, Actions=helpers.default_policy_actions | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     )["ProposalId"] | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Vote no with member 1 | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     conn.vote_on_proposal( | 
					
						
							| 
									
										
										
										
											2022-03-10 13:39:59 -01:00
										 |  |  |         NetworkId=network_id, ProposalId=proposal_id, VoterMemberId=member_id, Vote="NO" | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Vote no with member 2 | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     conn.vote_on_proposal( | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  |         NetworkId=network_id, | 
					
						
							|  |  |  |         ProposalId=proposal_id, | 
					
						
							|  |  |  |         VoterMemberId=member_id2, | 
					
						
							|  |  |  |         Vote="NO", | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Get proposal details | 
					
						
							|  |  |  |     response = conn.get_proposal(NetworkId=network_id, ProposalId=proposal_id) | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     assert response["Proposal"]["NetworkId"] == network_id | 
					
						
							|  |  |  |     assert response["Proposal"]["Status"] == "REJECTED" | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_managedblockchain | 
					
						
							|  |  |  | def test_vote_on_proposal_expiredproposal(): | 
					
						
							|  |  |  |     if os.environ.get("TEST_SERVER_MODE", "false").lower() == "true": | 
					
						
							|  |  |  |         raise SkipTest("Cant manipulate time in server mode") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     votingpolicy = { | 
					
						
							|  |  |  |         "ApprovalThresholdPolicy": { | 
					
						
							|  |  |  |             "ThresholdPercentage": 50, | 
					
						
							|  |  |  |             "ProposalDurationInHours": 1, | 
					
						
							|  |  |  |             "ThresholdComparator": "GREATER_THAN_OR_EQUAL_TO", | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     conn = boto3.client("managedblockchain", region_name="us-east-1") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     with freeze_time("2015-01-01 12:00:00"): | 
					
						
							|  |  |  |         # Create network - need a good network | 
					
						
							|  |  |  |         response = conn.create_network( | 
					
						
							|  |  |  |             Name="testnetwork1", | 
					
						
							|  |  |  |             Framework="HYPERLEDGER_FABRIC", | 
					
						
							|  |  |  |             FrameworkVersion="1.2", | 
					
						
							|  |  |  |             FrameworkConfiguration=helpers.default_frameworkconfiguration, | 
					
						
							|  |  |  |             VotingPolicy=votingpolicy, | 
					
						
							|  |  |  |             MemberConfiguration=helpers.default_memberconfiguration, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         network_id = response["NetworkId"] | 
					
						
							|  |  |  |         member_id = response["MemberId"] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |         proposal_id = conn.create_proposal( | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  |             NetworkId=network_id, | 
					
						
							|  |  |  |             MemberId=member_id, | 
					
						
							|  |  |  |             Actions=helpers.default_policy_actions, | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |         )["ProposalId"] | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     with freeze_time("2015-02-01 12:00:00"): | 
					
						
							|  |  |  |         # Vote yes - should set status to expired | 
					
						
							| 
									
										
										
										
											2021-05-13 10:36:56 +01:00
										 |  |  |         with pytest.raises(ClientError) as ex: | 
					
						
							|  |  |  |             conn.vote_on_proposal( | 
					
						
							|  |  |  |                 NetworkId=network_id, | 
					
						
							|  |  |  |                 ProposalId=proposal_id, | 
					
						
							|  |  |  |                 VoterMemberId=member_id, | 
					
						
							|  |  |  |                 Vote="YES", | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  |         err = ex.value.response["Error"] | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |         assert err["Code"] == "InvalidRequestException" | 
					
						
							|  |  |  |         assert ( | 
					
						
							| 
									
										
										
										
											2022-11-17 21:41:08 -01:00
										 |  |  |             f"Proposal {proposal_id} is expired and you cannot vote on it." | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |             in err["Message"] | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # Get proposal details - should be EXPIRED | 
					
						
							|  |  |  |         response = conn.get_proposal(NetworkId=network_id, ProposalId=proposal_id) | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |         assert response["Proposal"]["Status"] == "EXPIRED" | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-15 19:38:19 -05:00
										 |  |  | @mock_managedblockchain | 
					
						
							|  |  |  | def test_vote_on_proposal_status_check(): | 
					
						
							|  |  |  |     conn = boto3.client("managedblockchain", region_name="us-east-1") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Create network | 
					
						
							|  |  |  |     response = conn.create_network( | 
					
						
							|  |  |  |         Name="testnetwork1", | 
					
						
							|  |  |  |         Framework="HYPERLEDGER_FABRIC", | 
					
						
							|  |  |  |         FrameworkVersion="1.2", | 
					
						
							|  |  |  |         FrameworkConfiguration=helpers.default_frameworkconfiguration, | 
					
						
							|  |  |  |         VotingPolicy=helpers.default_votingpolicy, | 
					
						
							|  |  |  |         MemberConfiguration=helpers.default_memberconfiguration, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     network_id = response["NetworkId"] | 
					
						
							|  |  |  |     member_id = response["MemberId"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Create 2 more members | 
					
						
							|  |  |  |     for counter in range(2, 4): | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |         proposal_id = conn.create_proposal( | 
					
						
							| 
									
										
										
										
											2020-05-15 19:38:19 -05:00
										 |  |  |             NetworkId=network_id, | 
					
						
							|  |  |  |             MemberId=member_id, | 
					
						
							|  |  |  |             Actions=helpers.default_policy_actions, | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |         )["ProposalId"] | 
					
						
							| 
									
										
										
										
											2020-05-15 19:38:19 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |         # Vote yes | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |         conn.vote_on_proposal( | 
					
						
							| 
									
										
										
										
											2020-05-15 19:38:19 -05:00
										 |  |  |             NetworkId=network_id, | 
					
						
							|  |  |  |             ProposalId=proposal_id, | 
					
						
							|  |  |  |             VoterMemberId=member_id, | 
					
						
							|  |  |  |             Vote="YES", | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     memberidlist = [None, None, None] | 
					
						
							|  |  |  |     memberidlist[0] = member_id | 
					
						
							|  |  |  |     for counter in range(2, 4): | 
					
						
							|  |  |  |         # Get the invitation | 
					
						
							|  |  |  |         response = conn.list_invitations() | 
					
						
							|  |  |  |         invitation_id = helpers.select_invitation_id_for_network( | 
					
						
							|  |  |  |             response["Invitations"], network_id, "PENDING" | 
					
						
							|  |  |  |         )[0] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # Create the member | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |         member_id = conn.create_member( | 
					
						
							| 
									
										
										
										
											2020-05-15 19:38:19 -05:00
										 |  |  |             InvitationId=invitation_id, | 
					
						
							|  |  |  |             NetworkId=network_id, | 
					
						
							|  |  |  |             MemberConfiguration=helpers.create_member_configuration( | 
					
						
							|  |  |  |                 "testmember" + str(counter), | 
					
						
							|  |  |  |                 "admin", | 
					
						
							|  |  |  |                 "Admin12345", | 
					
						
							|  |  |  |                 False, | 
					
						
							|  |  |  |                 "Test Member " + str(counter), | 
					
						
							|  |  |  |             ), | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |         )["MemberId"] | 
					
						
							| 
									
										
										
										
											2020-05-15 19:38:19 -05:00
										 |  |  |         memberidlist[counter - 1] = member_id | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Should be no more pending invitations | 
					
						
							|  |  |  |     response = conn.list_invitations() | 
					
						
							|  |  |  |     pendinginvs = helpers.select_invitation_id_for_network( | 
					
						
							|  |  |  |         response["Invitations"], network_id, "PENDING" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     assert len(pendinginvs) == 0 | 
					
						
							| 
									
										
										
										
											2020-05-15 19:38:19 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Create another proposal | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     proposal_id = conn.create_proposal( | 
					
						
							| 
									
										
										
										
											2022-03-10 13:39:59 -01:00
										 |  |  |         NetworkId=network_id, MemberId=member_id, Actions=helpers.default_policy_actions | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     )["ProposalId"] | 
					
						
							| 
									
										
										
										
											2020-05-15 19:38:19 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Vote yes with member 1 | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     conn.vote_on_proposal( | 
					
						
							| 
									
										
										
										
											2020-05-15 19:38:19 -05:00
										 |  |  |         NetworkId=network_id, | 
					
						
							|  |  |  |         ProposalId=proposal_id, | 
					
						
							|  |  |  |         VoterMemberId=memberidlist[0], | 
					
						
							|  |  |  |         Vote="YES", | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Vote yes with member 2 | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     conn.vote_on_proposal( | 
					
						
							| 
									
										
										
										
											2020-05-15 19:38:19 -05:00
										 |  |  |         NetworkId=network_id, | 
					
						
							|  |  |  |         ProposalId=proposal_id, | 
					
						
							|  |  |  |         VoterMemberId=memberidlist[1], | 
					
						
							|  |  |  |         Vote="YES", | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Get proposal details - now approved (2 yes, 1 outstanding) | 
					
						
							|  |  |  |     response = conn.get_proposal(NetworkId=network_id, ProposalId=proposal_id) | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     assert response["Proposal"]["NetworkId"] == network_id | 
					
						
							|  |  |  |     assert response["Proposal"]["Status"] == "APPROVED" | 
					
						
							| 
									
										
										
										
											2020-05-15 19:38:19 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Should be one pending invitation | 
					
						
							|  |  |  |     response = conn.list_invitations() | 
					
						
							|  |  |  |     pendinginvs = helpers.select_invitation_id_for_network( | 
					
						
							|  |  |  |         response["Invitations"], network_id, "PENDING" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     assert len(pendinginvs) == 1 | 
					
						
							| 
									
										
										
										
											2020-05-15 19:38:19 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Vote with member 3 - should throw an exception and not create a new invitation | 
					
						
							| 
									
										
										
										
											2021-05-13 10:36:56 +01:00
										 |  |  |     with pytest.raises(ClientError) as ex: | 
					
						
							|  |  |  |         conn.vote_on_proposal( | 
					
						
							|  |  |  |             NetworkId=network_id, | 
					
						
							|  |  |  |             ProposalId=proposal_id, | 
					
						
							|  |  |  |             VoterMemberId=memberidlist[2], | 
					
						
							|  |  |  |             Vote="YES", | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |     err = ex.value.response["Error"] | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     assert err["Code"] == "InvalidRequestException" | 
					
						
							|  |  |  |     assert "and you cannot vote on it" in err["Message"] | 
					
						
							| 
									
										
										
										
											2020-05-15 19:38:19 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Should still be one pending invitation | 
					
						
							|  |  |  |     response = conn.list_invitations() | 
					
						
							|  |  |  |     pendinginvs = helpers.select_invitation_id_for_network( | 
					
						
							|  |  |  |         response["Invitations"], network_id, "PENDING" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     assert len(pendinginvs) == 1 | 
					
						
							| 
									
										
										
										
											2020-05-15 19:38:19 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  | @mock_managedblockchain | 
					
						
							|  |  |  | def test_vote_on_proposal_badnetwork(): | 
					
						
							|  |  |  |     conn = boto3.client("managedblockchain", region_name="us-east-1") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-13 10:36:56 +01:00
										 |  |  |     with pytest.raises(ClientError) as ex: | 
					
						
							|  |  |  |         conn.vote_on_proposal( | 
					
						
							|  |  |  |             NetworkId="n-ABCDEFGHIJKLMNOP0123456789", | 
					
						
							|  |  |  |             ProposalId="p-ABCDEFGHIJKLMNOP0123456789", | 
					
						
							|  |  |  |             VoterMemberId="m-ABCDEFGHIJKLMNOP0123456789", | 
					
						
							|  |  |  |             Vote="YES", | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |     err = ex.value.response["Error"] | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     assert err["Code"] == "ResourceNotFoundException" | 
					
						
							|  |  |  |     assert "Network n-ABCDEFGHIJKLMNOP0123456789 not found" in err["Message"] | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_managedblockchain | 
					
						
							|  |  |  | def test_vote_on_proposal_badproposal(): | 
					
						
							|  |  |  |     conn = boto3.client("managedblockchain", region_name="us-east-1") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Create network - need a good network | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     network_id = conn.create_network( | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  |         Name="testnetwork1", | 
					
						
							|  |  |  |         Framework="HYPERLEDGER_FABRIC", | 
					
						
							|  |  |  |         FrameworkVersion="1.2", | 
					
						
							|  |  |  |         FrameworkConfiguration=helpers.default_frameworkconfiguration, | 
					
						
							|  |  |  |         VotingPolicy=helpers.default_votingpolicy, | 
					
						
							|  |  |  |         MemberConfiguration=helpers.default_memberconfiguration, | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     )["NetworkId"] | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-13 10:36:56 +01:00
										 |  |  |     with pytest.raises(ClientError) as ex: | 
					
						
							|  |  |  |         conn.vote_on_proposal( | 
					
						
							|  |  |  |             NetworkId=network_id, | 
					
						
							|  |  |  |             ProposalId="p-ABCDEFGHIJKLMNOP0123456789", | 
					
						
							|  |  |  |             VoterMemberId="m-ABCDEFGHIJKLMNOP0123456789", | 
					
						
							|  |  |  |             Vote="YES", | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |     err = ex.value.response["Error"] | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     assert err["Code"] == "ResourceNotFoundException" | 
					
						
							|  |  |  |     assert "Proposal p-ABCDEFGHIJKLMNOP0123456789 not found" in err["Message"] | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_managedblockchain | 
					
						
							|  |  |  | def test_vote_on_proposal_badmember(): | 
					
						
							|  |  |  |     conn = boto3.client("managedblockchain", region_name="us-east-1") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Create network - need a good network | 
					
						
							|  |  |  |     response = conn.create_network( | 
					
						
							|  |  |  |         Name="testnetwork1", | 
					
						
							|  |  |  |         Framework="HYPERLEDGER_FABRIC", | 
					
						
							|  |  |  |         FrameworkVersion="1.2", | 
					
						
							|  |  |  |         FrameworkConfiguration=helpers.default_frameworkconfiguration, | 
					
						
							|  |  |  |         VotingPolicy=helpers.default_votingpolicy, | 
					
						
							|  |  |  |         MemberConfiguration=helpers.default_memberconfiguration, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     network_id = response["NetworkId"] | 
					
						
							|  |  |  |     member_id = response["MemberId"] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     proposal_id = conn.create_proposal( | 
					
						
							| 
									
										
										
										
											2022-03-10 13:39:59 -01:00
										 |  |  |         NetworkId=network_id, MemberId=member_id, Actions=helpers.default_policy_actions | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     )["ProposalId"] | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-13 10:36:56 +01:00
										 |  |  |     with pytest.raises(ClientError) as ex: | 
					
						
							|  |  |  |         conn.vote_on_proposal( | 
					
						
							|  |  |  |             NetworkId=network_id, | 
					
						
							|  |  |  |             ProposalId=proposal_id, | 
					
						
							|  |  |  |             VoterMemberId="m-ABCDEFGHIJKLMNOP0123456789", | 
					
						
							|  |  |  |             Vote="YES", | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |     err = ex.value.response["Error"] | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     assert err["Code"] == "ResourceNotFoundException" | 
					
						
							|  |  |  |     assert "Member m-ABCDEFGHIJKLMNOP0123456789 not found" in err["Message"] | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_managedblockchain | 
					
						
							|  |  |  | def test_vote_on_proposal_badvote(): | 
					
						
							|  |  |  |     conn = boto3.client("managedblockchain", region_name="us-east-1") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Create network - need a good network | 
					
						
							|  |  |  |     response = conn.create_network( | 
					
						
							|  |  |  |         Name="testnetwork1", | 
					
						
							|  |  |  |         Framework="HYPERLEDGER_FABRIC", | 
					
						
							|  |  |  |         FrameworkVersion="1.2", | 
					
						
							|  |  |  |         FrameworkConfiguration=helpers.default_frameworkconfiguration, | 
					
						
							|  |  |  |         VotingPolicy=helpers.default_votingpolicy, | 
					
						
							|  |  |  |         MemberConfiguration=helpers.default_memberconfiguration, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     network_id = response["NetworkId"] | 
					
						
							|  |  |  |     member_id = response["MemberId"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = conn.create_proposal( | 
					
						
							| 
									
										
										
										
											2022-03-10 13:39:59 -01:00
										 |  |  |         NetworkId=network_id, MemberId=member_id, Actions=helpers.default_policy_actions | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     proposal_id = response["ProposalId"] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-13 10:36:56 +01:00
										 |  |  |     with pytest.raises(ClientError) as ex: | 
					
						
							|  |  |  |         conn.vote_on_proposal( | 
					
						
							|  |  |  |             NetworkId=network_id, | 
					
						
							|  |  |  |             ProposalId=proposal_id, | 
					
						
							|  |  |  |             VoterMemberId=member_id, | 
					
						
							|  |  |  |             Vote="FOO", | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |     err = ex.value.response["Error"] | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     assert err["Code"] == "BadRequestException" | 
					
						
							|  |  |  |     assert "Invalid request body" in err["Message"] | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_managedblockchain | 
					
						
							|  |  |  | def test_vote_on_proposal_alreadyvoted(): | 
					
						
							|  |  |  |     conn = boto3.client("managedblockchain", region_name="us-east-1") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-15 19:38:19 -05:00
										 |  |  |     votingpolicy = { | 
					
						
							|  |  |  |         "ApprovalThresholdPolicy": { | 
					
						
							|  |  |  |             "ThresholdPercentage": 50, | 
					
						
							|  |  |  |             "ProposalDurationInHours": 24, | 
					
						
							|  |  |  |             "ThresholdComparator": "GREATER_THAN", | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  |     # Create network - need a good network | 
					
						
							|  |  |  |     response = conn.create_network( | 
					
						
							|  |  |  |         Name="testnetwork1", | 
					
						
							|  |  |  |         Framework="HYPERLEDGER_FABRIC", | 
					
						
							|  |  |  |         FrameworkVersion="1.2", | 
					
						
							|  |  |  |         FrameworkConfiguration=helpers.default_frameworkconfiguration, | 
					
						
							| 
									
										
										
										
											2020-05-15 19:38:19 -05:00
										 |  |  |         VotingPolicy=votingpolicy, | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  |         MemberConfiguration=helpers.default_memberconfiguration, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     network_id = response["NetworkId"] | 
					
						
							|  |  |  |     member_id = response["MemberId"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = conn.create_proposal( | 
					
						
							| 
									
										
										
										
											2022-03-10 13:39:59 -01:00
										 |  |  |         NetworkId=network_id, MemberId=member_id, Actions=helpers.default_policy_actions | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     proposal_id = response["ProposalId"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Vote yes | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     conn.vote_on_proposal( | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  |         NetworkId=network_id, | 
					
						
							|  |  |  |         ProposalId=proposal_id, | 
					
						
							|  |  |  |         VoterMemberId=member_id, | 
					
						
							|  |  |  |         Vote="YES", | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Get the invitation | 
					
						
							|  |  |  |     response = conn.list_invitations() | 
					
						
							|  |  |  |     invitation_id = response["Invitations"][0]["InvitationId"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Create the member | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     conn.create_member( | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  |         InvitationId=invitation_id, | 
					
						
							|  |  |  |         NetworkId=network_id, | 
					
						
							|  |  |  |         MemberConfiguration=helpers.create_member_configuration( | 
					
						
							|  |  |  |             "testmember2", "admin", "Admin12345", False, "Test Member 2" | 
					
						
							|  |  |  |         ), | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Create another proposal | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     proposal_id = conn.create_proposal( | 
					
						
							| 
									
										
										
										
											2022-03-10 13:39:59 -01:00
										 |  |  |         NetworkId=network_id, MemberId=member_id, Actions=helpers.default_policy_actions | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     )["ProposalId"] | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Get proposal details | 
					
						
							|  |  |  |     response = conn.get_proposal(NetworkId=network_id, ProposalId=proposal_id) | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     assert response["Proposal"]["NetworkId"] == network_id | 
					
						
							|  |  |  |     assert response["Proposal"]["Status"] == "IN_PROGRESS" | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Vote yes with member 1 | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     conn.vote_on_proposal( | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  |         NetworkId=network_id, | 
					
						
							|  |  |  |         ProposalId=proposal_id, | 
					
						
							|  |  |  |         VoterMemberId=member_id, | 
					
						
							|  |  |  |         Vote="YES", | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Vote yes with member 1 again | 
					
						
							| 
									
										
										
										
											2021-05-13 10:36:56 +01:00
										 |  |  |     with pytest.raises(ClientError) as ex: | 
					
						
							|  |  |  |         conn.vote_on_proposal( | 
					
						
							|  |  |  |             NetworkId=network_id, | 
					
						
							|  |  |  |             ProposalId=proposal_id, | 
					
						
							|  |  |  |             VoterMemberId=member_id, | 
					
						
							|  |  |  |             Vote="YES", | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |     err = ex.value.response["Error"] | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     assert err["Code"] == "ResourceAlreadyExistsException" | 
					
						
							|  |  |  |     assert ( | 
					
						
							| 
									
										
										
										
											2022-11-17 21:41:08 -01:00
										 |  |  |         f"Member {member_id} has already voted on proposal {proposal_id}." | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |         in err["Message"] | 
					
						
							| 
									
										
										
										
											2020-05-15 19:38:19 -05:00
										 |  |  |     ) | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_managedblockchain | 
					
						
							|  |  |  | def test_list_proposal_votes_badnetwork(): | 
					
						
							|  |  |  |     conn = boto3.client("managedblockchain", region_name="us-east-1") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-13 10:36:56 +01:00
										 |  |  |     with pytest.raises(ClientError) as ex: | 
					
						
							|  |  |  |         conn.list_proposal_votes( | 
					
						
							|  |  |  |             NetworkId="n-ABCDEFGHIJKLMNOP0123456789", | 
					
						
							|  |  |  |             ProposalId="p-ABCDEFGHIJKLMNOP0123456789", | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |     err = ex.value.response["Error"] | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     assert err["Code"] == "ResourceNotFoundException" | 
					
						
							|  |  |  |     assert "Network n-ABCDEFGHIJKLMNOP0123456789 not found" in err["Message"] | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_managedblockchain | 
					
						
							|  |  |  | def test_list_proposal_votes_badproposal(): | 
					
						
							|  |  |  |     conn = boto3.client("managedblockchain", region_name="us-east-1") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Create network | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     network_id = conn.create_network( | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  |         Name="testnetwork1", | 
					
						
							|  |  |  |         Framework="HYPERLEDGER_FABRIC", | 
					
						
							|  |  |  |         FrameworkVersion="1.2", | 
					
						
							|  |  |  |         FrameworkConfiguration=helpers.default_frameworkconfiguration, | 
					
						
							|  |  |  |         VotingPolicy=helpers.default_votingpolicy, | 
					
						
							|  |  |  |         MemberConfiguration=helpers.default_memberconfiguration, | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     )["NetworkId"] | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-13 10:36:56 +01:00
										 |  |  |     with pytest.raises(ClientError) as ex: | 
					
						
							|  |  |  |         conn.list_proposal_votes( | 
					
						
							| 
									
										
										
										
											2022-03-10 13:39:59 -01:00
										 |  |  |             NetworkId=network_id, ProposalId="p-ABCDEFGHIJKLMNOP0123456789" | 
					
						
							| 
									
										
										
										
											2021-05-13 10:36:56 +01:00
										 |  |  |         ) | 
					
						
							|  |  |  |     err = ex.value.response["Error"] | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     assert err["Code"] == "ResourceNotFoundException" | 
					
						
							|  |  |  |     assert "Proposal p-ABCDEFGHIJKLMNOP0123456789 not found" in err["Message"] |