open-standards/openpay/crates/op-crypto-extra/tests/permit2_encode.rs
Transaction Science 68b8a2dbee ingest wave F: 3 crates · op-crypto-extra + smart-byte-acdc + eoc-memory
OpenPay (1 crate, 3751 LOC, 83 tests)
  op-crypto-extra      Extended crypto rails. Stablecoin catalog (USDC, USDT,
                       PYUSD, DAI, RLUSD, EURC, FDUSD — 26 deployments). L2
                       catalog (12 chains incl. Optimism, Arbitrum, Base,
                       zkSync Era, Polygon zkEVM, Linea, Scroll, Starknet).
                       CCTP v2 BurnMessage encode/decode + domain ids +
                       attestation. ERC-4337 UserOperation v0.7 +
                       PackedUserOperation. EIP-7702 set-EOA-code with RLP
                       signing preimage. Uniswap Permit2 single + batch
                       transfer EIP-712 hashes. EIP-2612 ERC-20 permit.
                       BOLT-11 bech32 invoices + LNURL decode. Bitcoin
                       PSBT v2 (BIP-370). Atomic-swap HTLC. Solana SPL /
                       Aleo / Aztec confidential-transfer sketches.

Smart Byte (1 crate, 2304 LOC, 30 tests)
  smart-byte-acdc      Authentic Chained Data Containers (KERI ecosystem).
                       Acdc + AcdcBuilder (targeted + untargeted) with SAID
                       derivation. JSON Schema 2020-12 validator with
                       oneOf partial-disclosure. TEL (RIP/VRT/ISS/REV)
                       with hash-chained verification. IPEX (apply/offer/
                       agree/grant/admit/spurn) chained by SAID. Edge
                       records (I2I/NI2I/DI2I) + EdgeGraph BFS traversal
                       with cycle detection. Selective disclosure with
                       full/none/subset plans + compact packing.
                       CredentialRegistry trait + InMemoryRegistry over
                       TEL. Composes with smart-byte-core + smart-byte-keri-witness.

EOC (1 crate, 1764 LOC, 16 tests)
  eoc-memory           Long-term memory primitives. Memory trait + MemoryKind +
                       EpisodeId. Episodic event log with TimeIndex range
                       queries. RDF-style Triple store with S/P/O indices.
                       Bounded attention-budget Scratchpad with
                       salience-weighted eviction. Rolling SummaryBuffer +
                       FIFO SlidingWindow. Dream-cycle consolidate()
                       (episodic → semantic). Ebbinghaus forgetting curve
                       with reinforcement. Retriever blending cosine
                       similarity + recency + saturating frequency.
                       MemGpt three-tier shape (Main/Recall/Archival).

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-05-24 17:28:24 -04:00

75 lines
2.1 KiB
Rust

//! Integration: Permit2 typed-data struct hashes.
use op_crypto_extra::permit2::{
PERMIT2_ADDRESS, Permit2BatchTransfer, Permit2SingleTransfer, Permit2TokenPermissions,
};
#[test]
fn canonical_address_is_42_chars() {
assert_eq!(PERMIT2_ADDRESS.len(), 42);
assert!(PERMIT2_ADDRESS.starts_with("0x"));
// CREATE2-deployed everywhere, starts with many zeros.
assert!(PERMIT2_ADDRESS.starts_with("0x000000"));
}
#[test]
fn single_struct_hash_is_deterministic() {
let single = Permit2SingleTransfer {
permitted: Permit2TokenPermissions::new(
"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
5_000_000,
),
nonce: 42,
deadline: 1_900_000_000,
};
let h1 = single
.struct_hash("0x3333333333333333333333333333333333333333")
.unwrap();
let h2 = single
.struct_hash("0x3333333333333333333333333333333333333333")
.unwrap();
assert_eq!(h1, h2);
}
#[test]
fn single_struct_hash_changes_with_nonce() {
let base = Permit2SingleTransfer {
permitted: Permit2TokenPermissions::new(
"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
5_000_000,
),
nonce: 42,
deadline: 1_900_000_000,
};
let mut mutated = base.clone();
mutated.nonce += 1;
let h1 = base
.struct_hash("0x3333333333333333333333333333333333333333")
.unwrap();
let h2 = mutated
.struct_hash("0x3333333333333333333333333333333333333333")
.unwrap();
assert_ne!(h1, h2);
}
#[test]
fn batch_with_two_distinct_tokens_hashes() {
let batch = Permit2BatchTransfer {
permitted: vec![
Permit2TokenPermissions::new(
"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
1_000_000,
),
Permit2TokenPermissions::new(
"0xdac17f958d2ee523a2206206994597c13d831ec7",
2_000_000,
),
],
nonce: 0,
deadline: 1_900_000_000,
};
let h = batch
.struct_hash("0x3333333333333333333333333333333333333333")
.unwrap();
assert_ne!(h, [0u8; 32]);
}