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(marketplace): catch Marketplace_SlotIsFree and continue the cancelled process #1139

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

2-towns
Copy link
Contributor

@2-towns 2-towns commented Mar 3, 2025

Fix #1138

@2-towns 2-towns marked this pull request as ready for review March 3, 2025 11:16
@2-towns 2-towns self-assigned this Mar 6, 2025
@2-towns 2-towns added Marketplace See https://miro.com/app/board/uXjVNZ03E-c=/ for details and removed Marketplace See https://miro.com/app/board/uXjVNZ03E-c=/ for details labels Mar 6, 2025
try:
await market.freeSlot(slot.id)
except Marketplace_SlotIsFree as e:
info "The slot cannot be freed because it is already free."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this was a SP that had filled a slot, and the slot could not be freed, I would think this should be a warning. However, in other cases, this is normal behaviour. So I'd probably reduce this to a debug level because in either case, it's not essential that the user sees the log and we don't really need it to display in default Codex logging settings.

@@ -381,8 +384,8 @@ method canReserveSlot*(
func setCanReserveSlot*(market: MockMarket, canReserveSlot: bool) =
market.canReserveSlot = canReserveSlot

func setReserveSlotThrowError*(market: MockMarket, error: ?(ref MarketError)) =
market.reserveSlotThrowError = error
func setSlotThrowError*(market: MockMarket, error: ?(ref CatchableError)) =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Along the lines of the comment in the other PR, i'd make this specific to freeSlot, ie setErrorOnFreeSlot

await market.freeSlot(slot.id)

let error = newException(SaleFailedError, "Sale failed")
return some State(SaleErrored(error: error))
except CancelledError as e:
trace "SaleFailed.run was cancelled", error = e.msgDetail
except Marketplace_SlotIsFree as e:
info "The slot cannot be freed because it is already free.", error = e.msg
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, re: info -> debug

)

let error = newException(Marketplace_SlotIsFree, "")
market.setSlotThrowError(some cast[ref CatchableError](error))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment in other PR regarding use of generics to prevent a conversion/cast.

Comment on lines +45 to +47
returnBytesWas = bool.none
reprocessSlotWas = bool.none
returnedCollateralValue = UInt256.none
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be in setup, no?

Comment on lines +74 to +77
discard await state.run(agent)
check eventually returnBytesWas == some true
check eventually reprocessSlotWas == some false
check eventually returnedCollateralValue == some currentCollateral
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think maybe we can improve the assumptions we're testing here because although we call onCleanUp directly in run, we might also go to SaleErrored in run which also calls onCleanUp, and I believe this test passes because the returned collateral in onCleanUp is not the default value of none, which makes this test a bit fragile. We should instead maybe split this between two tests:

  1. Moves to SaleErrored if an unexpected error is raised
  2. Remains in SaleCancelled if "slot not free" error is raised

The test here covers #2, but would just need to check await state.run(agent) == none State instead of checking the values of onCleanUp that were called.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] calling market.freeSlot in SaleCancelled causes exception when slot not filled
2 participants