Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/github_actions/actions-c5109b1630
Browse files Browse the repository at this point in the history
  • Loading branch information
ajnavarro authored May 15, 2024
2 parents 18cfe15 + b907e44 commit 14b93c5
Show file tree
Hide file tree
Showing 11 changed files with 1,485 additions and 2,965 deletions.
698 changes: 692 additions & 6 deletions LICENSE.md

Large diffs are not rendered by default.

860 changes: 672 additions & 188 deletions examples/gno.land/r/gnoland/pages/page_license.gno

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions examples/gno.land/r/x/test_prev/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module gno.land/r/x/test_prev

require (
gno.land/p/demo/grc/grc20 v0.0.0-latest
gno.land/p/demo/ufmt v0.0.0-latest
gno.land/p/demo/users v0.0.0-latest
gno.land/r/demo/users v0.0.0-latest
)
18 changes: 18 additions & 0 deletions examples/gno.land/r/x/test_prev/test_prev.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package test_prev

import (
"std"

pusers "gno.land/p/demo/users"
"gno.land/r/demo/foo20"
)

func DoSomeWithUserBalance() string {
caller := std.GetOrigCaller()
balance := foo20.BalanceOf(pusers.AddressOrName(caller))

if balance > 100 {
return "rich user"
}
return "poor user"
}
32 changes: 32 additions & 0 deletions examples/gno.land/r/x/test_prev/test_prev_test.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package test_prev

import (
"std"
"testing"

"gno.land/r/demo/foo20"
)

func TestDoSomeWithUserBalancePoor(t *testing.T) {
std.TestSetOrigCaller("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5")
if DoSomeWithUserBalance() != "poor user" {
t.Error("expected poor user")
}
}

func TestDoSomeWithUserBalanceRichButPoor(t *testing.T) {
std.TestSetOrigCaller("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5")
foo20.Faucet() // foo20 will mint tokens to this realm(std.PrevRealm) not user
if DoSomeWithUserBalance() != "poor user" {
t.Error("expected poor user")
}
}

func TestDoSomeWithUserBalanceRich(t *testing.T) {
std.TestSetPrevAddr("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5")

foo20.Faucet() // foo20 will mint tokens to this realm not user
if DoSomeWithUserBalance() != "rich user" {
t.Error("expected rich user")
}
}
1,385 changes: 0 additions & 1,385 deletions gno.land/LICENSE.md

This file was deleted.

1,385 changes: 0 additions & 1,385 deletions gnovm/LICENSE.md

This file was deleted.

42 changes: 42 additions & 0 deletions gnovm/tests/stdlibs/native.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions gnovm/tests/stdlibs/std/std.gno
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ func ClearStoreCache() // injected

func TestSetOrigCaller(addr Address) { testSetOrigCaller(string(addr)) }
func TestSetOrigPkgAddr(addr Address) { testSetOrigPkgAddr(string(addr)) }
func TestSetPrevRealm(pkgPath string) { testSetPrevRealm(pkgPath) }
func TestSetPrevAddr(addr Address) { testSetPrevAddr(string(addr)) }
func TestSetOrigSend(sent, spent Coins) {
sentDenom, sentAmt := sent.expandNative()
spentDenom, spentAmt := spent.expandNative()
Expand All @@ -24,6 +26,8 @@ func callerAt(n int) string
// native bindings
func testSetOrigCaller(s string)
func testSetOrigPkgAddr(s string)
func testSetPrevRealm(s string)
func testSetPrevAddr(s string)
func testSetOrigSend(
sentDenom []string, sentAmt []int64,
spentDenom []string, spentAmt []int64)
Expand Down
17 changes: 17 additions & 0 deletions gnovm/tests/stdlibs/std/std.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"strings"
"testing"

"github.com/gnolang/gno/gnovm/stdlibs"

gno "github.com/gnolang/gno/gnovm/pkg/gnolang"
"github.com/gnolang/gno/gnovm/stdlibs/std"
"github.com/gnolang/gno/tm2/pkg/crypto"
Expand Down Expand Up @@ -100,6 +102,21 @@ func X_testSetOrigPkgAddr(m *gno.Machine, addr string) {
m.Context = ctx
}

func X_testSetPrevRealm(m *gno.Machine, pkgPath string) {
m.Frames[m.NumFrames()-2].LastPackage = &gno.PackageValue{PkgPath: pkgPath}
}

func X_testSetPrevAddr(m *gno.Machine, addr string) {
// clear all frames to return mocked origin caller
for i := m.NumFrames() - 1; i > 0; i-- {
m.Frames[i].LastPackage = nil
}

ctx := m.Context.(stdlibs.ExecContext)
ctx.OrigCaller = crypto.Bech32Address(addr)
m.Context = ctx
}

func X_testSetOrigSend(m *gno.Machine,
sentDenom []string, sentAmt []int64,
spentDenom []string, spentAmt []int64,
Expand Down
1 change: 0 additions & 1 deletion tm2/LICENSE.md → tm2/LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
Expand Down

0 comments on commit 14b93c5

Please sign in to comment.