From 235d987c2278813878b1237bb4ea9600eb96e3d7 Mon Sep 17 00:00:00 2001 From: n3wbie Date: Tue, 12 Sep 2023 17:50:32 +0900 Subject: [PATCH 1/2] fix: copy value in `cv.map` --- gnovm/pkg/gnolang/realm.go | 1 + 1 file changed, 1 insertion(+) diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 519b183ad3a..6cb2307d7e1 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -1356,6 +1356,7 @@ func fillTypesOfValue(store Store, val Value) Value { 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 } return cv case TypeValue: From 121dcb67b114d883c2deed491b60c4bfcc3c3a97 Mon Sep 17 00:00:00 2001 From: n3wbie Date: Tue, 13 Feb 2024 17:33:10 +0900 Subject: [PATCH 2/2] test: txtar --- gno.land/cmd/gnoland/testdata/pr-1112.txtar | 35 +++++++++++++++++++++ gnovm/pkg/gnolang/realm.go | 1 + 2 files changed, 36 insertions(+) create mode 100644 gno.land/cmd/gnoland/testdata/pr-1112.txtar diff --git a/gno.land/cmd/gnoland/testdata/pr-1112.txtar b/gno.land/cmd/gnoland/testdata/pr-1112.txtar new file mode 100644 index 00000000000..128bb48e1aa --- /dev/null +++ b/gno.land/cmd/gnoland/testdata/pr-1112.txtar @@ -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] +} \ No newline at end of file diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 6cb2307d7e1..a6c5d3d6cdb 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -1356,6 +1356,7 @@ func fillTypesOfValue(store Store, val Value) Value { 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 } return cv