def test_new_from_user_input_sets_good_keys(self, mock_ping): # Good hex key without 0x privkey = "7796b9ac433fab2a83d281e8064f29c935133139b62ec52c8e73de28440c0dc6" client_a = bnb.new_from_user_input({ "version": "1", "name": "banana", "testnet": True, "private_key": privkey }) # Good hex key with 0x client_b = bnb.new_from_user_input({ "version": "1", "name": "banana", "testnet": True, "private_key": f"0x{privkey}" }) # Good key from mnemonic string mnemonic = ("banana " * 24).rstrip() client_c = bnb.new_from_user_input({ "version": "1", "name": "banana", "testnet": True, "private_key": mnemonic }) from_hex = b"w\x96\xb9\xacC?\xab*\x83\xd2\x81\xe8\x06O)\xc95\x1319\xb6.\xc5,\x8es\xde(D\x0c\r\xc6" from_mem = b"\xc6G\xd2\xdf\xdb\x97\xb3B`\x82Yx\xe7\x10\xf9g\x0bY\xc7o\xa8n\xd0m\xf7\x07\xadv'\t\x17_" # Assertions: self.assertEqual(base64.b64decode(client_a.b64_private_key), from_hex) self.assertEqual(base64.b64decode(client_b.b64_private_key), from_hex) self.assertEqual(base64.b64decode(client_c.b64_private_key), from_mem)
def create_binance_interchain_v1( user_data: Dict[str, Any], conflict_check: bool = True) -> Dict[str, Any]: client = bnb.new_from_user_input(user_data) if conflict_check and interchain_dao.does_interchain_exist( "binance", client.name): _log.error("Binance network is already registered") raise exceptions.InterchainConflict( f"A binance interchain network with the name {client.name} is already registered" ) interchain_dao.save_interchain_client(client) return _get_output_dto_v1(client)
def test_new_from_user_input_no_testnet_parameter(self, mock_ping): # missing "testnet" parameter: user_input = { "version": "1", "name": "banana", "node_url": "b.a.n.a.n.a", "rpc_port": 27147, "api_port": 1169, "testnet": None, "private_key": "SVuyo/Ip6wq7K/caPcpWsx1gwSjf2B6ekH5e7bZ/GaA=", } client = bnb.new_from_user_input(user_input) self.assertTrue(client.testnet) # if None, should get set to True
def test_from_user_input_works_with_no_provided_key(self, mock_ping): client = bnb.new_from_user_input({ "version": "1", "name": "no_private_key", "node_url": "b.a.n.a.n.a", "rpc_port": 27147, "api_port": 1169, "testnet": True }) mock_ping.assert_called_once() self.assertEqual(client.name, "no_private_key") self.assertEqual(client.node_url, "b.a.n.a.n.a") self.assertEqual(client.rpc_port, 27147) self.assertEqual(client.api_port, 1169) self.assertTrue(client.testnet)