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: map delete #2017

Merged
merged 4 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
41 changes: 41 additions & 0 deletions gno.land/cmd/gnoland/testdata/map-delete.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
gnoland start

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

# delete map
gnokey maketx call -pkgpath gno.land/r/demo/mapdelete -func DeleteMap -args 3 -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1
stdout OK!

# check deletion
gnokey maketx call -pkgpath gno.land/r/demo/mapdelete -func GetMap -args 3 -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1
stdout OK!
stdout 'false bool'
# XXX without patching uverse.go, expected stdout is
# stdout 'true bool'



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

-- realm.gno --
package mapdelete

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

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

func DeleteMap(k uint64) {
delete(mapus, k)
}

func GetMap(k uint64) bool {
_, exist := mapus[k]
return exist
}
1 change: 1 addition & 0 deletions gnovm/pkg/gnolang/uverse.go
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,7 @@ func UverseNode() *PackageNode {
case *MapType:
mv := arg0.TV.V.(*MapValue)
mv.DeleteForKey(m.Store, &itv)
m.Realm.DidUpdate(mv, nil, nil)
r3v4s marked this conversation as resolved.
Show resolved Hide resolved
return
case *NativeType:
krv := reflect.New(cbt.Type.Key()).Elem()
Expand Down
Loading