Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Dunitrust
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
nodes
rust
Dunitrust
Commits
56ad07ae
Commit
56ad07ae
authored
6 years ago
by
Pascal Engélibert
Browse files
Options
Downloads
Patches
Plain Diff
[tests] blockchain: test block verification
parent
0d80c5b9
No related branches found
No related tags found
1 merge request
!117
WIP: Resolve "Add block checking (checking all rules of the unit protocol)"
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/modules/blockchain/blockchain/src/dubp/check/mod.rs
+98
-0
98 additions, 0 deletions
lib/modules/blockchain/blockchain/src/dubp/check/mod.rs
with
98 additions
and
0 deletions
lib/modules/blockchain/blockchain/src/dubp/check/mod.rs
+
98
−
0
View file @
56ad07ae
...
@@ -144,3 +144,101 @@ pub fn verify_block_validity<W: WebOfTrust>(
...
@@ -144,3 +144,101 @@ pub fn verify_block_validity<W: WebOfTrust>(
Ok
(())
Ok
(())
}
}
#[cfg(test)]
mod
tests
{
use
super
::
*
;
use
dubp_documents_tests_tools
::
mocks
::
*
;
use
dup_crypto_tests_tools
::
mocks
::
*
;
use
durs_blockchain_dal
::
entities
::
block
::
DALBlock
;
use
durs_blockchain_dal
::
entities
::
identity
::
*
;
#[test]
fn
test_verify_blocks
()
{
let
blocks_dbs
=
BlocksV10DBs
::
open
(
None
);
let
wot_dbs
=
WotsV10DBs
::
open
(
None
);
let
wot_index
:
HashMap
<
PubKey
,
NodeId
>
=
HashMap
::
new
();
let
idty_a
=
identity
::
gen_mock_idty
(
pubkey
(
'A'
),
BlockId
(
0
));
let
pubkey_a
=
idty_a
.issuers
()[
0
];
let
idty_b
=
identity
::
gen_mock_idty
(
pubkey
(
'B'
),
BlockId
(
0
));
let
pubkey_b
=
idty_b
.issuers
()[
0
];
let
mut
blocks
=
gen_empty_timed_blocks
(
2
,
300
);
// Valid block 0
blocks
[
0
]
.issuers_frame
=
1
;
blocks
[
0
]
.issuers
.push
(
pubkey_a
);
blocks
[
0
]
.identities
.push
(
idty_a
.clone
());
blocks
[
0
]
.identities
.push
(
idty_b
.clone
());
verify_genesis_block_validity
(
&
blocks
[
0
])
.expect
(
"Fail to valid genesis block"
);
blocks_dbs
.blockchain_db
.write
(|
db
|
{
db
.insert
(
blocks
[
0
]
.number
,
DALBlock
{
block
:
blocks
[
0
]
.clone
(),
expire_certs
:
None
,
},
);
})
.expect
(
"Fail write to blockchain db"
);
wot_dbs
.identities_db
.write
(|
db
|
{
db
.insert
(
pubkey_a
,
DALIdentity
{
hash
:
String
::
new
(),
state
:
DALIdentityState
::
Member
(
vec!
[]),
joined_on
:
blocks
[
0
]
.blockstamp
(),
expired_on
:
None
,
revoked_on
:
None
,
idty_doc
:
idty_a
,
wot_id
:
NodeId
(
0
),
ms_created_block_id
:
blocks
[
0
]
.number
,
ms_chainable_on
:
vec!
[
0
],
cert_chainable_on
:
vec!
[
0
],
},
);
db
.insert
(
pubkey_b
,
DALIdentity
{
hash
:
String
::
new
(),
state
:
DALIdentityState
::
Member
(
vec!
[]),
joined_on
:
blocks
[
0
]
.blockstamp
(),
expired_on
:
None
,
revoked_on
:
None
,
idty_doc
:
idty_b
,
wot_id
:
NodeId
(
1
),
ms_created_block_id
:
blocks
[
0
]
.number
,
ms_chainable_on
:
vec!
[
0
],
cert_chainable_on
:
vec!
[
0
],
},
);
})
.expect
(
"Fail write to idty db"
);
// Valid block 1
blocks
[
1
]
.issuers_count
=
1
;
blocks
[
1
]
.issuers_frame
=
1
;
blocks
[
1
]
.issuers_frame_var
=
5
;
blocks
[
1
]
.issuers
.push
(
pubkey_b
);
blocks
[
1
]
.previous_issuer
=
Some
(
pubkey_a
);
verify_block_validity
(
&
blocks
[
1
],
&
blocks_dbs
.blockchain_db
,
&
wot_dbs
.identities_db
,
&
wot_dbs
.certs_db
,
&
wot_index
,
&
wot_dbs
.wot_db
,
)
.expect
(
"Fail to valid block"
);
}
}
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