-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |