A test with feature "crypto-primitives" is not executed

Hi,

I’m trying to test my contract function that uses crypto-primitives. When I try to test it a testcase that does not use the mock (added #[cfg(feature = “crypto-primitives”)]) on top of test function, the test function is not executed when I run cargo concordium test. Thought of skipping cargo concordium test and doing the test via concordium-client invoke with a json param, but unfortunately it is giving an error (rejected because signature verify is not valid) that I don’t know the root cause of, which I think could have been caught by properly executing my unit test. Can you please help how to resolve this bypass error when turning on the feature crypto-primitive?

I’m using a macos

thanks

When you put code under a configuration directive such as

#[cfg(feature = "crypto-primitives")]
fn my_test() {
    assert_eq!(1,2)
}

Then it is only ever going to be executed if you do

cargo test --features=crypto-primitives

Otherwise it is not even compiled.

Perhaps you can provide a few more details on what you are trying to test exactly and maybe there is a better option.

Hi Abizjak,

Yes that did help. :slight_smile: I didn’t know I have to put that flag in cargo command for enabling the feature. Thank you!

It does not work for cargo concordium test though if add the --feature flag? Or in this case, I should just keep using the cargo test (where I can also just std outs :-)?

Anyway, I’ve run my verifier test and it seems the crypto-primitive.verify_ed25519_signature already returns false for me.

My input (signed using ed25519_dalek):
pub key (also from Dalek): PublicKeyEd25519([136, 145, 84, 221, 172, 221, 42, 92, 62, 248, 234, 114, 142, 124, 160, 19, 27, 226, 79, 248, 73, 185, 9, 64, 203, 215, 34, 247, 183, 100, 162, 140])
signature: SignatureEd25519([182, 7, 151, 157, 224, 156, 8, 232, 51, 181, 243, 250, 0, 11, 129, 202, 50, 133, 126, 38, 223, 193, 89, 177, 185, 220, 103, 13, 107, 6, 228, 25, 13, 53, 56, 242, 27, 98, 226, 103, 253, 162, 137, 11, 147, 21, 20, 50, 79, 24, 85, 243, 76, 220, 153, 193, 244, 219, 55, 176, 28, 50, 108, 2])
Message that was signed:[55, 97, 98, 56, 54, 100, 100, 51, 56, 51, 57, 102, 100, 100, 49, 102, 101, 101, 57, 98, 49, 55, 98, 55, 56, 99, 48, 56, 97, 53, 102, 52]

Can you please help investigate why this input is always false when calling crypto-primitive.verify?

@abizjak did you get the chance to look into my last query? Or should I just create a new post for it? Thanks! :slight_smile:

The reason for this is most likely that the signature is incorrect.

How did you produce the signature?

@abizjak I used the ed25519_dalek as you’ve suggested in a different thread. :slight_smile:

I used below code to generate the public key and the signature (the one used in the contract test-case also) and print them out so I can use them in one of the contract test cases for verification.

let keypair: Keypair = Keypair::generate(&mut OsRng);

let signature = keypair.sign("sample_txt".as_bytes());
let public_key: PublicKey = keypair.public;

Also, if I verify the sig, using the pub and original message in dalek lib, it returns ok, so everything is working on dalek side.

Please hold on. :slight_smile: It may just be incorrect signature as you say… Investigating…