Skip to content

fix: Reset lens state when calling Reset - #148

Merged
AndrewSisley merged 3 commits into
mainfrom
46-reset-module-state
Nov 12, 2025
Merged

fix: Reset lens state when calling Reset#148
AndrewSisley merged 3 commits into
mainfrom
46-reset-module-state

Conversation

@AndrewSisley

Copy link
Copy Markdown
Collaborator

Relevant issue(s)

Resolves #46

Description

Resets lens state when calling Reset to how it was after configuration but before items were passed through it.

@AndrewSisley AndrewSisley added this to the LensVM v1.0 milestone Nov 11, 2025
@AndrewSisley AndrewSisley self-assigned this Nov 11, 2025
@AndrewSisley
AndrewSisley requested a review from a team November 11, 2025 21:25

@islamaliev islamaliev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good overall. I left some minor suggestions/requets

Comment thread tests/action/transform.go
var _ Action = (*Add)(nil)
var _ Stateful = (*Add)(nil)

func (a *Transform) Execute() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

suggestion: shouldn't this have name t?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I think they are all a, for action. Makes copy-pasting them a little easier.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I though the was some kind of convention that we are trying to stick to.

25th frame: switch to this :)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I do like this/self 🤣

Comment thread tests/action/transform.go
Comment thread tests/action/transform.go
Comment thread tests/action/transform.go
require.NoError(a.s.T, err)
require.False(a.s.T, expectedHasNext)

a.Expected.Reset()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

todo: I might be missing something here, but the action is call Transform and calls for some reason Reset which I'm sure if test writer or reader would/should necessarily expect.

Please document it somewhere.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The expected enumerable is reset, not the actual. This allows the expected results to be iterated through multiple times, e.g. for each node.

I'm not sure this needs documentation and that you just misread glancing through - do you still want a code-comment?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

note: I've merged as I have other stuff I want to do in this repo and a clean main is nice to have, but if you want this let me know and I'll include it in the next PR.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

now that I know it, probably no need from my side, but some other dude might wonder. Up to you

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Will leave as-is then, if someone trips up on it you can fire a 'I told you so' my way :)


package action

type TransformReset struct {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

suggestion: documentation would be nice here

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

done

"github.com/sourcenetwork/lens/tests/modules"
)

func TestAddTransform(t *testing.T) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nitpick: from the test name it's not clear if you are testing adding of a transform or you are testing adding transform, i.e. transform that adds something

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Maybe in this context alone, but all the tests follow this pattern, and it matches the file names.

Config: model.Lens{
Lenses: []model.LensModule{
{
Path: modules.WasmPath4,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

note: (probably out of scope) the name of lenses are obscure. Would nice to have them more descriptive like module.WasmPathRenameField

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, they are horribly obscure :) They have documentation that shows up in intellisense. I'll make a mental note to clean these up when I do a bit of other clean-up.

@AndrewSisley
AndrewSisley merged commit 4c0af56 into main Nov 12, 2025
7 checks passed
@AndrewSisley
AndrewSisley deleted the 46-reset-module-state branch November 12, 2025 15:41
},
),
},
&action.TransformReset{

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

thought: Would be nice to show what happens if reset isn't called.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

As-in, a new test committed to main? I can try and remember to add one in my next PR.

If you want to see the previous behaviour you can see it in the commit history of this PR.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yes a new test committed to main. It would be good documentation that shows what could happen if reset is not used.

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.

Reset module state (not including params) on enumerable.Reset

3 participants