Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove import cycle in test files #1206

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions examples/gno.land/p/demo/rand/rand_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,36 @@ import (
"std"
"strings"
"testing"

"gno.land/p/demo/rand"
)

func TestInstance(t *testing.T) {
instance := rand.New()
instance := New()
if instance == nil {
t.Errorf("instance should not be nil")
}
}

func TestIntn(t *testing.T) {
baseRand := rand.New()
baseRand := New()
baseResult := computeIntn(t, baseRand)

sameHeightRand := rand.New()
sameHeightRand := New()
sameHeightResult := computeIntn(t, sameHeightRand)

if baseResult != sameHeightResult {
t.Errorf("should have the same result: new=%s, base=%s", sameHeightResult, baseResult)
}

std.TestSkipHeights(1)
differentHeightRand := rand.New()
differentHeightRand := New()
differentHeightResult := computeIntn(t, differentHeightRand)

if baseResult == differentHeightResult {
t.Errorf("should have different result: new=%s, base=%s", differentHeightResult, baseResult)
}
}

func computeIntn(t *testing.T, r *rand.Instance) string {
func computeIntn(t *testing.T, r *Instance) string {
t.Helper()

arr := []string{}
Expand Down
47 changes: 23 additions & 24 deletions examples/gno.land/r/gnoland/faucet/faucet_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"testing"

"gno.land/p/demo/testutils"
"gno.land/r/gnoland/faucet"
)

func TestPackage(t *testing.T) {
Expand Down Expand Up @@ -37,57 +36,57 @@ func TestPackage(t *testing.T) {

assertBalance(t, test1addr, 0)
std.TestSetOrigCaller(test1addr)
assertErr(t, faucet.Transfer(test1addr, 1000000))
assertErr(t, Transfer(test1addr, 1000000))

assertErr(t, faucet.AdminAddController(controlleraddr1))
assertErr(t, AdminAddController(controlleraddr1))
std.TestSetOrigCaller(controlleraddr1)
assertErr(t, faucet.Transfer(test1addr, 1000000))
assertErr(t, Transfer(test1addr, 1000000))

// as an admin, add the controller to contract and deposit more 2000gnot to contract
std.TestSetOrigCaller(adminaddr)
assertNoErr(t, faucet.AdminAddController(controlleraddr1))
assertNoErr(t, AdminAddController(controlleraddr1))
assertBalance(t, faucetaddr, 1000000000)

// now, send some tokens as controller.
std.TestSetOrigCaller(controlleraddr1)
assertNoErr(t, faucet.Transfer(test1addr, 1000000))
assertNoErr(t, Transfer(test1addr, 1000000))
assertBalance(t, test1addr, 1000000)
assertNoErr(t, faucet.Transfer(test1addr, 1000000))
assertNoErr(t, Transfer(test1addr, 1000000))
assertBalance(t, test1addr, 2000000)
assertBalance(t, faucetaddr, 998000000)

// remove controller
// as an admin, remove controller
std.TestSetOrigCaller(adminaddr)
assertNoErr(t, faucet.AdminRemoveController(controlleraddr1))
assertNoErr(t, AdminRemoveController(controlleraddr1))
std.TestSetOrigCaller(controlleraddr1)
assertErr(t, faucet.Transfer(test1addr, 1000000))
assertErr(t, Transfer(test1addr, 1000000))

// duplicate controller
std.TestSetOrigCaller(adminaddr)
assertNoErr(t, faucet.AdminAddController(controlleraddr1))
assertErr(t, faucet.AdminAddController(controlleraddr1))
assertNoErr(t, AdminAddController(controlleraddr1))
assertErr(t, AdminAddController(controlleraddr1))
// add more than more than allowed controllers
assertNoErr(t, faucet.AdminAddController(controlleraddr2))
assertNoErr(t, faucet.AdminAddController(controlleraddr3))
assertNoErr(t, faucet.AdminAddController(controlleraddr4))
assertNoErr(t, faucet.AdminAddController(controlleraddr5))
assertNoErr(t, faucet.AdminAddController(controlleraddr6))
assertNoErr(t, faucet.AdminAddController(controlleraddr7))
assertNoErr(t, faucet.AdminAddController(controlleraddr8))
assertNoErr(t, faucet.AdminAddController(controlleraddr9))
assertNoErr(t, faucet.AdminAddController(controlleraddr10))
assertErr(t, faucet.AdminAddController(controlleraddr11))
assertNoErr(t, AdminAddController(controlleraddr2))
assertNoErr(t, AdminAddController(controlleraddr3))
assertNoErr(t, AdminAddController(controlleraddr4))
assertNoErr(t, AdminAddController(controlleraddr5))
assertNoErr(t, AdminAddController(controlleraddr6))
assertNoErr(t, AdminAddController(controlleraddr7))
assertNoErr(t, AdminAddController(controlleraddr8))
assertNoErr(t, AdminAddController(controlleraddr9))
assertNoErr(t, AdminAddController(controlleraddr10))
assertErr(t, AdminAddController(controlleraddr11))

// send more than per transfer limit
std.TestSetOrigCaller(adminaddr)
faucet.AdminSetTransferLimit(300000000)
AdminSetTransferLimit(300000000)
std.TestSetOrigCaller(controlleraddr1)
assertErr(t, faucet.Transfer(test1addr, 301000000))
assertErr(t, Transfer(test1addr, 301000000))

// block transefer from the address not on the controllers list.
std.TestSetOrigCaller(controlleraddr11)
assertErr(t, faucet.Transfer(test1addr, 1000000))
assertErr(t, Transfer(test1addr, 1000000))
}

func assertErr(t *testing.T, err string) {
Expand Down
12 changes: 5 additions & 7 deletions examples/gno.land/r/x/manfred_outfmt/outfmt_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ package outfmt

import (
"testing"

"gno.land/r/x/manfred_outfmt"
)

func TestRender(t *testing.T) {
// home
{
got := outfmt.Render("")
got := Render("")
expected := `* [?fmt=stringer](/r/x/manfred_outfmt:?fmt=stringer)
* [?fmt=json](/r/x/manfred_outfmt:?fmt=json)
* [?fmt=jsonp](/r/x/manfred_outfmt:?fmt=jsonp)
Expand All @@ -21,7 +19,7 @@ func TestRender(t *testing.T) {

// stringer
{
got := outfmt.Render("?fmt=stringer")
got := Render("?fmt=stringer")
expected := `Text: Hello Gnomes!
Number: 957
Numbers: 3 54 32 88
Expand All @@ -33,7 +31,7 @@ Numbers: 3 54 32 88

// stringer again (different seed)
{
got := outfmt.Render("?fmt=stringer")
got := Render("?fmt=stringer")
expected := `Text: Hello Gnomes!
Number: 141
Numbers: 98 27
Expand All @@ -45,7 +43,7 @@ Numbers: 98 27

// json
{
got := outfmt.Render("?fmt=json")
got := Render("?fmt=json")
expected := `{"Number":801,"Text":"Hello Gnomes!","Numbers":[5,78,51,78,91,41]}`
if got != expected {
t.Fatalf("expected %q, got %q.", expected, got)
Expand All @@ -54,7 +52,7 @@ Numbers: 98 27

// jsonp
{
got := outfmt.Render("?fmt=jsonp")
got := Render("?fmt=jsonp")
expected := `callback({"Number":63,"Text":"Hello Gnomes!","Numbers":[2,66,50,73,81]})`
if got != expected {
t.Fatalf("expected %q, got %q.", expected, got)
Expand Down
Loading