Skip to content

Commit

Permalink
add test files
Browse files Browse the repository at this point in the history
  • Loading branch information
TATAUFO committed Jul 2, 2024
1 parent 05c545d commit 5c7b7b3
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
55 changes: 55 additions & 0 deletions node/node_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// node_test.go
package node

import (
"os"
"testing"
)

func TestNewNode(t *testing.T) {
peerPort := 4001
nodeKey := "node_test.key"
dbName := "pdu_test.db"

defer os.Remove(nodeKey)
defer os.Remove(dbName)

n, err := NewNode(peerPort, nodeKey, dbName)
if err != nil {
t.Fatalf("Failed to create node: %s", err)
}

if n.Host == nil {
t.Fatalf("Node host is nil")
}

if n.Universe == nil {
t.Fatalf("Node universe is nil")
}
}

func TestRunNode(t *testing.T) {
peerPort := 4001
webPort := 8546
rpcPort := 8545
nodeKey := "node_test.key"
dbName := "pdu_test.db"

defer os.Remove(nodeKey)
defer os.Remove(dbName)

n, err := NewNode(peerPort, nodeKey, dbName)
if err != nil {
t.Fatalf("Failed to create node: %s", err)
}

go n.Run(webPort, rpcPort)

// 在此添加更多检查和断言,以确保节点正确运行
// 例如,你可以检查 Web 和 RPC 服务器是否可访问

// 清理
defer n.Host.Close()
defer n.Universe.DB.CloseDB()

}
36 changes: 36 additions & 0 deletions params/version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// version_test.go
package params

import (
"fmt"
"testing"
)

func TestVersion(t *testing.T) {
expectedVersion := fmt.Sprintf("%d.%d.%d-%s", VersionMajor, VersionMinor, VersionPatch, VersionMeta)
if Version != expectedVersion {
t.Errorf("Expected version %s, but got %s", expectedVersion, Version)
}
}

func TestVersionFormat(t *testing.T) {
expectedVersion := "1.0.0-unstable"
if Version != expectedVersion {
t.Errorf("Expected version %s, but got %s", expectedVersion, Version)
}
}

func TestVersionComponents(t *testing.T) {
if VersionMajor != 1 {
t.Errorf("Expected VersionMajor to be 1, but got %d", VersionMajor)
}
if VersionMinor != 0 {
t.Errorf("Expected VersionMinor to be 0, but got %d", VersionMinor)
}
if VersionPatch != 0 {
t.Errorf("Expected VersionPatch to be 0, but got %d", VersionPatch)
}
if VersionMeta != "unstable" {
t.Errorf("Expected VersionMeta to be 'unstable', but got %s", VersionMeta)
}
}

0 comments on commit 5c7b7b3

Please sign in to comment.