2

Getting this error ONLY when deploying the smartpy contract. There are otherwise no errors when testing/compiling the code. Is there a way to get a better error message? Is there a way to trigger these errors without having to deploy the contract? It's hard to understand exactly what is wrong with the data I'm storing.

enter image description here Error:

failed(permanent: proto.008-PtEdo2Zk.michelson_v1.ill_typed_contract), (permanent: proto.008-PtEdo2Zk.michelson_v1.bad_stack), (permanent: proto.008-PtEdo2Zk.michelson_v1.bad_stack_item), (permanent: proto.008-PtEdo2Zk.michelson_v1.inconsistent_types), (permanent: proto.008-PtEdo2Zk.michelson_v1.inconsistent_annotations)

The culprit for this exception is the storage for TZOrder.purchased_items

class TZOrder:
    """
        Stored confirmed order.
    """
    def get_type():
        return sp.TRecord(
            buyer = sp.TAddress, 
            total_cost=sp.TNat, 
            purchased_items = sp.TList(TZItemOrderData.get_type())
        ).layout(( "buyer", ("total_cost", ("purchased_items"))))

    def make(buyer, total_cost, date, purchased_items):
        return sp.set_type_expr(
            sp.record(buyer = buyer, total_cost = total_cost, purchased_items = purchased_items),
            TZOrder.get_type())


@sp.entry_point
    def buy_item(self, params):
        sp.set_type(params.checkout, TZCheckoutParams.get_type())
        tz_item_orders_data = sp.local('tz_item_orders_data', sp.list())

        sp.for item_to_purchase in params.checkout.items_to_purchase.items():
            sp.set_type(item_to_purchase, sp.TRecord(key = sp.TNat, value = sp.TNat))
            
            # verify item exists
            sp.verify(self.data.shop_items.contains(item_to_purchase.key), message=TZErrorMessage.ITEM_DOESNT_EXIST)

            # verify there is enough inventory
            sp.verify(self.data.shop_items[item_to_purchase.key].amount >= item_to_purchase.value, message=TZErrorMessage.NOT_ENOUGH_INVENTORY)
            
            # deduct amount that was bought
            self.data.shop_items[item_to_purchase.key].amount = sp.as_nat(self.data.shop_items[item_to_purchase.key].amount - item_to_purchase.value)

            # append to list to save under the Order model
            tz_item_orders_data.value.push(TZItemOrderData.make(item_to_purchase.key,item_to_purchase.value))
        # ensure order id isn't already taken
        sp.verify(~self.data.orders.contains(self.data.next_order_id), message=TZErrorMessage.ID_ALREADY_IN_USE)

        self.data.orders[self.data.next_order_id] = TZOrder.make(
            sp.sender,
            # self.data.next_order_id,
            sp.as_nat(0),
            sp.now,
            tz_item_orders_data.value
        )

Full code here

1 Answer 1

2

That was fixed in granadanet by this merge request: https://gitlab.com/tezos/tezos/-/merge_requests/2815

You need to add self.add_flag("initial-cast") in the contract constructor to solve the issue until mainnet adopts the new protocol.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.