Skip to content

Commit b444b1d

Browse files
authored
Merge branch 'master' into false-positive-unused
2 parents 1773c3b + ec86630 commit b444b1d

File tree

179 files changed

+9062
-3962
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

179 files changed

+9062
-3962
lines changed

.github/workflows/examples.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ on:
66
- master
77
pull_request:
88
paths:
9-
- gnovm/**/*.gno
10-
- examples/**/*.gno
11-
- examples/**/gno.mod
9+
# any change to gnovm code can make examples fail
10+
- gnovm/**
11+
- examples/**
1212

1313
concurrency:
1414
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}

.github/workflows/gnovm.yml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88
paths:
99
- gnovm/**
1010
- tm2/** # GnoVM has a dependency on TM2 types
11+
- examples/** # gnovm has some tests that depend on examples
1112
# We trigger the testing workflow for changes to the main go.mod,
1213
# since this can affect test results
1314
- go.mod

docs/builders/deploy-packages.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ a third-party web extension wallet, such as Adena.
150150
[^1]: Read more about package paths [here](../resources/gno-packages.md).
151151
[^2]: Other network configurations can be found [here](../resources/gnoland-networks.md).
152152
[^3]: Address namespaces ([PA namespaces](../resources/gno-packages.md#package-path-structure)) are automatically granted to
153-
users. Users can register a username using the [gno.land user registry](https://gno.land/r/demo/users),
153+
users. Users can register a username using the [gno.land user registry](https://gno.land/r/gnoland/users),
154154
which will grant them access to a matching namespace for that specific network.
155155
[^4]: Automatic gas estimation is being worked on for `gnokey`. Follow progress
156156
[here](https://github.com/gnolang/gno/pull/3330).

docs/resources/glossary.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,9 @@ or calling a realm function.
265265
The smallest unit of GNOT. 1 GNOT = 1,000,000 ugnot (micro-GNOT).
266266

267267
### User Registry
268+
268269
A system realm that allows users to register usernames and claim matching
269-
namespaces for deploying code. Found at `gno.land/r/demo/users`.
270+
namespaces for deploying code. List of releases found at `gno.land/r/gnoland/users`.
270271
See [Users and Teams](./users-and-teams.md) for details.
271272

272273
### wugnot

docs/resources/gno-packages.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ depth as long as the full package path doesn't exceed `256` characters.
9393

9494
To register a custom namespace:
9595

96-
1. Register a username at `gno.land/r/demo/users`
96+
1. Register a username at `gno.land/r/gnoland/users`
9797
2. Once registered, you can deploy packages under that namespace
9898
3. Only you can deploy to your namespace
9999

docs/resources/users-and-teams.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,24 @@ In gno.land, users can register a unique username that:
1111

1212
To register a username:
1313

14-
1. Visit the user registry realm at [`gno.land/r/demo/users`](https://gno.land/r/demo/users)
15-
2. Check if your desired username is available
14+
1. Visit the user registry realm at [`gno.land/r/gnoland/users`](https://gno.land/r/gnoland/users)
15+
2. Check if your desired username is available by
1616
3. Register using the following command:
1717

1818
```bash
1919
gnokey maketx call \
20-
--pkgpath "gno.land/r/demo/users" \
20+
--pkgpath "gno.land/r/gnoland/users/v1" \
2121
--func "Register" \
2222
--args "YOUR_USERNAME" \
2323
--gas-fee 1000000ugnot \
2424
--gas-wanted 2000000 \
25+
--send "1000000ugnot" \
2526
--remote https://rpc.gno.land:443 \
2627
--chainid portal-loop \
2728
YOUR_KEY_NAME
2829
```
2930

30-
The registration costs 200 GNOT, which serves as an anti-spam measure and ensures users value their identities.
31+
The registration costs 1 GNOT, which serves as an anti-spam measure and ensures users value their identities.
3132

3233
## Username Ownership
3334

@@ -46,7 +47,7 @@ gno.land/p/YOUR_USERNAME/... # Pure packages
4647
gno.land/r/YOUR_USERNAME/... # Realms
4748
```
4849

49-
For example, a user with username "alice" could deploy:
50+
For example, a user with the username "alice" could deploy:
5051
- `gno.land/r/alice/blog` - A personal blog realm
5152
- `gno.land/p/alice/utils` - A utility package
5253

@@ -85,4 +86,4 @@ For more information on users and namespaces, refer to:
8586
- [Realms](./realms.md) - Learn about stateful applications that can be deployed under your namespace
8687
- [Deploying Packages](../builders/deploy-packages.md) - Instructions for deploying code under your namespace
8788

88-
To explore registered users, visit the [User Registry](https://gno.land/r/demo/users) on the Portal Loop network.
89+
To explore registered users, visit the [User Registry](https://gno.land/r/gnoland/users) on the Portal Loop network.

docs/users/explore-with-gnoweb.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Let's break it down:
3636
- `type` represents the type of package found on this path. There are two available
3737
options - `p` & `r` - pure packages and realms, respectively.
3838
- `namespace` is the namespace of the package. Namespaces can be registered using
39-
the `gno.land/r/demo/users` realm, granting a user permission to deploy under
39+
the `gno.land/r/gnoland/users` realms, granting a user permission to deploy under
4040
that specific namespace.
4141
- `package name` represents the name of the package found on the path. This part has
4242
to match the top-level package declaration in Gno files.

examples/Makefile

+1-8
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@ GOIMPORTS_FLAGS ?= $(GOFMT_FLAGS)
2222
# test suite flags.
2323
GOTEST_FLAGS ?= -v -p 1 -timeout=30m
2424

25-
# Official packages (non-overridable): more reliable and tested modules, distinct from the experimentation area.
26-
OFFICIAL_PACKAGES = ./gno.land/p
27-
OFFICIAL_PACKAGES += ./gno.land/r/demo
28-
OFFICIAL_PACKAGES += ./gno.land/r/gnoland
29-
OFFICIAL_PACKAGES += ./gno.land/r/sys
30-
OFFICIAL_PACKAGES += ./gno.land/r/gov
31-
3225
########################################
3326
# Dev tools
3427
.PHONY: transpile
@@ -45,7 +38,7 @@ test:
4538

4639
.PHONY: lint
4740
lint:
48-
go run ../gnovm/cmd/gno tool lint -v $(OFFICIAL_PACKAGES)
41+
go run ../gnovm/cmd/gno tool lint -v .
4942

5043
.PHONY: test.sync
5144
test.sync:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package forms
2+
3+
import (
4+
"std"
5+
"time"
6+
7+
"gno.land/p/demo/json"
8+
)
9+
10+
const dateFormat = "2006-01-02T15:04:05Z"
11+
12+
func CreateField(label string, fieldType string, required bool) Field {
13+
return Field{
14+
Label: label,
15+
FieldType: fieldType,
16+
Required: required,
17+
}
18+
}
19+
20+
// CreateForm creates a new form with the given parameters
21+
func (db *FormDB) CreateForm(title string, description string, openAt string, closeAt string, data string) (string, error) {
22+
// Parsing the dates
23+
var parsedOpenTime, parsedCloseTime time.Time
24+
25+
if openAt != "" {
26+
var err error
27+
parsedOpenTime, err = time.Parse(dateFormat, openAt)
28+
if err != nil {
29+
return "", errInvalidDate
30+
}
31+
}
32+
33+
if closeAt != "" {
34+
var err error
35+
parsedCloseTime, err = time.Parse(dateFormat, closeAt)
36+
if err != nil {
37+
return "", errInvalidDate
38+
}
39+
}
40+
41+
// Parsing the json submission
42+
node, err := json.Unmarshal([]byte(data))
43+
if err != nil {
44+
return "", errInvalidJson
45+
}
46+
47+
fieldsCount := node.Size()
48+
fields := make([]Field, fieldsCount)
49+
50+
// Parsing the json submission to create the gno data structures
51+
for i := 0; i < fieldsCount; i++ {
52+
field := node.MustIndex(i)
53+
54+
fields[i] = CreateField(
55+
field.MustKey("label").MustString(),
56+
field.MustKey("fieldType").MustString(),
57+
field.MustKey("required").MustBool(),
58+
)
59+
}
60+
61+
// Generating the form ID
62+
id := db.IDCounter.Next().String()
63+
64+
// Creating the form
65+
form := Form{
66+
ID: id,
67+
Owner: std.PreviousRealm().Address(),
68+
Title: title,
69+
Description: description,
70+
CreatedAt: time.Now(),
71+
openAt: parsedOpenTime,
72+
closeAt: parsedCloseTime,
73+
Fields: fields,
74+
}
75+
76+
// Adding the form to the database
77+
db.Forms = append(db.Forms, &form)
78+
79+
return id, nil
80+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package forms
2+
3+
import (
4+
"std"
5+
"testing"
6+
7+
"gno.land/p/demo/testutils"
8+
"gno.land/p/demo/urequire"
9+
)
10+
11+
func TestCreateForm(t *testing.T) {
12+
alice := testutils.TestAddress("alice")
13+
std.TestSetOriginCaller(alice)
14+
db := NewDB()
15+
title := "Simple Form"
16+
description := "This is a form"
17+
openAt := "2021-01-01T00:00:00Z"
18+
closeAt := "2021-01-02T00:00:00Z"
19+
data := `[
20+
{
21+
"label": "Name",
22+
"fieldType": "string",
23+
"required": true
24+
},
25+
{
26+
"label": "Age",
27+
"fieldType": "number",
28+
"required": false
29+
},
30+
{
31+
"label": "Is this a test?",
32+
"fieldType": "boolean",
33+
"required": false
34+
},
35+
{
36+
"label": "Favorite Food",
37+
"fieldType": "['Pizza', 'Schnitzel', 'Burger']",
38+
"required": true
39+
},
40+
{
41+
"label": "Favorite Foods",
42+
"fieldType": "{'Pizza', 'Schnitzel', 'Burger'}",
43+
"required": true
44+
}
45+
]`
46+
47+
urequire.NotPanics(t, func() {
48+
id, err := db.CreateForm(title, description, openAt, closeAt, data)
49+
if err != nil {
50+
panic(err)
51+
}
52+
urequire.True(t, id != "", "Form ID is empty")
53+
54+
form, err := db.GetForm(id)
55+
if err != nil {
56+
panic(err)
57+
}
58+
59+
urequire.True(t, form.ID == id, "Form ID is not correct")
60+
urequire.True(t, form.Owner == alice, "Owner is not correct")
61+
urequire.True(t, form.Title == title, "Title is not correct")
62+
urequire.True(t, form.Description == description, "Description is not correct")
63+
urequire.True(t, len(form.Fields) == 5, "Not enough fields were provided")
64+
urequire.True(t, form.Fields[0].Label == "Name", "Field 0 label is not correct")
65+
urequire.True(t, form.Fields[0].FieldType == "string", "Field 0 type is not correct")
66+
urequire.True(t, form.Fields[0].Required == true, "Field 0 required is not correct")
67+
urequire.True(t, form.Fields[1].Label == "Age", "Field 1 label is not correct")
68+
urequire.True(t, form.Fields[1].FieldType == "number", "Field 1 type is not correct")
69+
})
70+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// # Gno forms
2+
3+
// gno-forms is a package which demonstrates a form editing and sharing application in gno
4+
5+
// ## Features
6+
// - **Form Creation**: Create new forms with specified titles, descriptions, and fields.
7+
// - **Form Submission**: Submit answers to forms.
8+
// - **Form Retrieval**: Retrieve existing forms and their submissions.
9+
// - **Form Deadline**: Set a precise time range during which a form can be interacted with.
10+
11+
// ## Field Types
12+
// The system supports the following field types:
13+
14+
// | type | example |
15+
// |--------------|-------------------------------------------------------------------------------------------------|
16+
// | string | `{"label": "Name", "fieldType": "string", "required": true}` |
17+
// | number | `{"label": "Age", "fieldType": "number", "required": true}` |
18+
// | boolean | `{"label": "Is Student?", "fieldType": "boolean", "required": false}` |
19+
// | choice | `{"label": "Favorite Food", "fieldType": "['Pizza', 'Schnitzel', 'Burger']", "required": true}` |
20+
// | multi-choice | `{"label": "Hobbies", "fieldType": "{'Reading', 'Swimming', 'Gaming'}", "required": false}` |
21+
22+
// ## Web-app
23+
24+
// The external repo where the initial development took place and where you can find the frontend is [here](https://github.com/agherasie/gno-forms).
25+
package forms
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package forms
2+
3+
import "errors"
4+
5+
var (
6+
errNoOpenDate = errors.New("Form has no open date")
7+
errNoCloseDate = errors.New("Form has no close date")
8+
errInvalidJson = errors.New("Invalid JSON")
9+
errInvalidDate = errors.New("Invalid date")
10+
errFormNotFound = errors.New("Form not found")
11+
errAnswerNotFound = errors.New("Answer not found")
12+
errAlreadySubmitted = errors.New("You already submitted this form")
13+
errFormClosed = errors.New("Form is closed")
14+
errInvalidAnswers = errors.New("Invalid answers")
15+
)

0 commit comments

Comments
 (0)