Skip to content

Commit

Permalink
feat: add contents from portal (gnolang#19)
Browse files Browse the repository at this point in the history
* feat: add contents from portal

* feat: add contents from portal

* feat: add tutorials

* fixup

* Make Docusaurus happy

---------

Co-authored-by: Milos Zivkovic <milos.zivkovic@tendermint.com>
  • Loading branch information
dongwon8247 and zivkovicmilos authored Oct 10, 2023
1 parent c940c2c commit e2343c6
Show file tree
Hide file tree
Showing 41 changed files with 3,720 additions and 92 deletions.
7 changes: 0 additions & 7 deletions docs/gno-docs/docs/explanation/gno-cli/common-params.md

This file was deleted.

7 changes: 0 additions & 7 deletions docs/gno-docs/docs/explanation/gno-cli/gno.md

This file was deleted.

7 changes: 0 additions & 7 deletions docs/gno-docs/docs/explanation/gno-cli/gnofaucet.md

This file was deleted.

7 changes: 0 additions & 7 deletions docs/gno-docs/docs/explanation/gno-cli/gnokey.md

This file was deleted.

7 changes: 0 additions & 7 deletions docs/gno-docs/docs/explanation/gno-cli/gnoland.md

This file was deleted.

7 changes: 0 additions & 7 deletions docs/gno-docs/docs/explanation/gno-cli/gnotxsync.md

This file was deleted.

7 changes: 0 additions & 7 deletions docs/gno-docs/docs/explanation/gno-cli/gnoweb.md

This file was deleted.

28 changes: 27 additions & 1 deletion docs/gno-docs/docs/explanation/gno-language.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,30 @@ id: gno-language

# The Gno Language

TODO
Gnolang (Gno) is an interpretation of the widely-used Golang (Go) programming language for blockchain created by Cosmos co-founder Jae Kwon in 2022 to mark a new era in smart contracting. Gno is ~99% identical to Go, so Go programmers can start coding in Gno right away, with a minimal learning curve. For example, Gno comes with blockchain-specific standard libraries, but any code that doesn’t use blockchain-specific logic can run in Go with minimal processing. Libraries that don’t make sense in the blockchain context, such as network or operating-system access, are not available in Gno. Otherwise, Gno loads and uses many standard libraries that power Go, so most of the parsing of the source code is the same.

Under the hood, the Gno code is parsed into an abstract syntax tree (AST) and the AST itself is used in the interpreter, rather than bytecode as in many virtual machines such as Java, Python, or Wasm. This makes even the GnoVM accessible to any Go programmer. The novel design of the intuitive GnoVM interpreter allows Gno to freeze and resume the program by persisting and loading the entire memory state. Gno is deterministic, auto-persisted, and auto-Merkle-ized, allowing (smart contract) programs to be succinct, as the programmer doesn’t have to serialize and deserialize objects to persist them into a database (unlike programming applications with the Cosmos SDK).

## How Gno Differs from Go

The composable nature of Go/Gno allows for type-checked interactions between contracts, making Gno.land safer and more powerful, as well as operationally cheaper and faster. Smart contracts on Gno.land are light, simple, more focused, and easily interoperable—a network of interconnected contracts rather than siloed monoliths that limit interactions with other contracts.

## Gno Inherits Go’s Built-in Security Features

Go supports secure programming through exported/non-exported fields, enabling a “least-authority” design. It is easy to create objects and APIs that expose only what should be accessible to callers while hiding what should not be simply by the capitalization of letters, thus allowing a succinct representation of secure logic that can be called by multiple users.

Another major advantage of Go is that the language comes with an ecosystem of great tooling, like the compiler and third-party tools that statically analyze code. Gno inherits these advantages from Go directly to create a smart contract programming language that provides embedding, composability, type-check safety, and garbage collection, helping developers to write secure code relying on the compiler, parser, and interpreter to give warning alerts for common mistakes.

## Gno vs Solidity

The most widely-adopted smart contract language today is Ethereum’s EVM-compatible Solidity. With bytecode built from the ground up and Turing complete, Solidity opened up a world of possibilities for decentralized applications (dApps) and there are currently more than 10 million contracts deployed on Ethereum. However, Solidity provides limited tooling and its EVM has a stack limit and computational inefficiencies.

Solidity is designed for one purpose only (writing smart contracts) and is bound by the limitations of the EVM. In addition, developers have to learn several languages if they want to understand the whole stack or work across different ecosystems. Gno aspires to exceed Solidity on multiple fronts (and other smart contract languages like CosmWasm or Substrate) as every part of the stack is written in Gno. It’s easy for developers to understand the entire system just by studying a relatively small code base.

## Gno Is Essential for the Wider Adoption of Web3

Gno makes imports as easy as they are in web2 with runtime-based imports for seamless dependency flow comprehension, and support for complex structs, beyond primitive types. Gno is ultimately cost-effective as dependencies are loaded once, enabling remote function calls as local, and providing automatic and independent per-realm state persistence.

Using Gno, developers can rapidly accelerate application development and adopt a modular structure by reusing and reassembling existing modules without building from scratch. They can embed one structure inside another in an intuitive way while preserving localism, and the language specification is simple, successfully balancing practicality and minimalism.

The Go language is so well designed that the Gno smart contract system will become the new gold standard for smart contract development and other blockchain applications. As a programming language that is universally adopted, secure, composable, and complete, Gno is essential for the broader adoption of web3 and its sustainable growth.
77 changes: 76 additions & 1 deletion docs/gno-docs/docs/explanation/gno-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,79 @@ id: gno-test

# Gno Test

TODO
There are two methods for testing a realm or package during the development phase:

1. Calling the realm/package after deploying it on a local network (or testnet).
2. Using the `test` option within the [`gno`](../cli/gno.md) CLI.

While the first method is recommended for its accuracy and similarity to the actual deployment environment, it is more efficient to initially utilize the second method for composing test cases and then proceed to the first method if no errors are detected.

This section will teach you how to use the second method.

Writing test cases in Gnolang is similar to that of Golang, with general rules as the following:

* Test file naming conventions must be adhered to (ex: `xxx_test.gno`).
* Test functions must start with `Test`.
* The `t *testing.T` argument must be included in each test function.
* The `testing` package must be imported.
* Tests must be run with the `gno test` command.

Let's write a sample code and test it.

```go
// contract.gno

package demo

func Hello(name string) string {
return "Hello " + name + "!"
}
```

This is a simple code that returns the string-typed argument in a specific format.

Next, we'll write a test case that looks like the following:

```go
// contract_test.gno

package demo

import "testing"

func Test(t *testing.T) {
{
got := Hello("People")
expected := "Hello People!"
if got != expected {
t.Fatalf("expected %q, got %q.", expected, got)
}
}
{
got := Hello("")
expected := "Hello People!"
if got != expected {
t.Fatalf("expected %q, got %q.", expected, got)
}
}
}
```

Two conditions exist in the test case above.

1. "Hello People!" should be returned when calling `Hello("People")`.
2. "Hello People!" should be returned when calling `Hello("")`.

Upon examination of our realm code and the associated test results, the initial condition exhibited the desired behavior; however, an error was identified in the second condition. Despite the expected outcome of "Hello" being returned, the test case incorrectly specified that the expected output should be "Hello People!" instead.

Replacing the second test case with the following will successfully fix the issue and allow the test to pass.

```go
{
got := Hello("")
expected := "Hello !"
if got != expected {
t.Fatalf("expected %q, got %q.", expected, got)
}
}
```
16 changes: 16 additions & 0 deletions docs/gno-docs/docs/explanation/gno-tooling/cli/common-params.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
id: gno-tooling-common-params
---

# Common Parameters

Below is a list of common parameters.

| Name | Description | Default |
| ------------------------- | ------------------------------------ | ---------------------------------------- |
| `home` | The home directory. | `GNO_HOME` or the user's home directory. |
| `remote` | The remote node URL. | `127.0.0.1:26657` |
| `quiet` | For parsing output. | `false` |
| `insecure-password-stdin` | INSECURE! Takes password from stdin. | `false` |


66 changes: 66 additions & 0 deletions docs/gno-docs/docs/explanation/gno-tooling/cli/gno.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
id: gno-tooling-gno
---

# gno

`gno` is a handy tool for developing and prototyping Gno packages and realms. You may use `gno` to use the GnoVM without an actual blockchain to build or test realms in a local environment.

## Run `gno` Commands

The following command will run `gno`.

```bash
gno {SUB_COMMAND}
```

**Subcommands**

| Name | Description |
| ------------ | ------------------------------------------ |
| `build` | Builds a gno package. |
| `test` | Tests a gno package. |
| `precompile` | Precompiles a `.gno` file to a `.go` file. |
| `repl` | Starts a GnoVM REPL. |

### `build`

#### **Options**

| Name | Type | Description |
| --------- | ------- | ---------------------------------------------- |
| `verbose` | Boolean | Displays extended information. |
| go-binary | String | Go binary to use for building (default: `go`). |

### `test`

#### **Options**

| Name | Type | Description |
| ------------ | ------------- | ------------------------------------------------------------------ |
| `verbose` | Boolean | Displays extended information. |
| `root-dir` | String | Clones location of github.com/gnolang/gno (gno tries to guess it). |
| `run` | String | Test name filtering pattern. |
| `timeout` | time.Duration | The maximum execution time in ns. |
| `precompile` | Boolean | Precompiles a `.gno` file to a `.go` file before testing. |

### `precompile`

#### **Options**

| Name | Type | Description |
| ----------- | ------- | --------------------------------------------------------------- |
| `verbose` | Boolean | Displays extended information. |
| `skip-fmt` | Boolean | Skips the syntax checking of generated `.go` files. |
| `go-binary` | String | The go binary to use for building (default: `go`). |
| `go-binary` | String | The gofmt binary to use for syntax checking (default: `gofmt`). |
| `output` | String | The output directory (default: `.`). |

### `repl`

#### **Options**

| Name | Type | Description |
| ---------- | ------- | ------------------------------------------------------------------ |
| `verbose` | Boolean | Displays extended information. |
| `root-dir` | String | Clones location of github.com/gnolang/gno (gno tries to guess it). |
53 changes: 53 additions & 0 deletions docs/gno-docs/docs/explanation/gno-tooling/cli/gnofaucet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
id: gno-tooling-gnofaucet
---

# gnofaucet

`gnofaucet` is a server for distributing GNOT, the gas currency of Gnoland, to specific addresses in a local chain. Interact with the `gnofaucet` from an address with an empty balance in your locally built testnet to fuel it with GNOT to pay for transactions.

## Run `gnofaucet` Commands

Enable the faucet using the following command.

```bash
gnofaucet serve
```

#### **Options**

| Name | Type | Description |
| ------------------------- | ------- | ------------------------------------------------------------------------------------ |
| `chain-id` | String | The id of the chain (required). |
| `gas-wanted` | Int64 | The maximum amount of gas to use for the transaction (default: `50000`) |
| `gas-fee` | String | The gas fee to pay for the transaction. |
| `memo` | String | Any descriptive text (default: `""`) |
| `test-to` | String | Test address (optional) 부연설명 필요 |
| `send` | String | Coins to send (default: `"1000000ugnot"`). |
| `captcha-secret` | String | The secret key for the recaptcha. If empty, the captcha is disabled (default: `""`). |
| `is-behind-proxy` | Boolean | Uses X-Forwarded-For IP for throttling (default: `false`). |
| `insecure-password-stdin` | Boolean | INSECURE! Takes password from stdin (default: `false`). |

## Example

### **Step 1. Create an account named `test1` with the test seed phrase below.**

```bash
gnokey add test1 --recover
```

> **Test Seed Phrase:** source bonus chronic canvas draft south burst lottery vacant surface solve popular case indicate oppose farm nothing bullet exhibit title speed wink action roast
### **Step 2. Run `gnofaucet`**

```bash
gnofaucet serve test1 --chain-id dev --send 500000000ugnot
```

### **Step 3. Receive GNOTs from the faucet**

```bash
curl --location --request POST 'http://localhost:5050' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'toaddr={address to receive}'
```
Loading

0 comments on commit e2343c6

Please sign in to comment.