Fix for gtest

This commit is contained in:
Pascal Engélibert 2025-07-25 18:02:57 +02:00
commit e07f06d75f
4 changed files with 235 additions and 182 deletions

View file

@ -1,16 +1,7 @@
use crate::{DebtG2B, Opt};
use crate::DebtG2B;
use log::error;
use runtime::balances::calls::types::TransferKeepAlive;
use subxt::{
OnlineClient,
backend::{Backend, BackendExt},
ext::sp_core::{
Pair as _,
ed25519::{Pair, Public},
},
tx::{PairSigner, Signer},
};
use subxt::ext::sp_core::ed25519::Pair;
use tokio::sync::mpsc::Receiver;
use typed_sled::Tree;
@ -22,16 +13,9 @@ pub mod runtime {}
pub type Client = subxt::OnlineClient<Runtime>;
pub type AccountId = subxt::utils::AccountId32;
pub type IdtyId = u32;
pub type BlockNumber = u32;
pub type TxProgress = subxt::tx::TxProgress<Runtime, Client>;
pub type Balance = u64;
pub type AccountData =
runtime::runtime_types::pallet_duniter_account::types::AccountData<Balance, IdtyId>;
pub type AccountInfo = runtime::runtime_types::frame_system::AccountInfo<u32, AccountData>;
pub type Hash = sp_core::H256;
// declare runtime types
pub enum Runtime {}
impl subxt::config::Config for Runtime {
type AssetId = ();
@ -44,37 +28,16 @@ impl subxt::config::Config for Runtime {
type ExtrinsicParams = subxt::config::DefaultExtrinsicParams<Self>;
}
#[derive(Copy, Clone, Debug, Default, codec::Encode)]
pub struct Tip {
#[codec(compact)]
tip: u64,
}
impl Tip {
pub fn new(amount: u64) -> Self {
Tip { tip: amount }
}
}
impl From<u64> for Tip {
fn from(n: u64) -> Self {
Self::new(n)
}
}
pub enum Msg {
NewDebt,
Timer,
}
pub async fn run(
url: String,
pair: Pair,
mut recv: Receiver<DebtG2B>,
tree_debt_g2b: Tree<DebtG2B, ()>,
) {
let mut client = OnlineClient::<Runtime>::from_url(&url).await.ok();
let mut client = Client::from_url(&url).await.ok();
while let Some(msg) = recv.recv().await {
if client.is_none() {
client = OnlineClient::<Runtime>::from_url(&url).await.ok();
client = Client::from_url(&url).await.ok();
}
if let Some(client) = &client {
match client

View file

@ -5,19 +5,22 @@ mod indexer;
mod response;
use argp::FromArgs;
use log::error;
use serde::{Deserialize, Serialize};
use sp_core::Pair as _;
use sp_core::{
Pair as _,
crypto::{Ss58AddressFormat, Ss58Codec, set_default_ss58_version},
};
use std::{
collections::{hash_map::Entry, HashMap}, io::{BufRead, Read}, str::FromStr, sync::Arc
};
use subxt::{
ext::sp_core::ed25519::Pair,
utils::AccountId32,
collections::{HashMap, hash_map::Entry},
io::{BufRead, Read},
str::FromStr,
sync::Arc,
};
use subxt::{ext::sp_core::ed25519::Pair, utils::AccountId32};
use tiny_http::{Response, ResponseBox, Server};
use tokio::sync::mpsc::{Sender, channel};
use typed_sled::Tree;
use log::error;
/// Game to Blockchain
const TREE_DEBT_G2B: &'static str = "debt_g2b";
@ -30,7 +33,11 @@ struct Opt {
db: String,
/// Duniter indexer URL
#[argp(option, short = 'i', default = "String::from(\"https://squid.gdev.gyroi.de/v1/graphql\")")]
#[argp(
option,
short = 'i',
default = "String::from(\"https://gt-squid.axiom-team.fr/v1/graphql\")"
)]
indexer: String,
/// secret key is legacy (two passwords on the two first lines)
@ -85,8 +92,11 @@ async fn main() {
.expect("Cannot read secret key file");
Pair::from_string(sk_content.trim(), None).expect("Cannot decode secret key")
};
set_default_ss58_version(Ss58AddressFormat::custom(4450));
let pk: AccountId32 = pair.public().into();
let pk_str = pk.to_string();
let pk: sp_core::crypto::AccountId32 = pk.0.into();
let pk_str = dbg!(pk.to_ss58check_with_version(Ss58AddressFormat::custom(4450)));
simplelog::SimpleLogger::init(log::LevelFilter::Debug, simplelog::Config::default()).unwrap();