good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
2d4ef678
Commit
2d4ef678
authored
Jan 21, 2022
by
Shivam Sharma
Browse files
Options
Downloads
Patches
Plain Diff
Streamlined code
parent
8f7174fb
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/blockchain_bor_test.go
+55
-48
55 additions, 48 deletions
core/blockchain_bor_test.go
with
55 additions
and
48 deletions
core/blockchain_bor_test.go
+
55
−
48
View file @
2d4ef678
...
@@ -53,71 +53,78 @@ func TestChain2HeadEvent(t *testing.T) {
...
@@ -53,71 +53,78 @@ func TestChain2HeadEvent(t *testing.T) {
t
.
Fatalf
(
"failed to insert chain: %v"
,
err
)
t
.
Fatalf
(
"failed to insert chain: %v"
,
err
)
}
}
type
eventTest
struct
{
Type
string
Added
[]
common
.
Hash
Removed
[]
common
.
Hash
}
// To use in fatal log, indicates the readEvent which failed the test.
i
:=
0
i
:=
0
readEvent
:=
func
()
*
Chain2HeadEvent
{
readEvent
:=
func
(
expect
*
eventTest
)
{
select
{
select
{
case
ev
:=
<-
chain2HeadCh
:
case
ev
:=
<-
chain2HeadCh
:
i
++
i
++
return
&
ev
if
ev
.
Type
!=
expect
.
Type
{
t
.
Fatalf
(
"%d : type mismatch"
,
i
)
}
for
j
:=
0
;
j
<
len
(
ev
.
OldChain
);
j
++
{
if
ev
.
OldChain
[
j
]
.
Hash
()
!=
expect
.
Removed
[
j
]
{
t
.
Fatalf
(
"%d : Oldchain hashes Does Not Match"
,
i
)
}
}
for
j
:=
0
;
j
<
len
(
ev
.
NewChain
);
j
++
{
if
ev
.
NewChain
[
j
]
.
Hash
()
!=
expect
.
Added
[
j
]
{
t
.
Fatalf
(
"%d : Newchain hashes Does Not Match"
,
i
)
}
}
case
<-
time
.
After
(
2
*
time
.
Second
)
:
case
<-
time
.
After
(
2
*
time
.
Second
)
:
t
.
Fatal
(
"timeout"
)
t
.
Fatal
(
"timeout"
)
}
}
return
nil
}
}
// head event
// head event
event1
:=
readEvent
()
readEvent
(
&
eventTest
{
if
event1
.
Type
!=
Chain2HeadCanonicalEvent
{
Type
:
Chain2HeadCanonicalEvent
,
t
.
Fatal
(
"it should be type head"
)
Added
:
[]
common
.
Hash
{
}
chain
[
2
]
.
Hash
(),
if
event1
.
NewChain
[
0
]
.
Hash
()
!=
chain
[
2
]
.
Hash
()
{
}})
t
.
Fatalf
(
"%d : Hash Does Not Match"
,
i
)
}
// fork event
// fork event
event2
:=
readEvent
()
readEvent
(
&
eventTest
{
if
event2
.
Type
!=
Chain2HeadForkEvent
{
Type
:
Chain2HeadForkEvent
,
t
.
Fatal
(
"it should be type fork"
)
Added
:
[]
common
.
Hash
{
}
replacementBlocks
[
0
]
.
Hash
(),
if
event2
.
NewChain
[
0
]
.
Hash
()
!=
replacementBlocks
[
0
]
.
Hash
()
{
}})
t
.
Fatalf
(
"%d : Hash Does Not Match"
,
i
)
}
// fork event
// fork event
event3
:=
readEvent
()
readEvent
(
&
eventTest
{
if
event3
.
Type
!=
Chain2HeadForkEvent
{
Type
:
Chain2HeadForkEvent
,
t
.
Fatal
(
"it should be type fork"
)
Added
:
[]
common
.
Hash
{
}
replacementBlocks
[
1
]
.
Hash
(),
if
event3
.
NewChain
[
0
]
.
Hash
()
!=
replacementBlocks
[
1
]
.
Hash
()
{
}})
t
.
Fatalf
(
"%d : Hash Does Not Match"
,
i
)
}
// reorg event
// reorg event
//In this event the channel recieves an array of Blocks in NewChain and OldChain
//In this event the channel recieves an array of Blocks in NewChain and OldChain
expectedOldChainHashes
:=
[
3
]
common
.
Hash
{
0
:
chain
[
2
]
.
Hash
(),
1
:
chain
[
1
]
.
Hash
(),
2
:
chain
[
0
]
.
Hash
()}
readEvent
(
&
eventTest
{
expectedNewChainHashes
:=
[
3
]
common
.
Hash
{
0
:
replacementBlocks
[
2
]
.
Hash
(),
1
:
replacementBlocks
[
1
]
.
Hash
(),
2
:
replacementBlocks
[
0
]
.
Hash
()}
Type
:
Chain2HeadReorgEvent
,
Added
:
[]
common
.
Hash
{
event4
:=
readEvent
()
replacementBlocks
[
2
]
.
Hash
(),
if
event4
.
Type
!=
Chain2HeadReorgEvent
{
replacementBlocks
[
1
]
.
Hash
(),
t
.
Fatal
(
"it should be type reorg"
)
replacementBlocks
[
0
]
.
Hash
(),
}
},
for
j
:=
0
;
j
<
len
(
event4
.
OldChain
);
j
++
{
Removed
:
[]
common
.
Hash
{
if
event4
.
OldChain
[
j
]
.
Hash
()
!=
expectedOldChainHashes
[
j
]
{
chain
[
2
]
.
Hash
(),
t
.
Fatalf
(
"%d : Oldchain hashes Does Not Match"
,
i
)
chain
[
1
]
.
Hash
(),
}
chain
[
0
]
.
Hash
(),
}
},
for
j
:=
0
;
j
<
len
(
event4
.
NewChain
);
j
++
{
})
if
event4
.
NewChain
[
j
]
.
Hash
()
!=
expectedNewChainHashes
[
j
]
{
t
.
Fatalf
(
"%d : Newchain hashes Does Not Match"
,
i
)
}
}
// head event
// head event
event5
:=
readEvent
()
readEvent
(
&
eventTest
{
if
event5
.
Type
!=
Chain2HeadCanonicalEvent
{
Type
:
Chain2HeadCanonicalEvent
,
t
.
Fatal
(
"it should be type head"
)
Added
:
[]
common
.
Hash
{
}
replacementBlocks
[
3
]
.
Hash
(),
if
event5
.
NewChain
[
0
]
.
Hash
()
!=
replacementBlocks
[
3
]
.
Hash
()
{
}})
t
.
Fatalf
(
"%d : Hash Does Not Match"
,
i
)
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment