Skip to content

Commit 1491c4c

Browse files
committed
test: change test file
1 parent 7f70409 commit 1491c4c

File tree

4 files changed

+161
-317
lines changed

4 files changed

+161
-317
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package gnobounty
2+
3+
import (
4+
"testing"
5+
6+
"gno.land/p/nt/testutils"
7+
)
8+
9+
func TestAddValidator(t *testing.T) {
10+
// Add a validator
11+
validator1 := testutils.TestAddress("validator1")
12+
testing.SetOriginCaller(validator1)
13+
AddValidator(cross)
14+
15+
if !IsValidator(validator1) {
16+
t.Error("Validator should be active")
17+
}
18+
19+
count := GetActiveValidatorCount()
20+
if count < 1 {
21+
t.Error("Expected at least 1 active validator")
22+
}
23+
}
24+
25+
func TestValidatorList(t *testing.T) {
26+
// Add more validators
27+
validator2 := testutils.TestAddress("validator2")
28+
testing.SetOriginCaller(validator2)
29+
30+
// Check if already exists before adding
31+
if !IsValidator(validator2) {
32+
AddValidator(cross)
33+
}
34+
35+
if !IsValidator(validator2) {
36+
t.Error("Validator2 should be active")
37+
}
38+
39+
count := GetActiveValidatorCount()
40+
if count < 2 {
41+
t.Errorf("Expected at least 2 active validators, got %d", count)
42+
}
43+
}
44+
45+
func TestListValidators(t *testing.T) {
46+
list := ListValidators()
47+
if list == "" {
48+
t.Error("Expected non-empty validators list")
49+
}
50+
}
51+
52+
func TestIsValidatorCheck(t *testing.T) {
53+
// Test a non-validator address
54+
nonValidator := testutils.TestAddress("nonvalidator")
55+
if IsValidator(nonValidator) {
56+
t.Error("Non-validator should not be recognized as validator")
57+
}
58+
59+
// Test existing validator
60+
validator1 := testutils.TestAddress("validator1")
61+
if !IsValidator(validator1) {
62+
t.Error("validator1 should be recognized as validator")
63+
}
64+
}
65+
66+
func TestGetValidator(t *testing.T) {
67+
validator1 := testutils.TestAddress("validator1")
68+
v := GetValidator(validator1)
69+
70+
if v == nil {
71+
t.Fatal("Expected to find validator1")
72+
}
73+
74+
if v.Address != validator1 {
75+
t.Error("Validator address mismatch")
76+
}
77+
78+
if !v.Active {
79+
t.Error("Validator should be active")
80+
}
81+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package gnobounty
2+
3+
import (
4+
"chain"
5+
"testing"
6+
7+
"gno.land/p/nt/testutils"
8+
)
9+
10+
func TestCreateBounty(t *testing.T) {
11+
// Setup test environment
12+
testing.SetOriginCaller(testutils.TestAddress("alice"))
13+
testing.SetOriginSend(chain.Coins{chain.Coin{Denom: "ugnot", Amount: 5000000}})
14+
15+
// Create a bounty
16+
bountyID := CreateBounty(
17+
cross,
18+
"Fix Rendering Bug",
19+
"https://github.com/gnolang/gno/issues/1234",
20+
"Fix the rendering issue in the GRC20 token display",
21+
)
22+
23+
if bountyID != 1 {
24+
t.Errorf("Expected bounty ID 1, got %d", bountyID)
25+
}
26+
27+
// Check bounty was created
28+
bounty := GetBounty(bountyID)
29+
if bounty == nil {
30+
t.Fatal("Bounty not found")
31+
}
32+
33+
if bounty.Amount != 5000000 {
34+
t.Errorf("Expected amount 5000000, got %d", bounty.Amount)
35+
}
36+
37+
if bounty.IsClaimed {
38+
t.Error("Bounty should not be claimed yet")
39+
}
40+
41+
if bounty.Title != "Fix Rendering Bug" {
42+
t.Errorf("Expected title 'Fix Rendering Bug', got %s", bounty.Title)
43+
}
44+
}
45+
46+
func TestGetBountyCount(t *testing.T) {
47+
count := GetBountyCount()
48+
if count < 1 {
49+
t.Error("Expected at least 1 bounty from previous test")
50+
}
51+
}
52+
53+
func TestListBounties(t *testing.T) {
54+
list := ListBounties()
55+
if list == "" {
56+
t.Error("Expected non-empty bounties list")
57+
}
58+
if list == "No bounties available" {
59+
t.Error("Expected bounties to be listed")
60+
}
61+
}
62+
63+
func TestGetBountyDetails(t *testing.T) {
64+
// Test getting details for existing bounty
65+
details := GetBountyDetails(1)
66+
if details == "" {
67+
t.Error("Expected non-empty bounty details")
68+
}
69+
if details == "Bounty not found" {
70+
t.Error("Bounty #1 should exist")
71+
}
72+
}
73+
74+
func TestGetBountyDetailsNotFound(t *testing.T) {
75+
// Test getting details for non-existent bounty
76+
details := GetBountyDetails(99999)
77+
if details != "Bounty not found" {
78+
t.Error("Expected 'Bounty not found' for non-existent bounty")
79+
}
80+
}

packages/r/greg007/gnobounty/test/application_test.gno

Lines changed: 0 additions & 194 deletions
This file was deleted.

0 commit comments

Comments
 (0)