• R/O
  • HTTP
  • SSH
  • HTTPS

vapor: Commit

Golang implemented sidechain for Bytom


Commit MetaInfo

Revisionff232f9f63f27682dfd2c3d7b98bff28c9a29922 (tree)
Time2019-06-19 19:11:31
Authorpaladz <453256728@qq.c...>
Commiterpaladz

Log Message

add unit test

Change Summary

Incremental Difference

--- a/protocol/orphan_manage.go
+++ b/protocol/orphan_manage.go
@@ -105,7 +105,7 @@ func (o *OrphanManage) delete(hash *bc.Hash) {
105105 }
106106
107107 for i, preOrphan := range prevOrphans {
108- if preOrphan == hash {
108+ if *preOrphan == *hash {
109109 o.prevOrphans[block.Block.PreviousBlockHash] = append(prevOrphans[:i], prevOrphans[i+1:]...)
110110 return
111111 }
--- a/protocol/orphan_manage_test.go
+++ b/protocol/orphan_manage_test.go
@@ -32,6 +32,65 @@ func init() {
3232 }
3333 }
3434
35+func TestDeleteLRU(t *testing.T) {
36+ now := time.Now()
37+ cases := []struct {
38+ before *OrphanManage
39+ after *OrphanManage
40+ }{
41+ {
42+ before: &OrphanManage{
43+ orphan: map[bc.Hash]*orphanBlock{
44+ blockHashes[0]: &orphanBlock{testBlocks[0], now},
45+ },
46+ prevOrphans: map[bc.Hash][]*bc.Hash{
47+ bc.Hash{V0: 1}: []*bc.Hash{&blockHashes[0]},
48+ },
49+ },
50+ after: &OrphanManage{
51+ orphan: map[bc.Hash]*orphanBlock{},
52+ prevOrphans: map[bc.Hash][]*bc.Hash{},
53+ },
54+ },
55+ {
56+ before: &OrphanManage{
57+ orphan: map[bc.Hash]*orphanBlock{},
58+ prevOrphans: map[bc.Hash][]*bc.Hash{},
59+ },
60+ after: &OrphanManage{
61+ orphan: map[bc.Hash]*orphanBlock{},
62+ prevOrphans: map[bc.Hash][]*bc.Hash{},
63+ },
64+ },
65+ {
66+ before: &OrphanManage{
67+ orphan: map[bc.Hash]*orphanBlock{
68+ blockHashes[0]: &orphanBlock{testBlocks[0], now.Add(2)},
69+ blockHashes[1]: &orphanBlock{testBlocks[1], now.Add(1)},
70+ },
71+ prevOrphans: map[bc.Hash][]*bc.Hash{
72+ bc.Hash{V0: 1}: []*bc.Hash{&blockHashes[0], &blockHashes[1]},
73+ },
74+ },
75+ after: &OrphanManage{
76+ orphan: map[bc.Hash]*orphanBlock{
77+ blockHashes[0]: &orphanBlock{testBlocks[0], now.Add(2)},
78+ },
79+ prevOrphans: map[bc.Hash][]*bc.Hash{
80+ bc.Hash{V0: 1}: []*bc.Hash{&blockHashes[0]},
81+ },
82+ },
83+ },
84+ }
85+
86+ for i, c := range cases {
87+ c.before.deleteLRU()
88+ if !testutil.DeepEqual(c.before, c.after) {
89+ t.Errorf("case %d: got %v want %v", i, c.before, c.after)
90+ }
91+ }
92+}
93+
3594 func TestOrphanManageAdd(t *testing.T) {
3695 cases := []struct {
3796 before *OrphanManage
Show on old repository browser