diff --git a/common/src/tap_manager.rs b/common/src/tap_manager.rs index 50bc8849..156a1dd8 100644 --- a/common/src/tap_manager.rs +++ b/common/src/tap_manager.rs @@ -113,15 +113,14 @@ mod test { use crate::prelude::{AllocationStatus, SubgraphDeployment}; use alloy_primitives::Address; - use alloy_sol_types::{eip712_domain, Eip712Domain}; - use ethers::signers::{coins_bip39::English, LocalWallet, MnemonicBuilder, Signer}; use keccak_hash::H256; use sqlx::postgres::PgListener; use tap_core::tap_manager::SignedReceipt; use tap_core::{eip_712_signed_message::EIP712SignedMessage, tap_receipt::Receipt}; + use toolshed::thegraph::DeploymentId; - use crate::test_vectors; + use crate::test_vectors::{self, create_signed_receipt}; use super::*; @@ -180,7 +179,6 @@ mod test { let allocation_id = Address::from_str("0xdeadbeefcafebabedeadbeefcafebabedeadbeef").unwrap(); - let domain = domain(); let signed_receipt = create_signed_receipt(allocation_id, u64::MAX, u64::MAX, u128::MAX).await; @@ -211,8 +209,12 @@ mod test { let escrow_accounts = Eventual::from_value(HashMap::from_iter(vec![(keys().1, U256::from(123))])); - let tap_manager = - TapManager::new(pgpool.clone(), indexer_allocations, escrow_accounts, domain); + let tap_manager = TapManager::new( + pgpool.clone(), + indexer_allocations, + escrow_accounts, + test_vectors::TAP_EIP712_DOMAIN.to_owned(), + ); tap_manager .verify_and_store_receipt(signed_receipt.clone()) diff --git a/common/src/test_vectors.rs b/common/src/test_vectors.rs index 19890680..75d1fdab 100644 --- a/common/src/test_vectors.rs +++ b/common/src/test_vectors.rs @@ -4,8 +4,13 @@ use std::{collections::HashMap, str::FromStr}; use alloy_primitives::Address; +use alloy_sol_types::{eip712_domain, Eip712Domain}; +use ethers::signers::{coins_bip39::English, LocalWallet, MnemonicBuilder, Signer}; use ethers_core::types::U256; use lazy_static::lazy_static; +use tap_core::{ + eip_712_signed_message::EIP712SignedMessage, tap_manager::SignedReceipt, tap_receipt::Receipt, +}; use toolshed::thegraph::DeploymentId; use crate::prelude::{Allocation, AllocationStatus, SubgraphDeployment}; @@ -239,4 +244,45 @@ lazy_static! { (Address::from_str("0x90f8bf6a479f320ead074411a4b0e7944ea8c9c1").unwrap(), U256::from(24)), (Address::from_str("0x22d491bde2303f2f43325b2108d26f1eaba1e32b").unwrap(), U256::from(42)), ]); + + /// Fixture to generate a wallet and address + pub static ref TAP_SENDER: (LocalWallet, Address) = { + let wallet: LocalWallet = MnemonicBuilder::::default() + .phrase("abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about") + .build() + .unwrap(); + let address = wallet.address(); + + (wallet, Address::from_slice(address.as_bytes())) + }; + + pub static ref TAP_EIP712_DOMAIN: Eip712Domain = eip712_domain! { + name: "TAP", + version: "1", + chain_id: 1, + verifying_contract: Address::from([0x11u8; 20]), + }; +} + +/// Function to generate a signed receipt using the TAP_SENDER wallet. +pub async fn create_signed_receipt( + allocation_id: Address, + nonce: u64, + timestamp_ns: u64, + value: u128, +) -> SignedReceipt { + let (wallet, _) = &*self::TAP_SENDER; + + EIP712SignedMessage::new( + &self::TAP_EIP712_DOMAIN, + Receipt { + allocation_id, + nonce, + timestamp_ns, + value, + }, + wallet, + ) + .await + .unwrap() }