Skip to content

Commit

Permalink
Merge branch 'master' into fix_pop_push_slice
Browse files Browse the repository at this point in the history
  • Loading branch information
n0izn0iz authored Jul 31, 2023
2 parents bee1d29 + 6c9a1c6 commit f665d03
Show file tree
Hide file tree
Showing 20 changed files with 488 additions and 83 deletions.
14 changes: 3 additions & 11 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
Please provide a detailed description of the changes made in this pull request.
<!-- please provide a detailed description of the changes made in this pull request. -->

<details><summary>Checklists...</summary>

## Contributors Checklist
<details><summary>Contributors' checklist...</summary>

- [ ] Added new tests, or not needed, or not feasible
- [ ] Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory
- [ ] Updated the official documentation or not needed
- [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message was included in the description
- [ ] Added references to related issues and PRs
- [ ] Provided any useful hints for running manual tests
- [ ] Added new benchmarks to [generated graphs](https://gnoland.github.io/benchmarks), if any. More info [here](../.benchmarks/README.md).

## Maintainers Checklist

- [ ] Checked that the author followed the guidelines in `CONTRIBUTING.md`
- [ ] Checked the conventional-commit (especially PR title and verb, presence of `BREAKING CHANGE:` in the body)
- [ ] Ensured that this PR is not a significant change or confirmed that the review/consideration process was appropriate for the change
- [ ] Added new benchmarks to [generated graphs](https://gnoland.github.io/benchmarks), if any. More info [here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
</details>
6 changes: 3 additions & 3 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: run benchmarks
name: benchmarks
on:
workflow_call:
inputs:
Expand All @@ -10,7 +10,7 @@ on:
type: string
jobs:
benchmarks:
runs-on: ubuntu-latest
runs-on: [self-hosted, Linux, X64, benchmark-v1]
steps:
- name: checkout
uses: actions/checkout@v3
Expand All @@ -28,4 +28,4 @@ jobs:
INPUT_PUBLISH_BRANCH: gh-benchmarks
INPUT_BENCHMARKS_OUT: benchmarks.json
INPUT_CHECKS: ${{ !inputs.publish }}
INPUT_CHECKS_CONFIG: .benchmarks/gobenchdata-checks.yml
INPUT_CHECKS_CONFIG: .benchmarks/gobenchdata-checks.yml
56 changes: 40 additions & 16 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,51 @@
# This configuration file was automatically generated by Gitpod.
# Please adjust to your needs (see https://www.gitpod.io/docs/config-gitpod-file)
# and commit this file to your remote git repository to share the goodness with others.
# http://gitpod.io/#github.com/gnolang/gno

tasks:
- name: Dev Shell
init: >
echo "install developer tools" &&
(cd misc/devdeps && make install) &&
echo "download dependencies" &&
go mod download &&
go install ./gnovm/cmd/gno
- name: Gno Shell
before: cd ./examples/
init: |
(
set -xe
cd ..
echo "install developer tools"
(cd misc/devdeps && make install)
echo "download dependencies"
go mod download
go install ./gnovm/cmd/gno
echo "Deps installed."
)
command: gno --help

- name: Gnoland Node
before: cd ./gno.land/
init: go install ./cmd/gnoland
command: gnoland start

- name: Gnoland Website
init: go install ./gno.land/cmd/gnoweb
before: cd ./gno.land/
init: go install ./cmd/gnoweb
command: gnoweb --bind=0.0.0.0:8888

- name: Gnoland Node
init: go install ./gno.land/cmd/gnoland
command: gnoland start
#- name: faucet
# ...

ports:
- port: 8888
- name: gnoweb
description: "the Gno.land web server"
port: 8888
onOpen: open-preview
- port: 36657

- name: "gnoland RPC"
description: "the RPC server, managed by tendermint2"
port: 36657
onOpen: notify

github:
prebuilds:
master: true
branches: false
pullRequests: false
pullRequestsFromForks: false
addCheck: false
addComment: false
addBadge: false
21 changes: 19 additions & 2 deletions examples/gno.land/p/demo/ufmt/ufmt.gno
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
// Package ufmt provides utility functions for formatting strings, similarly
// to the Go package "fmt", of which only a subset is currently supported
// (hence the name µfmt - micro fmt).
package ufmt

import "strconv"

// Sprintf offers similar functionality to Go's fmt.Sprintf, or the sprintf
// equivalent available in many languages, including C/C++.
// The number of args passed must exactly match the arguments consumed by the format.
// A limited number of formatting verbs and features are currently supported,
// hence the name ufmt (µfmt, micro-fmt).
//
// The currently formatted verbs are the following:
//
// %s: places a string value directly.
// If the value implements the interface interface{ String() string },
// the String() method is called to retrieve the value.
// %d: formats an integer value using package "strconv".
// Currently supports only uint, uint64, int, int64.
// %t: formats a boolean value to "true" or "false".
// %%: outputs a literal %. Does not consume an argument.
func Sprintf(format string, args ...interface{}) string {
end := len(format)
argNum := 0
Expand Down Expand Up @@ -66,8 +84,7 @@ func Sprintf(format string, args ...interface{}) string {
default:
buf += "(unhandled)"
}
case '%':
buf += "%"
// % handled before, as it does not consume an argument
default:
buf += "(unhandled)"
}
Expand Down
30 changes: 24 additions & 6 deletions examples/gno.land/r/demo/foo20/foo20.gno
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,26 @@ func Allowance(owner, spender users.AddressOrName) uint64 {

func Transfer(to users.AddressOrName, amount uint64) {
caller := std.PrevRealm().Addr()
foo.Transfer(caller, to.Resolve(), amount)
err := foo.Transfer(caller, to.Resolve(), amount)
if err != nil {
panic(err)
}
}

func Approve(spender users.AddressOrName, amount uint64) {
caller := std.PrevRealm().Addr()
foo.Approve(caller, spender.Resolve(), amount)
err := foo.Approve(caller, spender.Resolve(), amount)
if err != nil {
panic(err)
}
}

func TransferFrom(from, to users.AddressOrName, amount uint64) {
caller := std.PrevRealm().Addr()
foo.TransferFrom(caller, from.Resolve(), to.Resolve(), amount)
err := foo.TransferFrom(caller, from.Resolve(), to.Resolve(), amount)
if err != nil {
panic(err)
}
}

// faucet.
Expand All @@ -68,21 +77,30 @@ func Faucet() {
// FIXME: add limits?
// FIXME: add payment in gnot?
caller := std.PrevRealm().Addr()
foo.Mint(caller, 1000*10000) // 1k
err := foo.Mint(caller, 1000*10000) // 1k
if err != nil {
panic(err)
}
}

// administration.

func Mint(address users.AddressOrName, amount uint64) {
caller := std.PrevRealm().Addr()
assertIsAdmin(caller)
foo.Mint(address.Resolve(), amount)
err := foo.Mint(address.Resolve(), amount)
if err != nil {
panic(err)
}
}

func Burn(address users.AddressOrName, amount uint64) {
caller := std.PrevRealm().Addr()
assertIsAdmin(caller)
foo.Burn(address.Resolve(), amount)
err := foo.Burn(address.Resolve(), amount)
if err != nil {
panic(err)
}
}

// render.
Expand Down
36 changes: 36 additions & 0 deletions examples/gno.land/r/demo/foo20/foo20_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,39 @@ func TestReadOnlyPublicMethods(t *testing.T) {
}
}
}

func TestErrConditions(t *testing.T) {
admin := std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")
empty := std.Address("")

type test struct {
name string
msg string
fn func()
}

std.TestSetOrigCaller(admin)
{
tests := []test{
{"Transfer(admin, 1)", "cannot send transfer to self", func() { Transfer(users.AddressOrName(admin), 1) }},
{"Approve(empty, 1))", "invalid address", func() { Approve(users.AddressOrName(empty), 1) }},
}
for _, tc := range tests {
shouldPanicWithMsg(t, tc.fn, tc.msg)
}
}
}

func shouldPanicWithMsg(t *testing.T, f func(), msg string) {
defer func() {
if r := recover(); r == nil {
t.Errorf("The code did not panic")
} else {
errMsg := error(r).Error()
if errMsg != msg {
t.Errorf("excepted panic(%v), got(%v)", msg, errMsg)
}
}
}()
f()
}
1 change: 1 addition & 0 deletions examples/gno.land/r/gnoland/blog/admin.gno
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func AdminSetAdminAddr(addr std.Address) {
}

func AdminSetInPause(state bool) {
assertIsAdmin()
inPause = state
}

Expand Down
86 changes: 86 additions & 0 deletions examples/gno.land/r/gnoland/pages/admin.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package gnopages

import (
"std"
"strings"

"gno.land/p/demo/avl"
)

var (
adminAddr std.Address
moderatorList avl.Tree
inPause bool
)

func init() {
// adminAddr = std.GetOrigCaller() // FIXME: find a way to use this from the main's genesis.
adminAddr = "g1u7y667z64x2h7vc6fmpcprgey4ck233jaww9zq"
}

func AdminSetAdminAddr(addr std.Address) {
assertIsAdmin()
adminAddr = addr
}

func AdminSetInPause(state bool) {
assertIsAdmin()
inPause = state
}

func AdminAddModerator(addr std.Address) {
assertIsAdmin()
moderatorList.Set(addr.String(), true)
}

func AdminRemoveModerator(addr std.Address) {
assertIsAdmin()
moderatorList.Set(addr.String(), false) // XXX: delete instead?
}

func ModAddPost(slug, title, body, tags string) {
assertIsModerator()

caller := std.GetOrigCaller()
tagList := strings.Split(tags, ",")
err := b.NewPost(caller, slug, title, body, tagList)
checkErr(err)
}

func ModEditPost(slug, title, body, tags string) {
assertIsModerator()

tagList := strings.Split(tags, ",")
err := b.GetPost(slug).Update(title, body, tagList)
checkErr(err)
}

func isAdmin(addr std.Address) bool {
return addr == adminAddr
}

func isModerator(addr std.Address) bool {
_, found := moderatorList.Get(addr.String())
return found
}

func assertIsAdmin() {
caller := std.GetOrigCaller()
if !isAdmin(caller) {
panic("access restricted.")
}
}

func assertIsModerator() {
caller := std.GetOrigCaller()
if isAdmin(caller) || isModerator(caller) {
return
}
panic("access restricted")
}

func assertNotInPause() {
if inPause {
panic("access restricted (pause)")
}
}
6 changes: 6 additions & 0 deletions examples/gno.land/r/gnoland/pages/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module gno.land/r/gnoland/pages

require (
"gno.land/p/demo/avl" v0.0.0-latest
"gno.land/p/demo/blog" v0.0.0-latest
)
21 changes: 21 additions & 0 deletions examples/gno.land/r/gnoland/pages/pages.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package gnopages

import (
"gno.land/p/demo/blog"
)

var b = &blog.Blog{
Title: "Gnoland's Pages",
Prefix: "/r/gnoland/pages:",
}

func init() {
_ = b.NewPost("", "gor", "Game of Realms", "Lorem Ipsum", nil)
_ = b.NewPost("", "events", "Events", "Lorem Ipsum", nil)
_ = b.NewPost("", "tokenomics", "Tokenomics", "Lorem Ipsum", nil)
_ = b.NewPost("", "start", "Getting Started", "Lorem Ipsum", nil)
}

func Render(path string) string {
return b.Render(path)
}
Loading

0 comments on commit f665d03

Please sign in to comment.