Skip to content

Commit

Permalink
Merge branch 'master' into feat/SetPrevRealm
Browse files Browse the repository at this point in the history
  • Loading branch information
moul authored Oct 5, 2023
2 parents fdf75c5 + 924d62d commit 49929f2
Show file tree
Hide file tree
Showing 47 changed files with 4,873 additions and 122 deletions.
15 changes: 15 additions & 0 deletions .github/.fossa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: 3

# https://github.com/fossas/fossa-cli/blob/master/docs/references/files/fossa-yml.md

project:
id: github.com/gnolang/gno
name: gno

targets:
only:
- type: gomod

paths:
exclude:
- ./misc/
50 changes: 50 additions & 0 deletions .github/workflows/fossa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Dependency License Scanning

on:
workflow_dispatch:
pull_request:
paths:
- ".github/.fossa.yml"
- ".github/workflows/fossa.yml"
schedule:
- cron: '0 0 * * 6' # At 00:00 on saturdays

permissions:
contents: read

jobs:
fossa:
name: Fossa
runs-on: ubuntu-latest
if: github.repository == 'gnolang/gno'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# we don't know what commit the last tag was it's safer to get entire repo so previousStableVersion resolves
fetch-depth: 0

- name: Move .fossa.yml to root dir
run: mv .github/.fossa.yml .

- name: Cache Coursier cache
uses: coursier/[email protected]

- name: Set up JDK 17
uses: coursier/[email protected]
with:
jvm: temurin:1.17

- name: Set up fossa CLI
run: "curl -H 'Cache-Control: no-cache' https://raw.githubusercontent.com/fossas/fossa-cli/master/install-latest.sh | bash"

- name: FOSSA analyze
run: fossa analyze
env:
FOSSA_API_KEY: "${{secrets.FOSSA_API_KEY}}"

- name: FOSSA test
run: fossa test
env:
FOSSA_API_KEY: "${{secrets.FOSSA_API_KEY}}"

29 changes: 24 additions & 5 deletions .github/workflows/gnoland.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,33 @@ jobs:
run: |
export GOPATH=$HOME/go
export GOTEST_FLAGS="-v -p 1 -timeout=30m -coverprofile=coverage.out -covermode=atomic"
export LOG_DIR="${{ runner.temp }}/logs/test-${{ matrix.goversion }}-gnoland"
make ${{ matrix.args }}
- if: ${{ runner.os == 'Linux' && matrix.goversion == '1.21.x' }}
- name: Upload Test Log
if: always()
uses: actions/upload-artifact@v3
with:
name: logs-test-gnoland-go${{ matrix.goversion }}
path: ${{ runner.temp }}/logs/**/*.log
- uses: actions/upload-artifact@v3
if: ${{ runner.os == 'Linux' && matrix.goversion == '1.21.x' }}
with:
name: ${{runner.os}}-coverage-gnoland-${{ matrix.args}}-${{matrix.goversion}}
path: ./gno.land/coverage.out

upload-coverage:
needs: test
runs-on: ubuntu-latest
steps:
- name: Download all previous coverage artifacts
uses: actions/download-artifact@v3
with:
path: ${{ runner.temp }}/coverage
- name: Upload combined coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
name: gno.land
flags: gno.land-${{matrix.args}}
files: ./gno.land/coverage.out
directory: ${{ runner.temp }}/coverage
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: ${{ github.repository == 'gnolang/gno' }}

docker-integration:
Expand Down
24 changes: 18 additions & 6 deletions .github/workflows/gnovm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,24 @@ jobs:
export GOPATH=$HOME/go
export GOTEST_FLAGS="-v -p 1 -timeout=30m -coverprofile=coverage.out -covermode=atomic"
make ${{ matrix.args }}
- if: ${{ runner.os == 'Linux' && matrix.goversion == '1.21.x' }}
- uses: actions/upload-artifact@v3
if: ${{ runner.os == 'Linux' && matrix.goversion == '1.21.x' }}
with:
name: ${{runner.os}}-coverage-gnovm-${{ matrix.args}}-${{matrix.goversion}}
path: ./gnovm/coverage.out

upload-coverage:
needs: test
runs-on: ubuntu-latest
steps:
- name: Download all previous coverage artifacts
uses: actions/download-artifact@v3
with:
path: ${{ runner.temp }}/coverage
- name: Upload combined coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
name: gnovm
verbose: true
flags: gnovm-${{matrix.args}}
files: ./gnovm/coverage.out
directory: ${{ runner.temp }}/coverage
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: ${{ github.repository == 'gnolang/gno' }}

