Skip to content

Commit

Permalink
chore: make tests pass gnopls linter (#1467)
Browse files Browse the repository at this point in the history
Signed-off-by: Norman <[email protected]>
  • Loading branch information
n0izn0iz authored Dec 29, 2024
1 parent 7f31f69 commit 3d27860
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 36 deletions.
16 changes: 8 additions & 8 deletions gno/r/dao_realm/dao_realm_test.gno
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package dao_realm

import (
"fmt"
"testing"

"gno.land/p/demo/json"
"gno.land/p/demo/ufmt"
"gno.land/p/teritori/dao_voting_group"
"gno.land/p/teritori/havl"
)
Expand Down Expand Up @@ -37,7 +37,7 @@ func TestUpdateMembers(t *testing.T) {
var membersJSON string

{
id := ProposeJSON(0, fmt.Sprintf(`{"title": "Test prop", "description": "A description", "messages": [{"type": "gno.land/p/teritori/dao_voting_group.UpdateMembers", "payload": [{"power": "2", "address": "g18syxa0vh0vmne90mwhtynjet0zgeqf6prh3ryy"}]}]}`))
id := ProposeJSON(0, ufmt.Sprintf(`{"title": "Test prop", "description": "A description", "messages": [{"type": "gno.land/p/teritori/dao_voting_group.UpdateMembers", "payload": [{"power": "2", "address": "g18syxa0vh0vmne90mwhtynjet0zgeqf6prh3ryy"}]}]}`))
VoteJSON(0, id, `{"vote": "Yes", "rationale": "testing"}`)
Execute(0, id)
members := group.GetMembers("", "", 0, havl.Latest)
Expand All @@ -47,7 +47,7 @@ func TestUpdateMembers(t *testing.T) {
}

membersJSON = json.ArrayNode("", iSlice).String()
expected := fmt.Sprintf(`[{"address":"g108cszmcvs4r3k67k7h5zuhm4el3qhlrxzhshtv","power":"1"},{"address":"g14u5eaheavy0ux4dmpykg2gvxpvqvexm9cyg58a","power":"1"},{"address":"g1747t5m2f08plqjlrjk2q0qld7465hxz8gkx59c","power":"1"},{"address":"g18syxa0vh0vmne90mwhtynjet0zgeqf6prh3ryy","power":"2"},{"address":"g1ckn395mpttp0vupgtratyufdaakgh8jgkmr3ym","power":"1"},{"address":"g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm","power":"1"}]`)
expected := ufmt.Sprintf(`[{"address":"g108cszmcvs4r3k67k7h5zuhm4el3qhlrxzhshtv","power":"1"},{"address":"g14u5eaheavy0ux4dmpykg2gvxpvqvexm9cyg58a","power":"1"},{"address":"g1747t5m2f08plqjlrjk2q0qld7465hxz8gkx59c","power":"1"},{"address":"g18syxa0vh0vmne90mwhtynjet0zgeqf6prh3ryy","power":"2"},{"address":"g1ckn395mpttp0vupgtratyufdaakgh8jgkmr3ym","power":"1"},{"address":"g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm","power":"1"}]`)
if membersJSON != expected {
t.Errorf("Expected:\n%s\nGot:\n%s", expected, membersJSON)
}
Expand All @@ -67,7 +67,7 @@ func TestUpdateMembers(t *testing.T) {
var member dao_voting_group.Member
member.FromJSON(children[0])

id := ProposeJSON(0, fmt.Sprintf(`{"title": "Test prop 2", "description": "A description", "messages": [{"type": "gno.land/p/teritori/dao_voting_group.UpdateMembers", "payload": [{"address": "%s", "power": "0"}]}]}`, member.Address.String()))
id := ProposeJSON(0, ufmt.Sprintf(`{"title": "Test prop 2", "description": "A description", "messages": [{"type": "gno.land/p/teritori/dao_voting_group.UpdateMembers", "payload": [{"address": "%s", "power": "0"}]}]}`, member.Address.String()))
VoteJSON(0, id, `{"vote": "Yes", "rationale": "testing"}`)
Execute(0, id)
members := group.GetMembers("", "", 0, havl.Latest)
Expand All @@ -93,23 +93,23 @@ func TestUpdateSettings(t *testing.T) {
// not sure why but in this test the proposal ids start at 3 and the voting power is 5 when all tests are run, shouldn't tests be isolated? TODO: investigate

{
id := ProposeJSON(0, fmt.Sprintf(`{"title": "Test prop", "description": "A description", "messages": [{"type": "gno.land/p/teritori/dao_proposal_single.UpdateSettings", "payload": {"threshold": {"thresholdQuorum": {"threshold": {"percent": 200}, "quorum": {"percent": 200}}}}}]}`))
id := ProposeJSON(0, ufmt.Sprintf(`{"title": "Test prop", "description": "A description", "messages": [{"type": "gno.land/p/teritori/dao_proposal_single.UpdateSettings", "payload": {"threshold": {"thresholdQuorum": {"threshold": {"percent": 200}, "quorum": {"percent": 200}}}}}]}`))
VoteJSON(0, id, `{"vote": "Yes", "rationale": "testing"}`)
Execute(0, id)
proposalJSON := getProposalJSON(0, id)
expected := fmt.Sprintf(`{"id":"%d","title":"Test prop","description":"A description","proposer":"g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm","startHeight":"123","totalPower":"6","messages":[{"type":"gno.land/p/teritori/dao_proposal_single.UpdateSettings","payload":{"threshold":{"thresholdQuorum":{"threshold":{"percent":200},"quorum":{"percent":200}}}}}],"status":"Executed","votes":{"yes":"1","no":"0","abstain":"0"},"allowRevoting":false,"ballots":{"g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm":{"power":"1","vote":"Yes","rationale":"testing"}},"expiration":{"atTime":"2009-03-27T23:31:30Z"},"threshold":{"thresholdQuorum":{"threshold":{"percent":100},"quorum":{"percent":100}}}}`, id)
expected := ufmt.Sprintf(`{"id":"%d","title":"Test prop","description":"A description","proposer":"g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm","startHeight":"123","totalPower":"6","messages":[{"type":"gno.land/p/teritori/dao_proposal_single.UpdateSettings","payload":{"threshold":{"thresholdQuorum":{"threshold":{"percent":200},"quorum":{"percent":200}}}}}],"status":"Executed","votes":{"yes":"1","no":"0","abstain":"0"},"allowRevoting":false,"ballots":{"g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm":{"power":"1","vote":"Yes","rationale":"testing"}},"expiration":{"atTime":"2009-03-27T23:31:30Z"},"threshold":{"thresholdQuorum":{"threshold":{"percent":100},"quorum":{"percent":100}}}}`, id)
if proposalJSON != expected {
t.Fatalf("Expected:\n%s\nGot:\n%s", expected, proposalJSON)
}
}

{
// make sentiment proposal
id := ProposeJSON(0, fmt.Sprintf(`{"title": "Test prop", "description": "A description", "messages": []}`))
id := ProposeJSON(0, ufmt.Sprintf(`{"title": "Test prop", "description": "A description", "messages": []}`))
VoteJSON(0, id, `{"vote": "Yes", "rationale": "testing"}`)
Execute(0, id)
proposalJSON := getProposalJSON(0, id)
expected := fmt.Sprintf(`{"id":"%d","title":"Test prop","description":"A description","proposer":"g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm","startHeight":"123","totalPower":"6","messages":[],"status":"Executed","votes":{"yes":"1","no":"0","abstain":"0"},"allowRevoting":false,"ballots":{"g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm":{"power":"1","vote":"Yes","rationale":"testing"}},"expiration":{"atTime":"2009-03-27T23:31:30Z"},"threshold":{"thresholdQuorum":{"threshold":{"percent":200},"quorum":{"percent":200}}}}`, id)
expected := ufmt.Sprintf(`{"id":"%d","title":"Test prop","description":"A description","proposer":"g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm","startHeight":"123","totalPower":"6","messages":[],"status":"Executed","votes":{"yes":"1","no":"0","abstain":"0"},"allowRevoting":false,"ballots":{"g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm":{"power":"1","vote":"Yes","rationale":"testing"}},"expiration":{"atTime":"2009-03-27T23:31:30Z"},"threshold":{"thresholdQuorum":{"threshold":{"percent":200},"quorum":{"percent":200}}}}`, id)
if proposalJSON != expected {
t.Fatalf("Expected:\n%s\nGot:\n%s", expected, proposalJSON)
}
Expand Down
16 changes: 8 additions & 8 deletions gno/r/dao_roles_realm.gno/dao_roles_realm_test.gno
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package dao_roles_realm

import (
"fmt"
"testing"

"gno.land/p/demo/json"
"gno.land/p/demo/ufmt"
"gno.land/p/teritori/dao_voting_group"
"gno.land/p/teritori/havl"
)
Expand Down Expand Up @@ -37,7 +37,7 @@ func TestUpdateMembers(t *testing.T) {
var membersJSON string

{
id := ProposeJSON(0, fmt.Sprintf(`{"title": "Test prop", "description": "A description", "messages": [{"type": "gno.land/p/teritori/dao_voting_group.UpdateMembers", "payload": [{"power": "2", "address": "g18syxa0vh0vmne90mwhtynjet0zgeqf6prh3ryy"}]}]}`))
id := ProposeJSON(0, ufmt.Sprintf(`{"title": "Test prop", "description": "A description", "messages": [{"type": "gno.land/p/teritori/dao_voting_group.UpdateMembers", "payload": [{"power": "2", "address": "g18syxa0vh0vmne90mwhtynjet0zgeqf6prh3ryy"}]}]}`))
VoteJSON(0, id, `{"vote": "Yes", "rationale": "testing"}`)
Execute(0, id)
members := group.GetMembers("", "", 0, havl.Latest)
Expand All @@ -47,7 +47,7 @@ func TestUpdateMembers(t *testing.T) {
}

membersJSON = json.ArrayNode("", iSlice).String()
expected := fmt.Sprintf(`[{"address":"g108cszmcvs4r3k67k7h5zuhm4el3qhlrxzhshtv","power":"1"},{"address":"g14u5eaheavy0ux4dmpykg2gvxpvqvexm9cyg58a","power":"1"},{"address":"g1747t5m2f08plqjlrjk2q0qld7465hxz8gkx59c","power":"1"},{"address":"g18syxa0vh0vmne90mwhtynjet0zgeqf6prh3ryy","power":"2"},{"address":"g1ckn395mpttp0vupgtratyufdaakgh8jgkmr3ym","power":"1"},{"address":"g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm","power":"1"}]`)
expected := ufmt.Sprintf(`[{"address":"g108cszmcvs4r3k67k7h5zuhm4el3qhlrxzhshtv","power":"1"},{"address":"g14u5eaheavy0ux4dmpykg2gvxpvqvexm9cyg58a","power":"1"},{"address":"g1747t5m2f08plqjlrjk2q0qld7465hxz8gkx59c","power":"1"},{"address":"g18syxa0vh0vmne90mwhtynjet0zgeqf6prh3ryy","power":"2"},{"address":"g1ckn395mpttp0vupgtratyufdaakgh8jgkmr3ym","power":"1"},{"address":"g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm","power":"1"}]`)
if membersJSON != expected {
t.Errorf("Expected:\n%s\nGot:\n%s", expected, membersJSON)
}
Expand All @@ -67,7 +67,7 @@ func TestUpdateMembers(t *testing.T) {
var member dao_voting_group.Member
member.FromJSON(children[0])

id := ProposeJSON(0, fmt.Sprintf(`{"title": "Test prop 2", "description": "A description", "messages": [{"type": "gno.land/p/teritori/dao_voting_group.UpdateMembers", "payload": [{"address": "%s", "power": "0"}]}]}`, member.Address.String()))
id := ProposeJSON(0, ufmt.Sprintf(`{"title": "Test prop 2", "description": "A description", "messages": [{"type": "gno.land/p/teritori/dao_voting_group.UpdateMembers", "payload": [{"address": "%s", "power": "0"}]}]}`, member.Address.String()))
VoteJSON(0, id, `{"vote": "Yes", "rationale": "testing"}`)
Execute(0, id)
members := group.GetMembers("", "", 0, havl.Latest)
Expand All @@ -93,23 +93,23 @@ func TestUpdateSettings(t *testing.T) {
// not sure why but in this test the proposal ids start at 3 and the voting power is 5 when all tests are run, shouldn't tests be isolated? TODO: investigate

{
id := ProposeJSON(0, fmt.Sprintf(`{"title": "Test prop", "description": "A description", "messages": [{"type": "gno.land/p/teritori/dao_proposal_single.UpdateSettings", "payload": {"threshold": {"thresholdQuorum": {"threshold": {"percent": 200}, "quorum": {"percent": 200}}}}}]}`))
id := ProposeJSON(0, ufmt.Sprintf(`{"title": "Test prop", "description": "A description", "messages": [{"type": "gno.land/p/teritori/dao_proposal_single.UpdateSettings", "payload": {"threshold": {"thresholdQuorum": {"threshold": {"percent": 200}, "quorum": {"percent": 200}}}}}]}`))
VoteJSON(0, id, `{"vote": "Yes", "rationale": "testing"}`)
Execute(0, id)
proposalJSON := getProposalJSON(0, id)
expected := fmt.Sprintf(`{"id":"%d","title":"Test prop","description":"A description","proposer":"g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm","startHeight":"123","totalPower":"6","messages":[{"type":"gno.land/p/teritori/dao_proposal_single.UpdateSettings","payload":{"threshold":{"thresholdQuorum":{"threshold":{"percent":200},"quorum":{"percent":200}}}}}],"status":"Executed","votes":{"yes":"1","no":"0","abstain":"0"},"allowRevoting":false,"ballots":{"g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm":{"power":"1","vote":"Yes","rationale":"testing"}},"expiration":{"atTime":"2009-03-27T23:31:30Z"},"threshold":{"thresholdQuorum":{"threshold":{"percent":100},"quorum":{"percent":100}}}}`, id)
expected := ufmt.Sprintf(`{"id":"%d","title":"Test prop","description":"A description","proposer":"g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm","startHeight":"123","totalPower":"6","messages":[{"type":"gno.land/p/teritori/dao_proposal_single.UpdateSettings","payload":{"threshold":{"thresholdQuorum":{"threshold":{"percent":200},"quorum":{"percent":200}}}}}],"status":"Executed","votes":{"yes":"1","no":"0","abstain":"0"},"allowRevoting":false,"ballots":{"g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm":{"power":"1","vote":"Yes","rationale":"testing"}},"expiration":{"atTime":"2009-03-27T23:31:30Z"},"threshold":{"thresholdQuorum":{"threshold":{"percent":100},"quorum":{"percent":100}}}}`, id)
if proposalJSON != expected {
t.Fatalf("Expected:\n%s\nGot:\n%s", expected, proposalJSON)
}
}

{
// make sentiment proposal
id := ProposeJSON(0, fmt.Sprintf(`{"title": "Test prop", "description": "A description", "messages": []}`))
id := ProposeJSON(0, ufmt.Sprintf(`{"title": "Test prop", "description": "A description", "messages": []}`))
VoteJSON(0, id, `{"vote": "Yes", "rationale": "testing"}`)
Execute(0, id)
proposalJSON := getProposalJSON(0, id)
expected := fmt.Sprintf(`{"id":"%d","title":"Test prop","description":"A description","proposer":"g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm","startHeight":"123","totalPower":"6","messages":[],"status":"Executed","votes":{"yes":"1","no":"0","abstain":"0"},"allowRevoting":false,"ballots":{"g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm":{"power":"1","vote":"Yes","rationale":"testing"}},"expiration":{"atTime":"2009-03-27T23:31:30Z"},"threshold":{"thresholdQuorum":{"threshold":{"percent":200},"quorum":{"percent":200}}}}`, id)
expected := ufmt.Sprintf(`{"id":"%d","title":"Test prop","description":"A description","proposer":"g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm","startHeight":"123","totalPower":"6","messages":[],"status":"Executed","votes":{"yes":"1","no":"0","abstain":"0"},"allowRevoting":false,"ballots":{"g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm":{"power":"1","vote":"Yes","rationale":"testing"}},"expiration":{"atTime":"2009-03-27T23:31:30Z"},"threshold":{"thresholdQuorum":{"threshold":{"percent":200},"quorum":{"percent":200}}}}`, id)
if proposalJSON != expected {
t.Fatalf("Expected:\n%s\nGot:\n%s", expected, proposalJSON)
}
Expand Down
14 changes: 4 additions & 10 deletions gno/r/launchpad_grc20/airdrop_grc20_test.gno
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package launchpad_grc20

import (
"fmt"
"std"
"strconv"
"testing"
"time"

"gno.land/p/demo/merkle"
"gno.land/p/demo/ufmt"
)

func TestNewAirdrop(t *testing.T) {
Expand Down Expand Up @@ -175,18 +175,12 @@ func TestClaimJSON(t *testing.T) {
root := tree.Root()
proofs, _ := tree.Proof(leaves[0])

erroneousProofs := []merkle.Node{
{[]byte("badproof")},
{[]byte("badproof")},
}

now := time.Now().Unix()
NewToken("TestClaimJSONAirDropToken", "TestClaimJSONAirDropToken", "noimage", 18, 21_000_000, 23_000_000, true, true)
airdropID := NewAirdrop("TestClaimJSONAirDropToken", root, 100, 0, 0)

proofsJSON := "["
for i, proof := range proofs {
proofsJSON += fmt.Sprintf("{\"hash\":\"%s\", \"pos\":\"%s\"}", proof.Hash(), strconv.Itoa(int(proof.Position())))
proofsJSON += ufmt.Sprintf("{\"hash\":\"%s\", \"pos\":\"%s\"}", proof.Hash(), strconv.Itoa(int(proof.Position())))
if i != len(proofs)-1 {
proofsJSON += ", "
}
Expand Down Expand Up @@ -259,8 +253,8 @@ func TestClaim(t *testing.T) {
proofs, _ := tree.Proof(leaves[0])

erroneousProofs := []merkle.Node{
{[]byte("badproof")},
{[]byte("badproof")},
merkle.NewNode([]byte("badproof"), 0),
merkle.NewNode([]byte("badproof"), 0),
}

now := time.Now().Unix()
Expand Down
3 changes: 1 addition & 2 deletions gno/r/launchpad_grc20/sale_grc20_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ func TestBuy(t *testing.T) {
badCoin := std.NewCoins(std.NewCoin("notugnot", 100*10))
manyCoins := std.NewCoins(std.NewCoin("ugnot", 100*10), std.NewCoin("notugnot", 100*10))
notEnoughCoins := std.NewCoins(std.NewCoin("ugnot", 100*5))
tooManyCoins := std.NewCoins(std.NewCoin("ugnot", 100*11))
emptyCoins := std.NewCoins()

tests := testBuyTestTable{
Expand Down Expand Up @@ -536,7 +535,7 @@ func TestFinalize(t *testing.T) {
NewToken("TestFinalizeToken", "TestFinalizeToken", "image", 18, 21_000_000, 23_000_000, true, true)
saleID := NewSale("TestFinalizeToken", "", startTimestamp, endTimestamp, 100, 15, 10, 20, true)
onGoingSaleID := NewSale("TestFinalizeToken", "", startTimestamp, onGoingEndTimestamp, 100, 15, 10, 20, true)
onGoingSaleID2 := NewSale("TestFinalizeToken", "", startTimestamp, onGoingEndTimestamp2, 100, 15, 10, 20, true)
_ = NewSale("TestFinalizeToken", "", startTimestamp, onGoingEndTimestamp2, 100, 15, 10, 20, true)

tests := testFinalizeTestTable{
"Success with 0 tokens sold": {
Expand Down
16 changes: 8 additions & 8 deletions gno/r/social_feeds/feeds_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func testCreateAndDeleteComment(t *testing.T) {

metadata := `empty_meta_data`

commentID1 := CreatePost(feed1.id, post1.id, cat1, metadata)
_ = CreatePost(feed1.id, post1.id, cat1, metadata)
commentID2 := CreatePost(feed1.id, post1.id, cat1, metadata)
comment2 := feed1.MustGetPost(commentID2)

Expand Down Expand Up @@ -255,10 +255,10 @@ func testFilterByCategories(t *testing.T) {
postID2 := CreatePost(feed2.id, rootPostID, cat1, "metadata")

// Create 1 posts on root with cat2
postID3 := CreatePost(feed2.id, rootPostID, cat2, "metadata")
_ = CreatePost(feed2.id, rootPostID, cat2, "metadata")

// Create comments on post 1
commentPostID1 := CreatePost(feed2.id, postID1, cat1, "metadata")
_ = CreatePost(feed2.id, postID1, cat1, "metadata")

// cat1: Should return max = limit
if count := countPosts(feed2.id, filter_cat1, 1); count != 1 {
Expand Down Expand Up @@ -313,11 +313,11 @@ func testFilterByCategories(t *testing.T) {

func testTipPost(t *testing.T) {
creator := testutils.TestAddress("creator")
std.TestIssueCoins(creator, std.Coins{{"ugnot", 100_000_000}})
std.TestIssueCoins(creator, std.Coins{{Denom: "ugnot", Amount: 100_000_000}})

// NOTE: Dont know why the address should be this to be able to call banker (= std.GetCallerAt(1))
tipper := testutils.TestAddress("tipper")
std.TestIssueCoins(tipper, std.Coins{{"ugnot", 50_000_000}})
std.TestIssueCoins(tipper, std.Coins{{Denom: "ugnot", Amount: 50_000_000}})

banker := std.GetBanker(std.BankerTypeReadonly)

Expand All @@ -341,7 +341,7 @@ func testTipPost(t *testing.T) {

// Tiper tips the ppst
std.TestSetOrigCaller(tipper)
std.TestSetOrigSend(std.Coins{{"ugnot", 1_000_000}}, nil)
std.TestSetOrigSend(std.Coins{{Denom: "ugnot", Amount: 1_000_000}}, nil)
TipPost(feed3.id, post1.id)

// Coin must be increased for creator
Expand All @@ -355,7 +355,7 @@ func testTipPost(t *testing.T) {
}

// Add more tip should update this total
std.TestSetOrigSend(std.Coins{{"ugnot", 2_000_000}}, nil)
std.TestSetOrigSend(std.Coins{{Denom: "ugnot", Amount: 2_000_000}}, nil)
TipPost(feed3.id, post1.id)

if post1.tipAmount != 3_000_000 {
Expand Down Expand Up @@ -426,7 +426,7 @@ func testHidePostForMe(t *testing.T) {
feed8 := mustGetFeed(feedID8)

postIDToHide := CreatePost(feed8.id, rootPostID, cat1, `{"metadata": "value"}`)
postID := CreatePost(feed8.id, rootPostID, cat1, `{"metadata": "value"}`)
_ = CreatePost(feed8.id, rootPostID, cat1, `{"metadata": "value"}`)

if count := countPosts(feed8.id, filter_all, 10); count != 2 {
t.Fatalf("expected posts count: 2, got %q.", count)
Expand Down

0 comments on commit 3d27860

Please sign in to comment.