Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add challenges/time-simple.txtar #2100

Closed
wants to merge 10 commits into from
2 changes: 1 addition & 1 deletion .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
with:
github-token: ${{ secrets.DOCS_DEPLOY_PAT }}
script: |
await github.rest.actions.createworkflowDispatch({
await github.rest.actions.createWorkflowDispatch({
owner: 'gnolang',
repo: 'docs.gno.land',
workflow_id: 'netlify.yml',
Expand Down
File renamed without changes.
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.

88 changes: 88 additions & 0 deletions gno.land/cmd/gnoland/testdata/realm_banker_issued_coin_denom.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# test for https://github.com/gnolang/gno/pull/875

## another test user, test2
adduser test2

## start a new node
gnoland start

## add realm_banker
gnokey maketx addpkg -pkgdir $WORK/short -pkgpath gno.land/r/test/realm_banker -gas-fee 1000000ugnot -gas-wanted 10000000 -broadcast -chainid=tendermint_test test1

## add realm_banker with long package_name
gnokey maketx addpkg -pkgdir $WORK/long -pkgpath gno.land/r/test/package89_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_1234567890 -gas-fee 1000000ugnot -gas-wanted 10000000 -broadcast -chainid=tendermint_test test1

## test2 spend all balance
gnokey maketx send -send "9999999ugnot" -to g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5 -gas-fee 1ugnot -gas-wanted 10000000 -broadcast -chainid=tendermint_test test2

## check test2 balance
gnokey query bank/balances/${USER_ADDR_test2}
stdout ''

## mint coin from banker
gnokey maketx call -pkgpath gno.land/r/test/realm_banker -func Mint -args ${USER_ADDR_test2} -args "ugnot" -args "31337" -gas-fee 1000000ugnot -gas-wanted 10000000 -broadcast -chainid=tendermint_test test1

## check balance after minting, without patching banker will return '31337ugnot'
gnokey query bank/balances/${USER_ADDR_test2}
stdout '"31337/gno.land/r/test/realm_banker:ugnot"'

## burn coin
gnokey maketx call -pkgpath gno.land/r/test/realm_banker -func Burn -args ${USER_ADDR_test2} -args "ugnot" -args "7" -gas-fee 1000000ugnot -gas-wanted 10000000 -broadcast -chainid=tendermint_test test1

## check balance after burning
gnokey query bank/balances/${USER_ADDR_test2}
stdout '"31330/gno.land/r/test/realm_banker:ugnot"'

## transfer 1ugnot to test2 for gas-fee of below tx
gnokey maketx send -send "1ugnot" -to ${USER_ADDR_test2} -gas-fee 1ugnot -gas-wanted 10000000 -broadcast -chainid=tendermint_test test1

## transfer coin
gnokey maketx send -send "1330/gno.land/r/test/realm_banker:ugnot" -to g1yr0dpfgthph7y6mepdx8afuec4q3ga2lg8tjt0 -gas-fee 1ugnot -gas-wanted 10000000 -broadcast -chainid=tendermint_test test2

## check sender balance
gnokey query bank/balances/${USER_ADDR_test2}
stdout '"30000/gno.land/r/test/realm_banker:ugnot"'

## check receiver balance
gnokey query bank/balances/g1yr0dpfgthph7y6mepdx8afuec4q3ga2lg8tjt0
stdout '"1330/gno.land/r/test/realm_banker:ugnot"'

## mint coin from long named package with banker
gnokey maketx call -pkgpath gno.land/r/test/package89_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_1234567890 -func Mint -args "g1cq2ecdq3eyn5qa0fzznpurg87zq3k77g63q6u7" -args "ugnot" -args "100" -gas-fee 1000000ugnot -gas-wanted 10000000 -broadcast -chainid=tendermint_test test1
gnokey query bank/balances/g1cq2ecdq3eyn5qa0fzznpurg87zq3k77g63q6u7
stdout '"100/gno.land/r/test/package89_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_1234567890:ugnot"'

-- short/realm_banker.gno --
package realm_banker

import (
"std"
)

func Mint(addr std.Address, denom string, amount int64) {
banker := std.GetBanker(std.BankerTypeRealmIssue)
banker.IssueCoin(addr, denom, amount)
}

func Burn(addr std.Address, denom string, amount int64) {
banker := std.GetBanker(std.BankerTypeRealmIssue)
banker.RemoveCoin(addr, denom, amount)
}

-- long/realm_banker.gno --
// package name is 130 characters long
package package89_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_1234567890

import (
"std"
)

func Mint(addr std.Address, denom string, amount int64) {
banker := std.GetBanker(std.BankerTypeRealmIssue)
banker.IssueCoin(addr, denom, amount)
}

func Burn(addr std.Address, denom string, amount int64) {
banker := std.GetBanker(std.BankerTypeRealmIssue)
banker.RemoveCoin(addr, denom, amount)
}
18 changes: 18 additions & 0 deletions gno.land/cmd/gnoland/testdata/time-simple.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Originally, the addpkg fails due to changes in PR https://github.com/gnolang/gno/pull/1702 .
# This bug was fixed with https://github.com/gnolang/gno/pull/2105 .

gnoland start

gnokey maketx addpkg -pkgdir $WORK -pkgpath gno.land/r/time_simple -gas-fee 1ugnot -gas-wanted 10000000 -broadcast -chainid=tendermint_test test1
stdout OK!

-- time_simple.gno --
package time_simple

import (
"time"
)

func GetUnixTime() int64 {
return time.Now().Unix()
}
Loading
Loading