Skip to content
Snippets Groups Projects
Commit 0749a76b authored by ROUSSET Noemie's avatar ROUSSET Noemie
Browse files

rule BR_G74 - Identity pubkey unicity - code + tests

parent 0c263250
Branches
Tags
No related merge requests found
......@@ -377,6 +377,12 @@ defmodule Index.Augmentation do
[{_key, entry}] = :ets.lookup(local_iindex, key)
entry.uidUnique == true
end
## BR_G74
def identityPubkeyUnicity(local_iindex, key) do
[{_key, entry}] = :ets.lookup(local_iindex, key)
entry.pubUnique == true
end
end
defmodule MIndex do
......
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
Index.Generation.add_identity("blockstamp_test", local_iindex, local_mindex, %{
"pub" => "pub_toto",
"block_uid" => "block_uid_test",
"user_id" => "user_id_toto"
})
Index.Generation.add_identity("blockstamp_test", local_iindex, local_mindex, %{
"pub" => "pub_tata",
"block_uid" => "block_uid_test",
"user_id" => "user_id_tata"
})
#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
[{"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})
#we search if the local iindex is not found in the global iindex with op="CREATE"
#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")
:dets.close(global_iindex)
:file.delete("test/global_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")
{:ok, pubKeyUniqueTrue: pubKeyUniqueTrue, pubKeyUniqueFalse: pubKeyUniqueFalse}
end
test "check pubUnique is the right value", state do
assert state.pubKeyUniqueTrue == true
assert state.pubKeyUniqueFalse == false
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment