diff --git a/node/node_test.go b/node/node_test.go new file mode 100644 index 0000000..7b564c4 --- /dev/null +++ b/node/node_test.go @@ -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() + +} diff --git a/params/version_test.go b/params/version_test.go new file mode 100644 index 0000000..1957498 --- /dev/null +++ b/params/version_test.go @@ -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) + } +}