Managedblockchain member additions (#2983)
* Added some member and proposal functions * Added additional member and proposal functions * Fixed admin password return and added update_member along with tests * Added network removal and member removal proposal * Fixed failing test * Fixed Python 2.7 test
This commit is contained in:
parent
774a764b69
commit
9bc393801f
12 changed files with 2638 additions and 74 deletions
1
tests/test_managedblockchain/__init__.py
Normal file
1
tests/test_managedblockchain/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
from __future__ import unicode_literals
|
||||
67
tests/test_managedblockchain/helpers.py
Normal file
67
tests/test_managedblockchain/helpers.py
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
|
||||
default_frameworkconfiguration = {"Fabric": {"Edition": "STARTER"}}
|
||||
|
||||
default_votingpolicy = {
|
||||
"ApprovalThresholdPolicy": {
|
||||
"ThresholdPercentage": 50,
|
||||
"ProposalDurationInHours": 24,
|
||||
"ThresholdComparator": "GREATER_THAN_OR_EQUAL_TO",
|
||||
}
|
||||
}
|
||||
|
||||
default_memberconfiguration = {
|
||||
"Name": "testmember1",
|
||||
"Description": "Test Member 1",
|
||||
"FrameworkConfiguration": {
|
||||
"Fabric": {"AdminUsername": "admin", "AdminPassword": "Admin12345"}
|
||||
},
|
||||
"LogPublishingConfiguration": {
|
||||
"Fabric": {"CaLogs": {"Cloudwatch": {"Enabled": False}}}
|
||||
},
|
||||
}
|
||||
|
||||
default_policy_actions = {"Invitations": [{"Principal": "123456789012"}]}
|
||||
|
||||
multiple_policy_actions = {
|
||||
"Invitations": [{"Principal": "123456789012"}, {"Principal": "123456789013"}]
|
||||
}
|
||||
|
||||
|
||||
def member_id_exist_in_list(members, memberid):
|
||||
memberidxists = False
|
||||
for member in members:
|
||||
if member["Id"] == memberid:
|
||||
memberidxists = True
|
||||
break
|
||||
return memberidxists
|
||||
|
||||
|
||||
def create_member_configuration(
|
||||
name, adminuser, adminpass, cloudwatchenabled, description=None
|
||||
):
|
||||
d = {
|
||||
"Name": name,
|
||||
"FrameworkConfiguration": {
|
||||
"Fabric": {"AdminUsername": adminuser, "AdminPassword": adminpass}
|
||||
},
|
||||
"LogPublishingConfiguration": {
|
||||
"Fabric": {"CaLogs": {"Cloudwatch": {"Enabled": cloudwatchenabled}}}
|
||||
},
|
||||
}
|
||||
|
||||
if description is not None:
|
||||
d["Description"] = description
|
||||
|
||||
return d
|
||||
|
||||
|
||||
def select_invitation_id_for_network(invitations, networkid, status=None):
|
||||
# Get invitations based on network and maybe status
|
||||
invitationsfornetwork = []
|
||||
for invitation in invitations:
|
||||
if invitation["NetworkSummary"]["Id"] == networkid:
|
||||
if status is None or invitation["Status"] == status:
|
||||
invitationsfornetwork.append(invitation["InvitationId"])
|
||||
return invitationsfornetwork
|
||||
|
|
@ -0,0 +1,142 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import boto3
|
||||
import sure # noqa
|
||||
|
||||
from moto.managedblockchain.exceptions import BadRequestException
|
||||
from moto import mock_managedblockchain
|
||||
from . import helpers
|
||||
|
||||
|
||||
@mock_managedblockchain
|
||||
def test_create_2_invitations():
|
||||
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
|
||||
response = conn.create_proposal(
|
||||
NetworkId=network_id,
|
||||
MemberId=member_id,
|
||||
Actions=helpers.multiple_policy_actions,
|
||||
)
|
||||
proposal_id = response["ProposalId"]
|
||||
|
||||
# Get proposal details
|
||||
response = conn.get_proposal(NetworkId=network_id, ProposalId=proposal_id)
|
||||
response["Proposal"]["NetworkId"].should.equal(network_id)
|
||||
response["Proposal"]["Status"].should.equal("IN_PROGRESS")
|
||||
|
||||
# Vote yes
|
||||
response = conn.vote_on_proposal(
|
||||
NetworkId=network_id,
|
||||
ProposalId=proposal_id,
|
||||
VoterMemberId=member_id,
|
||||
Vote="YES",
|
||||
)
|
||||
|
||||
# Get the invitation
|
||||
response = conn.list_invitations()
|
||||
response["Invitations"].should.have.length_of(2)
|
||||
response["Invitations"][0]["NetworkSummary"]["Id"].should.equal(network_id)
|
||||
response["Invitations"][0]["Status"].should.equal("PENDING")
|
||||
response["Invitations"][1]["NetworkSummary"]["Id"].should.equal(network_id)
|
||||
response["Invitations"][1]["Status"].should.equal("PENDING")
|
||||
|
||||
|
||||
@mock_managedblockchain
|
||||
def test_reject_invitation():
|
||||
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
|
||||
response = conn.create_proposal(
|
||||
NetworkId=network_id,
|
||||
MemberId=member_id,
|
||||
Actions=helpers.default_policy_actions,
|
||||
)
|
||||
proposal_id = response["ProposalId"]
|
||||
|
||||
# Get proposal details
|
||||
response = conn.get_proposal(NetworkId=network_id, ProposalId=proposal_id)
|
||||
response["Proposal"]["NetworkId"].should.equal(network_id)
|
||||
response["Proposal"]["Status"].should.equal("IN_PROGRESS")
|
||||
|
||||
# Vote yes
|
||||
response = conn.vote_on_proposal(
|
||||
NetworkId=network_id,
|
||||
ProposalId=proposal_id,
|
||||
VoterMemberId=member_id,
|
||||
Vote="YES",
|
||||
)
|
||||
|
||||
# Get the invitation
|
||||
response = conn.list_invitations()
|
||||
response["Invitations"][0]["NetworkSummary"]["Id"].should.equal(network_id)
|
||||
response["Invitations"][0]["Status"].should.equal("PENDING")
|
||||
invitation_id = response["Invitations"][0]["InvitationId"]
|
||||
|
||||
# Reject - thanks but no thanks
|
||||
response = conn.reject_invitation(InvitationId=invitation_id)
|
||||
|
||||
# Check the invitation status
|
||||
response = conn.list_invitations()
|
||||
response["Invitations"][0]["InvitationId"].should.equal(invitation_id)
|
||||
response["Invitations"][0]["Status"].should.equal("REJECTED")
|
||||
|
||||
|
||||
@mock_managedblockchain
|
||||
def test_reject_invitation_badinvitation():
|
||||
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(
|
||||
NetworkId=network_id,
|
||||
MemberId=member_id,
|
||||
Actions=helpers.default_policy_actions,
|
||||
)
|
||||
|
||||
proposal_id = response["ProposalId"]
|
||||
|
||||
response = conn.vote_on_proposal(
|
||||
NetworkId=network_id,
|
||||
ProposalId=proposal_id,
|
||||
VoterMemberId=member_id,
|
||||
Vote="YES",
|
||||
)
|
||||
|
||||
response = conn.reject_invitation.when.called_with(
|
||||
InvitationId="in-ABCDEFGHIJKLMNOP0123456789",
|
||||
).should.throw(Exception, "InvitationId in-ABCDEFGHIJKLMNOP0123456789 not found.")
|
||||
669
tests/test_managedblockchain/test_managedblockchain_members.py
Normal file
669
tests/test_managedblockchain/test_managedblockchain_members.py
Normal file
|
|
@ -0,0 +1,669 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import boto3
|
||||
import sure # noqa
|
||||
|
||||
from moto.managedblockchain.exceptions import BadRequestException
|
||||
from moto import mock_managedblockchain
|
||||
from . import helpers
|
||||
|
||||
|
||||
@mock_managedblockchain
|
||||
def test_create_another_member():
|
||||
conn = boto3.client("managedblockchain", region_name="us-east-1")
|
||||
|
||||
# Create network
|
||||
response = conn.create_network(
|
||||
Name="testnetwork1",
|
||||
Description="Test Network 1",
|
||||
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
|
||||
response = conn.create_proposal(
|
||||
NetworkId=network_id,
|
||||
MemberId=member_id,
|
||||
Actions=helpers.default_policy_actions,
|
||||
)
|
||||
proposal_id = response["ProposalId"]
|
||||
|
||||
# Get proposal details
|
||||
response = conn.get_proposal(NetworkId=network_id, ProposalId=proposal_id)
|
||||
response["Proposal"]["NetworkId"].should.equal(network_id)
|
||||
response["Proposal"]["Status"].should.equal("IN_PROGRESS")
|
||||
|
||||
# Vote yes
|
||||
response = conn.vote_on_proposal(
|
||||
NetworkId=network_id,
|
||||
ProposalId=proposal_id,
|
||||
VoterMemberId=member_id,
|
||||
Vote="YES",
|
||||
)
|
||||
|
||||
# Get the invitation
|
||||
response = conn.list_invitations()
|
||||
response["Invitations"][0]["NetworkSummary"]["Id"].should.equal(network_id)
|
||||
response["Invitations"][0]["Status"].should.equal("PENDING")
|
||||
invitation_id = response["Invitations"][0]["InvitationId"]
|
||||
|
||||
# Create the member
|
||||
response = conn.create_member(
|
||||
InvitationId=invitation_id,
|
||||
NetworkId=network_id,
|
||||
MemberConfiguration=helpers.create_member_configuration(
|
||||
"testmember2", "admin", "Admin12345", False
|
||||
),
|
||||
)
|
||||
member_id2 = response["MemberId"]
|
||||
|
||||
# Check the invitation status
|
||||
response = conn.list_invitations()
|
||||
response["Invitations"][0]["InvitationId"].should.equal(invitation_id)
|
||||
response["Invitations"][0]["Status"].should.equal("ACCEPTED")
|
||||
|
||||
# Find member in full list
|
||||
response = conn.list_members(NetworkId=network_id)
|
||||
members = response["Members"]
|
||||
members.should.have.length_of(2)
|
||||
helpers.member_id_exist_in_list(members, member_id2).should.equal(True)
|
||||
|
||||
# Get member 2 details
|
||||
response = conn.get_member(NetworkId=network_id, MemberId=member_id2)
|
||||
response["Member"]["Name"].should.equal("testmember2")
|
||||
|
||||
# Update member
|
||||
logconfignewenabled = not helpers.default_memberconfiguration[
|
||||
"LogPublishingConfiguration"
|
||||
]["Fabric"]["CaLogs"]["Cloudwatch"]["Enabled"]
|
||||
logconfignew = {
|
||||
"Fabric": {"CaLogs": {"Cloudwatch": {"Enabled": logconfignewenabled}}}
|
||||
}
|
||||
conn.update_member(
|
||||
NetworkId=network_id,
|
||||
MemberId=member_id2,
|
||||
LogPublishingConfiguration=logconfignew,
|
||||
)
|
||||
|
||||
# Get member 2 details
|
||||
response = conn.get_member(NetworkId=network_id, MemberId=member_id2)
|
||||
response["Member"]["LogPublishingConfiguration"]["Fabric"]["CaLogs"]["Cloudwatch"][
|
||||
"Enabled"
|
||||
].should.equal(logconfignewenabled)
|
||||
|
||||
|
||||
@mock_managedblockchain
|
||||
def test_create_another_member_withopts():
|
||||
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
|
||||
response = conn.create_proposal(
|
||||
NetworkId=network_id,
|
||||
MemberId=member_id,
|
||||
Actions=helpers.default_policy_actions,
|
||||
)
|
||||
proposal_id = response["ProposalId"]
|
||||
|
||||
# Get proposal details
|
||||
response = conn.get_proposal(NetworkId=network_id, ProposalId=proposal_id)
|
||||
response["Proposal"]["NetworkId"].should.equal(network_id)
|
||||
response["Proposal"]["Status"].should.equal("IN_PROGRESS")
|
||||
|
||||
# Vote yes
|
||||
response = conn.vote_on_proposal(
|
||||
NetworkId=network_id,
|
||||
ProposalId=proposal_id,
|
||||
VoterMemberId=member_id,
|
||||
Vote="YES",
|
||||
)
|
||||
|
||||
# Get the invitation
|
||||
response = conn.list_invitations()
|
||||
response["Invitations"][0]["NetworkSummary"]["Id"].should.equal(network_id)
|
||||
response["Invitations"][0]["Status"].should.equal("PENDING")
|
||||
invitation_id = response["Invitations"][0]["InvitationId"]
|
||||
|
||||
# Create the member
|
||||
response = conn.create_member(
|
||||
InvitationId=invitation_id,
|
||||
NetworkId=network_id,
|
||||
MemberConfiguration=helpers.create_member_configuration(
|
||||
"testmember2", "admin", "Admin12345", False, "Test Member 2"
|
||||
),
|
||||
)
|
||||
member_id2 = response["MemberId"]
|
||||
|
||||
# Check the invitation status
|
||||
response = conn.list_invitations()
|
||||
response["Invitations"][0]["InvitationId"].should.equal(invitation_id)
|
||||
response["Invitations"][0]["Status"].should.equal("ACCEPTED")
|
||||
|
||||
# Find member in full list
|
||||
response = conn.list_members(NetworkId=network_id)
|
||||
members = response["Members"]
|
||||
members.should.have.length_of(2)
|
||||
helpers.member_id_exist_in_list(members, member_id2).should.equal(True)
|
||||
|
||||
# Get member 2 details
|
||||
response = conn.get_member(NetworkId=network_id, MemberId=member_id2)
|
||||
response["Member"]["Description"].should.equal("Test Member 2")
|
||||
|
||||
# Try to create member with already used invitation
|
||||
response = conn.create_member.when.called_with(
|
||||
InvitationId=invitation_id,
|
||||
NetworkId=network_id,
|
||||
MemberConfiguration=helpers.create_member_configuration(
|
||||
"testmember2", "admin", "Admin12345", False, "Test Member 2 Duplicate"
|
||||
),
|
||||
).should.throw(Exception, "Invitation {0} not valid".format(invitation_id))
|
||||
|
||||
# Delete member 2
|
||||
conn.delete_member(NetworkId=network_id, MemberId=member_id2)
|
||||
|
||||
# Member is still in the list
|
||||
response = conn.list_members(NetworkId=network_id)
|
||||
members = response["Members"]
|
||||
members.should.have.length_of(2)
|
||||
|
||||
# But cannot get
|
||||
response = conn.get_member.when.called_with(
|
||||
NetworkId=network_id, MemberId=member_id2,
|
||||
).should.throw(Exception, "Member {0} not found".format(member_id2))
|
||||
|
||||
# Delete member 1
|
||||
conn.delete_member(NetworkId=network_id, MemberId=member_id)
|
||||
|
||||
# Network should be gone
|
||||
response = conn.list_networks()
|
||||
mbcnetworks = response["Networks"]
|
||||
mbcnetworks.should.have.length_of(0)
|
||||
|
||||
# Verify the invitation network status is DELETED
|
||||
# Get the invitation
|
||||
response = conn.list_invitations()
|
||||
response["Invitations"].should.have.length_of(1)
|
||||
response["Invitations"][0]["NetworkSummary"]["Id"].should.equal(network_id)
|
||||
response["Invitations"][0]["NetworkSummary"]["Status"].should.equal("DELETED")
|
||||
|
||||
|
||||
@mock_managedblockchain
|
||||
def test_create_and_delete_member():
|
||||
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 (create additional member)
|
||||
response = conn.create_proposal(
|
||||
NetworkId=network_id,
|
||||
MemberId=member_id,
|
||||
Actions=helpers.default_policy_actions,
|
||||
)
|
||||
proposal_id = response["ProposalId"]
|
||||
|
||||
# Vote yes
|
||||
response = conn.vote_on_proposal(
|
||||
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
|
||||
response = conn.create_member(
|
||||
InvitationId=invitation_id,
|
||||
NetworkId=network_id,
|
||||
MemberConfiguration=helpers.create_member_configuration(
|
||||
"testmember2", "admin", "Admin12345", False, "Test Member 2"
|
||||
),
|
||||
)
|
||||
member_id2 = response["MemberId"]
|
||||
|
||||
both_policy_actions = {
|
||||
"Invitations": [{"Principal": "123456789012"}],
|
||||
"Removals": [{"MemberId": member_id2}],
|
||||
}
|
||||
|
||||
# Create proposal (invite and remove member)
|
||||
response = conn.create_proposal(
|
||||
NetworkId=network_id, MemberId=member_id, Actions=both_policy_actions,
|
||||
)
|
||||
proposal_id2 = response["ProposalId"]
|
||||
|
||||
# Get proposal details
|
||||
response = conn.get_proposal(NetworkId=network_id, ProposalId=proposal_id2)
|
||||
response["Proposal"]["NetworkId"].should.equal(network_id)
|
||||
response["Proposal"]["Status"].should.equal("IN_PROGRESS")
|
||||
|
||||
# Vote yes
|
||||
response = conn.vote_on_proposal(
|
||||
NetworkId=network_id,
|
||||
ProposalId=proposal_id2,
|
||||
VoterMemberId=member_id,
|
||||
Vote="YES",
|
||||
)
|
||||
|
||||
# Check the invitation status
|
||||
response = conn.list_invitations()
|
||||
invitations = helpers.select_invitation_id_for_network(
|
||||
response["Invitations"], network_id, "PENDING"
|
||||
)
|
||||
invitations.should.have.length_of(1)
|
||||
|
||||
# Member is still in the list
|
||||
response = conn.list_members(NetworkId=network_id)
|
||||
members = response["Members"]
|
||||
members.should.have.length_of(2)
|
||||
foundmember2 = False
|
||||
for member in members:
|
||||
if member["Id"] == member_id2 and member["Status"] == "DELETED":
|
||||
foundmember2 = True
|
||||
foundmember2.should.equal(True)
|
||||
|
||||
|
||||
@mock_managedblockchain
|
||||
def test_create_too_many_members():
|
||||
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 4 more members - create invitations for 5
|
||||
for counter in range(2, 7):
|
||||
# Create proposal
|
||||
response = conn.create_proposal(
|
||||
NetworkId=network_id,
|
||||
MemberId=member_id,
|
||||
Actions=helpers.default_policy_actions,
|
||||
)
|
||||
proposal_id = response["ProposalId"]
|
||||
|
||||
# Vote yes
|
||||
response = conn.vote_on_proposal(
|
||||
NetworkId=network_id,
|
||||
ProposalId=proposal_id,
|
||||
VoterMemberId=member_id,
|
||||
Vote="YES",
|
||||
)
|
||||
|
||||
for counter in range(2, 6):
|
||||
# Get the invitation
|
||||
response = conn.list_invitations()
|
||||
invitation_id = helpers.select_invitation_id_for_network(
|
||||
response["Invitations"], network_id, "PENDING"
|
||||
)[0]
|
||||
|
||||
# Create the member
|
||||
response = conn.create_member(
|
||||
InvitationId=invitation_id,
|
||||
NetworkId=network_id,
|
||||
MemberConfiguration=helpers.create_member_configuration(
|
||||
"testmember" + str(counter),
|
||||
"admin",
|
||||
"Admin12345",
|
||||
False,
|
||||
"Test Member " + str(counter),
|
||||
),
|
||||
)
|
||||
member_id = response["MemberId"]
|
||||
|
||||
# Find member in full list
|
||||
response = conn.list_members(NetworkId=network_id)
|
||||
members = response["Members"]
|
||||
members.should.have.length_of(counter)
|
||||
helpers.member_id_exist_in_list(members, member_id).should.equal(True)
|
||||
|
||||
# Get member details
|
||||
response = conn.get_member(NetworkId=network_id, MemberId=member_id)
|
||||
response["Member"]["Description"].should.equal("Test Member " + str(counter))
|
||||
|
||||
# Try to create the sixth
|
||||
response = conn.list_invitations()
|
||||
invitation_id = helpers.select_invitation_id_for_network(
|
||||
response["Invitations"], network_id, "PENDING"
|
||||
)[0]
|
||||
|
||||
# Try to create member with already used invitation
|
||||
response = conn.create_member.when.called_with(
|
||||
InvitationId=invitation_id,
|
||||
NetworkId=network_id,
|
||||
MemberConfiguration=helpers.create_member_configuration(
|
||||
"testmember6", "admin", "Admin12345", False, "Test Member 6"
|
||||
),
|
||||
).should.throw(
|
||||
Exception,
|
||||
"5 is the maximum number of members allowed in a STARTER Edition network",
|
||||
)
|
||||
|
||||
|
||||
@mock_managedblockchain
|
||||
def test_create_another_member_alreadyhave():
|
||||
conn = boto3.client("managedblockchain", region_name="us-east-1")
|
||||
|
||||
# Create network
|
||||
response = conn.create_network(
|
||||
Name="testnetwork1",
|
||||
Description="Test Network 1",
|
||||
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
|
||||
response = conn.create_proposal(
|
||||
NetworkId=network_id,
|
||||
MemberId=member_id,
|
||||
Actions=helpers.default_policy_actions,
|
||||
)
|
||||
proposal_id = response["ProposalId"]
|
||||
|
||||
# Vote yes
|
||||
response = conn.vote_on_proposal(
|
||||
NetworkId=network_id,
|
||||
ProposalId=proposal_id,
|
||||
VoterMemberId=member_id,
|
||||
Vote="YES",
|
||||
)
|
||||
|
||||
# Get the invitation
|
||||
response = conn.list_invitations()
|
||||
invitation_id = response["Invitations"][0]["InvitationId"]
|
||||
|
||||
# Should fail trying to create with same name
|
||||
response = conn.create_member.when.called_with(
|
||||
NetworkId=network_id,
|
||||
InvitationId=invitation_id,
|
||||
MemberConfiguration=helpers.create_member_configuration(
|
||||
"testmember1", "admin", "Admin12345", False
|
||||
),
|
||||
).should.throw(
|
||||
Exception,
|
||||
"Member name {0} already exists in network {1}".format(
|
||||
"testmember1", network_id
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@mock_managedblockchain
|
||||
def test_create_another_member_badnetwork():
|
||||
conn = boto3.client("managedblockchain", region_name="us-east-1")
|
||||
|
||||
response = conn.create_member.when.called_with(
|
||||
NetworkId="n-ABCDEFGHIJKLMNOP0123456789",
|
||||
InvitationId="id-ABCDEFGHIJKLMNOP0123456789",
|
||||
MemberConfiguration=helpers.create_member_configuration(
|
||||
"testmember2", "admin", "Admin12345", False
|
||||
),
|
||||
).should.throw(Exception, "Network n-ABCDEFGHIJKLMNOP0123456789 not found")
|
||||
|
||||
|
||||
@mock_managedblockchain
|
||||
def test_create_another_member_badinvitation():
|
||||
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"]
|
||||
|
||||
response = conn.create_member.when.called_with(
|
||||
NetworkId=network_id,
|
||||
InvitationId="in-ABCDEFGHIJKLMNOP0123456789",
|
||||
MemberConfiguration=helpers.create_member_configuration(
|
||||
"testmember2", "admin", "Admin12345", False
|
||||
),
|
||||
).should.throw(Exception, "Invitation in-ABCDEFGHIJKLMNOP0123456789 not valid")
|
||||
|
||||
|
||||
@mock_managedblockchain
|
||||
def test_create_another_member_adminpassword():
|
||||
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"]
|
||||
|
||||
# Create proposal
|
||||
response = conn.create_proposal(
|
||||
NetworkId=network_id,
|
||||
MemberId=member_id,
|
||||
Actions=helpers.default_policy_actions,
|
||||
)
|
||||
proposal_id = response["ProposalId"]
|
||||
|
||||
# Get proposal details
|
||||
response = conn.get_proposal(NetworkId=network_id, ProposalId=proposal_id)
|
||||
response["Proposal"]["NetworkId"].should.equal(network_id)
|
||||
response["Proposal"]["Status"].should.equal("IN_PROGRESS")
|
||||
|
||||
# Vote yes
|
||||
response = conn.vote_on_proposal(
|
||||
NetworkId=network_id,
|
||||
ProposalId=proposal_id,
|
||||
VoterMemberId=member_id,
|
||||
Vote="YES",
|
||||
)
|
||||
|
||||
# Get the invitation
|
||||
response = conn.list_invitations()
|
||||
invitation_id = response["Invitations"][0]["InvitationId"]
|
||||
|
||||
badadminpassmemberconf = helpers.create_member_configuration(
|
||||
"testmember2", "admin", "Admin12345", False
|
||||
)
|
||||
|
||||
# Too short
|
||||
badadminpassmemberconf["FrameworkConfiguration"]["Fabric"][
|
||||
"AdminPassword"
|
||||
] = "badap"
|
||||
response = conn.create_member.when.called_with(
|
||||
NetworkId=network_id,
|
||||
InvitationId=invitation_id,
|
||||
MemberConfiguration=badadminpassmemberconf,
|
||||
).should.throw(
|
||||
Exception,
|
||||
"Invalid length for parameter MemberConfiguration.FrameworkConfiguration.Fabric.AdminPassword",
|
||||
)
|
||||
|
||||
# No uppercase or numbers
|
||||
badadminpassmemberconf["FrameworkConfiguration"]["Fabric"][
|
||||
"AdminPassword"
|
||||
] = "badadminpwd"
|
||||
response = conn.create_member.when.called_with(
|
||||
NetworkId=network_id,
|
||||
InvitationId=invitation_id,
|
||||
MemberConfiguration=badadminpassmemberconf,
|
||||
).should.throw(Exception, "Invalid request body")
|
||||
|
||||
# No lowercase or numbers
|
||||
badadminpassmemberconf["FrameworkConfiguration"]["Fabric"][
|
||||
"AdminPassword"
|
||||
] = "BADADMINPWD"
|
||||
response = conn.create_member.when.called_with(
|
||||
NetworkId=network_id,
|
||||
InvitationId=invitation_id,
|
||||
MemberConfiguration=badadminpassmemberconf,
|
||||
).should.throw(Exception, "Invalid request body")
|
||||
|
||||
# No numbers
|
||||
badadminpassmemberconf["FrameworkConfiguration"]["Fabric"][
|
||||
"AdminPassword"
|
||||
] = "badAdminpwd"
|
||||
response = conn.create_member.when.called_with(
|
||||
NetworkId=network_id,
|
||||
InvitationId=invitation_id,
|
||||
MemberConfiguration=badadminpassmemberconf,
|
||||
).should.throw(Exception, "Invalid request body")
|
||||
|
||||
# Invalid character
|
||||
badadminpassmemberconf["FrameworkConfiguration"]["Fabric"][
|
||||
"AdminPassword"
|
||||
] = "badAdmin@pwd1"
|
||||
response = conn.create_member.when.called_with(
|
||||
NetworkId=network_id,
|
||||
InvitationId=invitation_id,
|
||||
MemberConfiguration=badadminpassmemberconf,
|
||||
).should.throw(Exception, "Invalid request body")
|
||||
|
||||
|
||||
@mock_managedblockchain
|
||||
def test_list_members_badnetwork():
|
||||
conn = boto3.client("managedblockchain", region_name="us-east-1")
|
||||
|
||||
response = conn.list_members.when.called_with(
|
||||
NetworkId="n-ABCDEFGHIJKLMNOP0123456789",
|
||||
).should.throw(Exception, "Network n-ABCDEFGHIJKLMNOP0123456789 not found")
|
||||
|
||||
|
||||
@mock_managedblockchain
|
||||
def test_get_member_badnetwork():
|
||||
conn = boto3.client("managedblockchain", region_name="us-east-1")
|
||||
|
||||
response = conn.get_member.when.called_with(
|
||||
NetworkId="n-ABCDEFGHIJKLMNOP0123456789",
|
||||
MemberId="m-ABCDEFGHIJKLMNOP0123456789",
|
||||
).should.throw(Exception, "Network n-ABCDEFGHIJKLMNOP0123456789 not found")
|
||||
|
||||
|
||||
@mock_managedblockchain
|
||||
def test_get_member_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"]
|
||||
|
||||
response = conn.get_member.when.called_with(
|
||||
NetworkId=network_id, MemberId="m-ABCDEFGHIJKLMNOP0123456789",
|
||||
).should.throw(Exception, "Member m-ABCDEFGHIJKLMNOP0123456789 not found")
|
||||
|
||||
|
||||
@mock_managedblockchain
|
||||
def test_delete_member_badnetwork():
|
||||
conn = boto3.client("managedblockchain", region_name="us-east-1")
|
||||
|
||||
response = conn.delete_member.when.called_with(
|
||||
NetworkId="n-ABCDEFGHIJKLMNOP0123456789",
|
||||
MemberId="m-ABCDEFGHIJKLMNOP0123456789",
|
||||
).should.throw(Exception, "Network n-ABCDEFGHIJKLMNOP0123456789 not found")
|
||||
|
||||
|
||||
@mock_managedblockchain
|
||||
def test_delete_member_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"]
|
||||
|
||||
response = conn.delete_member.when.called_with(
|
||||
NetworkId=network_id, MemberId="m-ABCDEFGHIJKLMNOP0123456789",
|
||||
).should.throw(Exception, "Member m-ABCDEFGHIJKLMNOP0123456789 not found")
|
||||
|
||||
|
||||
@mock_managedblockchain
|
||||
def test_update_member_badnetwork():
|
||||
conn = boto3.client("managedblockchain", region_name="us-east-1")
|
||||
|
||||
response = conn.update_member.when.called_with(
|
||||
NetworkId="n-ABCDEFGHIJKLMNOP0123456789",
|
||||
MemberId="m-ABCDEFGHIJKLMNOP0123456789",
|
||||
LogPublishingConfiguration=helpers.default_memberconfiguration[
|
||||
"LogPublishingConfiguration"
|
||||
],
|
||||
).should.throw(Exception, "Network n-ABCDEFGHIJKLMNOP0123456789 not found")
|
||||
|
||||
|
||||
@mock_managedblockchain
|
||||
def test_update_member_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"]
|
||||
|
||||
response = conn.update_member.when.called_with(
|
||||
NetworkId=network_id,
|
||||
MemberId="m-ABCDEFGHIJKLMNOP0123456789",
|
||||
LogPublishingConfiguration=helpers.default_memberconfiguration[
|
||||
"LogPublishingConfiguration"
|
||||
],
|
||||
).should.throw(Exception, "Member m-ABCDEFGHIJKLMNOP0123456789 not found")
|
||||
|
|
@ -5,28 +5,7 @@ import sure # noqa
|
|||
|
||||
from moto.managedblockchain.exceptions import BadRequestException
|
||||
from moto import mock_managedblockchain
|
||||
|
||||
|
||||
default_frameworkconfiguration = {"Fabric": {"Edition": "STARTER"}}
|
||||
|
||||
default_votingpolicy = {
|
||||
"ApprovalThresholdPolicy": {
|
||||
"ThresholdPercentage": 50,
|
||||
"ProposalDurationInHours": 24,
|
||||
"ThresholdComparator": "GREATER_THAN_OR_EQUAL_TO",
|
||||
}
|
||||
}
|
||||
|
||||
default_memberconfiguration = {
|
||||
"Name": "testmember1",
|
||||
"Description": "Test Member 1",
|
||||
"FrameworkConfiguration": {
|
||||
"Fabric": {"AdminUsername": "admin", "AdminPassword": "Admin12345"}
|
||||
},
|
||||
"LogPublishingConfiguration": {
|
||||
"Fabric": {"CaLogs": {"Cloudwatch": {"Enabled": False}}}
|
||||
},
|
||||
}
|
||||
from . import helpers
|
||||
|
||||
|
||||
@mock_managedblockchain
|
||||
|
|
@ -37,12 +16,14 @@ def test_create_network():
|
|||
Name="testnetwork1",
|
||||
Framework="HYPERLEDGER_FABRIC",
|
||||
FrameworkVersion="1.2",
|
||||
FrameworkConfiguration=default_frameworkconfiguration,
|
||||
VotingPolicy=default_votingpolicy,
|
||||
MemberConfiguration=default_memberconfiguration,
|
||||
FrameworkConfiguration=helpers.default_frameworkconfiguration,
|
||||
VotingPolicy=helpers.default_votingpolicy,
|
||||
MemberConfiguration=helpers.default_memberconfiguration,
|
||||
)
|
||||
response["NetworkId"].should.match("n-[A-Z0-9]{26}")
|
||||
response["MemberId"].should.match("m-[A-Z0-9]{26}")
|
||||
network_id = response["NetworkId"]
|
||||
member_id = response["MemberId"]
|
||||
network_id.should.match("n-[A-Z0-9]{26}")
|
||||
member_id.should.match("m-[A-Z0-9]{26}")
|
||||
|
||||
# Find in full list
|
||||
response = conn.list_networks()
|
||||
|
|
@ -51,7 +32,6 @@ def test_create_network():
|
|||
mbcnetworks[0]["Name"].should.equal("testnetwork1")
|
||||
|
||||
# Get network details
|
||||
network_id = mbcnetworks[0]["Id"]
|
||||
response = conn.get_network(NetworkId=network_id)
|
||||
response["Network"]["Name"].should.equal("testnetwork1")
|
||||
|
||||
|
|
@ -65,12 +45,14 @@ def test_create_network_withopts():
|
|||
Description="Test Network 1",
|
||||
Framework="HYPERLEDGER_FABRIC",
|
||||
FrameworkVersion="1.2",
|
||||
FrameworkConfiguration=default_frameworkconfiguration,
|
||||
VotingPolicy=default_votingpolicy,
|
||||
MemberConfiguration=default_memberconfiguration,
|
||||
FrameworkConfiguration=helpers.default_frameworkconfiguration,
|
||||
VotingPolicy=helpers.default_votingpolicy,
|
||||
MemberConfiguration=helpers.default_memberconfiguration,
|
||||
)
|
||||
response["NetworkId"].should.match("n-[A-Z0-9]{26}")
|
||||
response["MemberId"].should.match("m-[A-Z0-9]{26}")
|
||||
network_id = response["NetworkId"]
|
||||
member_id = response["MemberId"]
|
||||
network_id.should.match("n-[A-Z0-9]{26}")
|
||||
member_id.should.match("m-[A-Z0-9]{26}")
|
||||
|
||||
# Find in full list
|
||||
response = conn.list_networks()
|
||||
|
|
@ -79,7 +61,6 @@ def test_create_network_withopts():
|
|||
mbcnetworks[0]["Description"].should.equal("Test Network 1")
|
||||
|
||||
# Get network details
|
||||
network_id = mbcnetworks[0]["Id"]
|
||||
response = conn.get_network(NetworkId=network_id)
|
||||
response["Network"]["Description"].should.equal("Test Network 1")
|
||||
|
||||
|
|
@ -93,9 +74,9 @@ def test_create_network_noframework():
|
|||
Description="Test Network 1",
|
||||
Framework="HYPERLEDGER_VINYL",
|
||||
FrameworkVersion="1.2",
|
||||
FrameworkConfiguration=default_frameworkconfiguration,
|
||||
VotingPolicy=default_votingpolicy,
|
||||
MemberConfiguration=default_memberconfiguration,
|
||||
FrameworkConfiguration=helpers.default_frameworkconfiguration,
|
||||
VotingPolicy=helpers.default_votingpolicy,
|
||||
MemberConfiguration=helpers.default_memberconfiguration,
|
||||
).should.throw(Exception, "Invalid request body")
|
||||
|
||||
|
||||
|
|
@ -108,9 +89,9 @@ def test_create_network_badframeworkver():
|
|||
Description="Test Network 1",
|
||||
Framework="HYPERLEDGER_FABRIC",
|
||||
FrameworkVersion="1.X",
|
||||
FrameworkConfiguration=default_frameworkconfiguration,
|
||||
VotingPolicy=default_votingpolicy,
|
||||
MemberConfiguration=default_memberconfiguration,
|
||||
FrameworkConfiguration=helpers.default_frameworkconfiguration,
|
||||
VotingPolicy=helpers.default_votingpolicy,
|
||||
MemberConfiguration=helpers.default_memberconfiguration,
|
||||
).should.throw(
|
||||
Exception, "Invalid version 1.X requested for framework HYPERLEDGER_FABRIC"
|
||||
)
|
||||
|
|
@ -128,8 +109,8 @@ def test_create_network_badedition():
|
|||
Framework="HYPERLEDGER_FABRIC",
|
||||
FrameworkVersion="1.2",
|
||||
FrameworkConfiguration=frameworkconfiguration,
|
||||
VotingPolicy=default_votingpolicy,
|
||||
MemberConfiguration=default_memberconfiguration,
|
||||
VotingPolicy=helpers.default_votingpolicy,
|
||||
MemberConfiguration=helpers.default_memberconfiguration,
|
||||
).should.throw(Exception, "Invalid request body")
|
||||
|
||||
|
||||
|
|
@ -138,5 +119,5 @@ def test_get_network_badnetwork():
|
|||
conn = boto3.client("managedblockchain", region_name="us-east-1")
|
||||
|
||||
response = conn.get_network.when.called_with(
|
||||
NetworkId="n-BADNETWORK",
|
||||
).should.throw(Exception, "Network n-BADNETWORK not found")
|
||||
NetworkId="n-ABCDEFGHIJKLMNOP0123456789",
|
||||
).should.throw(Exception, "Network n-ABCDEFGHIJKLMNOP0123456789 not found")
|
||||
|
|
|
|||
199
tests/test_managedblockchain/test_managedblockchain_proposals.py
Normal file
199
tests/test_managedblockchain/test_managedblockchain_proposals.py
Normal file
|
|
@ -0,0 +1,199 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import boto3
|
||||
import sure # noqa
|
||||
|
||||
from moto.managedblockchain.exceptions import BadRequestException
|
||||
from moto import mock_managedblockchain
|
||||
from . import helpers
|
||||
|
||||
|
||||
@mock_managedblockchain
|
||||
def test_create_proposal():
|
||||
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"]
|
||||
network_id.should.match("n-[A-Z0-9]{26}")
|
||||
member_id.should.match("m-[A-Z0-9]{26}")
|
||||
|
||||
# Create proposal
|
||||
response = conn.create_proposal(
|
||||
NetworkId=network_id,
|
||||
MemberId=member_id,
|
||||
Actions=helpers.default_policy_actions,
|
||||
)
|
||||
proposal_id = response["ProposalId"]
|
||||
proposal_id.should.match("p-[A-Z0-9]{26}")
|
||||
|
||||
# Find in full list
|
||||
response = conn.list_proposals(NetworkId=network_id)
|
||||
proposals = response["Proposals"]
|
||||
proposals.should.have.length_of(1)
|
||||
proposals[0]["ProposalId"].should.equal(proposal_id)
|
||||
|
||||
# Get proposal details
|
||||
response = conn.get_proposal(NetworkId=network_id, ProposalId=proposal_id)
|
||||
response["Proposal"]["NetworkId"].should.equal(network_id)
|
||||
|
||||
|
||||
@mock_managedblockchain
|
||||
def test_create_proposal_withopts():
|
||||
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"]
|
||||
network_id.should.match("n-[A-Z0-9]{26}")
|
||||
member_id.should.match("m-[A-Z0-9]{26}")
|
||||
|
||||
# Create proposal
|
||||
response = conn.create_proposal(
|
||||
NetworkId=network_id,
|
||||
MemberId=member_id,
|
||||
Actions=helpers.default_policy_actions,
|
||||
Description="Adding a new member",
|
||||
)
|
||||
proposal_id = response["ProposalId"]
|
||||
proposal_id.should.match("p-[A-Z0-9]{26}")
|
||||
|
||||
# Get proposal details
|
||||
response = conn.get_proposal(NetworkId=network_id, ProposalId=proposal_id)
|
||||
response["Proposal"]["Description"].should.equal("Adding a new member")
|
||||
|
||||
|
||||
@mock_managedblockchain
|
||||
def test_create_proposal_badnetwork():
|
||||
conn = boto3.client("managedblockchain", region_name="us-east-1")
|
||||
|
||||
response = conn.create_proposal.when.called_with(
|
||||
NetworkId="n-ABCDEFGHIJKLMNOP0123456789",
|
||||
MemberId="m-ABCDEFGHIJKLMNOP0123456789",
|
||||
Actions=helpers.default_policy_actions,
|
||||
).should.throw(Exception, "Network n-ABCDEFGHIJKLMNOP0123456789 not found")
|
||||
|
||||
|
||||
@mock_managedblockchain
|
||||
def test_create_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"]
|
||||
|
||||
response = conn.create_proposal.when.called_with(
|
||||
NetworkId=network_id,
|
||||
MemberId="m-ABCDEFGHIJKLMNOP0123456789",
|
||||
Actions=helpers.default_policy_actions,
|
||||
).should.throw(Exception, "Member m-ABCDEFGHIJKLMNOP0123456789 not found")
|
||||
|
||||
|
||||
@mock_managedblockchain
|
||||
def test_create_proposal_badinvitationacctid():
|
||||
conn = boto3.client("managedblockchain", region_name="us-east-1")
|
||||
|
||||
# Must be 12 digits
|
||||
actions = {"Invitations": [{"Principal": "1234567890"}]}
|
||||
|
||||
# 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.when.called_with(
|
||||
NetworkId=network_id, MemberId=member_id, Actions=actions,
|
||||
).should.throw(Exception, "Account ID format specified in proposal is not valid")
|
||||
|
||||
|
||||
@mock_managedblockchain
|
||||
def test_create_proposal_badremovalmemid():
|
||||
conn = boto3.client("managedblockchain", region_name="us-east-1")
|
||||
|
||||
# Must be 12 digits
|
||||
actions = {"Removals": [{"MemberId": "m-ABCDEFGHIJKLMNOP0123456789"}]}
|
||||
|
||||
# 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.when.called_with(
|
||||
NetworkId=network_id, MemberId=member_id, Actions=actions,
|
||||
).should.throw(Exception, "Member ID format specified in proposal is not valid")
|
||||
|
||||
|
||||
@mock_managedblockchain
|
||||
def test_list_proposal_badnetwork():
|
||||
conn = boto3.client("managedblockchain", region_name="us-east-1")
|
||||
|
||||
response = conn.list_proposals.when.called_with(
|
||||
NetworkId="n-ABCDEFGHIJKLMNOP0123456789",
|
||||
).should.throw(Exception, "Network n-ABCDEFGHIJKLMNOP0123456789 not found")
|
||||
|
||||
|
||||
@mock_managedblockchain
|
||||
def test_get_proposal_badnetwork():
|
||||
conn = boto3.client("managedblockchain", region_name="us-east-1")
|
||||
|
||||
response = conn.get_proposal.when.called_with(
|
||||
NetworkId="n-ABCDEFGHIJKLMNOP0123456789",
|
||||
ProposalId="p-ABCDEFGHIJKLMNOP0123456789",
|
||||
).should.throw(Exception, "Network n-ABCDEFGHIJKLMNOP0123456789 not found")
|
||||
|
||||
|
||||
@mock_managedblockchain
|
||||
def test_get_proposal_badproposal():
|
||||
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"]
|
||||
|
||||
response = conn.get_proposal.when.called_with(
|
||||
NetworkId=network_id, ProposalId="p-ABCDEFGHIJKLMNOP0123456789",
|
||||
).should.throw(Exception, "Proposal p-ABCDEFGHIJKLMNOP0123456789 not found")
|
||||
|
|
@ -0,0 +1,529 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
|
||||
import boto3
|
||||
import sure # noqa
|
||||
from freezegun import freeze_time
|
||||
from nose import SkipTest
|
||||
|
||||
from moto.managedblockchain.exceptions import BadRequestException
|
||||
from moto import mock_managedblockchain, settings
|
||||
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
|
||||
response = conn.create_proposal(
|
||||
NetworkId=network_id,
|
||||
MemberId=member_id,
|
||||
Actions=helpers.default_policy_actions,
|
||||
)
|
||||
proposal_id = response["ProposalId"]
|
||||
|
||||
# Get proposal details
|
||||
response = conn.get_proposal(NetworkId=network_id, ProposalId=proposal_id)
|
||||
response["Proposal"]["NetworkId"].should.equal(network_id)
|
||||
response["Proposal"]["Status"].should.equal("IN_PROGRESS")
|
||||
|
||||
# Vote yes
|
||||
response = conn.vote_on_proposal(
|
||||
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)
|
||||
response["ProposalVotes"][0]["MemberId"].should.equal(member_id)
|
||||
|
||||
# Get proposal details - should be APPROVED
|
||||
response = conn.get_proposal(NetworkId=network_id, ProposalId=proposal_id)
|
||||
response["Proposal"]["Status"].should.equal("APPROVED")
|
||||
response["Proposal"]["YesVoteCount"].should.equal(1)
|
||||
response["Proposal"]["NoVoteCount"].should.equal(0)
|
||||
response["Proposal"]["OutstandingVoteCount"].should.equal(0)
|
||||
|
||||
|
||||
@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
|
||||
response = conn.create_proposal(
|
||||
NetworkId=network_id,
|
||||
MemberId=member_id,
|
||||
Actions=helpers.default_policy_actions,
|
||||
)
|
||||
proposal_id = response["ProposalId"]
|
||||
|
||||
# Get proposal details
|
||||
response = conn.get_proposal(NetworkId=network_id, ProposalId=proposal_id)
|
||||
response["Proposal"]["NetworkId"].should.equal(network_id)
|
||||
response["Proposal"]["Status"].should.equal("IN_PROGRESS")
|
||||
|
||||
# Vote no
|
||||
response = conn.vote_on_proposal(
|
||||
NetworkId=network_id,
|
||||
ProposalId=proposal_id,
|
||||
VoterMemberId=member_id,
|
||||
Vote="NO",
|
||||
)
|
||||
|
||||
# List proposal votes
|
||||
response = conn.list_proposal_votes(NetworkId=network_id, ProposalId=proposal_id)
|
||||
response["ProposalVotes"][0]["MemberId"].should.equal(member_id)
|
||||
|
||||
# Get proposal details - should be REJECTED
|
||||
response = conn.get_proposal(NetworkId=network_id, ProposalId=proposal_id)
|
||||
response["Proposal"]["Status"].should.equal("REJECTED")
|
||||
response["Proposal"]["YesVoteCount"].should.equal(0)
|
||||
response["Proposal"]["NoVoteCount"].should.equal(1)
|
||||
response["Proposal"]["OutstandingVoteCount"].should.equal(0)
|
||||
|
||||
|
||||
@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"]
|
||||
|
||||
response = conn.create_proposal(
|
||||
NetworkId=network_id,
|
||||
MemberId=member_id,
|
||||
Actions=helpers.default_policy_actions,
|
||||
)
|
||||
|
||||
proposal_id = response["ProposalId"]
|
||||
|
||||
# Vote yes
|
||||
response = conn.vote_on_proposal(
|
||||
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
|
||||
response = conn.create_member(
|
||||
InvitationId=invitation_id,
|
||||
NetworkId=network_id,
|
||||
MemberConfiguration=helpers.create_member_configuration(
|
||||
"testmember2", "admin", "Admin12345", False, "Test Member 2"
|
||||
),
|
||||
)
|
||||
member_id2 = response["MemberId"]
|
||||
|
||||
# Create another proposal
|
||||
response = conn.create_proposal(
|
||||
NetworkId=network_id,
|
||||
MemberId=member_id,
|
||||
Actions=helpers.default_policy_actions,
|
||||
)
|
||||
|
||||
proposal_id = response["ProposalId"]
|
||||
|
||||
# Vote yes with member 1
|
||||
response = conn.vote_on_proposal(
|
||||
NetworkId=network_id,
|
||||
ProposalId=proposal_id,
|
||||
VoterMemberId=member_id,
|
||||
Vote="YES",
|
||||
)
|
||||
|
||||
# Get proposal details
|
||||
response = conn.get_proposal(NetworkId=network_id, ProposalId=proposal_id)
|
||||
response["Proposal"]["NetworkId"].should.equal(network_id)
|
||||
response["Proposal"]["Status"].should.equal("IN_PROGRESS")
|
||||
|
||||
|
||||
@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"]
|
||||
|
||||
response = conn.create_proposal(
|
||||
NetworkId=network_id,
|
||||
MemberId=member_id,
|
||||
Actions=helpers.default_policy_actions,
|
||||
)
|
||||
|
||||
proposal_id = response["ProposalId"]
|
||||
|
||||
# Vote yes
|
||||
response = conn.vote_on_proposal(
|
||||
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
|
||||
response = conn.create_member(
|
||||
InvitationId=invitation_id,
|
||||
NetworkId=network_id,
|
||||
MemberConfiguration=helpers.create_member_configuration(
|
||||
"testmember2", "admin", "Admin12345", False, "Test Member 2"
|
||||
),
|
||||
)
|
||||
member_id2 = response["MemberId"]
|
||||
|
||||
# Create another proposal
|
||||
response = conn.create_proposal(
|
||||
NetworkId=network_id,
|
||||
MemberId=member_id,
|
||||
Actions=helpers.default_policy_actions,
|
||||
)
|
||||
|
||||
proposal_id = response["ProposalId"]
|
||||
|
||||
# Vote no with member 1
|
||||
response = conn.vote_on_proposal(
|
||||
NetworkId=network_id,
|
||||
ProposalId=proposal_id,
|
||||
VoterMemberId=member_id,
|
||||
Vote="NO",
|
||||
)
|
||||
|
||||
# Vote no with member 2
|
||||
response = conn.vote_on_proposal(
|
||||
NetworkId=network_id,
|
||||
ProposalId=proposal_id,
|
||||
VoterMemberId=member_id2,
|
||||
Vote="NO",
|
||||
)
|
||||
|
||||
# Get proposal details
|
||||
response = conn.get_proposal(NetworkId=network_id, ProposalId=proposal_id)
|
||||
response["Proposal"]["NetworkId"].should.equal(network_id)
|
||||
response["Proposal"]["Status"].should.equal("REJECTED")
|
||||
|
||||
|
||||
@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"]
|
||||
|
||||
response = conn.create_proposal(
|
||||
NetworkId=network_id,
|
||||
MemberId=member_id,
|
||||
Actions=helpers.default_policy_actions,
|
||||
)
|
||||
|
||||
proposal_id = response["ProposalId"]
|
||||
|
||||
with freeze_time("2015-02-01 12:00:00"):
|
||||
# Vote yes - should set status to expired
|
||||
response = conn.vote_on_proposal(
|
||||
NetworkId=network_id,
|
||||
ProposalId=proposal_id,
|
||||
VoterMemberId=member_id,
|
||||
Vote="YES",
|
||||
)
|
||||
|
||||
# Get proposal details - should be EXPIRED
|
||||
response = conn.get_proposal(NetworkId=network_id, ProposalId=proposal_id)
|
||||
response["Proposal"]["Status"].should.equal("EXPIRED")
|
||||
|
||||
|
||||
@mock_managedblockchain
|
||||
def test_vote_on_proposal_badnetwork():
|
||||
conn = boto3.client("managedblockchain", region_name="us-east-1")
|
||||
|
||||
response = conn.vote_on_proposal.when.called_with(
|
||||
NetworkId="n-ABCDEFGHIJKLMNOP0123456789",
|
||||
ProposalId="p-ABCDEFGHIJKLMNOP0123456789",
|
||||
VoterMemberId="m-ABCDEFGHIJKLMNOP0123456789",
|
||||
Vote="YES",
|
||||
).should.throw(Exception, "Network n-ABCDEFGHIJKLMNOP0123456789 not found")
|
||||
|
||||
|
||||
@mock_managedblockchain
|
||||
def test_vote_on_proposal_badproposal():
|
||||
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"]
|
||||
|
||||
response = conn.vote_on_proposal.when.called_with(
|
||||
NetworkId=network_id,
|
||||
ProposalId="p-ABCDEFGHIJKLMNOP0123456789",
|
||||
VoterMemberId="m-ABCDEFGHIJKLMNOP0123456789",
|
||||
Vote="YES",
|
||||
).should.throw(Exception, "Proposal p-ABCDEFGHIJKLMNOP0123456789 not found")
|
||||
|
||||
|
||||
@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"]
|
||||
|
||||
response = conn.create_proposal(
|
||||
NetworkId=network_id,
|
||||
MemberId=member_id,
|
||||
Actions=helpers.default_policy_actions,
|
||||
)
|
||||
|
||||
proposal_id = response["ProposalId"]
|
||||
|
||||
response = conn.vote_on_proposal.when.called_with(
|
||||
NetworkId=network_id,
|
||||
ProposalId=proposal_id,
|
||||
VoterMemberId="m-ABCDEFGHIJKLMNOP0123456789",
|
||||
Vote="YES",
|
||||
).should.throw(Exception, "Member m-ABCDEFGHIJKLMNOP0123456789 not found")
|
||||
|
||||
|
||||
@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(
|
||||
NetworkId=network_id,
|
||||
MemberId=member_id,
|
||||
Actions=helpers.default_policy_actions,
|
||||
)
|
||||
|
||||
proposal_id = response["ProposalId"]
|
||||
|
||||
response = conn.vote_on_proposal.when.called_with(
|
||||
NetworkId=network_id,
|
||||
ProposalId=proposal_id,
|
||||
VoterMemberId=member_id,
|
||||
Vote="FOO",
|
||||
).should.throw(Exception, "Invalid request body")
|
||||
|
||||
|
||||
@mock_managedblockchain
|
||||
def test_vote_on_proposal_alreadyvoted():
|
||||
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(
|
||||
NetworkId=network_id,
|
||||
MemberId=member_id,
|
||||
Actions=helpers.default_policy_actions,
|
||||
)
|
||||
|
||||
proposal_id = response["ProposalId"]
|
||||
|
||||
# Vote yes
|
||||
response = conn.vote_on_proposal(
|
||||
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
|
||||
response = conn.create_member(
|
||||
InvitationId=invitation_id,
|
||||
NetworkId=network_id,
|
||||
MemberConfiguration=helpers.create_member_configuration(
|
||||
"testmember2", "admin", "Admin12345", False, "Test Member 2"
|
||||
),
|
||||
)
|
||||
member_id2 = response["MemberId"]
|
||||
|
||||
# Create another proposal
|
||||
response = conn.create_proposal(
|
||||
NetworkId=network_id,
|
||||
MemberId=member_id,
|
||||
Actions=helpers.default_policy_actions,
|
||||
)
|
||||
|
||||
proposal_id = response["ProposalId"]
|
||||
|
||||
# Get proposal details
|
||||
response = conn.get_proposal(NetworkId=network_id, ProposalId=proposal_id)
|
||||
response["Proposal"]["NetworkId"].should.equal(network_id)
|
||||
response["Proposal"]["Status"].should.equal("IN_PROGRESS")
|
||||
|
||||
# Vote yes with member 1
|
||||
response = conn.vote_on_proposal(
|
||||
NetworkId=network_id,
|
||||
ProposalId=proposal_id,
|
||||
VoterMemberId=member_id,
|
||||
Vote="YES",
|
||||
)
|
||||
|
||||
# Vote yes with member 1 again
|
||||
response = conn.vote_on_proposal.when.called_with(
|
||||
NetworkId=network_id,
|
||||
ProposalId=proposal_id,
|
||||
VoterMemberId=member_id,
|
||||
Vote="YES",
|
||||
).should.throw(Exception, "Invalid request body")
|
||||
|
||||
|
||||
@mock_managedblockchain
|
||||
def test_list_proposal_votes_badnetwork():
|
||||
conn = boto3.client("managedblockchain", region_name="us-east-1")
|
||||
|
||||
response = conn.list_proposal_votes.when.called_with(
|
||||
NetworkId="n-ABCDEFGHIJKLMNOP0123456789",
|
||||
ProposalId="p-ABCDEFGHIJKLMNOP0123456789",
|
||||
).should.throw(Exception, "Network n-ABCDEFGHIJKLMNOP0123456789 not found")
|
||||
|
||||
|
||||
@mock_managedblockchain
|
||||
def test_list_proposal_votes_badproposal():
|
||||
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"]
|
||||
|
||||
response = conn.list_proposal_votes.when.called_with(
|
||||
NetworkId=network_id, ProposalId="p-ABCDEFGHIJKLMNOP0123456789",
|
||||
).should.throw(Exception, "Proposal p-ABCDEFGHIJKLMNOP0123456789 not found")
|
||||
Loading…
Add table
Add a link
Reference in a new issue