Skip to content

Commit

Permalink
add python hash check
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex6323 committed Dec 1, 2023
1 parent 4c81dde commit 7037102
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
8 changes: 8 additions & 0 deletions bindings/python/iota_sdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@ def transaction_id(payload: SignedTransactionPayload) -> HexStr:
'payload': payload.as_dict()
})

@staticmethod
def protocol_parameters_hash(params: ProtocolParameters) -> HexStr:
""" Compute the hash of a ProtocolParameters instance.
"""
return _call_method('protocolParametersHash', {
'protocolParameters': params.to_dict(),
})

@staticmethod
def transaction_signing_hash(transaction: Transaction) -> HexStr:
""" Compute the signing hash of a transaction.
Expand Down
12 changes: 7 additions & 5 deletions bindings/python/tests/test_protocol_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
# SPDX-License-Identifier: Apache-2.0

import json
from dacite import from_dict
from iota_sdk import ProtocolParameters
from iota_sdk import ProtocolParameters, Utils


protocol_params = {}
protocol_params_json = {}
with open('../../sdk/tests/types/fixtures/protocol_parameters.json', "r", encoding="utf-8") as json_file:
protocol_params = json.load(json_file)
protocol_params_json = json.load(json_file)

def test_protocol_parameters():
protocol_params_dict = protocol_params['params']
protocol_params_dict = protocol_params_json['params']
protocol_params = ProtocolParameters.from_dict(protocol_params_dict)
assert protocol_params.to_dict() == protocol_params_dict

expected_hash = protocol_params_json['hash']
assert Utils.protocol_parameters_hash(protocol_params) == expected_hash

0 comments on commit 7037102

Please sign in to comment.