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

[Linter] Public mut tx context #16878

Merged

Conversation

tx-tomcat
Copy link
Contributor

@tx-tomcat tx-tomcat commented Mar 26, 2024

Description

This linter checks public functions to ensure they use &mut TxContext instead of &TxContext for better upgradability. Here's a step-by-step breakdown of how to implement this linter:

Implement the main logic :

check_function_parameters: Iterate through function parameters.
is_immutable_tx_context: Check if a parameter is an immutable TxContext.
is_tx_context_type: Check if a type is TxContext.
is_sui_tx_context: Verify if the type is from the sui::tx_context module.

Test plan

Added more use case including false positive, false negative case

Release notes

  • Protocol:
  • Nodes (Validators and Full nodes):
  • Indexer:
  • JSON-RPC:
  • GraphQL:
  • CLI: Move will now lint against using &TxContext instead of &mut TxContext in public functions
  • Rust SDK:

Copy link

vercel bot commented Mar 26, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
mysten-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 14, 2024 10:23pm
sui-core ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 14, 2024 10:23pm
sui-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 14, 2024 10:23pm
4 Skipped Deployments
Name Status Preview Comments Updated (UTC)
explorer ⬜️ Ignored (Inspect) Visit Preview Aug 14, 2024 10:23pm
multisig-toolkit ⬜️ Ignored (Inspect) Visit Preview Aug 14, 2024 10:23pm
sui-kiosk ⬜️ Ignored (Inspect) Visit Preview Aug 14, 2024 10:23pm
sui-typescript-docs ⬜️ Ignored (Inspect) Visit Preview Aug 14, 2024 10:23pm

Copy link

vercel bot commented May 31, 2024

@tx-tomcat is attempting to deploy a commit to the Mysten Labs Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

@tnowacki tnowacki left a comment

Choose a reason for hiding this comment

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

See comments in the PR but I don't quite understand how tests here are split.
This particular lint does not have false negative/positive tests. And I think many of these tests could be condensed down to two files (with an additional one for suppression)

@tnowacki tnowacki enabled auto-merge (squash) August 14, 2024 23:01
@tnowacki tnowacki merged commit 474cc58 into MystenLabs:main Aug 14, 2024
41 of 44 checks passed
suiwombat pushed a commit that referenced this pull request Sep 16, 2024
## Description 

This linter checks public functions to ensure they use `&mut TxContext`
instead of `&TxContext `for better upgradability. Here's a step-by-step
breakdown of how to implement this linter:

Implement the main logic :

`check_function_parameters`: Iterate through function parameters.
`is_immutable_tx_context`: Check if a parameter is an immutable
`TxContext`.
`is_tx_context_type`: Check if a type is `TxContext`.
`is_sui_tx_context`: Verify if the type is from the `sui::tx_context`
module.

## Test plan
Added more use case including false positive, false negative case

## Release notes

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [X] CLI: Move will now lint against using `&TxContext` instead of
`&mut TxContext` in public functions
- [ ] Rust SDK:

---------

Co-authored-by: jamedzung <dung.dinhnguyen@digitalavenues.com>
Co-authored-by: Todd Nowacki <tmn@mystenlabs.com>
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.

4 participants