24 changes: 18 additions & 6 deletions .github/workflows/tm2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,24 @@ jobs:
export GOTEST_FLAGS="-v -p 1 -timeout=30m -coverprofile=coverage.out -covermode=atomic"
make ${{ matrix.args }}
touch coverage.out
- if: ${{ runner.os == 'Linux' && matrix.goversion == '1.21.x' }}
- uses: actions/upload-artifact@v3
if: ${{ runner.os == 'Linux' && matrix.goversion == '1.21.x' }}
with:
name: ${{runner.os}}-coverage-tm2-${{ matrix.args}}-${{matrix.goversion}}
path: ./tm2/coverage.out

upload-coverage:
needs: test
runs-on: ubuntu-latest
steps:
- name: Download all previous coverage artifacts
uses: actions/download-artifact@v3
with:
path: ${{ runner.temp }}/coverage
- name: Upload combined coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
name: tm2
verbose: true
flags: tm2-${{matrix.args}}
files: ./tm2/coverage.out
directory: ${{ runner.temp }}/coverage
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: ${{ github.repository == 'gnolang/gno' }}

19 changes: 14 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,15 @@ Add to your `.vimrc` file:

```vim
function! GnoFmt()
cexpr system('gofmt -e -w ' . expand('%')) "or replace with gofumpt, see below
edit!
cexpr system('gofmt -e -w ' . expand('%')) " or replace with gofumpt, see below
edit!
set syntax=go
endfunction
command! GnoFmt call GnoFmt()
augroup gno_autocmd
autocmd!
autocmd BufNewFile,BufRead *.gno set filetype=go
autocmd BufWritePost *.gno GnoFmt
autocmd!
autocmd BufNewFile,BufRead *.gno set syntax=go
autocmd BufWritePost *.gno GnoFmt
augroup END
```

Expand All @@ -96,6 +97,9 @@ To use *gofumpt* instead of *gofmt*, as hinted in the comment, you may either ha
cexpr system('go run -modfile </path/to/gno>/misc/devdeps/go.mod mvdan.cc/gofumpt -w ' . expand('%'))
```

There is an experimental and unofficial [Gno Language Server](https://github.com/jdkato/gnols)
developed by the community, with an installation guide for Neovim.

#### Emacs Support

1. Install [go-mode.el](https://github.com/dominikh/go-mode.el).
Expand All @@ -105,6 +109,11 @@ cexpr system('go run -modfile </path/to/gno>/misc/devdeps/go.mod mvdan.cc/gofump
(add-to-list 'auto-mode-alist '("\\.gno\\'" . go-mode))
```

#### Sublime Text

