| 
									
										
										
										
											2020-05-03 18:13:40 -05:00
										 |  |  | import boto3 | 
					
						
							| 
									
										
										
										
											2021-05-13 10:36:56 +01:00
										 |  |  | import pytest | 
					
						
							|  |  |  | from botocore.exceptions import ClientError | 
					
						
							| 
									
										
										
										
											2023-11-30 07:55:51 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-03 18:13:40 -05: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 | 
					
						
							| 
									
										
										
										
											2020-05-06 21:12:48 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-03 18:13:40 -05:00
										 |  |  | @mock_managedblockchain | 
					
						
							|  |  |  | def test_create_network(): | 
					
						
							|  |  |  |     conn = boto3.client("managedblockchain", region_name="us-east-1") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-06 21:12:48 -05:00
										 |  |  |     response = conn.create_network( | 
					
						
							|  |  |  |         Name="testnetwork1", | 
					
						
							|  |  |  |         Framework="HYPERLEDGER_FABRIC", | 
					
						
							|  |  |  |         FrameworkVersion="1.2", | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  |         FrameworkConfiguration=helpers.default_frameworkconfiguration, | 
					
						
							|  |  |  |         VotingPolicy=helpers.default_votingpolicy, | 
					
						
							|  |  |  |         MemberConfiguration=helpers.default_memberconfiguration, | 
					
						
							| 
									
										
										
										
											2020-05-06 21:12:48 -05:00
										 |  |  |     ) | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  |     network_id = response["NetworkId"] | 
					
						
							|  |  |  |     member_id = response["MemberId"] | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     assert network_id.startswith("n-") | 
					
						
							|  |  |  |     assert len(network_id) == 28 | 
					
						
							|  |  |  |     assert member_id.startswith("m-") | 
					
						
							|  |  |  |     assert len(member_id) == 28 | 
					
						
							| 
									
										
										
										
											2020-05-03 18:13:40 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-06 21:12:48 -05:00
										 |  |  |     # Find in full list | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     mbcnetworks = conn.list_networks()["Networks"] | 
					
						
							|  |  |  |     assert len(mbcnetworks) == 1 | 
					
						
							|  |  |  |     assert mbcnetworks[0]["Name"] == "testnetwork1" | 
					
						
							| 
									
										
										
										
											2020-05-06 21:12:48 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Get network details | 
					
						
							|  |  |  |     response = conn.get_network(NetworkId=network_id) | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     assert response["Network"]["Name"] == "testnetwork1" | 
					
						
							| 
									
										
										
										
											2020-05-03 18:13:40 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-06 21:12:48 -05:00
										 |  |  | @mock_managedblockchain | 
					
						
							| 
									
										
										
										
											2023-09-01 07:07:54 +00:00
										 |  |  | def test_create_network_with_description(): | 
					
						
							| 
									
										
										
										
											2020-05-06 21:12:48 -05:00
										 |  |  |     conn = boto3.client("managedblockchain", region_name="us-east-1") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = conn.create_network( | 
					
						
							| 
									
										
										
										
											2020-05-03 18:13:40 -05:00
										 |  |  |         Name="testnetwork1", | 
					
						
							|  |  |  |         Description="Test Network 1", | 
					
						
							|  |  |  |         Framework="HYPERLEDGER_FABRIC", | 
					
						
							|  |  |  |         FrameworkVersion="1.2", | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  |         FrameworkConfiguration=helpers.default_frameworkconfiguration, | 
					
						
							|  |  |  |         VotingPolicy=helpers.default_votingpolicy, | 
					
						
							|  |  |  |         MemberConfiguration=helpers.default_memberconfiguration, | 
					
						
							| 
									
										
										
										
											2020-05-03 18:13:40 -05:00
										 |  |  |     ) | 
					
						
							| 
									
										
										
										
											2020-05-13 06:28:22 -05:00
										 |  |  |     network_id = response["NetworkId"] | 
					
						
							| 
									
										
										
										
											2020-05-03 18:13:40 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Find in full list | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     mbcnetworks = conn.list_networks()["Networks"] | 
					
						
							|  |  |  |     assert len(mbcnetworks) == 1 | 
					
						
							|  |  |  |     assert mbcnetworks[0]["Description"] == "Test Network 1" | 
					
						
							| 
									
										
										
										
											2020-05-03 18:13:40 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Get network details | 
					
						
							|  |  |  |     response = conn.get_network(NetworkId=network_id) | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     assert response["Network"]["Description"] == "Test Network 1" | 
					
						
							| 
									
										
										
										
											2020-05-06 21:12:48 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_managedblockchain | 
					
						
							|  |  |  | def test_create_network_noframework(): | 
					
						
							|  |  |  |     conn = boto3.client("managedblockchain", region_name="us-east-1") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-13 10:36:56 +01:00
										 |  |  |     with pytest.raises(ClientError) as ex: | 
					
						
							|  |  |  |         conn.create_network( | 
					
						
							|  |  |  |             Name="testnetwork1", | 
					
						
							|  |  |  |             Description="Test Network 1", | 
					
						
							|  |  |  |             Framework="HYPERLEDGER_VINYL", | 
					
						
							|  |  |  |             FrameworkVersion="1.2", | 
					
						
							|  |  |  |             FrameworkConfiguration=helpers.default_frameworkconfiguration, | 
					
						
							|  |  |  |             VotingPolicy=helpers.default_votingpolicy, | 
					
						
							|  |  |  |             MemberConfiguration=helpers.default_memberconfiguration, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |     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-06 21:12:48 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_managedblockchain | 
					
						
							|  |  |  | def test_create_network_badframeworkver(): | 
					
						
							|  |  |  |     conn = boto3.client("managedblockchain", region_name="us-east-1") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-13 10:36:56 +01:00
										 |  |  |     with pytest.raises(ClientError) as ex: | 
					
						
							|  |  |  |         conn.create_network( | 
					
						
							|  |  |  |             Name="testnetwork1", | 
					
						
							|  |  |  |             Description="Test Network 1", | 
					
						
							|  |  |  |             Framework="HYPERLEDGER_FABRIC", | 
					
						
							|  |  |  |             FrameworkVersion="1.X", | 
					
						
							|  |  |  |             FrameworkConfiguration=helpers.default_frameworkconfiguration, | 
					
						
							|  |  |  |             VotingPolicy=helpers.default_votingpolicy, | 
					
						
							|  |  |  |             MemberConfiguration=helpers.default_memberconfiguration, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |     err = ex.value.response["Error"] | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |     assert err["Code"] == "BadRequestException" | 
					
						
							|  |  |  |     assert ( | 
					
						
							| 
									
										
										
										
											2021-05-13 10:36:56 +01:00
										 |  |  |         "Invalid version 1.X requested for framework HYPERLEDGER_FABRIC" | 
					
						
							| 
									
										
										
										
											2023-08-13 10:15:19 +00:00
										 |  |  |         in err["Message"] | 
					
						
							| 
									
										
										
										
											2020-05-06 21:12:48 -05:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_managedblockchain | 
					
						
							|  |  |  | def test_create_network_badedition(): | 
					
						
							|  |  |  |     conn = boto3.client("managedblockchain", region_name="us-east-1") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     frameworkconfiguration = {"Fabric": {"Edition": "SUPER"}} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-13 10:36:56 +01:00
										 |  |  |     with pytest.raises(ClientError) as ex: | 
					
						
							|  |  |  |         conn.create_network( | 
					
						
							|  |  |  |             Name="testnetwork1", | 
					
						
							|  |  |  |             Description="Test Network 1", | 
					
						
							|  |  |  |             Framework="HYPERLEDGER_FABRIC", | 
					
						
							|  |  |  |             FrameworkVersion="1.2", | 
					
						
							|  |  |  |             FrameworkConfiguration=frameworkconfiguration, | 
					
						
							|  |  |  |             VotingPolicy=helpers.default_votingpolicy, | 
					
						
							|  |  |  |             MemberConfiguration=helpers.default_memberconfiguration, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |     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-06 21:54:59 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_managedblockchain | 
					
						
							|  |  |  | def test_get_network_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.get_network(NetworkId="n-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"] |