diff --git a/lib-xps/tests/integration.rs b/lib-xps/tests/integration.rs index 83d0ea0..1b322d0 100644 --- a/lib-xps/tests/integration.rs +++ b/lib-xps/tests/integration.rs @@ -3,4 +3,5 @@ mod integration_util; mod it { mod contact_ops; mod messaging; + mod xps; } diff --git a/lib-xps/tests/it/contact_ops.rs b/lib-xps/tests/it/contact_ops.rs index 9f277ec..0031669 100644 --- a/lib-xps/tests/it/contact_ops.rs +++ b/lib-xps/tests/it/contact_ops.rs @@ -2,119 +2,16 @@ use std::str::FromStr; use anyhow::Error; -use ethers::providers::Middleware; -use ethers::types::{Address, Bytes, TransactionRequest, U256}; -use ethers::utils::keccak256; -use ethers::{signers::LocalWallet, signers::Signer}; use crate::integration_util::*; +use ethers::types::{Address, U256}; +use ethers::{signers::LocalWallet, signers::Signer}; use jsonrpsee::core::ClientError; use lib_didethresolver::{ did_registry::RegistrySignerExt, types::{DidUrl, KeyEncoding, XmtpAttribute, XmtpKeyPurpose, NULL_ADDRESS}, }; use lib_xps::rpc::{XpsClient, DEFAULT_ATTRIBUTE_VALIDITY}; -use messaging::ConversationSignerExt; -use xps_types::{Message, Status, Unit}; - -#[tokio::test] -async fn test_say_hello() -> Result<(), Error> { - with_xps_client(None, None, |client, _, _, _| async move { - let result = client.status().await?; - assert_eq!(result, "OK"); - Ok(()) - }) - .await -} - -#[tokio::test] -async fn test_send_message() -> Result<(), Error> { - with_xps_client(None, None, |client, context, _resolver, anvil| async move { - let wallet: LocalWallet = anvil.keys()[3].clone().into(); - let me = get_user(&anvil, 3).await; - - let conversation_id = keccak256(b"conversation_id"); - let payload = Bytes::from_static(b"payload"); - - let signature = wallet - .sign_xmtp_message( - &context.conversation, - conversation_id, - payload.clone(), - me.address(), - ) - .await?; - - let message = Message { - conversation_id, - payload, - identity: me.address(), - signature, - }; - - let pre_nonce = context.conversation.nonce(me.address()).call().await?; - assert!(pre_nonce == U256::zero()); - - let result = client.send_message(message).await; - assert!(result.is_ok()); - assert!(result.unwrap().status == Status::Success); - - // post-nonce should be same as pre-nonce + 1 - let post_nonce = context.conversation.nonce(me.address()).call().await?; - assert!(post_nonce == pre_nonce + 1); - Ok(()) - }) - .await -} - -#[tokio::test] -async fn test_send_message_fail() -> Result<(), Error> { - with_xps_client(None, None, |client, context, _resolver, anvil| async move { - let wallet: LocalWallet = anvil.keys()[3].clone().into(); - let me = get_user(&anvil, 3).await; - - let conversation_id = keccak256(b"conversation_id"); - let payload = Bytes::from_static(b"payload"); - - let signature = wallet - .sign_xmtp_message( - &context.conversation, - keccak256(b"unmatched_conversation_id"), - payload.clone(), - me.address(), - ) - .await?; - - let message = Message { - conversation_id, - payload, - identity: me.address(), - signature, - }; - - let pre_nonce = context.conversation.nonce(me.address()).call().await?; - assert!(pre_nonce == U256::zero()); - - let result = client.send_message(message).await; - assert!(result.is_err()); - println!("{:?}", result.err()); - - // post-nonce should be same as pre-nonce - let post_nonce = context.conversation.nonce(me.address()).call().await?; - assert!(post_nonce == pre_nonce); - Ok(()) - }) - .await -} - -#[tokio::test] -async fn test_wallet_address() -> Result<(), Error> { - with_xps_client(None, None, |client, _, _, _| async move { - let result = client.wallet_address().await?; - assert_ne!(result, Address::zero()); - Ok(()) - }) - .await -} +use xps_types::Status; #[tokio::test] async fn test_grant_revoke() -> Result<(), Error> { @@ -389,40 +286,6 @@ async fn test_revoke_installation() -> Result<(), Error> { .await } -#[tokio::test] -async fn test_balance() -> Result<(), Error> { - with_xps_client( - None, - Some(0.into()), - |client, context, _resolver, _anvil| async move { - // by default, we have no balance. verify that. - let mut balance = client.balance().await?; - assert_eq!(balance.balance, U256::from(0)); - assert_eq!(balance.unit, Unit::Eth); - - // fund the wallet account. - let accounts = context.signer.get_accounts().await?; - let from = accounts[1]; - let tx = TransactionRequest::new() - .to(client.wallet_address().await?) - .value(5_000_000_000_000_000_000_000_u128) - .from(from); - context.signer.send_transaction(tx, None).await?.await?; - - // check to see if the balance gets updated. - balance = client.balance().await?; - assert_eq!( - balance.balance, - U256::from(5_000_000_000_000_000_000_000_u128) - ); - assert_eq!(balance.unit, Unit::Eth); - - Ok(()) - }, - ) - .await -} - #[tokio::test] async fn test_fetch_key_packages() -> Result<(), Error> { with_xps_client(None, None, |client, context, _, anvil| async move { diff --git a/lib-xps/tests/it/xps.rs b/lib-xps/tests/it/xps.rs new file mode 100644 index 0000000..7973bb4 --- /dev/null +++ b/lib-xps/tests/it/xps.rs @@ -0,0 +1,52 @@ +use anyhow::Error; + +use crate::integration_util::*; +use ethers::providers::Middleware; +use ethers::types::{TransactionRequest, U256}; + +use lib_xps::rpc::XpsClient; +use xps_types::Unit; + +#[tokio::test] +async fn test_say_hello() -> Result<(), Error> { + with_xps_client(None, None, |client, _, _, _| async move { + let result = client.status().await?; + assert_eq!(result, "OK"); + Ok(()) + }) + .await +} + +#[tokio::test] +async fn test_balance() -> Result<(), Error> { + with_xps_client( + None, + Some(0.into()), + |client, context, _resolver, _anvil| async move { + // by default, we have no balance. verify that. + let mut balance = client.balance().await?; + assert_eq!(balance.balance, U256::from(0)); + assert_eq!(balance.unit, Unit::Eth); + + // fund the wallet account. + let accounts = context.signer.get_accounts().await?; + let from = accounts[1]; + let tx = TransactionRequest::new() + .to(client.wallet_address().await?) + .value(5_000_000_000_000_000_000_000_u128) + .from(from); + context.signer.send_transaction(tx, None).await?.await?; + + // check to see if the balance gets updated. + balance = client.balance().await?; + assert_eq!( + balance.balance, + U256::from(5_000_000_000_000_000_000_000_u128) + ); + assert_eq!(balance.unit, Unit::Eth); + + Ok(()) + }, + ) + .await +}