-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reorganize Integration Tests, re-introduce integration test module (#74)
- Loading branch information
Showing
4 changed files
with
151 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
mod integration_util; | ||
|
||
mod it { | ||
mod contact_ops; | ||
mod messaging; | ||
mod xps; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
use anyhow::Error; | ||
|
||
use crate::integration_util::*; | ||
use ethers::signers::LocalWallet; | ||
use ethers::types::{Bytes, U256}; | ||
use ethers::utils::keccak256; | ||
use lib_xps::rpc::XpsClient; | ||
use messaging::ConversationSignerExt; | ||
use xps_types::{Message, Status}; | ||
|
||
#[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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |