Skip to content
This repository has been archived by the owner on Nov 11, 2022. It is now read-only.

Add concrete (polkadot) BEEFY signature tests #84

Open
tomusdrw opened this issue Feb 9, 2021 · 0 comments
Open

Add concrete (polkadot) BEEFY signature tests #84

tomusdrw opened this issue Feb 9, 2021 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@tomusdrw
Copy link
Contributor

tomusdrw commented Feb 9, 2021

Example

	#[test]
	fn beefy_test() {
		let signature = hex!(
			"c557781c98f8ba8f8025accf037b83e4861101712e7cf316474f7d2f05f1894f55ea99db6a735d004e226b3aa5d3537b301bfedf1b4a095110eb7afc05b0563700"
			// "bdb33475db0157a6f93d12b72c6ed78e3ec6fd5f09cdf79d01da11603fa594bd73240f9823995c71ee6b62062603cca9fd7184d0c249e821f928db010af671a100"
		).to_vec();
		let signature: BeefySignature = signature.try_into().unwrap();

		let payload = H256::from_slice(&hex!(
			"a148e08efa4936efd7fb46109a917ee24ded43e230625da90a123929e1f9b8a5"
		));
		let block_number: BlockNumber = 1366;
		let validator_set_id = 0;
		let commitment = beefy_primitives::Commitment {
			payload,
			block_number,
			validator_set_id,
		};
		let message = commitment.encode();

		println!("Message: {}", hex::encode(&message));
		println!("Hashed: {}", hex::encode(sp_core::blake2_256(&message)));

		let untyped: <BeefySignature as sp_application_crypto::AppKey>::UntypedGeneric = signature.into();
		let public = untyped.recover(message).unwrap();
		println!("Public: {:?}", public);
		let public = secp256k1::PublicKey::parse_compressed(&public.0).unwrap();
		println!("Uncompressed: {:?}", hex::encode(public.serialize()));

		println!("Keccak256: {:?}", hex::encode(
			sp_core::keccak_256(&public.serialize()[1..])
		));

                // TODO: some assertions
	}

Currently it's hard to get concrete test data for signed commitments that would make it easy to compare with Ethereum implementation.
I imagine this would be added to the light client tests.

@tomusdrw tomusdrw added enhancement New feature or request good first issue Good for newcomers labels Feb 9, 2021
@tomusdrw tomusdrw added this to the Some Day Maybe milestone Nov 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
No open projects
Status: Some Day Maybe
Development

No branches or pull requests

1 participant