From fff080398f5d73a4ec6b1aa628415d29fe82eaf3 Mon Sep 17 00:00:00 2001 From: Tsachi Herman <24438559+tsachiherman@users.noreply.github.com> Date: Mon, 29 Jan 2024 13:26:54 -0500 Subject: [PATCH] update --- xps-gateway/tests/integration_test.rs | 66 ++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/xps-gateway/tests/integration_test.rs b/xps-gateway/tests/integration_test.rs index 58d3f61..c144f2f 100644 --- a/xps-gateway/tests/integration_test.rs +++ b/xps-gateway/tests/integration_test.rs @@ -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::*; @@ -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 {