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

[Cadence Testing Framework] Pretty Print Error Messages when running tests #3403

Open
joshuahannan opened this issue Jun 6, 2024 · 4 comments

Comments

@joshuahannan
Copy link
Member

joshuahannan commented Jun 6, 2024

Issue to be solved

When running tests with the Cadence testing framework, the errors are spat out as a huge wall of text. It would be great if they were printed in a way that makes them easier to read.

Example:

joshuahannan@Joshuas-MacBook-Pro-2 flow-usdc % flow-c1 test --cover --covercode="contracts" tests/*.cdc
❌ Command Error: Execution failed:
error: assertion failed: given value is: I.Test.Test.Error(message: "[Error Code: 1101] error caused by: 1 error occurred:\n\t* transaction execute failed: [Error Code: 1101] cadence runtime error: Execution failed:\nerror: cannot deploy invalid contract\n --> 751d5fec3fe39dfac9e27973430720b5fcf70588d93503e349d5f4b88f80e0e4:4:16\n  |\n4 |                 signer.contracts.add(name: \"FiatToken\", code: \"696d706f72742043727970746f0a696d706f72742046756e6769626c65546f6b656e2066726f6d203078303030303030303030303030303030320a696d706f72742046756e6769626c65546f6b656e4d6574616461746156696577732066726f6d203078303030303030303030303030303030320a696d706f7274204d6574616461746156696577732066726f6d203078303030303030303030303030303030310a696d706f7274204f6e436861696e4d756c74695369672066726f6d203078303030303030303030303030303030370a696d706f72742049427... \n  |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nerror: resource `FiatToken.Admin` does not conform to resource interface `OnChainMultiSig.PublicSigner`\n   --> 0000000000000007.FiatToken:334:22\n    |\n334 | \taccess(all)\tresource Admin: OnChainMultiSig.PublicSigner, ResourceId, AdminCapReceiver { \n    | \t           \t         ^\n   ... \n    |\n391 | \t\taccess(all) fun UUID(): UInt64{ \n    | \t\t                ---- mismatch here\n   ... \n    |\n395 | \t\taccess(all) fun getTxIndex(): UInt64{ \n    | \t\t                ---------- mismatch here\n\n\n")
  --> test_helpers.cdc:26:4

Suggested Solution

Format the output so that the errors are easy to read and understand

@turbolent
Copy link
Member

@joshuahannan Can you please share (a link to) the test code you are running?

@turbolent turbolent transferred this issue from onflow/cadence-tools Jun 6, 2024
@turbolent
Copy link
Member

Test already has a fun assertError(_ result: {Result}, errorMessage: String), maybe we should add something like:

fun assertNoError(_ result: {Result}) {
    if let error = result.error {
        assert(false, message: "error: ".concat(error.message))
    }
}

@turbolent
Copy link
Member

cc @m-Peter

@m-Peter
Copy link
Contributor

m-Peter commented Jun 13, 2024

Test already has a fun assertError(_ result: {Result}, errorMessage: String), maybe we should add something like:

fun assertNoError(_ result: {Result}) {
    if let error = result.error {
        assert(false, message: "error: ".concat(error.message))
    }
}

@turbolent That's a neat idea 🙌

But the issue being raised here by Joshua, is something related to the printing of a Cadence interpreter error:

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
\n\nerror: resource `FiatToken.Admin` does not conform to resource interface `OnChainMultiSig.PublicSigner`
\n   --> 0000000000000007.FiatToken:334:22
\n    |
\n334 | \taccess(all)\tresource Admin: OnChainMultiSig.PublicSigner, ResourceId, AdminCapReceiver {
\n    | \t           \t         ^\n   ... \n    |\n391 | \t\taccess(all) fun UUID(): UInt64{
\n    | \t\t                ---- mismatch here
\n   ... \n    |\n395 | \t\taccess(all) fun getTxIndex(): UInt64{
\n    | \t\t                ---------- mismatch here
\n\n\n")

I will check to see why it happens. Most likely something in the flow test command, or something related.

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

No branches or pull requests

3 participants