def test_1_service_init(self): # -y: accept defaults for any argument that is not provided argv = ["service", "init", "-y"] parser = arguments.get_root_parser(self.config) args = parser.parse_args(argv) service_cmd = ServiceCommand(self.config, args, out_f=self.output_f, err_f=self.output_f) # Init (create) a new service json file service_cmd.init() response = self.output_f.getvalue().strip() # Response: # { # "name": "snet-cli-testing", # "service_spec": "service_spec/", # "organization": "", # "path": "", # "price": 0, # "endpoint": "", # "tags": [], # "metadata": { # "description": "" # } # } self.assertIn("name", response) self.assertIn("service_spec", response) self.assertIn("organization", response)
def test_4_service_delete(self): no_confirm = "--no-confirm" gas_price_f = "--gas-price" gas_price = "1000000000" argv = [ "service", "delete", no_confirm, gas_price_f, gas_price, self.service_json["organization"], self.service_json["name"] ] parser = arguments.get_root_parser(self.config) args = parser.parse_args(argv) service_cmd = ServiceCommand(self.config, args, out_f=self.output_f, err_f=self.output_f) # Delete the service on network service_cmd.delete() response = self.output_f.getvalue().strip() # Response: # Removing current contract address from session... # # unset current_agent_at # # Service was deleted! self.assertIn("Service was deleted!", response)
def test_3_org_create(self): no_confirm = "--no-confirm" gas_price_f = "--gas-price" gas_price = "1000000000" org_name = "NEW_ORG_TEST" member_1 = "0x0123456789012345678901234567890123456789" member_2 = "0x2222222222222222222222222222222222222222" member_3 = "0x3333333333333333333333333333333333333333" members = "{},{},{}".format(member_1, member_2, member_3) argv = [ "organization", "create", no_confirm, gas_price_f, gas_price, org_name, members ] parser = arguments.get_root_parser(self.config) args = parser.parse_args(argv) org_cmd = OrganizationCommand(self.config, args, out_f=self.output_f, err_f=self.output_f) # Create NEW_ORG_TEST org_cmd.create() # Try to create NEW_ORG_TEST again org_cmd.create() response = self.output_f.getvalue().strip() # Response (org already exists): # [0] NEW_ORG_TEST already exists! self.assertIn("NEW_ORG_TEST already exists", response)
def test_9_org_change_owner(self): no_confirm = "--no-confirm" gas_price_f = "--gas-price" gas_price = "1000000000" org_name = "NEW_ORG_TEST" new_owner = "0x7fA3FBCFAc5c56367cB33821968Fc8c086199989" argv = [ "organization", "change-owner", no_confirm, gas_price_f, gas_price, org_name, new_owner ] parser = arguments.get_root_parser(self.config) args = parser.parse_args(argv) org_cmd = OrganizationCommand(self.config, args, out_f=self.output_f, err_f=self.output_f) # Change owner of NEW_ORG_TEST (doesn't exist anymore...) # If you change the NEW_ORG_TEST's owner you'll have to change your # session private_key (new owner) to keep interacting with it. org_cmd.change_owner() response = self.output_f.getvalue().strip() # Response (org must exist): # [0] Creating transaction to change organization NEW_ORG_TEST's owner... # [-] But: NEW_ORG_TEST doesn't exist! self.assertIn("NEW_ORG_TEST doesn't exist!", response)
def test_2_org_info(self): org_name = "SNET_BH" argv = ["organization", "info", org_name] parser = arguments.get_root_parser(self.config) args = parser.parse_args(argv) org_cmd = OrganizationCommand(self.config, args, out_f=self.output_f, err_f=self.output_f) # Get information about an Organization org_cmd.info() response = self.output_f.getvalue().strip() # Response: # Owner: # - OWNER_ADDRESS # # Members: # - MEMBER_1_ADDRESS # - MEMBER_2_ADDRESS # - MEMBER_n_ADDRESS # # Services: # - SERVICE_NAME_1 # - SERVICE_NAME_2 # - SERVICE_NAME_n self.assertIn("Owner:", response) self.assertIn("Members", response) self.assertIn("Services:", response)
def test_8_org_delete_nonexistent(self): no_confirm = "--no-confirm" gas_price_f = "--gas-price" gas_price = "1000000000" org_name = "NEW_ORG_TEST" argv = [ "organization", "delete", no_confirm, gas_price_f, gas_price, org_name ] parser = arguments.get_root_parser(self.config) args = parser.parse_args(argv) org_cmd = OrganizationCommand(self.config, args, out_f=self.output_f, err_f=self.output_f) # Delete NEW_ORG_TEST org_cmd.delete() response = self.output_f.getvalue().strip() # Response: # [0] NEW_ORG_TEST doesn't exist! self.assertIn("NEW_ORG_TEST doesn't exist!", response)
def test_7_org_delete_existent(self): no_confirm = "--no-confirm" gas_price_f = "--gas-price" gas_price = "1000000000" org_name = "NEW_ORG_TEST" argv = [ "organization", "delete", no_confirm, gas_price_f, gas_price, org_name ] parser = arguments.get_root_parser(self.config) args = parser.parse_args(argv) org_cmd = OrganizationCommand(self.config, args, out_f=self.output_f, err_f=self.output_f) # Delete NEW_ORG_TEST org_cmd.delete() response = self.output_f.getvalue().strip() # Response: # [0] Creating transaction to delete organization NEW_ORG_TEST... # [1] Submitting transaction... self.assertIn( "Creating transaction to delete organization NEW_ORG_TEST...", response)
def test_6_org_rem_members(self): no_confirm = "--no-confirm" gas_price_f = "--gas-price" gas_price = "1000000000" org_name = "NEW_ORG_TEST" member_1 = "0x2222222222222222222222222222222222222222" member_2 = "0x3333333333333333333333333333333333333333" members = "{},{}".format(member_1, member_2) argv = [ "organization", "rem-members", no_confirm, gas_price_f, gas_price, org_name, members ] parser = arguments.get_root_parser(self.config) args = parser.parse_args(argv) org_cmd = OrganizationCommand(self.config, args, out_f=self.output_f, err_f=self.output_f) # Remove members from NEW_ORG_TEST org_cmd.rem_members() response = self.output_f.getvalue().strip() # Response (org must exists): # [0] Creating transaction to remove [n] members from organization NEW_ORG_TEST... self.assertIn("Creating transaction to remove", response)
def test_3_service_update(self): no_confirm = "--no-confirm" gas_price_f = "--gas-price" gas_price = "1000000000" argv = ["service", "update", no_confirm, gas_price_f, gas_price] parser = arguments.get_root_parser(self.config) args = parser.parse_args(argv) service_cmd = ServiceCommand(self.config, args, out_f=self.output_f, err_f=self.output_f) self._service_json(update=True, price=2, endpoint="http://localhost:7777") if not os.path.exists("service_spec/"): os.makedirs("service_spec/") # Update a published service service_cmd.update() if os.path.exists("service_spec/"): shutil.rmtree("service_spec/") response = self.output_f.getvalue().strip() # Response: # Service is updated! self.assertIn("Service is updated!", response)
def test_2_service_publish(self): no_confirm = "--no-confirm" gas_price_f = "--gas-price" gas_price = "1000000000" argv = ["service", "publish", no_confirm, gas_price_f, gas_price] parser = arguments.get_root_parser(self.config) args = parser.parse_args(argv) service_cmd = ServiceCommand(self.config, args, out_f=self.output_f, err_f=self.output_f) self._service_json() if not os.path.exists("service_spec/"): os.makedirs("service_spec/") # Publish the service on network service_cmd.publish() if os.path.exists("service_spec/"): shutil.rmtree("service_spec/") response = self.output_f.getvalue().strip() # Response: # Service published! self.assertIn("Service published!", response)
def main(): argv = sys.argv[1:] parser = arguments.get_root_parser(conf) try: args = parser.parse_args(argv) except TypeError: args = parser.parse_args(argv + ["-h"]) getattr(args.cmd(conf, args), args.fn)()
def main(): argv = sys.argv[1:] parser = arguments.get_root_parser(conf) try: args = parser.parse_args(argv) except TypeError: args = parser.parse_args(argv + ["-h"]) try: getattr(args.cmd(conf, args), args.fn)() except Exception as e: if (args.print_traceback): raise else: print("Error:", e) print("If you want to see full Traceback then run:") print("snet --print-traceback [parameters]")
def test_3_session_unset(self): argv = ["unset", "current_agent_at"] parser = arguments.get_root_parser(self.config) args = parser.parse_args(argv) session_cmd = SessionCommand(self.config, args, out_f=self.output_f, err_f=self.output_f) # Unset session key 'current_agent_at' session_cmd.unset() response = self.output_f.getvalue().strip() # Response (if current_agent_at is set): # [0] unset current_agent_at # Response (if current_agent_at is not set): # [0] (no output) self.assertEqual(" ".join(argv), response)
def test_1_org_list(self): argv = ["organization", "list"] parser = arguments.get_root_parser(self.config) args = parser.parse_args(argv) org_cmd = OrganizationCommand(self.config, args, out_f=self.output_f, err_f=self.output_f) # List all registered Organizations org_cmd.list() response = self.output_f.getvalue().strip() # Response: # [0] List of Organizations: # [1] - ORG_NAME_1 # [2] - ORG_NAME_2 # [n] - ORG_NAME_n self.assertGreaterEqual(len(response.split('\n')), 1)
def test_2_session_set(self): argv = [ "set", "current_agent_at", "0x2222222222222222222222222222222222222222" ] parser = arguments.get_root_parser(self.config) args = parser.parse_args(argv) session_cmd = SessionCommand(self.config, args, out_f=self.output_f, err_f=self.output_f) # Set session key 'current_agent_at' session_cmd.set() response = self.output_f.getvalue().strip() # Response: # [0] set current_agent_at 0x2222222222222222222222222222222222222222 self.assertEqual(" ".join(argv), response)
def test_4_org_list_services(self): org_name = "SNET_BH" argv = ["organization", "list-services", org_name] parser = arguments.get_root_parser(self.config) args = parser.parse_args(argv) org_cmd = OrganizationCommand(self.config, args, out_f=self.output_f, err_f=self.output_f) # List all organization's services org_cmd.list_services() response = self.output_f.getvalue().strip() # Response: # [0] List of ORG_NAME's Services: # [1] - SERVICE_NAME_1 # [2] - SERVICE_NAME_2 # [n] - SERVICE_NAME_n self.assertGreaterEqual(len(response.split('\n')), 1)
def test_1_session_show(self): argv = ["session"] parser = arguments.get_root_parser(self.config) args = parser.parse_args(argv) session_cmd = SessionCommand(self.config, args, out_f=self.output_f, err_f=self.output_f) # Show session keys session_cmd.show() response = self.output_f.getvalue().strip() # Response: # [0] session: # default_eth_rpc_endpoint: https://kovan.infura.io # default_gas_price: '1000000000' # default_wallet_index: '0' # identity_name: MY_ID self.assertGreaterEqual(len(response.split('\n')), 1)
def main(): try: argv = sys.argv[1:] conf = Config() parser = arguments.get_root_parser(conf) argcomplete.autocomplete(parser) try: args = parser.parse_args(argv) except TypeError: args = parser.parse_args(argv + ["-h"]) getattr(args.cmd(conf, args), args.fn)() except Exception as e: if (sys.argv[1] == "--print-traceback"): raise else: print("Error:", e) print("If you want to see full Traceback then run:") print("snet --print-traceback [parameters]") sys.exit(42)