fix: Small improvements
- Rename test - Improve error messages - Remove unnecessary asserts --- don't change below this line --- ENG-4063 Took 52 seconds
This commit is contained in:
@@ -34,14 +34,11 @@ pub struct Permit2 {
|
|||||||
|
|
||||||
/// Type alias for representing allowance data as a tuple of (amount, expiration, nonce). Used for
|
/// Type alias for representing allowance data as a tuple of (amount, expiration, nonce). Used for
|
||||||
/// decoding
|
/// decoding
|
||||||
type Allowance = (U160, U48, U48); // (amount, expiration, nonce)
|
type Allowance = (U160, U48, U48);
|
||||||
/// Expiration period for permits, set to 30 days (in seconds).
|
/// Expiration period for permits, set to 30 days (in seconds).
|
||||||
const PERMIT_EXPIRATION: u64 = 30 * 24 * 60 * 60;
|
const PERMIT_EXPIRATION: u64 = 30 * 24 * 60 * 60;
|
||||||
/// Expiration period for signatures, set to 30 minutes (in seconds).
|
/// Expiration period for signatures, set to 30 minutes (in seconds).
|
||||||
const PERMIT_SIG_EXPIRATION: u64 = 30 * 60;
|
const PERMIT_SIG_EXPIRATION: u64 = 30 * 60;
|
||||||
const MAX_UINT48: U48 = U48::MAX;
|
|
||||||
const MAX_UINT160: U160 = U160::MAX;
|
|
||||||
const MAX_UINT256: U256 = U256::MAX;
|
|
||||||
|
|
||||||
sol! {
|
sol! {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -105,7 +102,7 @@ impl Permit2 {
|
|||||||
Ok(allowance)
|
Ok(allowance)
|
||||||
}
|
}
|
||||||
Err(err) => Err(EncodingError::RecoverableError(format!(
|
Err(err) => Err(EncodingError::RecoverableError(format!(
|
||||||
"Call to permit 2 allowance method failed with error: {:?}",
|
"Call to permit2 allowance method failed with error: {:?}",
|
||||||
err
|
err
|
||||||
))),
|
))),
|
||||||
}
|
}
|
||||||
@@ -128,12 +125,6 @@ impl UserApprovalsManager for Permit2 {
|
|||||||
let sig_deadline = U256::from(current_time + PERMIT_SIG_EXPIRATION);
|
let sig_deadline = U256::from(current_time + PERMIT_SIG_EXPIRATION);
|
||||||
let amount = U160::from(biguint_to_u256(&approval.amount));
|
let amount = U160::from(biguint_to_u256(&approval.amount));
|
||||||
|
|
||||||
// validations
|
|
||||||
assert!(MAX_UINT256 > sig_deadline, "signature deadline out of range");
|
|
||||||
assert!(MAX_UINT48 > nonce, "nonce out of range");
|
|
||||||
assert!(MAX_UINT160 > amount, "amount out of range");
|
|
||||||
assert!(MAX_UINT48 > expiration, "expiration out of range");
|
|
||||||
|
|
||||||
let details = PermitDetails {
|
let details = PermitDetails {
|
||||||
token: bytes_to_address(&approval.token)?,
|
token: bytes_to_address(&approval.token)?,
|
||||||
amount,
|
amount,
|
||||||
@@ -213,7 +204,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_allowance_data() {
|
fn test_get_existing_allowance() {
|
||||||
let signer = PrivateKeySigner::random();
|
let signer = PrivateKeySigner::random();
|
||||||
let manager = Permit2::new(signer, 1).unwrap();
|
let manager = Permit2::new(signer, 1).unwrap();
|
||||||
|
|
||||||
@@ -229,6 +220,7 @@ mod tests {
|
|||||||
(Uint::<160, 3>::from(0), Uint::<48, 1>::from(0), Uint::<48, 1>::from(0))
|
(Uint::<160, 3>::from(0), Uint::<48, 1>::from(0), Uint::<48, 1>::from(0))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_encode_approvals() {
|
fn test_encode_approvals() {
|
||||||
// Set up a mock private key for signing
|
// Set up a mock private key for signing
|
||||||
|
|||||||
Reference in New Issue
Block a user