Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Truite
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
EcoMobiCoin
Truite
Commits
d0f01417
Commit
d0f01417
authored
1 year ago
by
Anthony GRAIGNIC
Browse files
Options
Downloads
Patches
Plain Diff
Add unit tests to reproduce issue #123
parent
b3bb4535
Branches
123-node-clock-is-stuck-in-time-and-generate-futureblock-errors
No related tags found
1 merge request
!93
Add unit tests to reproduce issue #123
Pipeline
#6089
failed
1 year ago
Stage: lint
Stage: build
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/consensus/base.rs
+74
-0
74 additions, 0 deletions
src/consensus/base.rs
with
74 additions
and
0 deletions
src/consensus/base.rs
+
74
−
0
View file @
d0f01417
...
...
@@ -213,6 +213,11 @@ pub type BlockRewardSchedule = BlockSchedule<U256>;
#[cfg(test)]
mod
tests
{
use
std
::{
thread
::
sleep
,
time
::{
Duration
,
UNIX_EPOCH
},
};
use
crate
::
res
::
chainspec
::
MAINNET
;
use
super
::
*
;
...
...
@@ -334,4 +339,73 @@ mod tests {
assert_eq!
(
schedule
.for_block
(
BlockNumber
(
block
)),
expected_reward
);
}
}
#[test]
fn
validate_block_header_error_future_block_issue_123
()
{
// ARRANGE
let
consensus_engine_base
=
ConsensusEngineBase
::
new
(
ChainId
(
63
),
None
,
None
);
let
now
=
SystemTime
::
now
()
.duration_since
(
SystemTime
::
UNIX_EPOCH
)
.unwrap
()
.as_secs
();
sleep
(
Duration
::
from_secs
(
3
));
let
mut
header
=
BlockHeader
::
default
();
header
.timestamp
=
SystemTime
::
now
()
.duration_since
(
UNIX_EPOCH
)
.unwrap
()
.as_secs
()
+
5
;
let
parent
=
BlockHeader
::
default
();
sleep
(
Duration
::
from_secs
(
3
));
// ACT
let
result
=
consensus_engine_base
.validate_block_header
(
&
header
,
&
parent
,
true
);
// ASSERT
assert!
(
result
.is_err
());
}
#[test]
fn
validate_block_header_error_future_block
()
{
// ARRANGE
let
consensus_engine_base
=
ConsensusEngineBase
::
new
(
ChainId
(
63
),
None
,
None
);
let
mut
header
=
BlockHeader
::
default
();
header
.timestamp
=
SystemTime
::
now
()
.duration_since
(
UNIX_EPOCH
)
.unwrap
()
.as_secs
()
+
1_000_000
;
let
parent
=
BlockHeader
::
default
();
// ACT
let
result
=
consensus_engine_base
.validate_block_header
(
&
header
,
&
parent
,
true
);
// ASSERT
assert!
(
result
.is_err
());
}
#[test]
fn
validate_block_header_should_work
()
{
// ARRANGE
let
consensus_engine_base
=
ConsensusEngineBase
::
new
(
ChainId
(
63
),
None
,
None
);
let
mut
header
=
BlockHeader
::
default
();
header
.timestamp
=
SystemTime
::
now
()
.duration_since
(
UNIX_EPOCH
)
.unwrap
()
.as_secs
()
-
3600
;
let
parent
=
BlockHeader
::
default
();
// ACT
let
result
=
consensus_engine_base
.validate_block_header
(
&
header
,
&
parent
,
true
);
// ASSERT
assert!
(
result
.is_ok
());
}
}
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