Add testing helpers

This commit is contained in:
Hsiao-Wei Wang 2019-08-01 14:22:01 +08:00
parent 3aba05e252
commit db29250256
No known key found for this signature in database
GPG Key ID: 95B070122902DEA4
1 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,37 @@
from eth2spec.test.helpers.keys import privkeys
from eth2spec.utils.bls import (
bls_aggregate_signatures,
bls_sign,
)
def sign_shard_attestation(spec, shard_state, beacon_state, block, participants):
signatures = []
message_hash = block.core.parent_root
block_epoch = spec.compute_epoch_of_shard_slot(block.core.slot)
for validator_index in participants:
privkey = privkeys[validator_index]
signatures.append(
get_attestation_signature(
spec,
shard_state,
beacon_state,
message_hash,
block_epoch,
privkey,
)
)
return bls_aggregate_signatures(signatures)
def get_attestation_signature(spec, shard_state, beacon_state, message_hash, block_epoch, privkey):
return bls_sign(
message_hash=message_hash,
privkey=privkey,
domain=spec.get_domain(
state=beacon_state,
domain_type=spec.DOMAIN_SHARD_ATTESTER,
message_epoch=block_epoch,
)
)