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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions gno.land/cmd/gnoland/testdata/pr-1112.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Test for https://github.com/gnolang/gno/pull/1112

gnoland start

# add contract
gnokey maketx addpkg -pkgdir $WORK -pkgpath gno.land/r/demo/mapindex -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1
stdout OK!

# call map
gnokey maketx call -pkgpath gno.land/r/demo/mapindex -func FindMapWithKey -args 3 -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1
stdout OK!
stdout '"three" string'

# XXX without patching realm.go, expected stdout is
# stdout ' string'


-- gno.mod --
module gno.land/r/demo/mapindex


-- realm.gno --
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]
}
2 changes: 2 additions & 0 deletions gnovm/pkg/gnolang/realm.go
Original file line number Diff line number Diff line change
Expand Up @@ -1356,6 +1356,8 @@
for cur := cv.List.Head; cur != nil; cur = cur.Next {
fillTypesTV(store, &cur.Key)
fillTypesTV(store, &cur.Value)

cv.vmap[cur.Key.ComputeMapKey(store, false)] = cur

Check warning on line 1360 in gnovm/pkg/gnolang/realm.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/realm.go#L1359-L1360

Added lines #L1359 - L1360 were not covered by tests
}
return cv
case TypeValue:
Expand Down
Loading