docs: sync example tutorials from cosmos/example#261
Conversation
Greptile SummaryThis PR adds a six-page tutorial series ( Three issues were identified:
Confidence Score: 3/5
Important Files Changed
Last reviewed commit: "docs: sync example t..." |
| You should see the following output, which means the counter is starting at `0`: | ||
|
|
||
|
|
||
| ```text | ||
| {} | ||
| ``` | ||
|
|
There was a problem hiding this comment.
Ambiguous zero-value output format
The initial query output is shown as {}, which is the JSON representation of an empty object (proto3 omits zero-value fields in JSON). However, the subsequent query output (after adding 5) uses YAML format: count: "5". This inconsistency is confusing for beginners — the reader may assume the command returned an empty or failed response rather than count: 0.
Consider either consistently using YAML for both outputs:
| You should see the following output, which means the counter is starting at `0`: | |
| ```text | |
| {} | |
| ``` | |
| You should see the following output, which means the counter is starting at `0`: | |
| ```yaml | |
| count: "0" |
Or add a short clarifying note explaining why the zero-value field is omitted in the initial output.
<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>
| func (k *Keeper) AddCount(ctx context.Context, sender string, amount uint64) (uint64, error) { | ||
| if amount >= math.MaxUint64 { | ||
| return 0, ErrNumTooLarge | ||
| } |
There was a problem hiding this comment.
Ineffective overflow guard for
uint64
The overflow check if amount >= math.MaxUint64 is logically equivalent to if amount == math.MaxUint64 because a uint64 value can never exceed math.MaxUint64. This means the check only blocks the single edge case of amount == 18446744073709551615 while entirely missing the real overflow risk: count + amount wrapping around when both values are large but neither is at the maximum individually.
For example, if count = 10 and amount = math.MaxUint64 - 5, the addition silently overflows to 4 without triggering this guard.
The correct check would be:
if amount > math.MaxUint64 - count {
return 0, ErrNumTooLarge
}Since this tutorial is meant to teach best practices for module development, presenting a flawed overflow guard as example code could mislead developers who copy this pattern into production modules.
|
|
||
| # Update module parameters (requires governance authority) | ||
| exampled tx counter update-params --from alice --chain-id demo --yes | ||
| ``` |
There was a problem hiding this comment.
update-params example will fail as shown
The comment acknowledges this requires governance authority, but the command uses --from alice. Alice is a regular funded test account, not the governance module account. Submitting this transaction from Alice will be rejected with ErrInvalidSigner at the module level because the authority check in MsgServer.UpdateParams compares msg.Authority against the governance module address (authtypes.NewModuleAddress(govtypes.ModuleName)).
This example should either:
- Be removed since it cannot be exercised in the quickstart environment, or
- Be replaced with a note explaining that params can only be updated via a governance proposal (
exampled tx gov submit-proposal ...) rather than a direct transaction.
Showing a command that silently fails for non-obvious reasons may confuse readers debugging why their transaction always errors.
Auto-synced from cosmos/example. Transforms docs/.md to sdk/next/tutorials/example/.mdx. Do not edit these files directly — edit the source in cosmos/example and let the sync bot update them.