def check_privatenet(self): """ Check if privatenet is running, and if container is same as the current Chains/privnet database. Raises: PrivnetConnectionError: if the private net couldn't be reached or the nonce does not match """ rpc_settings.setup(self.RPC_LIST) client = RPCClient() version = client.get_version() if not version: raise PrivnetConnectionError("Error: private network container doesn't seem to be running, or RPC is not enabled.") print("Privatenet useragent '%s', nonce: %s" % (version["useragent"], version["nonce"])) # Now check if nonce is the same as in the chain path nonce_container = str(version["nonce"]) neopy_chain_meta_filename = os.path.join(self.chain_leveldb_path, ".privnet-nonce") if os.path.isfile(neopy_chain_meta_filename): nonce_chain = open(neopy_chain_meta_filename, "r").read() if nonce_chain != nonce_container: raise PrivnetConnectionError( "Chain database in Chains/privnet is for a different private network than the current container. " "Consider deleting the Chain directory with 'rm -rf %s/privnet*'." % self.chain_leveldb_path ) else: # When the Chains/privnet folder is removed, we need to create the directory if not os.path.isdir(self.chain_leveldb_path): os.mkdir(self.chain_leveldb_path) # Write the nonce to the meta file with open(neopy_chain_meta_filename, "w") as f: f.write(nonce_container)
def check_privatenet(self): """ Check if privatenet is running, and if container is same as the current Chains/privnet database. Raises: PrivnetConnectionError: if the private net couldn't be reached or the nonce does not match """ rpc_settings.setup(self.RPC_LIST) client = RPCClient() version = client.get_version() if not version: raise PrivnetConnectionError("Error: private network container doesn't seem to be running, or RPC is not enabled.") print("Privatenet useragent '%s', nonce: %s" % (version["useragent"], version["nonce"])) # Now check if nonce is the same as in the chain path nonce_container = str(version["nonce"]) neopy_chain_meta_filename = os.path.join(self.chain_leveldb_path, ".privnet-nonce") if os.path.isfile(neopy_chain_meta_filename): nonce_chain = open(neopy_chain_meta_filename, "r").read() if nonce_chain != nonce_container: raise PrivnetConnectionError( "Chain database in Chains/privnet is for a different private network than the current container. " "Consider deleting the Chain directory with 'rm -rf %s*'." % self.chain_leveldb_path ) else: # When the Chains/privnet folder is removed, we need to create the directory if not os.path.isdir(self.chain_leveldb_path): os.mkdir(self.chain_leveldb_path) # Write the nonce to the meta file with open(neopy_chain_meta_filename, "w") as f: f.write(nonce_container)
def test_get_version(self): client = RPCClient() version = client.get_version() self.assertIn("port", version) self.assertIn("nonce", version) self.assertIn("useragent", version)