Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(wallet-integration): remove sign_call_data test #384

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(())
}
}
Loading