diff --git a/Cargo.lock b/Cargo.lock index c65651a7ba7d1ff90411daa0d0d442568b9e8b24..2d222269db39754a629341eed02674859eed21af 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", diff --git a/end2end-tests/Cargo.toml b/end2end-tests/Cargo.toml index ccea29014d8c9b0b077e31b53239e85988c3b693..b088152b59566e4b5d5fe39a07f9f694bb1ed7a8 100644 --- a/end2end-tests/Cargo.toml +++ b/end2end-tests/Cargo.toml @@ -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" diff --git a/end2end-tests/tests/common/balances.rs b/end2end-tests/tests/common/balances.rs index 47be324774e7600397d166fef3f879bcfda872d5..dc35383bd2b2a4bf58907f64baa51274483214d8 100644 --- a/end2end-tests/tests/common/balances.rs +++ b/end2end-tests/tests/common/balances.rs @@ -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()), diff --git a/end2end-tests/tests/common/cert.rs b/end2end-tests/tests/common/cert.rs index d380720a92253525a3cf6006ea077df41d962595..6b78e324829ee1236d5d5079d068c562d4971fd9 100644 --- a/end2end-tests/tests/common/cert.rs +++ b/end2end-tests/tests/common/cert.rs @@ -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(); diff --git a/end2end-tests/tests/common/identity.rs b/end2end-tests/tests/common/identity.rs index 58e881264a4daed837fdc4bc0a039e3f2428f27c..fcbb3e256b678ed53da221c0e1264cc3a6a30e41 100644 --- a/end2end-tests/tests/common/identity.rs +++ b/end2end-tests/tests/common/identity.rs @@ -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!( diff --git a/end2end-tests/tests/common/mod.rs b/end2end-tests/tests/common/mod.rs index 56ccdea5deadfb58b23dc74f2b7a818f245e3f97..0a23f8d7d505c9c7db8f27dcd397f45946fbded2 100644 --- a/end2end-tests/tests/common/mod.rs +++ b/end2end-tests/tests/common/mod.rs @@ -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)] diff --git a/end2end-tests/tests/common/oneshot.rs b/end2end-tests/tests/common/oneshot.rs index fcd9419375f80faae03c13576daf085282bdb674..6bfe2189d5e2dd730bd99ba90ab54c0159fdb702 100644 --- a/end2end-tests/tests/common/oneshot.rs +++ b/end2end-tests/tests/common/oneshot.rs @@ -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), diff --git a/end2end-tests/tests/cucumber_tests.rs b/end2end-tests/tests/cucumber_tests.rs index 094932d4bfd8ac137e6bae82f74be7f69d379046..b487a175a4b54c153c54fe7a1a0cf031510ced0c 100644 --- a/end2end-tests/tests/cucumber_tests.rs +++ b/end2end-tests/tests/cucumber_tests.rs @@ -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