generated from moul/gno-hello
-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Manfred Touron <[email protected]>
- Loading branch information
Showing
6 changed files
with
88 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,4 @@ | ||
-include ../single.mk | ||
|
||
# ''gnodev build' does not work yet w/ this demo. | ||
build: | ||
@exit 0 | ||
|
||
# install gno.land/p/dom if not yet existing | ||
publish: publish-dom publish-default | ||
publish-dom: | ||
$(call publish_pkg,gno.land/p/dom,"${GNO_ROOT}/examples/gno.land/p/dom") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,31 @@ | ||
# [r/moul_basics_import_v1](https://test2.gno.land/r/moul_basics_import_v1) | ||
# [r/moul_basics_grc20_v1](https://test2.gno.land/r/moul_basics_grc20_v1) | ||
_`README.md` generated by "make integration"._ | ||
|
||
## Examples | ||
|
||
```console | ||
foo@bar:~$ gnokey maketx call "MYWALLET" --gas-fee "1ugnot" \ | ||
> --broadcast "true" --chainid "test2" --remote "test2.gno.land:36657" \ | ||
> --gas-wanted "500000" --pkgpath gno.land/r/moul_basics_import_v1 \ | ||
> --func Render --args | ||
> --gas-wanted "500000" --pkgpath gno.land/r/moul_basics_grc20_v1 \ | ||
> --func MyBalance | ||
(100000000 uint64) | ||
OK! | ||
GAS WANTED: 500000 | ||
GAS USED: 289953 | ||
``` | ||
|
||
## `gnodev test` | ||
|
||
```console | ||
foo@bar:~$ gnodev test . --verbose | ||
=== RUN Test | ||
--- PASS: Test (0.00s) | ||
ok ./. 3.07s | ||
``` | ||
|
||
## How to publish locally | ||
|
||
```sh | ||
gnokey maketx addpkg "MYWALLET" --deposit "1ugnot" --gas-fee "1ugnot" --gas-wanted "5000000" --broadcast "true" --remote "localhost:26657" --chainid "dev" --pkgpath "gno.land/r/moul_basics_grc20_v1" --pkgdir "." | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,29 @@ | ||
package demo | ||
|
||
import ( | ||
"gno.land/p/avl" | ||
"gno.land/p/dom" | ||
"std" | ||
|
||
"gno.land/p/grc/grc20" | ||
) | ||
|
||
func Render(path string) string { | ||
thread := dom.Plot{Name: "Hello!"} | ||
thread.AddPost("Foo", "foo foo foo") | ||
thread.AddPost("Bar", "bar bar bar") | ||
return thread.String() | ||
// FooToken is exported. Other contracts can interact with it. | ||
var FooToken grc20.IGRC20 | ||
|
||
func init() { | ||
// generate minter and mint some tokens to test1. | ||
const test1 = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") | ||
minter := grc20.NewAdminToken("Foo Token", "FOO", 4) | ||
minter.Mint(test1, 100000000) | ||
|
||
// publicly expose an unprivileged implementation of IGRC20. | ||
FooToken = minter.GRC20() | ||
} | ||
|
||
func MyBalance() uint64 { | ||
caller := std.GetOrigCaller() | ||
balance, err := FooToken.BalanceOf(caller) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return balance | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,54 @@ | ||
package demo | ||
|
||
import ( | ||
"std" | ||
"strings" | ||
"testing" | ||
|
||
"gno.land/p/testutils" | ||
) | ||
|
||
func Test(t *testing.T) { | ||
got := Render("") | ||
expected := ` | ||
# [plot] Hello! | ||
## Foo | ||
foo foo foo | ||
## Bar | ||
bar bar bar | ||
` | ||
if strings.TrimSpace(got) != strings.TrimSpace(expected) { | ||
t.Fatalf("expected %q, got %q.", expected, got) | ||
test1 := std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") | ||
test2 := testutils.TestAddress("test2") | ||
std.TestSetOrigCaller(test1) | ||
|
||
// check token metadata. | ||
{ | ||
got := FooToken.GetName() | ||
expected := "Foo Token" | ||
if strings.TrimSpace(got) != strings.TrimSpace(expected) { | ||
t.Fatalf("expected %q, got %q.", expected, got) | ||
} | ||
} | ||
|
||
// check balance of test1. | ||
{ | ||
got, _ := FooToken.BalanceOf(test1) | ||
expected := 100000000 | ||
if got != expected { | ||
t.Fatalf("expected %d, got %d.", expected, got) | ||
} | ||
} | ||
|
||
// transfer tokens to test2. | ||
_ = FooToken.Transfer(test2, 1000) | ||
|
||
// check balance of test1. | ||
{ | ||
got, _ := FooToken.BalanceOf(test1) | ||
expected := 99999000 | ||
if got != expected { | ||
t.Fatalf("expected %d, got %d.", expected, got) | ||
} | ||
} | ||
|
||
// check balance of test2. | ||
{ | ||
got, _ := FooToken.BalanceOf(test2) | ||
expected := 1000 | ||
if got != expected { | ||
t.Fatalf("expected %d, got %d.", expected, got) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
r/moul_basics_import_v1 | ||
r/moul_basics_grc20_v1 |