diff --git a/append_bug.sh b/append_bug.sh new file mode 100644 index 00000000000..8cf9137f136 --- /dev/null +++ b/append_bug.sh @@ -0,0 +1,27 @@ +# cd gno.land && go run ./cmd/gnoland start in an other terminal first +# +# Call Append 1 +gnokey maketx call -pkgpath "gno.land/r/demo/bug/append" -func "Append" -gas-fee 1000000ugnot -gas-wanted 2000000 -send "" -broadcast -chainid "dev" -args "1" -remote "127.0.0.1:26657" $1 +# Call Append 2 +gnokey maketx call -pkgpath "gno.land/r/demo/bug/append" -func "Append" -gas-fee 1000000ugnot -gas-wanted 2000000 -send "" -broadcast -chainid "dev" -args "2" -remote "127.0.0.1:26657" $1 +# Call Append 3 +gnokey maketx call -pkgpath "gno.land/r/demo/bug/append" -func "Append" -gas-fee 1000000ugnot -gas-wanted 2000000 -send "" -broadcast -chainid "dev" -args "3" -remote "127.0.0.1:26657" $1 + +# Call render +gnokey maketx call -pkgpath "gno.land/r/demo/bug/append" -func "Render" -gas-fee 1000000ugnot -gas-wanted 2000000 -send "" -broadcast -chainid "dev" -args "" -remote "127.0.0.1:26657" $1 +# Outputs ("1
2
3
" string) -> OK + +# Call Pop +gnokey maketx call -pkgpath "gno.land/r/demo/bug/append" -func "Pop" -gas-fee 1000000ugnot -gas-wanted 2000000 -send "" -broadcast -chainid "dev" -remote "127.0.0.1:26657" $1 +# Call render +gnokey maketx call -pkgpath "gno.land/r/demo/bug/append" -func "Render" -gas-fee 1000000ugnot -gas-wanted 2000000 -send "" -broadcast -chainid "dev" -args "" -remote "127.0.0.1:26657" $1 +# Outputs ("1
2
" string) -> WRONG! Pop removes the first item so +# it should be ("2
3
" string) + +# Call Append 42 +gnokey maketx call -pkgpath "gno.land/r/demo/bug/append" -func "Append" -gas-fee 1000000ugnot -gas-wanted 2000000 -send "" -broadcast -chainid "dev" -args "42" -remote "127.0.0.1:26657" $1 + +# Call render +gnokey maketx call -pkgpath "gno.land/r/demo/bug/append" -func "Render" -gas-fee 1000000ugnot -gas-wanted 2000000 -send "" -broadcast -chainid "dev" -args "" -remote "127.0.0.1:26657" $1 +# Ouputs ("1
2
3
" string) -> WTF where is 42 ??? + diff --git a/examples/gno.land/r/demo/bug/append/append.gno b/examples/gno.land/r/demo/bug/append/append.gno new file mode 100644 index 00000000000..b6b12bf0e15 --- /dev/null +++ b/examples/gno.land/r/demo/bug/append/append.gno @@ -0,0 +1,25 @@ +package append + +import ( + "gno.land/p/demo/ufmt" +) + +type T struct{ i int } + +var a []T + +func Append(i int) { + a = append(a, T{i: i}) +} + +func Pop() { + a = append(a[:0], a[1:]...) +} + +func Render(_ string) string { + var s string + for i := 0; i < len(a); i++ { + s += ufmt.Sprintf("%d
", a[i].i) + } + return s +} diff --git a/examples/gno.land/r/demo/bug/append/gno.mod b/examples/gno.land/r/demo/bug/append/gno.mod new file mode 100644 index 00000000000..0823c7fac68 --- /dev/null +++ b/examples/gno.land/r/demo/bug/append/gno.mod @@ -0,0 +1 @@ +module gno.land/r/demo/bug/append