Skip to content

Commit

Permalink
Adapt crypto-verify contract ed25519 support to VerificationError
Browse files Browse the repository at this point in the history
  • Loading branch information
maurolacy committed Feb 17, 2021
1 parent b0e3630 commit accf545
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
21 changes: 15 additions & 6 deletions contracts/crypto-verify/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ pub fn query_verify_tendermint(
public_key: &[u8],
) -> StdResult<VerifyResponse> {
// Verification
let verifies = deps.api.ed25519_verify(message, signature, public_key);

Ok(VerifyResponse { verifies })
let result = deps.api.ed25519_verify(message, signature, public_key);
match result {
Ok(verifies) => Ok(VerifyResponse { verifies }),
Err(err) => Err(err.into()),
}
}

pub fn query_list_verifications(deps: Deps) -> StdResult<ListVerificationsResponse> {
Expand Down Expand Up @@ -164,8 +166,7 @@ mod tests {
}

#[test]
#[should_panic(expected = "empty")]
fn cosmos_signature_verify_panics() {
fn cosmos_signature_verify_errors() {
let deps = setup();

let message = hex::decode(SECP256K1_MESSAGE_HEX).unwrap();
Expand All @@ -177,7 +178,15 @@ mod tests {
signature: Binary(signature),
public_key: Binary(public_key),
};
query(deps.as_ref(), mock_env(), verify_msg).unwrap();

let res = query(deps.as_ref(), mock_env(), verify_msg);
assert!(res.is_err());
assert_eq!(
res.unwrap_err(),
StdError::VerificationErr {
source: VerificationError::PublicKeyErr
}
)
}

#[test]
Expand Down
8 changes: 4 additions & 4 deletions contracts/crypto-verify/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ fn cosmos_signature_verify_fails() {
}

#[test]
#[should_panic(expected = "empty")]
fn cosmos_signature_verify_panics() {
fn cosmos_signature_verify_errors() {
let mut deps = setup();

let message = hex::decode(SECP256K1_MESSAGE_HEX).unwrap();
Expand All @@ -112,7 +111,8 @@ fn cosmos_signature_verify_panics() {
signature: Binary(signature),
public_key: Binary(public_key),
};
let _ = query(&mut deps, mock_env(), verify_msg).unwrap();
let res = query(&mut deps, mock_env(), verify_msg);
assert_eq!(res.unwrap_err(), "Verification error: Public key error")
}

#[test]
Expand Down Expand Up @@ -158,7 +158,7 @@ fn tendermint_signature_verify_fails() {
}

#[test]
fn tendermint_signature_verify_errs() {
fn tendermint_signature_verify_errors() {
let mut deps = setup();

let message = hex::decode(ED25519_MESSAGE_HEX).unwrap();
Expand Down

0 comments on commit accf545

Please sign in to comment.