Skip to content

Commit

Permalink
Merge branch 'master' into daosdk
Browse files Browse the repository at this point in the history
  • Loading branch information
n0izn0iz authored Apr 17, 2024
2 parents 3501f28 + 3297d0c commit d7cdd9c
Show file tree
Hide file tree
Showing 17 changed files with 269 additions and 89 deletions.
89 changes: 89 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ "master", "chain/*" ]
pull_request:
branches: [ "master", "chain/*" ]
schedule:
- cron: '22 17 * * 3'

jobs:
analyze:
name: Analyze (${{ matrix.language }})
# Runner size impacts CodeQL analysis time. To learn more, please see:
# - https://gh.io/recommended-hardware-resources-for-running-codeql
# - https://gh.io/supported-runners-and-hardware-resources
# - https://gh.io/using-larger-runners (GitHub.com only)
# Consider using larger runners or machines with greater resources for possible analysis time improvements.
runs-on: ubuntu-latest
timeout-minutes: 360
permissions:
# required for all workflows
security-events: write

# only required for workflows in private repositories
actions: read
contents: read

strategy:
fail-fast: false
matrix:
include:
- language: go
build-mode: autobuild
# CodeQL supports the following values keywords for 'language': 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift'
# Use `c-cpp` to analyze code written in C, C++ or both
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
# Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
# To learn more about changing the languages that are analyzed or customizing the build mode for your analysis,
# see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning.
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
steps:
- name: Checkout repository
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality

# If the analyze step fails for one of the languages you are analyzing with
# "We were unable to automatically build your code", modify the matrix above
# to set the build mode to "manual" for that language. Then modify this step
# to build your code.
# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
- if: matrix.build-mode == 'manual'
run: |
echo 'If you are using a "manual" build mode for one or more of the' \
'languages you are analyzing, replace this with the commands to build' \
'your code, for example:'
echo ' make bootstrap'
echo ' make release'
exit 1
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
35 changes: 35 additions & 0 deletions docs/concepts/namespaces.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
id: namespaces
---

# Namespaces

Namespaces provide users with the exclusive capability to publish contracts under their designated namespaces, similar to GitHub's user and organization model.

This feature is currently a work in progress (WIP). To learn more about namespaces, please checkout https://github.com/gnolang/gno/issues/1107.

# Package Path

A package path is a unique identifier for each package/realm. It specifies the location of the package source code which helps differentiate it from others. You can use a package path to:

- Call a specific function from a package/realm. (e.g using `gnokey maketx call`)
- Import it in other packages/realms.

Here's a breakdown of the structure of a package path:

