Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 2 additions & 6 deletions examples/gno.land/p/demo/ownable/ownable.gno
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,12 @@ func (o *Ownable) OwnedByPrevious() bool {
if o == nil {
return false
}
return std.CurrentRealm().Address() == o.owner
return std.PreviousRealm().Address() == o.owner
}

// AssertOwnedByPrevious panics if the caller is not the owner
func (o *Ownable) AssertOwnedByPrevious() {
if o == nil {
panic(ErrUnauthorized)
}
caller := std.CurrentRealm().Address()
if caller != o.owner {
if !o.OwnedByPrevious() {
panic(ErrUnauthorized)
}
}
12 changes: 12 additions & 0 deletions examples/gno.land/r/demo/atomicswap/atomicswap.gno
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,17 @@ var (
// NewCoinSwap creates a new atomic swap contract for native coins.
// It uses a default timelock duration.
func NewCoinSwap(recipient std.Address, hashlock string) (int, *Swap) {
crossing()

timelock := time.Now().Add(defaultTimelockDuration)
return NewCustomCoinSwap(recipient, hashlock, timelock)
}

// NewGRC20Swap creates a new atomic swap contract for grc20 tokens.
// It uses gno.land/r/demo/grc20reg to lookup for a registered token.
func NewGRC20Swap(recipient std.Address, hashlock string, tokenRegistryKey string) (int, *Swap) {
crossing()

timelock := time.Now().Add(defaultTimelockDuration)
tokenGetter := grc20reg.MustGet(tokenRegistryKey)
token := tokenGetter()
Expand All @@ -76,6 +80,8 @@ func NewGRC20Swap(recipient std.Address, hashlock string, tokenRegistryKey strin
// It allows specifying a custom timelock duration.
// It is not callable with `gnokey maketx call`, but can be imported by another contract or `gnokey maketx run`.
func NewCustomCoinSwap(recipient std.Address, hashlock string, timelock time.Time) (int, *Swap) {
crossing()

sender := std.PreviousRealm().Address()
sent := std.OriginSend()
require(len(sent) != 0, "at least one coin needs to be sent")
Expand All @@ -98,6 +104,8 @@ func NewCustomCoinSwap(recipient std.Address, hashlock string, timelock time.Tim
// NewCustomGRC20Swap creates a new atomic swap contract for grc20 tokens.
// It is not callable with `gnokey maketx call`, but can be imported by another contract or `gnokey maketx run`.
func NewCustomGRC20Swap(recipient std.Address, hashlock string, timelock time.Time, token *grc20.Token) (int, *Swap) {
crossing()

sender := std.PreviousRealm().Address()
curAddr := std.CurrentRealm().Address()

Expand Down Expand Up @@ -125,12 +133,16 @@ func NewCustomGRC20Swap(recipient std.Address, hashlock string, timelock time.Ti

// Claim loads a registered swap and tries to claim it.
func Claim(id int, secret string) {
crossing()

swap := mustGet(id)
swap.Claim(secret)
}

// Refund loads a registered swap and tries to refund it.
func Refund(id int) {
crossing()

swap := mustGet(id)
swap.Refund()
}
Expand Down
2 changes: 0 additions & 2 deletions examples/gno.land/r/demo/echo/echo.gno
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,5 @@ package echo
* See also r/demo/print (to print various thing like user address)
*/
func Render(path string) string {
crossing()

return path
}
2 changes: 0 additions & 2 deletions examples/gno.land/r/demo/wugnot/wugnot.gno
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ func Withdraw(amount uint64) {
}

func Render(path string) string {
crossing()

parts := strings.Split(path, "/")
c := len(parts)

Expand Down
2 changes: 0 additions & 2 deletions examples/gno.land/r/gnoland/ghverify/contract.gno
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@ func GetAddressByHandle(handle string) string {

// Render returns a json object string will all verified handle -> address mappings.
func Render(_ string) string {
crossing()

result := "{"
var appendComma bool
handleToAddressMap.Iterate("", "", func(handle string, address any) bool {
Expand Down
2 changes: 1 addition & 1 deletion gno.land/pkg/integration/testdata/addpkg_namespace.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ stderr 'is not authorized to deploy packages to namespace'

# test gui register namespace
# gui call -> gnoland/users/v1.Register
gnokey maketx call -pkgpath gno.land/r/gnoland/users/v1 -func Register -send "1000000ugnot" -gas-fee 1000000ugnot -gas-wanted 12000000 -broadcast -chainid=tendermint_test -args 'guigui123' gui
gnokey maketx call -pkgpath gno.land/r/gnoland/users/v1 -func Register -send "1000000ugnot" -gas-fee 1000000ugnot -gas-wanted 13000000 -broadcast -chainid=tendermint_test -args 'guigui123' gui
stdout 'OK!'

# Test gui publishing on guigui123/one
Expand Down
33 changes: 12 additions & 21 deletions gno.land/pkg/integration/testdata/append.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,23 @@ gnokey maketx call -pkgpath gno.land/r/append -func Append -gas-fee 1000000ugnot
stdout OK!

# Call render
gnokey maketx call -pkgpath gno.land/r/append -func Render -gas-fee 1000000ugnot -gas-wanted 3000000 -args '' -broadcast -chainid=tendermint_test test1
stdout '("1-2-3-" string)'
stdout OK!
gnokey query vm/qrender --data 'gno.land/r/append:'
stdout '1-2-3-'

# Call Pop
gnokey maketx call -pkgpath gno.land/r/append -func Pop -gas-fee 1000000ugnot -gas-wanted 300000 -broadcast -chainid=tendermint_test test1
stdout OK!

# Call render
gnokey maketx call -pkgpath gno.land/r/append -func Render -gas-fee 1000000ugnot -gas-wanted 3000000 -args '' -broadcast -chainid=tendermint_test test1
stdout '("2-3-" string)'
stdout OK!
gnokey query vm/qrender --data 'gno.land/r/append:'
stdout '2-3-'

# Call Append 42
gnokey maketx call -pkgpath gno.land/r/append -func Append -gas-fee 1000000ugnot -gas-wanted 300000 -args '42' -broadcast -chainid=tendermint_test test1
stdout OK!

# Call render
gnokey maketx call -pkgpath gno.land/r/append -func Render -gas-fee 1000000ugnot -gas-wanted 3000000 -args '' -broadcast -chainid=tendermint_test test1
stdout '("2-3-42-" string)'
stdout OK!
gnokey query vm/qrender --data 'gno.land/r/append:'
stdout '2-3-42-'

gnokey maketx call -pkgpath gno.land/r/append -func CopyAppend -gas-fee 1000000ugnot -gas-wanted 300000 -broadcast -chainid=tendermint_test test1
stdout OK!
Expand All @@ -51,23 +47,20 @@ gnokey maketx call -pkgpath gno.land/r/append -func PopB -gas-fee 1000000ugnot -
stdout OK!

# Call render
gnokey maketx call -pkgpath gno.land/r/append -func Render -gas-fee 1000000ugnot -gas-wanted 3000000 -args '' -broadcast -chainid=tendermint_test test1
stdout '("2-3-42-" string)'
stdout OK!
gnokey query vm/qrender --data 'gno.land/r/append:'
stdout '2-3-42-'

gnokey maketx call -pkgpath gno.land/r/append -func AppendMoreAndC -gas-fee 1000000ugnot -gas-wanted 350000 -broadcast -chainid=tendermint_test test1
stdout OK!

gnokey maketx call -pkgpath gno.land/r/append -func ReassignC -gas-fee 1000000ugnot -gas-wanted 350000 -broadcast -chainid=tendermint_test test1
stdout OK!

gnokey maketx call -pkgpath gno.land/r/append -func Render -gas-fee 1000000ugnot -gas-wanted 3000000 -args '' -broadcast -chainid=tendermint_test test1
stdout '("2-3-42-70-100-" string)'
stdout OK!
gnokey query vm/qrender --data 'gno.land/r/append:'
stdout '2-3-42-70-100-'

gnokey maketx call -pkgpath gno.land/r/append -func Render -gas-fee 1000000ugnot -gas-wanted 3000000 -args 'd' -broadcast -chainid=tendermint_test test1
stdout '("1-" string)'
stdout OK!
gnokey query vm/qrender --data 'gno.land/r/append:d'
stdout '1-'

-- append.gno --
package append
Expand Down Expand Up @@ -132,8 +125,6 @@ func AppendNil() {
}

func Render(path string) string {
crossing()

source := a
if path == "d" {
source = d
Expand Down
57 changes: 45 additions & 12 deletions gno.land/pkg/integration/testdata/assertorigincall.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
loadpkg gno.land/r/myrlm $WORK/r/myrlm
loadpkg gno.land/r/foo $WORK/r/foo
loadpkg gno.land/p/demo/bar $WORK/p/demo/bar

gnoland start

# The PANIC is expected to fail at the transaction simulation stage, which is why we set gas-wanted to 1.
Expand Down Expand Up @@ -84,19 +85,19 @@ stdout 'OK!'
stderr 'invalid non-origin call'

## 13. MsgRun -> run.main -> foo.A: PANIC
! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 10_000_000 -broadcast -chainid tendermint_test test1 $WORK/run/fooA.gno
! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 15_000_000 -broadcast -chainid tendermint_test test1 $WORK/run/fooA.gno
stderr 'invalid non-origin call'

## 14. MsgRun -> run.main -> foo.B: PASS
gnokey maketx run -gas-fee 100000ugnot -gas-wanted 10_000_000 -broadcast -chainid tendermint_test test1 $WORK/run/fooB.gno
stdout 'OK!'

## 15. MsgRun -> run.main -> foo.C: PANIC
! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 10_000_000 -broadcast -chainid tendermint_test test1 $WORK/run/fooC.gno
! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 15_000_000 -broadcast -chainid tendermint_test test1 $WORK/run/fooC.gno
stderr 'invalid non-origin call'

## 16. MsgRun -> run.main -> bar.A: PANIC
! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 10_000_000 -broadcast -chainid tendermint_test test1 $WORK/run/barA.gno
! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 15_000_000 -broadcast -chainid tendermint_test test1 $WORK/run/barA.gno
stderr 'invalid non-origin call'

## 17. MsgRun -> run.main -> bar.B: PASS
Expand All @@ -123,16 +124,22 @@ package myrlm
import "std"

func A() {
crossing()

C()
}

func B() {
crossing()

if false {
C()
}
}

func C() {
crossing()

std.AssertOriginCall()
}
-- r/foo/foo.gno --
Expand All @@ -141,15 +148,21 @@ package foo
import "gno.land/r/myrlm"

func A() {
myrlm.A()
crossing()

cross(myrlm.A)()
}

func B() {
myrlm.B()
crossing()

cross(myrlm.B)()
}

func C() {
myrlm.C()
crossing()

cross(myrlm.C)()
}
-- p/demo/bar/bar.gno --
package bar
Expand All @@ -174,54 +187,68 @@ package main
import myrlm "gno.land/r/myrlm"

func main() {
myrlm.A()
crossing()

cross(myrlm.A)()
}
-- run/myrlmB.gno --
package main

import "gno.land/r/myrlm"

func main() {
myrlm.B()
crossing()

cross(myrlm.B)()
}
-- run/myrlmC.gno --
package main

import "gno.land/r/myrlm"

func main() {
myrlm.C()
crossing()

cross(myrlm.C)()
}
-- run/fooA.gno --
package main

import "gno.land/r/foo"

func main() {
foo.A()
crossing()

cross(foo.A)()
}
-- run/fooB.gno --
package main

import "gno.land/r/foo"

func main() {
foo.B()
crossing()

cross(foo.B)()
}
-- run/fooC.gno --
package main

import "gno.land/r/foo"

func main() {
foo.C()
crossing()

cross(foo.C)()
}
-- run/barA.gno --
package main

import "gno.land/p/demo/bar"

func main() {
crossing()

bar.A()
}
-- run/barB.gno --
Expand All @@ -230,6 +257,8 @@ package main
import "gno.land/p/demo/bar"

func main() {
crossing()

bar.B()
}
-- run/barC.gno --
Expand All @@ -238,6 +267,8 @@ package main
import "gno.land/p/demo/bar"

func main() {
crossing()

bar.C()
}
-- run/baz.gno --
Expand All @@ -246,5 +277,7 @@ package main
import "std"

func main() {
crossing()

std.AssertOriginCall()
}
7 changes: 3 additions & 4 deletions gno.land/pkg/integration/testdata/atomicswap.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,17 @@ stdout '(1 int)'
stdout ".*$test2_user_addr.*$test3_user_addr.*12345ugnot.*"
stdout 'OK!'

gnokey maketx call -pkgpath gno.land/r/demo/atomicswap -func Render -gas-fee 1000000ugnot -gas-wanted 10000000 -args '' -broadcast -chainid=tendermint_test test2
stdout 'OK!'
gnokey query vm/qrender --data 'gno.land/r/demo/atomicswap:'

gnokey query auth/accounts/$test2_user_addr
stdout 'coins.*:.*1007987655ugnot'
stdout 'coins.*:.*1008987655ugnot'
gnokey query auth/accounts/$test3_user_addr
stdout 'coins.*:.*1010000000ugnot'

gnokey maketx call -pkgpath gno.land/r/demo/atomicswap -func Claim -gas-fee 1000000ugnot -gas-wanted 10000000 -args '1' -args 'secret' -broadcast -chainid=tendermint_test test3
stdout 'OK!'

gnokey query auth/accounts/$test2_user_addr
stdout 'coins.*:.*1007987655ugnot'
stdout 'coins.*:.*1008987655ugnot'
gnokey query auth/accounts/$test3_user_addr
stdout 'coins.*:.*1009012345ugnot'
4 changes: 2 additions & 2 deletions gno.land/pkg/integration/testdata/ghverify.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ stdout "deelawn"
gnokey maketx call -pkgpath gno.land/r/gnoland/ghverify -func GetAddressByHandle -args 'deelawn' -gas-fee 1000000ugnot -gas-wanted 800000 -broadcast -chainid=tendermint_test test1
stdout "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5"

gnokey maketx call -pkgpath gno.land/r/gnoland/ghverify -func Render -args '' -gas-fee 1000000ugnot -gas-wanted 800000 -broadcast -chainid=tendermint_test test1
stdout '\("\{\\"deelawn\\": \\"g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5\\"\}" string\)'
gnokey query vm/qrender --data 'gno.land/r/gnoland/ghverify:'
stdout '{"deelawn": "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5"}'
Loading
Loading