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
8f47b394
Commit
8f47b394
authored
May 18, 2020
by
atvanguard
Browse files
Options
Downloads
Patches
Plain Diff
test: Handle 204 and add test for new deposit mechanism
parent
fa0266a3
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
consensus/bor/bor.go
+3
-0
3 additions, 0 deletions
consensus/bor/bor.go
consensus/bor/bor_test/bor_test.go
+78
-4
78 additions, 4 deletions
consensus/bor/bor_test/bor_test.go
with
81 additions
and
4 deletions
consensus/bor/bor.go
+
3
−
0
View file @
8f47b394
...
...
@@ -1099,6 +1099,9 @@ func (c *Bor) CommitStates(
return
err
}
var
_eventRecords
[]
*
EventRecordWithTime
if
response
.
Result
==
nil
{
// status 204
break
}
if
err
:=
json
.
Unmarshal
(
response
.
Result
,
&
_eventRecords
);
err
!=
nil
{
return
err
}
...
...
This diff is collapsed.
Click to expand it.
consensus/bor/bor_test/bor_test.go
+
78
−
4
View file @
8f47b394
...
...
@@ -2,12 +2,15 @@ package bortest
import
(
"encoding/hex"
"encoding/json"
"fmt"
"math/big"
"testing"
"time"
"github.com/maticnetwork/bor/consensus/bor"
"github.com/maticnetwork/bor/core/rawdb"
"github.com/maticnetwork/bor/crypto"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
...
...
@@ -54,6 +57,64 @@ func TestInsertingSpanSizeBlocks(t *testing.T) {
}
}
func
TestFetchStateSyncEvents
(
t
*
testing
.
T
)
{
init
:=
buildEthereumInstance
(
t
,
rawdb
.
NewMemoryDatabase
())
chain
:=
init
.
ethereum
.
BlockChain
()
engine
:=
init
.
ethereum
.
Engine
()
_bor
:=
engine
.
(
*
bor
.
Bor
)
// A. Insert blocks for 0th sprint
db
:=
init
.
ethereum
.
ChainDb
()
block
:=
init
.
genesis
.
ToBlock
(
db
)
// Insert sprintSize # of blocks so that span is fetched at the start of a new sprint
for
i
:=
uint64
(
1
);
i
<
sprintSize
;
i
++
{
block
=
buildNextBlock
(
t
,
_bor
,
chain
,
block
,
nil
,
init
.
genesis
.
Config
.
Bor
)
insertNewBlock
(
t
,
chain
,
block
)
}
// B. Before inserting 1st block of the next sprint, mock heimdall deps
// B.1 Mock /bor/span/1
res
,
_
:=
loadSpanFromFile
(
t
)
h
:=
&
mocks
.
IHeimdallClient
{}
h
.
On
(
"FetchWithRetry"
,
"bor"
,
"span"
,
"1"
)
.
Return
(
res
,
nil
)
// B.2 Mock State Sync events
// read heimdall api response from file
res
=
stateSyncEventsPayload
(
t
)
var
_eventRecords
[]
*
bor
.
EventRecordWithTime
if
err
:=
json
.
Unmarshal
(
res
.
Result
,
&
_eventRecords
);
err
!=
nil
{
t
.
Fatalf
(
"%s"
,
err
)
}
// use that as a sample to generate bor.stateFetchLimit events
eventRecords
:=
generateFakeStateSyncEvents
(
_eventRecords
[
0
],
50
)
_res
,
_
:=
json
.
Marshal
(
eventRecords
)
response
:=
bor
.
ResponseWithHeight
{
Height
:
"0"
}
if
err
:=
json
.
Unmarshal
(
_res
,
&
response
.
Result
);
err
!=
nil
{
t
.
Fatalf
(
"%s"
,
err
)
}
// at # sprintSize, events are fetched for the internal [from, (block-1).Time)
from
:=
1
to
:=
int64
(
block
.
Header
()
.
Time
)
page
:=
1
query1
:=
fmt
.
Sprintf
(
"clerk/event-record/list?from-time=%d&to-time=%d&page=%d&limit=50"
,
from
,
to
,
page
)
h
.
On
(
"FetchWithRetry"
,
query1
)
.
Return
(
&
response
,
nil
)
page
=
2
query2
:=
fmt
.
Sprintf
(
"clerk/event-record/list?from-time=%d&to-time=%d&page=%d&limit=50"
,
from
,
to
,
page
)
h
.
On
(
"FetchWithRetry"
,
query2
)
.
Return
(
&
bor
.
ResponseWithHeight
{},
nil
)
_bor
.
SetHeimdallClient
(
h
)
block
=
buildNextBlock
(
t
,
_bor
,
chain
,
block
,
nil
,
init
.
genesis
.
Config
.
Bor
)
insertNewBlock
(
t
,
chain
,
block
)
assert
.
True
(
t
,
h
.
AssertCalled
(
t
,
"FetchWithRetry"
,
"bor"
,
"span"
,
"1"
))
assert
.
True
(
t
,
h
.
AssertCalled
(
t
,
"FetchWithRetry"
,
query1
))
assert
.
True
(
t
,
h
.
AssertCalled
(
t
,
"FetchWithRetry"
,
query2
))
}
func
TestOutOfTurnSigning
(
t
*
testing
.
T
)
{
init
:=
buildEthereumInstance
(
t
,
rawdb
.
NewMemoryDatabase
())
chain
:=
init
.
ethereum
.
BlockChain
()
...
...
@@ -130,9 +191,22 @@ func getMockedHeimdallClient(t *testing.T) (*mocks.IHeimdallClient, *bor.Heimdal
res
,
heimdallSpan
:=
loadSpanFromFile
(
t
)
h
:=
&
mocks
.
IHeimdallClient
{}
h
.
On
(
"FetchWithRetry"
,
"bor"
,
"span"
,
"1"
)
.
Return
(
res
,
nil
)
res
=
stateSyncEventsPayload
(
t
)
// query := fmt.Sprintf("clerk/event-record/list?from-time=%d&to-time=%d&page=1&limit=50", 1, 1589709047)
h
.
On
(
"FetchWithRetry"
,
mock
.
AnythingOfType
(
"string"
))
.
Return
(
res
,
nil
)
h
.
On
(
"FetchWithRetry"
,
mock
.
AnythingOfType
(
"string"
))
.
Return
(
stateSyncEventsPayload
(
t
),
nil
)
return
h
,
heimdallSpan
}
func
generateFakeStateSyncEvents
(
sample
*
bor
.
EventRecordWithTime
,
count
int
)
[]
*
bor
.
EventRecordWithTime
{
events
:=
make
([]
*
bor
.
EventRecordWithTime
,
count
)
event
:=
*
sample
event
.
ID
=
0
event
.
Time
=
time
.
Now
()
events
[
0
]
=
&
bor
.
EventRecordWithTime
{}
*
events
[
0
]
=
event
for
i
:=
1
;
i
<
count
;
i
++
{
event
.
ID
=
uint64
(
i
)
event
.
Time
=
event
.
Time
.
Add
(
1
*
time
.
Second
)
events
[
i
]
=
&
bor
.
EventRecordWithTime
{}
*
events
[
i
]
=
event
}
return
events
}
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