def test_generate_hash_key_uses_shalib256_digested_hmac_hexdigests(): url = "http://test.net" privkey = b"my_private_key" strategy = GAS_STRATEGIES["FAST"] expected = hmac.new(privkey, (url + strategy.__name__).encode("UTF-8"), hashlib.sha256).hexdigest() assert generate_hash_key(url, privkey, strategy) == expected
def test_getitem_with_valid_tuple_creates_stores_and_returns_rpc_instance( self, mock_rpc_client, valid_tuple): registry = RPCRegistry() chain_url, privkey, *strategy = valid_tuple expected_id = generate_hash_key(chain_url, privkey) # Assert the registry does not have the instance. with pytest.raises(werkzeug.exceptions.NotFound): registry[expected_id] instance, actual_id = registry[valid_tuple] mock_rpc_client.assert_called_once() assert actual_id == expected_id assert isinstance(instance, JSONRPCClient) assert registry[actual_id] == (instance, actual_id)
def test_getitem_with_valid_tuple_creates_stores_and_returns_rpc_instance( self, mock_parent, valid_tuple): registry = RPCRegistry() chain_url, privkey, strategy = ( "https://test.net", b"12345678909876543211234567890098", GAS_STRATEGIES["FAST"], ) expected_id = generate_hash_key(chain_url, privkey, strategy) # Assert the registry does not have the instance. with pytest.raises(KeyError): registry[expected_id] instance = registry[valid_tuple] assert instance.client_id == expected_id assert isinstance(instance, RPCClient) assert registry[instance.client_id] == instance
def rpc_client_id(deserialized_create_rpc_instance_request_parameters): params = deserialized_create_rpc_instance_request_parameters return generate_hash_key(params["chain_url"], params["privkey"], GAS_STRATEGIES["FAST"])
def test_generate_hash_key_uses_shalib256_digested_hmac_hexdigests(): url = "http://test.net" privkey = b"my_private_key" expected = hmac.new(privkey, url.encode("UTF-8"), hashlib.sha256).hexdigest() assert generate_hash_key(url, privkey) == expected