#Asset problems in test optInAsset function

5 messages · Page 1 of 1 (latest)

atomic maple
#

Hello Algo friends! I am learning to work with Algorand Python to make an app that exchanges loyalty points. I wrote my smart contract and now i want to write unit tests for it. When i tried to run the tests it has some problem with the test assets that i created. I don't understand who needs to opt in the assets because the "seller" puts assets in the contract and the "buyer" will buy the assets and will pay with other type of asset(for exemple the buyer puts in the contract 5 TacoBellPoints and exchanges 1 TacoBell point for 2 McDonaldsPoints). Bouth types of assets need to be optedIn? Bellow i will provide the code for the contract and the test code.

hybrid sorrel
#

Did you launch the localnet before running the test?

atomic maple
#

Yes

hybrid sorrel
#

oh I didn't see the entire error message haha. yeah so "unavailable asset" error happens when you don't provide the asset as an available resource to the contract.

#
    result1 = loyalty_exchange_contract_client.opt_in_to_assets(
        mbrPay=TransactionWithSigner(txn=mbr_pay_txn1, signer=creator.signer),
        transaction_parameters=algokit_utils.TransactionParameters(
            # We are using this asset in the contract , thus we need to tell the AVM that we using this asset
            foreign_assets=[test_asset_id1]
        ),
    )

here you provide reference to only one asset but according to your contract method, you are opting into 2 assets. so just add the asset id of the second asset in the foreign_assets array and it should work.