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

[Test] Unable to use events as a return type #268

Open
austinkline opened this issue Jan 2, 2024 · 1 comment
Open

[Test] Unable to use events as a return type #268

austinkline opened this issue Jan 2, 2024 · 1 comment
Labels
Bug The issue represents a bug, malfunction, regression Feedback

Comments

@austinkline
Copy link

Current Behavior

I am not able to use an event signature as a return type in the cadence testing framework:
image

Expected Behavior

It would be great to allow these kinds of return signatures so I can cut down on copy/paste code. Usually I need the same type of event over and over when writing tests and was hoping I could write a helper to achieve this more easily

Steps To Reproduce

import Test
import "Foo"

// some tests here
...

// this method is invalid
pub fun getLatestEvent(): Foo.SomeEvent {
    return Test.eventsOfType(Type<Foo.SomeEvent>()).removeLast() as! Foo.SomeEvent
}

Environment

- Cadence version: v1.9.2
- Network: Testing
@austinkline austinkline added Bug The issue represents a bug, malfunction, regression Feedback labels Jan 2, 2024
@m-Peter
Copy link
Contributor

m-Peter commented Jan 3, 2024

Unfortunately this comes from Cadence itself. Events are currently not "first-class" citizens, in that they cannot be used as argument types / return types or be constructed and assigned to variables. However, we can use their type for type-casting, as you have done here:

let events = Test.eventsOfType(Type<Foo.SomeEvent>()).removeLast() as! Foo.SomeEvent

The above methods contain the business logic for which CompositeTypes can be used as argument types & return types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug The issue represents a bug, malfunction, regression Feedback
Projects
None yet
Development

No branches or pull requests

2 participants