There is an experimental and unofficial [Gno Language Server](https://github.com/jdkato/gnols)
developed by the community, with an installation guide for Sublime Text.

### Local Setup

To get started with Gno development, the process is relatively straightforward.
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ RUN rm -rf /opt/gno/src/.git

# runtime-base + runtime-tls
FROM debian:stable-slim AS runtime-base
ENV PATH="${PATH}:/opt/gno/bin"
ENV PATH="${PATH}:/opt/gno/bin" \
GNOROOT="/opt/gno/src"
WORKDIR /opt/gno/src
FROM runtime-base AS runtime-tls
RUN apt-get update && apt-get install -y expect ca-certificates && update-ca-certificates
Expand Down
86 changes: 86 additions & 0 deletions docs/testing_guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Gnoland Testing Guide

This guide provides an overview of our testing practices and conventions. While most of our testing aligns with typical Go practices, there are exceptions and specifics you should be aware of.

## Standard Package Testing

For most packages, tests are written and executed in the standard Go manner:

- Tests are located alongside the code they test.
- The `go test` command can be used to execute tests.

However, as mentioned earlier, there are some exceptions. In the following sections, we will explore our specialized tests and how to work with them.

## Gno Filetests

**Location:** `gnovm/test/files`

These are our custom file-based tests tailored specifically for this project.

**Execution:**

From the gnovm directory, There are two main commands to run Gno filetests:

1. To test native files, use:
```
make _test.gnolang.native
```

2. To test standard libraries, use:
```
make _test.gnolang.stdlibs
```

**Golden Files Update:**

Golden files are references for expected outputs. Sometimes, after certain updates, these need to be synchronized. To do so:

1. For native tests:
```
make _test.gnolang.native.sync
```

2. For standard library tests:
```
make _test.gnolang.stdlibs.sync
```

## Integration Tests

**Location:** `gno.land/**/testdata`

From the gno.land directory, Integration tests are designed to ensure different parts of the project work cohesively. Specifically:

1. **InMemory Node Integration Testing:**
Found in `gno.land/cmd/gnoland/testdata`, these are dedicated to running integration tests against a genuine `gnoland` node.

2. **Integration Features Testing:**
Located in `gno.land/pkg/integration/testdata`, these tests target integrations specific commands.

These integration tests utilize the `testscript` package and follow the `txtar` file specifications.

**Documentation:**

- For general `testscript` package documentation, refer to: [testscript documentation](https://github.com/rogpeppe/go-internal/blob/v1.11.0/testscript/doc.go)

- For more specific details about our integration tests, consult our extended documentation: [gnoland integration documentation](https://github.com/gnolang/gno/blob/master/gno.land/pkg/integration/doc.go)

**Execution:**

To run the integration tests (alongside other packages):

```
make _test.pkgs
```

**Golden Files Update within txtar:**

For tests utilizing the `cmp` command inside `txtar` files, golden files can be synchronized using:

```
make _test.pkgs.sync
```

---

As the project evolves, this guide might be updated.
8 changes: 4 additions & 4 deletions examples/gno.land/p/demo/grc/grc721/basic_nft.gno
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (s *basicNFT) Approve(to std.Address, tid TokenID) error {
return ErrApprovalToCurrentOwner
}

caller := std.GetOrigCaller()
caller := std.PrevRealm().Addr()
if caller != owner && !s.IsApprovedForAll(owner, caller) {
return ErrCallerIsNotOwnerOrApproved
}
Expand Down Expand Up @@ -123,15 +123,15 @@ func (s *basicNFT) SetApprovalForAll(operator std.Address, approved bool) error
return ErrInvalidAddress
}

caller := std.GetOrigCaller()
caller := std.PrevRealm().Addr()
return s.setApprovalForAll(caller, operator, approved)
}

// Safely transfers `tokenId` token from `from` to `to`, checking that
// contract recipients are aware of the GRC721 protocol to prevent
// tokens from being forever locked.
func (s *basicNFT) SafeTransferFrom(from, to std.Address, tid TokenID) error {
caller := std.GetOrigCaller()
caller := std.PrevRealm().Addr()
if !s.isApprovedOrOwner(caller, tid) {
return ErrCallerIsNotOwnerOrApproved
}
Expand All @@ -150,7 +150,7 @@ func (s *basicNFT) SafeTransferFrom(from, to std.Address, tid TokenID) error {

// Transfers `tokenId` token from `from` to `to`.
func (s *basicNFT) TransferFrom(from, to std.Address, tid TokenID) error {
caller := std.GetOrigCaller()
caller := std.PrevRealm().Addr()
if !s.isApprovedOrOwner(caller, tid) {
return ErrCallerIsNotOwnerOrApproved
}
Expand Down
11 changes: 7 additions & 4 deletions gno.land/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ test: _test.gnoland _test.gnoweb _test.gnokey _test.pkgs

GOTEST_FLAGS ?= -v -p 1 -timeout=30m

_test.gnoland:; go test $(GOTEST_FLAGS) ./cmd/gnoland
_test.gnoweb:; go test $(GOTEST_FLAGS) ./cmd/gnoweb
_test.gnokey:; go test $(GOTEST_FLAGS) ./cmd/gnokey
_test.pkgs:; go test $(GOTEST_FLAGS) ./pkg/...
_test.gnoland:; go test $(GOTEST_FLAGS) ./cmd/gnoland
_test.gnoweb:; go test $(GOTEST_FLAGS) ./cmd/gnoweb
_test.gnokey:; go test $(GOTEST_FLAGS) ./cmd/gnokey
_test.pkgs:; go test $(GOTEST_FLAGS) ./pkg/...
_test.pkgs.sync:; UPDATE_SCRIPTS=true go test $(GOTEST_FLAGS) ./pkg/...


3 changes: 2 additions & 1 deletion gno.land/cmd/gnokey/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import (
"fmt"
"os"

"github.com/gnolang/gno/tm2/pkg/commands"
"github.com/gnolang/gno/tm2/pkg/crypto/keys/client"
)

func main() {
cmd := client.NewRootCmd()
cmd := client.NewRootCmd(commands.NewDefaultIO())

if err := cmd.ParseAndRun(context.Background(), os.Args[1:]); err != nil {
_, _ = fmt.Fprintf(os.Stderr, "%+v\n", err)
Expand Down
12 changes: 12 additions & 0 deletions gno.land/cmd/gnoland/integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package main

import (
"testing"

"github.com/gnolang/gno/gno.land/pkg/integration"
"github.com/rogpeppe/go-internal/testscript"
)

func TestTestdata(t *testing.T) {
testscript.Run(t, integration.SetupGnolandTestScript(t, "testdata"))
}
Loading

0 comments on commit 49929f2

Please sign in to comment.