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

chore: converting some tests to v3 #21

Merged
merged 3 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
220 changes: 120 additions & 100 deletions smart_contracts/artifacts/base_d_asa/base_d_asa_client.py

Large diffs are not rendered by default.

242 changes: 132 additions & 110 deletions smart_contracts/artifacts/fixed_coupon_bond/fixed_coupon_bond_client.py

Large diffs are not rendered by default.

242 changes: 132 additions & 110 deletions smart_contracts/artifacts/perpetual_bond/perpetual_bond_client.py

Large diffs are not rendered by default.

220 changes: 120 additions & 100 deletions smart_contracts/artifacts/zero_coupon_bond/zero_coupon_bond_client.py

Large diffs are not rendered by default.

17 changes: 12 additions & 5 deletions tests/base_d_asa/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
AssignRoleArgs,
BaseDAsaClient,
BaseDAsaFactory,
CommonAppCallParams,
OpenAccountArgs,
PrimaryDistributionArgs,
SetAssetSuspensionArgs,
Expand Down Expand Up @@ -198,7 +199,7 @@ def primary_dealer(
account_to_fund=account.address,
min_spending_balance=INITIAL_ALGO_FUNDS,
)
state = base_d_asa_client_active.send.get_global_state()
state = base_d_asa_client_active.state.global_state
role_config = utils.set_role_config(
state.primary_distribution_opening_date, state.primary_distribution_closure_date
)
Expand Down Expand Up @@ -256,11 +257,14 @@ def base_d_asa_client_primary(
) -> BaseDAsaClient:
state = base_d_asa_client_active.state.global_state.get_all()
base_d_asa_client_active.send.set_secondary_time_events(
SetSecondaryTimeEventsArgs(
secondary_market_time_events=[state.issuance_date, state.maturity_date]
args=SetSecondaryTimeEventsArgs(
secondary_market_time_events=[
state["issuance_date"],
state["maturity_date"],
aorumbayev marked this conversation as resolved.
Show resolved Hide resolved
]
)
)
utils.time_warp(state.primary_distribution_opening_date)
utils.time_warp(state["primary_distribution_opening_date"])
aorumbayev marked this conversation as resolved.
Show resolved Hide resolved
return base_d_asa_client_active


Expand Down Expand Up @@ -295,7 +299,7 @@ def base_d_asa_client_ongoing(
base_d_asa_client_primary: BaseDAsaClient,
) -> BaseDAsaClient:
state = base_d_asa_client_primary.state.global_state.get_all()
utils.time_warp(state.issuance_date)
utils.time_warp(state["issuance_date"])
aorumbayev marked this conversation as resolved.
Show resolved Hide resolved
return base_d_asa_client_primary


Expand All @@ -305,5 +309,8 @@ def base_d_asa_client_suspended(
) -> BaseDAsaClient:
base_d_asa_client_ongoing.send.set_asset_suspension(
SetAssetSuspensionArgs(suspended=True),
params=CommonAppCallParams(
sender=authority.address,
),
cusma marked this conversation as resolved.
Show resolved Hide resolved
)
return base_d_asa_client_ongoing
34 changes: 17 additions & 17 deletions tests/base_d_asa/test_asset_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,54 +29,54 @@ def test_pass_asset_config(
expected_time_events = base_d_asa_client_empty.send.get_time_events().abi_return

# Asset Configuration
assert state.denomination_asset_id() == currency.id
assert state.settlement_asset_id() == state.denomination_asset_id()
assert state.unit_value() == base_d_asa_cfg.minimum_denomination
assert state.day_count_convention() == base_d_asa_cfg.day_count_convention
assert state.denomination_asset_id == currency.id
assert state.settlement_asset_id == state.denomination_asset_id
assert state.unit_value == base_d_asa_cfg.minimum_denomination
assert state.day_count_convention == base_d_asa_cfg.day_count_convention

# Principal and Supply
assert (
state.total_units()
state.total_units
== base_d_asa_cfg.principal // base_d_asa_cfg.minimum_denomination
)
assert not state.circulating_units()
assert not state.principal_discount()
assert not state.circulating_units
assert not state.principal_discount

# Interest Rate
assert state.interest_rate() == base_d_asa_cfg.interest_rate
assert state.interest_rate == base_d_asa_cfg.interest_rate

# Coupons
assert expected_coupon_rates == base_d_asa_cfg.coupon_rates
assert state.total_coupons() == base_d_asa_cfg.total_coupons
assert state.total_coupons == base_d_asa_cfg.total_coupons

# Time Schedule
assert expected_time_events == base_d_asa_cfg.time_events
assert (
state.primary_distribution_opening_date()
state.primary_distribution_opening_date
== base_d_asa_cfg.time_events[sc_cfg.PRIMARY_DISTRIBUTION_OPENING_DATE_IDX]
# == time_schedule_limits.primary_distribution_opening_date
)
assert (
state.primary_distribution_closure_date()
state.primary_distribution_closure_date
== base_d_asa_cfg.time_events[sc_cfg.PRIMARY_DISTRIBUTION_CLOSURE_DATE_IDX]
# == time_schedule_limits.primary_distribution_closure_date
)
assert (
state.issuance_date()
state.issuance_date
== base_d_asa_cfg.time_events[sc_cfg.ISSUANCE_DATE_IDX]
# == time_schedule_limits.issuance_date
)
assert not state.secondary_market_opening_date()
assert not state.secondary_market_closure_date()
assert not state.secondary_market_opening_date
assert not state.secondary_market_closure_date
assert (
state.maturity_date()
state.maturity_date
== base_d_asa_cfg.time_events[sc_cfg.MATURITY_DATE_IDX]
# == time_schedule_limits.maturity_date
)

# Status
assert state.status() == sc_cfg.STATUS_ACTIVE
assert not state.suspended()
assert state.status == sc_cfg.STATUS_ACTIVE
assert not state.suspended


def test_fail_unauthorized(
Expand Down
36 changes: 18 additions & 18 deletions tests/base_d_asa/test_asset_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ def test_pass_asset_create(
state = base_d_asa_client.state.global_state

# Roles
assert encode_address(state.arranger()) == arranger.address
assert encode_address(state.arranger) == arranger.address

# Asset Configuration
assert not state.denomination_asset_id()
assert not state.settlement_asset_id()
assert not state.unit_value()
assert not state.day_count_convention()
assert not state.denomination_asset_id
assert not state.settlement_asset_id
assert not state.unit_value
assert not state.day_count_convention

# Metadata
assert state.metadata() == TupleType(
assert state.metadata == TupleType(
[
UintType(8), # Contract Type
UintType(8), # Calendar
Expand All @@ -63,24 +63,24 @@ def test_pass_asset_create(
)

# Principal and Supply
assert not state.total_units()
assert not state.circulating_units()
assert not state.principal_discount()
assert not state.total_units
assert not state.circulating_units
assert not state.principal_discount

# Coupons
assert not state.total_coupons()
assert not state.total_coupons

# Time Schedule
assert not state.primary_distribution_opening_date()
assert not state.primary_distribution_closure_date()
assert not state.issuance_date()
assert not state.secondary_market_opening_date()
assert not state.secondary_market_closure_date()
assert not state.maturity_date()
assert not state.primary_distribution_opening_date
assert not state.primary_distribution_closure_date
assert not state.issuance_date
assert not state.secondary_market_opening_date
assert not state.secondary_market_closure_date
assert not state.maturity_date

# Status
assert state.status() == sc_cfg.STATUS_EMPTY
assert not state.suspended()
assert state.status == sc_cfg.STATUS_EMPTY
assert not state.suspended


def test_fail_invalid_state_schema() -> None:
Expand Down
14 changes: 8 additions & 6 deletions tests/base_d_asa/test_asset_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from smart_contracts import errors as err
from smart_contracts.artifacts.base_d_asa.base_d_asa_client import (
AssetMetadata,
AssetUpdateArgs,
BaseDAsaClient,
CommonAppCallParams,
)
Expand All @@ -25,7 +26,9 @@ def test_pass_update(
prospectus_hash=bytes(32),
prospectus_url="Updated Prospectus",
)
base_d_asa_client_active.send.asset_update(metadata=updated_metadata)
base_d_asa_client_active.send.update.asset_update(
args=AssetUpdateArgs(metadata=updated_metadata)
)
metadata = base_d_asa_client_active.send.get_asset_metadata().abi_return
assert metadata.prospectus_url == updated_metadata.prospectus_url

Expand All @@ -36,9 +39,8 @@ def test_fail_unauthorized(
base_d_asa_client_active: BaseDAsaClient,
) -> None:
with pytest.raises(LogicError, match=err.UNAUTHORIZED):
base_d_asa_client_active.send.asset_update(
metadata=asset_metadata,
transaction_parameters=CommonAppCallParams(
sender=oscar.address, signer=oscar.signer
),
base_d_asa_client_active.send.update.asset_update(
args=AssetUpdateArgs(metadata=asset_metadata),
params=CommonAppCallParams(sender=oscar.address, signer=oscar.signer),
compilation_params={},
aorumbayev marked this conversation as resolved.
Show resolved Hide resolved
)
15 changes: 2 additions & 13 deletions tests/base_d_asa/test_get_time_events.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
from algokit_utils import OnCompleteCallParameters

from smart_contracts import constants as sc_cst
from smart_contracts.artifacts.base_d_asa.base_d_asa_client import BaseDAsaClient
from tests.utils import DAsaConfig


def test_pass_get_time_events(
base_d_asa_cfg: DAsaConfig, base_d_asa_client_active: BaseDAsaClient
) -> None:
time_events = base_d_asa_client_active.get_time_events(
transaction_parameters=OnCompleteCallParameters(
boxes=[(base_d_asa_client_active.app_id, sc_cst.BOX_ID_TIME_EVENTS)]
)
).return_value
time_events = base_d_asa_client_active.send.get_time_events().abi_return
assert time_events == base_d_asa_cfg.time_events


def test_pass_not_configured(base_d_asa_client_empty: BaseDAsaClient) -> None:
time_events = base_d_asa_client_empty.get_time_events(
transaction_parameters=OnCompleteCallParameters(
boxes=[(base_d_asa_client_empty.app_id, sc_cst.BOX_ID_TIME_EVENTS)]
)
).return_value
time_events = base_d_asa_client_empty.send.get_time_events().abi_return
assert not time_events
93 changes: 34 additions & 59 deletions tests/base_d_asa/test_open_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@

import pytest
from algokit_utils import (
AlgoAmount,
AlgorandClient,
LogicError,
OnCompleteCallParameters,
SigningAccount,
)

from smart_contracts import errors as err
from smart_contracts.artifacts.base_d_asa.base_d_asa_client import BaseDAsaClient
from smart_contracts.artifacts.base_d_asa.base_d_asa_client import (
BaseDAsaClient,
CommonAppCallParams,
GetAccountInfoArgs,
OpenAccountArgs,
)
from tests.utils import DAsaAccount, DAsaAccountManager

ACCOUNT_TEST_UNITS: Final[int] = 7
Expand All @@ -23,32 +28,26 @@ def test_pass_open_account(
holding = algorand.account.random()
payment = algorand.account.random()

base_d_asa_client_empty.open_account(
holding_address=holding.address,
payment_address=payment.address,
transaction_parameters=OnCompleteCallParameters(
base_d_asa_client_empty.send.open_account(
args=OpenAccountArgs(
holding_address=holding.address,
payment_address=payment.address,
),
params=CommonAppCallParams(
sender=account_manager.address,
signer=account_manager.signer,
boxes=[
(base_d_asa_client_empty.app_id, account_manager.box_id),
(
base_d_asa_client_empty.app_id,
DAsaAccount.box_id_from_address(holding.address),
),
],
static_fee=AlgoAmount.from_algo(1),
cusma marked this conversation as resolved.
Show resolved Hide resolved
),
)

d_asa_account_info = base_d_asa_client_empty.get_account_info(
holding_address=holding.address,
transaction_parameters=OnCompleteCallParameters(
boxes=[
(
base_d_asa_client_empty.app_id,
DAsaAccount.box_id_from_address(holding.address),
)
]
d_asa_account_info = base_d_asa_client_empty.send.get_account_info(
args=GetAccountInfoArgs(
holding_address=holding.address,
),
).return_value
params=CommonAppCallParams(
signer=account_manager.signer,
),
).abi_return

assert d_asa_account_info.payment_address == payment.address
assert d_asa_account_info.units == 0
Expand All @@ -66,21 +65,10 @@ def test_fail_unauthorized_caller(
payment = algorand.account.random()

with pytest.raises(LogicError, match=err.UNAUTHORIZED):
base_d_asa_client_empty.open_account(
holding_address=holding.address,
payment_address=payment.address,
transaction_parameters=OnCompleteCallParameters(
signer=oscar.signer,
boxes=[
(
base_d_asa_client_empty.app_id,
DAsaAccountManager.box_id_from_address(oscar.address),
),
(
base_d_asa_client_empty.app_id,
DAsaAccount.box_id_from_address(holding.address),
),
],
base_d_asa_client_empty.send.open_account(
args=(holding.address, payment.address),
aorumbayev marked this conversation as resolved.
Show resolved Hide resolved
params=CommonAppCallParams(
sender=oscar.address,
),
)

Expand All @@ -102,18 +90,10 @@ def test_fail_suspended(
payment = algorand.account.random()

with pytest.raises(LogicError, match=err.SUSPENDED):
base_d_asa_client_suspended.open_account(
holding_address=holding.address,
payment_address=payment.address,
transaction_parameters=OnCompleteCallParameters(
signer=account_manager.signer,
boxes=[
(base_d_asa_client_suspended.app_id, account_manager.box_id),
(
base_d_asa_client_suspended.app_id,
DAsaAccount.box_id_from_address(holding.address),
),
],
base_d_asa_client_suspended.send.open_account(
args=(holding.address, payment.address),
aorumbayev marked this conversation as resolved.
Show resolved Hide resolved
params=CommonAppCallParams(
sender=account_manager.address,
),
)

Expand All @@ -124,14 +104,9 @@ def test_fail_invalid_holding_address(
account_a: DAsaAccount,
) -> None:
with pytest.raises(LogicError, match=err.INVALID_HOLDING_ADDRESS):
base_d_asa_client_empty.open_account(
holding_address=account_a.holding_address,
payment_address=account_a.payment_address,
transaction_parameters=OnCompleteCallParameters(
signer=account_manager.signer,
boxes=[
(base_d_asa_client_empty.app_id, account_manager.box_id),
(base_d_asa_client_empty.app_id, account_a.box_id),
],
base_d_asa_client_empty.send.open_account(
args=(account_a.holding_address, account_a.payment_address),
aorumbayev marked this conversation as resolved.
Show resolved Hide resolved
params=CommonAppCallParams(
sender=account_manager.address,
),
)