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

wip

parent fe298c11
Branches
Tags
No related merge requests found
Feature: Identity creation
Scenario: alice invites a new member to join the web of trust
When alice creates identity for ferdie
When alice creates identity for ferdie
When 2 block later
Then ferdie identity should be created
// Copyright 2021 Axiom-Team
//
// This file is part of Substrate-Libre-Currency.
//
// Substrate-Libre-Currency is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, version 3 of the License.
//
// Substrate-Libre-Currency is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with Substrate-Libre-Currency. If not, see <https://www.gnu.org/licenses/>.
use super::gdev;
use super::gdev::runtime_types::pallet_identity;
use super::*;
use sp_keyring::AccountKeyring;
use subxt::tx::PairSigner;
pub async fn create_identity(
client: &Client,
from: AccountKeyring,
to: AccountKeyring,
) -> Result<()> {
let from = PairSigner::new(from.pair());
let to = to.to_account_id();
let _events = create_block_with_extrinsic(
client,
client
.tx()
.create_signed(
&gdev::tx().identity().create_identity(to),
&from,
BaseExtrinsicParamsBuilder::new(),
)
.await?,
)
.await?;
Ok(())
}
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
pub mod balances; pub mod balances;
pub mod cert; pub mod cert;
pub mod identity;
pub mod oneshot; pub mod oneshot;
#[subxt::subxt(runtime_metadata_path = "../resources/metadata.scale")] #[subxt::subxt(runtime_metadata_path = "../resources/metadata.scale")]
......
...@@ -297,6 +297,15 @@ async fn certifies(world: &mut DuniterWorld, from: String, to: String) -> Result ...@@ -297,6 +297,15 @@ async fn certifies(world: &mut DuniterWorld, from: String, to: String) -> Result
common::cert::certify(world.client(), from, to).await common::cert::certify(world.client(), from, to).await
} }
#[when(regex = r"([a-zA-Z]+) creates identity for ([a-zA-Z]+)")]
async fn creates_identity(world: &mut DuniterWorld, from: String, to: String) -> Result<()> {
// Parse inputs
let from = AccountKeyring::from_str(&from).expect("unknown from");
let to = AccountKeyring::from_str(&to).expect("unknown to");
common::identity::create_identity(world.client(), from, to).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)")]
...@@ -377,6 +386,7 @@ async fn should_be_certified_by( ...@@ -377,6 +386,7 @@ async fn should_be_certified_by(
.expect("unknown to") .expect("unknown to")
.to_account_id(); .to_account_id();
// get corresponding identities index
let issuer_index = world let issuer_index = world
.read( .read(
&gdev::storage() &gdev::storage()
...@@ -398,6 +408,7 @@ async fn should_be_certified_by( ...@@ -398,6 +408,7 @@ async fn should_be_certified_by(
.read_or_default(&gdev::storage().cert().certs_by_receiver(&receiver_index)) .read_or_default(&gdev::storage().cert().certs_by_receiver(&receiver_index))
.await?; .await?;
// look for certification by issuer/receiver pair
match issuers.binary_search_by(|(issuer_, _)| issuer_index.cmp(issuer_)) { match issuers.binary_search_by(|(issuer_, _)| issuer_index.cmp(issuer_)) {
Ok(_) => Ok(()), Ok(_) => Ok(()),
Err(_) => Err(anyhow::anyhow!( Err(_) => Err(anyhow::anyhow!(
...@@ -410,6 +421,36 @@ async fn should_be_certified_by( ...@@ -410,6 +421,36 @@ async fn should_be_certified_by(
} }
} }
#[then(regex = r"([a-zA-Z]+) identity should be created")]
async fn identity_should_be_created(world: &mut DuniterWorld, receiver: String) -> Result<()> {
// Parse inputs
let receiver_account = AccountKeyring::from_str(&receiver)
.expect("unknown to")
.to_account_id();
let receiver_index = world
.read(
&gdev::storage()
.identity()
.identity_index_of(&receiver_account),
)
.await?
.ok_or_else(|| anyhow::anyhow!("identity {} has no associated index", receiver))
.unwrap();
let _identity_value = world
.read(&gdev::storage().identity().identities(&receiver_index))
.await?
.ok_or_else(|| {
anyhow::anyhow!(
"indentity index {} does not have associated value",
receiver_index
)
})?;
Ok(())
}
// ============================================================ // ============================================================
#[derive(clap::Args)] #[derive(clap::Args)]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment