Skip to content

Instantly share code, notes, and snippets.

@thehowl
Created November 1, 2023 18:59
Show Gist options
  • Save thehowl/e36b0f0d652a2a348a2fcd331a310417 to your computer and use it in GitHub Desktop.
Save thehowl/e36b0f0d652a2a348a2fcd331a310417 to your computer and use it in GitHub Desktop.
# Reproducible Test for https://github.com/gnolang/gno/issues/1167
gnoland start
# add contract
gnokey maketx addpkg -pkgdir $WORK -pkgpath gno.land/r/demo/xx -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1
stdout OK!
# execute New
gnokey maketx call -pkgpath gno.land/r/demo/xx -func New -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1
stdout OK!
# execute Delta for the first time
gnokey maketx call -pkgpath gno.land/r/demo/xx -func Delta -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1
stdout OK!xx
-- gno.mod --
module gno.land/r/demo/xx
require (
gno.land/p/demo/avl v0.0.0-latest
)
-- realm.gno --
package xx
import (
"strconv"
"gno.land/p/demo/avl"
)
type Move struct {
N1, N2, N3 byte
}
type S struct {
Moves []Move
}
func (s S) clone() S {
mv := s.Moves
return S{Moves: mv}
}
func (olds S) change() S {
s := olds.clone()
counter++
s.Moves = append([]Move{}, s.Moves...)
s.Moves = append(s.Moves, Move{counter, counter, counter})
return s
}
var el *S
var counter byte
func New() {
el = &S{}
}
func Delta() string {
n := el.change()
*el = n
return Values()
}
func Values() string {
s := ""
for _, val := range el.Moves {
s += strconv.Itoa(int(val.N1)) + "," + strconv.Itoa(int(val.N2)) + "," + strconv.Itoa(int(val.N3)) + ";"
}
return s
}
@thehowl
Copy link
Author

thehowl commented Nov 1, 2023

Fails because *el = n puts n in the realm, but apparently it is not caught & converted to a "real" (???)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment