-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(gnovm): map key deletion in realms (#2017)
<!-- please provide a detailed description of the changes made in this pull request. --> after value is delete in map by `delete(map, key)`, map variable wasn't updating it-self <details><summary>Contributors' checklist...</summary> - [x] Added new tests, or not needed, or not feasible - [ ] 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 - [ ] 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>
- Loading branch information
Showing
4 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package mapdelete | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestGetMap(t *testing.T) { | ||
if !(GetMap(3)) { | ||
t.Error("Expected true, got ", GetMap(3)) | ||
} | ||
} | ||
|
||
func TestDeleteMap(t *testing.T) { | ||
DeleteMap(3) | ||
} | ||
|
||
func TestGetMapAfterDelete(t *testing.T) { | ||
if GetMap(3) { | ||
t.Error("Expected false, got ", GetMap(3)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters