Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Asset from_model bug to use passed in asset_id when initializing #46

Merged
merged 3 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

### Fixed
- Fix bug in `Asset.from_model` where passed in asset ID was not used when creating a gwei or wei asset.

## [0.10.3] - 2024-11-07

### Added
Expand Down
2 changes: 1 addition & 1 deletion cdp/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def from_model(cls, model: AssetModel, asset_id: str | None = None) -> "Asset":

return cls(
network_id=model.network_id,
asset_id=model.asset_id,
asset_id=asset_id or model.asset_id,
contract_address=model.contract_address,
decimals=decimals,
)
Expand Down
2 changes: 2 additions & 0 deletions tests/test_asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def test_asset_from_model_with_gwei(asset_model_factory):
asset_model = asset_model_factory(asset_id="eth", decimals=18)

asset = Asset.from_model(asset_model, asset_id="gwei")
assert asset.asset_id == "gwei"
assert asset.decimals == 9


Expand All @@ -40,6 +41,7 @@ def test_asset_from_model_with_wei(asset_model_factory):
asset_model = asset_model_factory(asset_id="eth", decimals=18)

asset = Asset.from_model(asset_model, asset_id="wei")
assert asset.asset_id == "wei"
assert asset.decimals == 0


Expand Down
2 changes: 1 addition & 1 deletion tests/test_balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_balance_from_model_with_asset_id(balance_model_factory):
balance = Balance.from_model(balance_model, asset_id="gwei")
assert balance.amount == Decimal("1000000000")
assert isinstance(balance.asset, Asset)
assert balance.asset.asset_id == "eth"
assert balance.asset.asset_id == "gwei"
assert balance.asset_id == "gwei"


Expand Down
Loading