def test_agreement_hash(ddo_sample): """ This test verifies generating agreement hash using fixed inputs and ddo example. This will make it easier to compare the hash generated from different languages. """ w3 = Web3 did = "did:nv:0c184915b07b44c888d468be85a9b28253e80070e5294b1aaed81c2f0264e430" template_id = w3.toChecksumAddress( "0x00bd138abd70e2f00903268f3db08f2d25677c9e") agreement_id = '0xf136d6fadecb48fdb2fc1fb420f5a5d1c32d22d9424e47ab9461556e058fefaa' sa = ServiceAgreement.from_service_dict( ddo_sample.get_service(ServiceTypes.ASSET_ACCESS).as_dictionary()) sa.service_agreement_template.set_template_id(template_id) assert template_id == sa.template_id, '' assert did == ddo_sample.did # Don't generate condition ids, use fixed ids so we get consistent hash # (access_id, lock_id, escrow_id) = sa.generate_agreement_condition_ids( # agreement_id, ddo.asset_id, consumer, publisher, keeper) access_id = '0x2d7c1d60dc0c3f52aa9bd71ffdbe434a0e58435571e64c893bc9646fea7f6ec1' lock_id = '0x1e265c434c14e668695dda1555088f0ea4356f596bdecb8058812e7dcba9ee73' escrow_id = '0xe487fa6d435c2f09ef14b65b34521302f1532ac82ba8f6c86116acd8566e2da3' print(f'condition ids: \n' f'{access_id} \n' f'{lock_id} \n' f'{escrow_id}') agreement_hash = ServiceAgreement.generate_service_agreement_hash( sa.template_id, (access_id, lock_id, escrow_id), sa.conditions_timelocks, sa.conditions_timeouts, agreement_id, generate_multi_value_hash) print('agreement hash: ', agreement_hash.hex()) expected = '0x96732b390dacec0f19ad304ac176b3407968a0184d01b3262687fd23a3f0995e' print('expected hash: ', expected) assert agreement_hash.hex() == expected, 'hash does not match.'
def test_agreement(): template_id = Web3.toChecksumAddress('0x' + ('f' * 40)) agreement_id = '0x' + ('e' * 64) access_id = '0x' + ('a' * 64) lock_id = '0x' + ('b' * 64) escrow_id = '0x' + ('c' * 64) signature = ServiceAgreement.generate_service_agreement_hash( template_id, [access_id, lock_id, escrow_id], [0, 0, 0], [0, 0, 0], agreement_id, generate_multi_value_hash) print({signature}) assert (signature == Web3.toBytes( hexstr= "0x67901517c18a3d23e05806fff7f04235cc8ae3b1f82345b8bfb3e4b02b5800c7") ), "The signature is not correct."