Skip to content
Snippets Groups Projects
Commit 35a9f5ca authored by Hugo Trentesaux's avatar Hugo Trentesaux
Browse files

wip

parent 6242ae33
No related branches found
No related tags found
No related merge requests found
This commit is part of merge request !82. Comments created here will be created in the context of that merge request.
Feature: Identity creation Feature: Identity creation
Scenario: alice invites a new member to join the web of trust Scenario: alice invites a new member to join the web of trust
When alice sends 6 ĞD to ferdie
When 22 block later
When alice creates identity for ferdie When alice creates identity for ferdie
When alice creates identity for ferdie
When 2 block later
Then ferdie identity should be created Then ferdie identity should be created
When ferdie confirms his identity with pseudo "Ferdie"
Then ferdie identity should be confirmed
...@@ -2,12 +2,12 @@ ...@@ -2,12 +2,12 @@
"first_ud": 1000, "first_ud": 1000,
"first_ud_reeval": 100, "first_ud_reeval": 100,
"genesis_parameters": { "genesis_parameters": {
"genesis_certs_expire_on": 100000, "genesis_certs_expire_on": 1000,
"genesis_certs_min_received": 2, "genesis_certs_min_received": 2,
"genesis_memberships_expire_on": 100000, "genesis_memberships_expire_on": 1000,
"genesis_smith_certs_expire_on": 100000, "genesis_smith_certs_expire_on": 1000,
"genesis_smith_certs_min_received": 2, "genesis_smith_certs_min_received": 2,
"genesis_smith_memberships_expire_on": 100000 "genesis_smith_memberships_expire_on": 1000
}, },
"identities": { "identities": {
"Alice": { "Alice": {
......
...@@ -43,3 +43,22 @@ pub async fn create_identity( ...@@ -43,3 +43,22 @@ pub async fn create_identity(
Ok(()) Ok(())
} }
pub async fn confirm_identity(client: &Client, from: AccountKeyring, pseudo: String) -> Result<()> {
let from = PairSigner::new(from.pair());
let _events = create_block_with_extrinsic(
client,
client
.tx()
.create_signed(
&gdev::tx().identity().confirm_identity(pseudo),
&from,
BaseExtrinsicParamsBuilder::new(),
)
.await?,
)
.await?;
Ok(())
}
...@@ -306,6 +306,13 @@ async fn creates_identity(world: &mut DuniterWorld, from: String, to: String) -> ...@@ -306,6 +306,13 @@ async fn creates_identity(world: &mut DuniterWorld, from: String, to: String) ->
common::identity::create_identity(world.client(), from, to).await common::identity::create_identity(world.client(), from, to).await
} }
#[when(regex = r#"([a-zA-Z]+) confirms (?:his|her) identity with pseudo "([a-zA-Z]+)""#)]
async fn confirm_identity(world: &mut DuniterWorld, from: String, pseudo: String) -> Result<()> {
let from = AccountKeyring::from_str(&from).expect("unknown from");
common::identity::confirm_identity(world.client(), from, pseudo).await
}
// ===== then ==== // ===== then ====
#[then(regex = r"([a-zA-Z]+) should have (\d+) (ĞD|cĞD)")] #[then(regex = r"([a-zA-Z]+) should have (\d+) (ĞD|cĞD)")]
...@@ -421,33 +428,61 @@ async fn should_be_certified_by( ...@@ -421,33 +428,61 @@ async fn should_be_certified_by(
} }
} }
// TODO refactor getting identity value from name
#[then(regex = r"([a-zA-Z]+) identity should be created")] #[then(regex = r"([a-zA-Z]+) identity should be created")]
async fn identity_should_be_created(world: &mut DuniterWorld, receiver: String) -> Result<()> { async fn identity_should_be_created(world: &mut DuniterWorld, receiver: String) -> Result<()> {
// Parse inputs let account = AccountKeyring::from_str(&receiver)
let receiver_account = AccountKeyring::from_str(&receiver) .expect("unknown account")
.expect("unknown to")
.to_account_id(); .to_account_id();
let receiver_index = world let identity_index = world
.read( .read(&gdev::storage().identity().identity_index_of(&account))
&gdev::storage()
.identity()
.identity_index_of(&receiver_account),
)
.await? .await?
.ok_or_else(|| anyhow::anyhow!("identity {} has no associated index", receiver)) .ok_or_else(|| anyhow::anyhow!("identity {} has no associated index", receiver))
.unwrap(); .unwrap();
let _identity_value = world let _identity_value = world
.read(&gdev::storage().identity().identities(&receiver_index)) .read(&gdev::storage().identity().identities(&identity_index))
.await?
.ok_or_else(|| {
anyhow::anyhow!(
"indentity index {} does not have associated value",
identity_index
)
})?;
// TODO check that
// _identity_value.status == IdtyStatus::Created
Ok(())
}
#[then(regex = r"([a-zA-Z]+) identity should be confirmed")]
async fn identity_should_be_confirmed(world: &mut DuniterWorld, name: String) -> Result<()> {
let account = AccountKeyring::from_str(&name)
.expect("unknown account")
.to_account_id();
let identity_index = world
.read(&gdev::storage().identity().identity_index_of(&account))
.await?
.ok_or_else(|| anyhow::anyhow!("identity {} has no associated index", name))
.unwrap();
let _identity_value = world
.read(&gdev::storage().identity().identities(&identity_index))
.await? .await?
.ok_or_else(|| { .ok_or_else(|| {
anyhow::anyhow!( anyhow::anyhow!(
"indentity index {} does not have associated value", "indentity index {} does not have associated value",
receiver_index identity_index
) )
})?; })?;
// TODO check that
// _identity_value.status == IdtyStatus::ConfirmedByOwner
Ok(()) Ok(())
} }
......
...@@ -39,7 +39,7 @@ pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Pu ...@@ -39,7 +39,7 @@ pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Pu
.public() .public()
} }
/*/// Generate an account ID from pain. /*/// Generate an account ID from pair.
pub fn get_account_id_from_pair<TPublic: Public>(pair: TPublic::Pair) -> AccountId pub fn get_account_id_from_pair<TPublic: Public>(pair: TPublic::Pair) -> AccountId
where where
AccountPublic: From<<TPublic::Pair as Pair>::Public>, AccountPublic: From<<TPublic::Pair as Pair>::Public>,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment