Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
tsachiherman committed Jan 29, 2024
1 parent 7286f1a commit fff0803
Showing 1 changed file with 65 additions and 1 deletion.
66 changes: 65 additions & 1 deletion xps-gateway/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use lib_didethresolver::{
};
use xps_gateway::rpc::XpsClient;

use ethers::types::{Address, U256};
use ethers::middleware::Middleware;
use ethers::types::{Address, U256, U64};
use gateway_types::Message;

use integration_util::*;
Expand Down Expand Up @@ -51,6 +52,69 @@ async fn test_wallet_address() -> Result<(), Error> {
.await
}

#[tokio::test]
async fn test_grant_installation() -> Result<(), Error> {
with_xps_client(None, |client, context, resolver, anvil| async move {
let wallet: LocalWallet = anvil.keys()[3].clone().into();
let me = get_user(&anvil, 3).await;
let name = *b"xmtp/installation/hex ";
let value = b"02b97c30de767f084ce3080168ee293053ba33b235d7116a3263d29f1450936b71";

let attribute = XmtpAttribute {
purpose: XmtpKeyPurpose::Installation,
encoding: KeyEncoding::Hex,
};

let block_number = context.signer.get_block_number().await.unwrap();
let validity_period: U64 = U64::from(60 * 60 * 24 * 365 / 5); // number of round in one year, assuming 5-second round.
let validity = block_number + validity_period;

let signature = wallet
.sign_attribute(
&context.registry,
name,
value.to_vec(),
U256::from(validity.as_u64()),
)
.await?;

client
.grant_installation(
format!("0x{}", hex::encode(me.address())),
attribute,
value.to_vec(),
signature,
)
.await?;

let doc = resolver
.resolve_did(me.address(), None)
.await
.unwrap()
.document;

assert_eq!(doc.verification_method.len(), 2);
assert_eq!(
doc.verification_method[0].id,
DidUrl::parse(format!(
"did:ethr:0x{}#controller",
hex::encode(me.address())
))
.unwrap()
);
assert_eq!(
doc.verification_method[1].id,
DidUrl::parse(format!(
"did:ethr:0x{}?meta=installation#xmtp-0",
hex::encode(me.address())
))
.unwrap()
);
Ok(())
})
.await
}

#[tokio::test]
async fn test_revoke_installation() -> Result<(), Error> {
with_xps_client(None, |client, context, resolver, anvil| async move {
Expand Down

0 comments on commit fff0803

Please sign in to comment.