Skip to content

Commit

Permalink
test(wallet-integration): remove sign_call_data test
Browse files Browse the repository at this point in the history
  • Loading branch information
al3mart committed Dec 16, 2024
1 parent 6b13134 commit 99a016b
Showing 1 changed file with 0 additions and 60 deletions.
60 changes: 0 additions & 60 deletions crates/pop-cli/src/common/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,63 +29,3 @@ pub async fn wait_for_signature(call_data: Vec<u8>, url: String) -> anyhow::Resu
let signed_payload = wallet.state.lock().await.signed_payload.clone();
Ok(signed_payload)
}

#[cfg(test)]
mod tests {
use super::*;
use subxt::utils::to_hex;

// TODO: delete this test.
// This is a helper test for an actual running pop CLI.
// It can serve as the "frontend" to query the payload, sign it
// and submit back to the CLI.
#[tokio::test]
async fn sign_call_data() -> anyhow::Result<()> {
use subxt::{config::DefaultExtrinsicParamsBuilder as Params, tx::Payload};
// This struct implements the [`Payload`] trait and is used to submit
// pre-encoded SCALE call data directly, without the dynamic construction of transactions.
struct CallData(Vec<u8>);

impl Payload for CallData {
fn encode_call_data_to(
&self,
_: &subxt::Metadata,
out: &mut Vec<u8>,
) -> Result<(), subxt::ext::subxt_core::Error> {
out.extend_from_slice(&self.0);
Ok(())
}
}

use subxt_signer::sr25519::dev;
let payload = reqwest::get(&format!("{}/payload", "http://127.0.0.1:9090"))
.await
.expect("Failed to get payload")
.json::<TransactionData>()
.await
.expect("Failed to parse payload");

let url = "ws://localhost:9944";
let rpc_client = subxt::backend::rpc::RpcClient::from_url(url).await?;
let client =
subxt::OnlineClient::<subxt::SubstrateConfig>::from_rpc_client(rpc_client).await?;

let signer = dev::alice();

let payload = CallData(payload.call_data());
let ext_params = Params::new().build();
let signed = client.tx().create_signed(&payload, &signer, ext_params).await?;

let _response = reqwest::Client::new()
.post(&format!("{}/submit", "http://localhost:9090"))
.json(&to_hex(signed.encoded()))
.send()
.await
.expect("Failed to submit payload")
.text()
.await
.expect("Failed to parse JSON response");

Ok(())
}
}

0 comments on commit 99a016b

Please sign in to comment.