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

Runtime error in read-only function but test passes #998

Closed
MarvinJanssen opened this issue May 9, 2023 · 3 comments
Closed

Runtime error in read-only function but test passes #998

MarvinJanssen opened this issue May 9, 2023 · 3 comments
Assignees
Milestone

Comments

@MarvinJanssen
Copy link

I am writing a unit test for a public function. Inside that public function I call into a read-only function that encounters a runtime error (failed unwrap-panic), however the test runner still reports the test as OK.

Example:

(define-map example uint bool)

(define-read-only (this-fails)
	(unwrap-panic (map-get? example u0))
)

(define-public (test-something)
	(begin
		(this-fails)
		(ok true)
	)
)

clarinet test output:

Readonly Contract call runtime error: ST1....contract-name::test-something() -> Runtime Error: Runtime error while interpreting ST1....contract-call: Runtime(UnwrapFailure, Some([FunctionIdentifier { identifier: "ST1....contract-name:test-something" }, FunctionIdentifier { identifier: "ST1....contract-name:this-fails" }, FunctionIdentifier { identifier: "_native_:native_unwrap" }]))
.file.ts => test-something ... ok (19ms)
@smcclellan
Copy link
Contributor

@hugocaillard to investigate.

@hugocaillard
Copy link
Collaborator

Hey @MarvinJanssen

Currently, a runtime error in clarity won't make the test fail.

    const block = chain.mineBlock([
      Tx.contractCall(
        "contract",
        "will-panic", // will run time error
        [],
        wallet_1.address
      ),
    ]); // won't throw an error

So the test has to actually check the result of the call or the block height or something like assertEquals(block.receipts.length, 1).

Does that make sense?

Also we are currently thinking about revamping clarinet test so we could definitely consider changing this behavior (so that a clarity runtime error throws an error on the JS side)

@hugocaillard
Copy link
Collaborator

I'll close for now, it'll be considered as part of #1052 (and following issues)

@github-project-automation github-project-automation bot moved this from 🆕 New to ✅ Done in DevTools Jun 21, 2023
@smcclellan smcclellan added this to the Q2-2023 milestone Jun 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

3 participants