Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
dunixir
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
teaching
dunixir
Commits
3f41892f
Commit
3f41892f
authored
3 years ago
by
ROUSSET Noemie
Browse files
Options
Downloads
Patches
Plain Diff
correction of implementation of issue BR_G74 code + tests
parent
43871078
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
lib/local_augmentation_example.ex
+9
-3
9 additions, 3 deletions
lib/local_augmentation_example.ex
test/identity/augmentation/identity_pub_key_unicity_test.exs
+69
-41
69 additions, 41 deletions
test/identity/augmentation/identity_pub_key_unicity_test.exs
with
78 additions
and
44 deletions
lib/local_augmentation_example.ex
+
9
−
3
View file @
3f41892f
...
...
@@ -385,9 +385,15 @@ defmodule Index.Augmentation do
end
## BR_G74
def
identityPubkeyUnicity
(
local_iindex
,
key
)
do
[{
_key
,
entry
}]
=
:ets
.
lookup
(
local_iindex
,
key
)
entry
.
pubUnique
==
true
def
identityPubkeyUnicity
(
local_iindex
)
do
:ets
.
match
(
local_iindex
,
{
:_
,
:"$1"
})
|>
Enum
.
reduce
(
true
,
fn
[
entry
],
acc
->
if
entry
[
:pubUnique
]
!=
nil
do
(
entry
[
:pubUnique
]
==
true
)
&&
acc
else
acc
end
end
)
end
end
...
...
This diff is collapsed.
Click to expand it.
test/identity/augmentation/identity_pub_key_unicity_test.exs
+
69
−
41
View file @
3f41892f
defmodule
IdentityPubKeyUnicityTest
do
use
ExUnit
.
Case
doctest
Index
.
Augmentation
.
IIndex
setup_all
do
local_iindex
=
:ets
.
new
(
:local_iindex
,
[
:set
,
:protected
])
local_mindex
=
:ets
.
new
(
:local_mindex
,
[
:set
,
:protected
])
#we create 2 new local identities in the local iindex
@identPubKeyUnique
%{
op:
'CREATE'
,
uid:
"tic"
,
pub:
"5B8iMAzq1dNmFe3ZxFTBQkqhq4fsztg1gZvxHXCk1XYH"
,
created_on:
"7543-000044410C5370DE8DBA911A358F318096B7A269CFC2BB93272E397CC513EA0A"
,
written_on:
"167884-0001DFCA28002A8C96575E53B8CEF8317453A7B0BA255542CCF0EC8AB5E99038"
,
member:
true
,
wasMember:
true
,
kick:
false
,
pubUnique:
true
}
Index
.
Generation
.
add_identity
(
"blockstamp_test"
,
local_iindex
,
local_mindex
,
%{
"pub"
=>
"pub_toto"
,
"block_uid"
=>
"block_uid_test"
,
"user_id"
=>
"user_id_toto"
})
@identPubKeyNonUnique
%{
op:
'CREATE'
,
uid:
"tac"
,
pub:
"5B8iMAzq1dNmFe3ZxFTBQkqhq4fsztg1gZvxHXCk1XYH"
,
created_on:
"7543-000044410C5370DE8DBA911A358F318096B7A269CFC2BB93272E397CC513EA0A"
,
written_on:
"167884-0001DFCA28002A8C96575E53B8CEF8317453A7B0BA255542CCF0EC8AB5E99038"
,
member:
true
,
wasMember:
true
,
kick:
false
,
pubUnique:
false
}
Index
.
Generation
.
add_identity
(
"blockstamp_test"
,
local_iindex
,
local_mindex
,
%{
"pub"
=>
"pub_tata"
,
"block_uid"
=>
"block_uid_test"
,
"user_id"
=>
"user_id_tata"
})
@identPubKeyWithoutField
%{
op:
'CREATE'
,
uid:
"tac"
,
pub:
"5B8iMAzq1dNmFe3ZxFTBQkqhq4fsztg1gZvxHXCk1XYH"
,
created_on:
"7543-000044410C5370DE8DBA911A358F318096B7A269CFC2BB93272E397CC513EA0A"
,
written_on:
"167884-0001DFCA28002A8C96575E53B8CEF8317453A7B0BA255542CCF0EC8AB5E99038"
,
member:
true
,
wasMember:
true
,
kick:
false
}
#we copy these identities into the global iindex table
{
:ok
,
global_iindex
}
=
:dets
.
open_file
(
:"test/global_iindex"
,
type:
:set
)
:ets
.
to_dets
(
local_iindex
,
global_iindex
)
#we replace the public key pub_toto to pub_tutu in the global iindex
doctest
Index
.
Augmentation
.
IIndex
[{
"pub_toto"
,
elt
}]
=
:dets
.
lookup
(
global_iindex
,
"pub_toto"
)
:dets
.
delete
(
global_iindex
,
"pub_toto"
)
new_elt
=
Map
.
replace!
(
elt
,
:pub
,
"pub_tutu"
)
:dets
.
insert
(
global_iindex
,
{
"pub_tutu"
,
new_elt
})
setup_all
do
#test with a uid unique
local_iindex
=
:ets
.
new
(
:"test/local_iindex"
,
[
:set
,
:protected
])
:ets
.
insert
(
local_iindex
,
{
0
,
@identPubKeyUnique
})
pubKeyUniqueOneElt
=
Index
.
Augmentation
.
IIndex
.
identityPubkeyUnicity
(
local_iindex
)
:file
.
delete
(
"test/local_iindex"
)
#we search if the local iindex is not found in the global iindex with op="CREATE"
#test with a uid unique
local_iindex
=
:ets
.
new
(
:"test/local_iindex"
,
[
:set
,
:protected
])
:ets
.
insert
(
local_iindex
,
{
0
,
@identPubKeyWithoutField
})
pubKeyUniqueOneEltWithoutField
=
Index
.
Augmentation
.
IIndex
.
identityPubkeyUnicity
(
local_iindex
)
:file
.
delete
(
"test/local_iindex"
)
#toto.pubUnique is set to true
Index
.
Augmentation
.
IIndex
.
pubUnique
(
local_iindex
,
global_iindex
,
"pub_toto"
)
#tata.pubUnique is set to false
Index
.
Augmentation
.
IIndex
.
pubUnique
(
local_iindex
,
global_iindex
,
"pub_tata"
)
#test with a uid unique
local_iindex
=
:ets
.
new
(
:"test/local_iindex"
,
[
:set
,
:protected
])
:ets
.
insert
(
local_iindex
,
{
0
,
@identPubKeyWithoutField
})
:ets
.
insert
(
local_iindex
,
{
1
,
@identPubKeyUnique
})
pubKeyUniqueManyElt
=
Index
.
Augmentation
.
IIndex
.
identityPubkeyUnicity
(
local_iindex
)
:file
.
delete
(
"test/local_iindex"
)
:dets
.
close
(
global_iindex
)
:file
.
delete
(
"test/global_iindex"
)
#test with a uid non unique
local_iindex
=
:ets
.
new
(
:"test/local_iindex"
,
[
:set
,
:protected
])
:ets
.
insert
(
local_iindex
,
{
0
,
@identPubKeyNonUnique
})
pubKeyNonUniqueOneElt
=
Index
.
Augmentation
.
IIndex
.
identityPubkeyUnicity
(
local_iindex
)
:file
.
delete
(
"test/local_iindex"
)
#check if the public key is unique or not
pubKeyUniqueTrue
=
Index
.
Augmentation
.
IIndex
.
identityPubkeyUnicity
(
local_iindex
,
"pub_toto"
)
pubKeyUniqueFalse
=
Index
.
Augmentation
.
IIndex
.
identityPubkeyUnicity
(
local_iindex
,
"pub_tata"
)
#test with a uid non unique
local_iindex
=
:ets
.
new
(
:"test/local_iindex"
,
[
:set
,
:protected
])
:ets
.
insert
(
local_iindex
,
{
0
,
@identPubKeyWithoutField
})
:ets
.
insert
(
local_iindex
,
{
1
,
@identPubKeyNonUnique
})
:ets
.
insert
(
local_iindex
,
{
2
,
@identPubKeyUnique
})
pubKeyNonUniqueManyElt
=
Index
.
Augmentation
.
IIndex
.
identityPubkeyUnicity
(
local_iindex
)
:file
.
delete
(
"test/local_iindex"
)
{
:ok
,
pubKeyUnique
True:
pubKeyUniqueTrue
,
pubKeyUniqueFalse
:
pubKeyUnique
False
}
{
:ok
,
pubKeyUnique
OneElt:
pubKeyUniqueOneElt
,
pubKeyUniqueOneEltWithoutField:
pubKeyUniqueOneEltWithoutField
,
pubKeyUniqueManyElt:
pubKeyUniqueManyElt
,
pubKeyNonUniqueOneElt
:
pubKey
Non
Unique
OneElt
,
pubKeyNonUniqueManyElt:
pubKeyNonUniqueManyElt
}
end
test
"check pubUnique is the right value"
,
state
do
assert
state
.
pubKeyUniqueTrue
==
true
assert
state
.
pubKeyUniqueFalse
==
false
test
"check pubUnique"
,
state
do
assert
state
.
pubKeyUniqueOneElt
==
true
assert
state
.
pubKeyUniqueOneEltWithoutField
==
true
assert
state
.
pubKeyUniqueManyElt
==
true
assert
state
.
pubKeyNonUniqueOneElt
==
false
assert
state
.
pubKeyNonUniqueManyElt
==
false
end
end
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