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

fix: copy value in cv.map #1112

Merged
merged 2 commits into from
Mar 4, 2024
Merged

Conversation

r3v4s
Copy link
Contributor

@r3v4s r3v4s commented Sep 12, 2023

package mapindex

var mapus map[uint64]string = make(map[uint64]string)

func init() {
	mapus[3] = "three"
	mapus[5] = "five"
	mapus[9] = "nine"
}

func FindMapWithKey(k uint64) string {
	return mapus[k]
}

println(mapus[5]) will return 'five' in test cases run by gno test which is expected

HOWEVER, with deployed package

$ gnokey maketx addpkg \
-remote 127.0.0.1:26657 \
-broadcast=true \
-chainid dev \
-gas-fee 1ugnot \
-gas-wanted 9000000 \
-memo "" \
-pkgdir ./ \
-pkgpath gno.land/r/demo/mapindex \
test1

calling

$ gnokey maketx call \
-remote 127.0.0.1:26657 \
-broadcast=true \
-chainid dev \
-gas-fee 1ugnot \
-gas-wanted 9000000 \
-memo "" \
-pkgpath gno.land/r/demo/mapindex \
-func FindMapWithKey \
-args "3" \
test1

will return nothing for value, and 'string' for type

$ gnokey maketx call \
-remote 127.0.0.1:26657 \
-broadcast=true \
-chainid dev \
-gas-fee 1ugnot \
-gas-wanted 9000000 \
-memo "" \
-pkgpath gno.land/r/demo/mapindex \
-func FindMapWithKey \
-args "3" \
test1
Enter password.

( string)
OK!
GAS WANTED: 9000000
GAS USED:   73301

Related PR

Contributors' checklist...
  • Added new tests, or not needed, or not feasible
  • Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory
  • Updated the official documentation or not needed
  • No breaking changes were made, or a BREAKING CHANGE: xxx message was included in the description
  • Added references to related issues and PRs
  • Provided any useful hints for running manual tests
  • Added new benchmarks to generated graphs, if any. More info here.

@github-actions github-actions bot added the 📦 🤖 gnovm Issues or PRs gnovm related label Sep 12, 2023
@moul
Copy link
Member

moul commented Sep 13, 2023

Looks good.

It would be beneficial if you could incorporate a unit test to prevent potential regressions in the future. Thank you.

@r3v4s
Copy link
Contributor Author

r3v4s commented Sep 13, 2023

@moul This bug only occurs in actual environment.
which means you have to run your own gnoland local node then publish package and call it

both of running test file(_test.gno) with gno test or something like this file doesn't reproduce this bug.

So, I'm not sure about what you meant by unit test (at least for this case), could be more specific?

@moul moul added this to the 🚀 main.gno.land (required) milestone Sep 13, 2023
@moul
Copy link
Member

moul commented Sep 13, 2023

@gfanton is developing a new txtar-based integration system (https://github.com/gnolang/gno/compare/master...gfanton:feat/gnoland-txtar-driver?expand=1) designed for crafting such tests.

However, for straightforward tests like these, a simpler alternative might be more fitting.

Regardless, your PR is solid. I'll append a label for enhanced QA in the future. Edit: #1115. Edit: blocked until we finish a more straightforward integration test system to use this PR as a good use case.

moul
moul previously requested changes Sep 14, 2023
Copy link
Member

@moul moul left a comment

Choose a reason for hiding this comment

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

Blocked until we have a better integration test system.

i.e., #1117, cc @gfanton

@thehowl
Copy link
Member

thehowl commented Nov 7, 2023

@r3v4s master now has txtar integration tests; you're welcome to update this PR and add reproducible tests for what you outlined in the OP :)

@r3v4s r3v4s requested a review from thehowl as a code owner February 13, 2024 08:33
@github-actions github-actions bot added the 📦 ⛰️ gno.land Issues or PRs gno.land package related label Feb 13, 2024
Copy link

codecov bot commented Feb 13, 2024

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (a2b5f29) 56.17% compared to head (121dcb6) 56.16%.

Files Patch % Lines
gnovm/pkg/gnolang/realm.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1112      +/-   ##
==========================================
- Coverage   56.17%   56.16%   -0.01%     
==========================================
  Files         439      439              
  Lines       66242    66244       +2     
==========================================
- Hits        37209    37204       -5     
- Misses      26143    26149       +6     
- Partials     2890     2891       +1     
Flag Coverage Δ
go-1.21.x ∅ <ø> (∅)
misc ∅ <ø> (∅)
misc-_test.genstd ∅ <ø> (∅)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@thehowl thehowl dismissed moul’s stale review March 4, 2024 20:05

Reason for blocking has been resolved; @moul had previously approved the PR.

@thehowl thehowl merged commit aca00f6 into gnolang:master Mar 4, 2024
186 of 187 checks passed
leohhhn pushed a commit to leohhhn/gno that referenced this pull request Mar 6, 2024
<!-- please provide a detailed description of the changes made in this
pull request. -->

```go
package mapindex

var mapus map[uint64]string = make(map[uint64]string)

func init() {
	mapus[3] = "three"
	mapus[5] = "five"
	mapus[9] = "nine"
}

func FindMapWithKey(k uint64) string {
	return mapus[k]
}

```


`println(mapus[5])` will return 'five' in test cases run by `gno test`
which is expected

HOWEVER, with deployed package
```bash
$ gnokey maketx addpkg \
-remote 127.0.0.1:26657 \
-broadcast=true \
-chainid dev \
-gas-fee 1ugnot \
-gas-wanted 9000000 \
-memo "" \
-pkgdir ./ \
-pkgpath gno.land/r/demo/mapindex \
test1

```

calling
```bash
$ gnokey maketx call \
-remote 127.0.0.1:26657 \
-broadcast=true \
-chainid dev \
-gas-fee 1ugnot \
-gas-wanted 9000000 \
-memo "" \
-pkgpath gno.land/r/demo/mapindex \
-func FindMapWithKey \
-args "3" \
test1
```

will return nothing for value, and 'string' for type
```bash
$ gnokey maketx call \
-remote 127.0.0.1:26657 \
-broadcast=true \
-chainid dev \
-gas-fee 1ugnot \
-gas-wanted 9000000 \
-memo "" \
-pkgpath gno.land/r/demo/mapindex \
-func FindMapWithKey \
-args "3" \
test1
Enter password.

( string)
OK!
GAS WANTED: 9000000
GAS USED:   73301
```

## Related PR
- [x] gnolang#932 @tbruyelle 


<details><summary>Contributors' checklist...</summary>

- [x] Added new tests, or not needed, or not feasible
- [x] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [x] Updated the official documentation or not needed
- [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [x] Added references to related issues and PRs
- [ ] Provided any useful hints for running manual tests
- [ ] Added new benchmarks to [generated
graphs](https://gnoland.github.io/benchmarks), if any. More info
[here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
</details>
@r3v4s r3v4s deleted the fix/cv.map-is-nil branch March 18, 2024 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 ⛰️ gno.land Issues or PRs gno.land package related 📦 🤖 gnovm Issues or PRs gnovm related
Projects
Status: 🚀 Needed for Launch
Status: Done
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants