Skip to content
Snippets Groups Projects
Unverified Commit 0c74c299 authored by bgallois's avatar bgallois
Browse files

wip: fix end2end-test

parent 22fdbdd9
No related branches found
No related tags found
No related merge requests found
......@@ -9924,7 +9924,9 @@ dependencies = [
"scale-value",
"serde",
"serde_json",
"sp-core",
"sp-core-hashing 8.0.0",
"sp-runtime",
"subxt-macro",
"subxt-metadata",
"thiserror",
......
......@@ -17,12 +17,13 @@ cucumber = "0.11"
env_logger = "0.9.0"
hex = "0.4"
notify = "4.0"
parity-scale-codec = "3.1.5"
parity-scale-codec = "3.4.0"
portpicker = "0.1.1"
serde_json = "1.0.64"
serde_json = "1.0.96"
sp-keyring = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.42", default-features = false }
subxt = { git = 'https://github.com/duniter/subxt.git', branch = 'duniter-substrate-v0.9.42', default-features = false }
tokio = { version = "1.24.2", features = ["macros"], default-features = false }
subxt = { git = 'https://github.com/duniter/subxt.git', branch = 'duniter-substrate-v0.9.42', default-features = false, features = ["substrate-compat", "jsonrpsee-ws"] }
tokio = { version = "1.28", features = ["macros", "time", "rt-multi-thread"], default-features = false }
sp-runtime = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.42', default-features = false , features = ["std"] }
[[test]]
name = "cucumber_tests"
......
......@@ -18,7 +18,7 @@ use super::gdev;
use super::gdev::runtime_types::pallet_balances;
use super::*;
use sp_keyring::AccountKeyring;
use subxt::{ext::sp_runtime::MultiAddress, tx::PairSigner};
use subxt::{tx::PairSigner, utils::MultiAddress};
pub async fn set_balance(client: &Client, who: AccountKeyring, amount: u64) -> Result<()> {
let _events = create_block_with_extrinsic(
......@@ -29,10 +29,9 @@ pub async fn set_balance(client: &Client, who: AccountKeyring, amount: u64) -> R
&gdev::tx()
.sudo()
.sudo(gdev::runtime_types::gdev_runtime::RuntimeCall::Balances(
pallet_balances::pallet::Call::set_balance {
who: MultiAddress::Id(who.to_account_id()),
pallet_balances::pallet::Call::force_set_balance {
who: MultiAddress::Id(who.to_account_id().into()),
new_free: amount,
new_reserved: 0,
},
)),
&PairSigner::new(SUDO_ACCOUNT.pair()),
......
......@@ -18,7 +18,7 @@ use super::gdev;
use super::gdev::runtime_types::pallet_certification;
use super::*;
use sp_keyring::AccountKeyring;
use subxt::{ext::sp_runtime::MultiAddress, tx::PairSigner};
use subxt::{tx::PairSigner, utils::MultiAddress};
pub async fn certify(client: &Client, from: AccountKeyring, to: AccountKeyring) -> Result<()> {
let signer = PairSigner::new(from.pair());
......@@ -27,12 +27,18 @@ pub async fn certify(client: &Client, from: AccountKeyring, to: AccountKeyring)
let issuer_index = client
.storage()
.fetch(&gdev::storage().identity().identity_index_of(&from), None)
.at_latest()
.await
.unwrap()
.fetch(&gdev::storage().identity().identity_index_of(&from.into()))
.await?
.unwrap();
let receiver_index = client
.storage()
.fetch(&gdev::storage().identity().identity_index_of(&to), None)
.at_latest()
.await
.unwrap()
.fetch(&gdev::storage().identity().identity_index_of(&to.into()))
.await?
.unwrap();
......
......@@ -22,7 +22,7 @@ use sp_keyring::AccountKeyring;
use subxt::tx::PairSigner;
type BlockNumber = u32;
type AccountId = subxt::ext::sp_core::crypto::AccountId32;
type AccountId = subxt::utils::AccountId32;
type IdtyData = gdev::runtime_types::common_runtime::entities::IdtyData;
type IdtyValue =
gdev::runtime_types::pallet_identity::types::IdtyValue<BlockNumber, AccountId, IdtyData>;
......@@ -42,7 +42,7 @@ pub async fn create_identity(
client
.tx()
.create_signed(
&gdev::tx().identity().create_identity(to),
&gdev::tx().identity().create_identity(to.into()),
&from,
BaseExtrinsicParamsBuilder::new(),
)
......@@ -93,12 +93,14 @@ pub async fn validate_identity(client: &Client, from: AccountKeyring, to: u32) -
// get identity index from account keyring name
pub async fn get_identity_index(world: &mut DuniterWorld, account: String) -> Result<u32> {
let account = AccountKeyring::from_str(&account)
let account: AccountId = AccountKeyring::from_str(&account)
.expect("unknown account")
.to_account_id();
.to_account_id()
.into();
let identity_index = world
.read(&gdev::storage().identity().identity_index_of(&account))
.await
.await?
.ok_or_else(|| anyhow::anyhow!("identity {} has no associated index", account))
.unwrap();
......@@ -111,6 +113,7 @@ pub async fn get_identity_value(world: &mut DuniterWorld, account: String) -> Re
let identity_value = world
.read(&gdev::storage().identity().identities(identity_index))
.await
.await?
.ok_or_else(|| {
anyhow::anyhow!(
......
......@@ -35,9 +35,9 @@ use std::io::prelude::*;
use std::path::PathBuf;
use std::process::Command;
use std::str::FromStr;
use subxt::config::extrinsic_params::BaseExtrinsicParamsBuilder;
use subxt::ext::{sp_core, sp_runtime};
use subxt::rpc::rpc_params;
use subxt::tx::BaseExtrinsicParamsBuilder;
pub type Client = subxt::OnlineClient<GdevConfig>;
pub type Event = gdev::Event;
......@@ -48,14 +48,14 @@ pub type TxProgress = subxt::tx::TxProgress<GdevConfig, Client>;
pub enum GdevConfig {}
impl subxt::config::Config for GdevConfig {
type Index = u32;
type BlockNumber = u32;
type Hash = sp_core::H256;
type Hashing = sp_runtime::traits::BlakeTwo256;
type AccountId = sp_runtime::AccountId32;
type Address = sp_runtime::MultiAddress<Self::AccountId, u32>;
type Header = sp_runtime::generic::Header<Self::BlockNumber, sp_runtime::traits::BlakeTwo256>;
type Header =
subxt::config::substrate::SubstrateHeader<u32, subxt::config::substrate::BlakeTwo256>;
type Hasher = subxt::config::substrate::BlakeTwo256;
type Signature = sp_runtime::MultiSignature;
type ExtrinsicParams = subxt::tx::BaseExtrinsicParams<Self, Tip>;
type ExtrinsicParams = subxt::config::extrinsic_params::BaseExtrinsicParams<Self, Tip>;
}
#[derive(Copy, Clone, Debug, Default, Encode)]
......
......@@ -19,10 +19,8 @@ use super::gdev::runtime_types::pallet_balances;
use super::gdev::runtime_types::pallet_oneshot_account;
use super::*;
use sp_keyring::AccountKeyring;
use subxt::{
ext::sp_runtime::{AccountId32, MultiAddress},
tx::PairSigner,
};
use subxt::utils::AccountId32;
use subxt::{tx::PairSigner, utils::MultiAddress};
pub enum Account {
Normal(AccountKeyring),
......
......@@ -64,37 +64,39 @@ impl DuniterWorld {
self.ignore_errors
}
// Read storage entry on last block
fn read<'a, Address>(
async fn read<'a, Address>(
&self,
address: &'a Address,
) -> impl std::future::Future<
Output = std::result::Result<
Option<<Address::Target as subxt::metadata::DecodeWithMetadata>::Target>,
subxt::error::Error,
>,
Output = std::result::Result<Option<Address::Target>, subxt::error::Error>,
> + 'a
where
Address: subxt::storage::StorageAddress<IsFetchable = subxt::storage::address::Yes> + 'a,
{
self.client().storage().fetch(address, None)
self.client()
.storage()
.at_latest()
.await
.unwrap()
.fetch(address)
}
// Read storage entry with default value (on last block)
fn read_or_default<'a, Address>(
async fn read_or_default<'a, Address>(
&self,
address: &'a Address,
) -> impl std::future::Future<
Output = std::result::Result<
<Address::Target as subxt::metadata::DecodeWithMetadata>::Target,
subxt::error::Error,
>,
> + 'a
) -> impl std::future::Future<Output = std::result::Result<Address::Target, subxt::error::Error>> + 'a
where
Address: subxt::storage::StorageAddress<
IsFetchable = subxt::storage::address::Yes,
IsDefaultable = subxt::storage::address::Yes,
> + 'a,
{
self.client().storage().fetch_or_default(address, None)
self.client()
.storage()
.at_latest()
.await
.unwrap()
.fetch_or_default(address)
}
}
......@@ -153,6 +155,7 @@ async fn who_have(world: &mut DuniterWorld, who: String, amount: u64, unit: Stri
if is_ud {
let current_ud_amount = world
.read(&gdev::storage().universal_dividend().current_ud())
.await
.await?
.unwrap_or_default();
amount = (amount * current_ud_amount) / 1_000;
......@@ -332,13 +335,15 @@ async fn should_have(
unit: String,
) -> Result<()> {
// Parse inputs
let who = AccountKeyring::from_str(&who)
let who: subxt::utils::AccountId32 = AccountKeyring::from_str(&who)
.expect("unknown to")
.to_account_id();
.to_account_id()
.into();
let (amount, _is_ud) = parse_amount(amount, &unit);
let who_account = world
.read_or_default(&gdev::storage().system().account(&who))
.await
.await?;
assert_eq!(who_account.data.free, amount);
Ok(())
......@@ -352,13 +357,15 @@ async fn should_have_oneshot(
unit: String,
) -> Result<()> {
// Parse inputs
let who = AccountKeyring::from_str(&who)
let who: subxt::utils::AccountId32 = AccountKeyring::from_str(&who)
.expect("unknown to")
.to_account_id();
.to_account_id()
.into();
let (amount, _is_ud) = parse_amount(amount, &unit);
let oneshot_amount = world
.read(&gdev::storage().oneshot_account().oneshot_accounts(&who))
.await
.await?;
assert_eq!(oneshot_amount.unwrap_or(0), amount);
Ok(())
......@@ -373,6 +380,7 @@ async fn current_ud_amount_should_be(
let expected = (amount * 100) + cents;
let actual = world
.read_or_default(&gdev::storage().universal_dividend().current_ud())
.await
.await?;
assert_eq!(actual, expected);
Ok(())
......@@ -383,6 +391,7 @@ async fn monetary_mass_should_be(world: &mut DuniterWorld, amount: u64, cents: u
let expected = (amount * 100) + cents;
let actual = world
.read_or_default(&gdev::storage().universal_dividend().monetary_mass())
.await
.await?;
assert_eq!(actual, expected);
Ok(())
......@@ -395,12 +404,14 @@ async fn should_be_certified_by(
issuer: String,
) -> Result<()> {
// Parse inputs
let receiver_account = AccountKeyring::from_str(&receiver)
let receiver_account: subxt::utils::AccountId32 = AccountKeyring::from_str(&receiver)
.expect("unknown to")
.to_account_id();
let issuer_account = AccountKeyring::from_str(&issuer)
.to_account_id()
.into();
let issuer_account: subxt::utils::AccountId32 = AccountKeyring::from_str(&issuer)
.expect("unknown to")
.to_account_id();
.to_account_id()
.into();
// get corresponding identities index
let issuer_index = world
......@@ -409,6 +420,7 @@ async fn should_be_certified_by(
.identity()
.identity_index_of(&issuer_account),
)
.await
.await?
.unwrap();
let receiver_index = world
......@@ -417,11 +429,13 @@ async fn should_be_certified_by(
.identity()
.identity_index_of(&receiver_account),
)
.await
.await?
.unwrap();
let issuers = world
.read_or_default(&gdev::storage().cert().certs_by_receiver(receiver_index))
.await
.await?;
// look for certification by issuer/receiver pair
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment