hyperledger-iroha / iroha-python

Python library for Hyperledger Iroha, a simple distributed ledger.
https://wiki.hyperledger.org/display/iroha
Apache License 2.0
103 stars 81 forks source link

[BUG] TypeError when transferring asset due to incorrect argument type conversion #205

Closed AlexStroke closed 3 months ago

AlexStroke commented 4 months ago

Description: A TypeError occurs when attempting to transfer an asset in the test test_transfer_asset. The function transfer expects an argument of type AssetId, but a string is being passed instead.

Steps to Reproduce:

def test_transfer_asset(
    GIVEN_minted_asset,
    GIVEN_registered_account):
    with allure.step(
            f'WHEN client transfers an asset'):
        (client.submit_executable_only_success(
            [iroha.Instruction.
            transfer(
                5,
                GIVEN_minted_asset,
                GIVEN_registered_account)]))

Expected Behavior: The transfer function should successfully convert the string argument to the appropriate AssetId type within the Rust implementation, avoiding the TypeError.

Actual Behavior: telegram-cloud-photo-size-2-5411619597544708960-y

Code Reference:

...[pymethods]
impl PyAssetId {
    #[new]
    fn new(definition_id: PyAssetDefinitionId, account_id: PyAccountId) -> PyResult<Self> {
        Ok(Self(AssetId::new(definition_id.into(), account_id.into())))
    }

Developer's Comment: "I think this API is not good. I should change it to take a string from Python and convert inside Rust to the right type."

SamHSmith commented 3 months ago

Fixed by this PR https://github.com/hyperledger/iroha-python/pull/211