- Domain: The domain of the blockchain where the package is deployed. Currently, only `gno.land/` is supported.
- Type: Defines the type of package.
- `p/`: [Package](packages.md)
- `r/`: [Realm](realms.md)
- Namespace: A namespace can be included after the type (e.g., user or organization name). Namespaces are a way to group related packages or realms, but currently ownership cannot be claimed. (see [Issue #1107](https://github.com/gnolang/gno/issues/1107) for more info)
- Remaining Path: The remaining part of the path.
- Can only contain alphanumeric characters (letters and numbers) and underscores.
- No special characters allowed (except underscore).
- Cannot consist solely of underscores. It must have at least one allowed alphanumeric character.
- Cannot start with a number. It should begin with a letter.
- Cannot end with a trailing slash (`/`).

Examples:

- `gno.land/p/demo/avl`: This signifies a package named `avl` within the `demo` namespace.
- `gno.land/r/gnoland/home`: This signifies a realm named `home` within the `gnoland` namespace.
2 changes: 2 additions & 0 deletions examples/gno.land/r/demo/wugnot/gno.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ module gno.land/r/demo/wugnot
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
)
24 changes: 14 additions & 10 deletions examples/gno.land/r/demo/wugnot/wugnot.gno
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import (

"gno.land/p/demo/grc/grc20"
"gno.land/p/demo/ufmt"

"gno.land/r/demo/users"

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

var (
Expand Down Expand Up @@ -82,16 +86,16 @@ func TotalSupply() uint64 {
return wugnot.TotalSupply()
}

func BalanceOf(owner std.Address) uint64 {
balance, err := wugnot.BalanceOf(owner)
func BalanceOf(owner pusers.AddressOrName) uint64 {
balance, err := wugnot.BalanceOf(users.Resolve(owner))
if err != nil {
panic(err)
}
return balance
}

func Allowance(owner, spender std.Address) uint64 {
allowance, err := wugnot.Allowance(owner, spender)
func Allowance(owner, spender pusers.AddressOrName) uint64 {
allowance, err := wugnot.Allowance(users.Resolve(owner), users.Resolve(spender))
if err != nil {
panic(err)
}
Expand All @@ -101,25 +105,25 @@ func Allowance(owner, spender std.Address) uint64 {
// setters.
//

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

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

func TransferFrom(from, to std.Address, amount uint64) {
func TransferFrom(from, to pusers.AddressOrName, amount uint64) {
caller := std.PrevRealm().Addr()
err := wugnot.TransferFrom(caller, from, to, amount)
err := wugnot.TransferFrom(caller, users.Resolve(from), users.Resolve(to), amount)
if err != nil {
panic(err)
}
Expand Down
4 changes: 3 additions & 1 deletion examples/gno.land/r/demo/wugnot/z0_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (

"gno.land/p/demo/testutils"
"gno.land/r/demo/wugnot"

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

var (
Expand Down Expand Up @@ -37,7 +39,7 @@ func main() {

func printBalances() {
printSingleBalance := func(name string, addr std.Address) {
wugnotBal := wugnot.BalanceOf(addr)
wugnotBal := wugnot.BalanceOf(pusers.AddressOrName(addr))
std.TestSetOrigCaller(addr)
abanker := std.GetBanker(std.BankerTypeOrigSend)
acoins := abanker.GetCoins(addr).AmountOf("ugnot")
Expand Down
15 changes: 13 additions & 2 deletions gno.land/cmd/gnoland/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ import (
"go.uber.org/zap/zapcore"
)

var startGraphic = fmt.Sprintf(`
__ __
____ _____ ____ / /___ _____ ____/ /
/ __ %c/ __ \/ __ \/ / __ %c/ __ \/ __ /
/ /_/ / / / / /_/ / / /_/ / / / / /_/ /
\__, /_/ /_/\____/_/\__,_/_/ /_/\__,_/
/____/
`, '`', '`')

type startCfg struct {
gnoRootDir string
skipFailingGenesisTxs bool
Expand Down Expand Up @@ -268,13 +277,15 @@ func execStart(c *startCfg, io commands.IO) error {
}
cfg.LocalApp = gnoApp

if logFormat != log.JSONFormat {
io.Println(startGraphic)
}

gnoNode, err := node.DefaultNewNode(cfg, logger)
if err != nil {
return fmt.Errorf("error in creating node: %w", err)
}

fmt.Fprintln(io.Err(), "Node created.")

if c.skipStart {
io.ErrPrintln("'--skip-start' is set. Exiting.")
return nil
Expand Down
69 changes: 30 additions & 39 deletions gno.land/cmd/gnoland/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,43 @@ package main
import (
"bytes"
"context"
"os"
"path/filepath"
"strings"
"testing"
"time"

"github.com/gnolang/gno/tm2/pkg/commands"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestStartInitialize(t *testing.T) {
t.Parallel()

cases := []struct {
args []string
}{
{[]string{"start", "--skip-start", "--skip-failing-genesis-txs"}},
// {[]string{"--skip-start"}},
// FIXME: test seems flappy as soon as we have multiple cases.
}
os.Chdir(filepath.Join("..", "..")) // go to repo's root dir

for _, tc := range cases {
tc := tc
name := strings.Join(tc.args, " ")
t.Run(name, func(t *testing.T) {
t.Parallel()

mockOut := new(bytes.Buffer)
mockErr := new(bytes.Buffer)
io := commands.NewTestIO()
io.SetOut(commands.WriteNopCloser(mockOut))
io.SetErr(commands.WriteNopCloser(mockErr))
cmd := newRootCmd(io)

t.Logf(`Running "gnoland %s"`, strings.Join(tc.args, " "))
err := cmd.ParseAndRun(context.Background(), tc.args)
require.NoError(t, err)

stdout := mockOut.String()
stderr := mockErr.String()

require.Contains(t, stderr, "Node created.", "failed to create node")
require.Contains(t, stderr, "'--skip-start' is set. Exiting.", "not exited with skip-start")
require.NotContains(t, stdout, "panic:")
})
}
var (
nodeDir = t.TempDir()

args = []string{
"start",
"--skip-start",
"--skip-failing-genesis-txs",
"--data-dir",
nodeDir,
}
)

// Prepare the IO
mockOut := new(bytes.Buffer)
mockErr := new(bytes.Buffer)
io := commands.NewTestIO()
io.SetOut(commands.WriteNopCloser(mockOut))
io.SetErr(commands.WriteNopCloser(mockErr))

// Create and run the command
ctx, cancelFn := context.WithTimeout(context.Background(), 5*time.Second)
defer cancelFn()

cmd := newRootCmd(io)
require.NoError(t, cmd.ParseAndRun(ctx, args))

// Make sure the directory is created
assert.DirExists(t, nodeDir)
}

// TODO: test various configuration files?
7 changes: 4 additions & 3 deletions gno.land/cmd/gnoland/testdata/issue-1786.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import (
"gno.land/r/demo/wugnot"

"gno.land/p/demo/ufmt"
pusers "gno.land/p/demo/users"
)

func ProxyWrap() {
Expand All @@ -65,17 +66,17 @@ func ProxyWrap() {
wugnot.Deposit() // `proxywugnot` has ugnot

// SEND WUGNOT: PROXY_WUGNOT -> USER
wugnot.Transfer(std.GetOrigCaller(), ugnotSent)
wugnot.Transfer(pusers.AddressOrName(std.GetOrigCaller()), ugnotSent)
}

func ProxyUnwrap(wugnotAmount uint64) {
if wugnotAmount == 0 {
return
}
userOldWugnot := wugnot.BalanceOf(std.GetOrigCaller())
userOldWugnot := wugnot.BalanceOf(pusers.AddressOrName(std.GetOrigCaller()))

// SEND WUGNOT: USER -> PROXY_WUGNOT
wugnot.TransferFrom(std.GetOrigCaller(), std.CurrentRealm().Addr(), wugnotAmount)
wugnot.TransferFrom(pusers.AddressOrName(std.GetOrigCaller()), pusers.AddressOrName(std.CurrentRealm().Addr()), wugnotAmount)

// UNWRAP IT
wugnot.Withdraw(wugnotAmount)
Expand Down
13 changes: 7 additions & 6 deletions gno.land/pkg/gnoland/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/gnolang/gno/gno.land/pkg/sdk/vm"
"github.com/gnolang/gno/gnovm/pkg/gnoenv"
"github.com/gnolang/gno/tm2/pkg/amino"
abci "github.com/gnolang/gno/tm2/pkg/bft/abci/types"
dbm "github.com/gnolang/gno/tm2/pkg/db"
"github.com/gnolang/gno/tm2/pkg/log"
Expand Down Expand Up @@ -169,13 +168,15 @@ func InitChainer(baseApp *sdk.BaseApp, acctKpr auth.AccountKeeperI, bankKpr bank
}

// Run genesis txs.
for i, tx := range genState.Txs {
for _, tx := range genState.Txs {
res := baseApp.Deliver(tx)
if res.IsErr() {
ctx.Logger().Error("LOG", "log", res.Log)
ctx.Logger().Error(fmt.Sprintf("#%d", i), "value", string(amino.MustMarshalJSON(tx)))
} else {
ctx.Logger().Info("SUCCESS:", "value", string(amino.MustMarshalJSON(tx)))
ctx.Logger().Error(
"Unable to deliver genesis tx",
"log", res.Log,
"error", res.Error,
"gas-used", res.GasUsed,
)
}

resHandler(ctx, tx, res)
Expand Down
Loading

0 comments on commit d7cdd9c

Please sign in to comment.