public void RandomHash_Test() { var blockHash = Hash.FromString("blockHash"); var result = _randomHashCacheService.GetRandomHash(blockHash); result.ShouldBe(Hash.Empty); var randomHash = Hash.FromString("randomHash"); _randomHashCacheService.SetRandomHash(blockHash, randomHash); var queryResult = _randomHashCacheService.GetRandomHash(blockHash); queryResult.ShouldBe(randomHash); }
public async Task <BytesValue> GetTriggerInformationForBlockHeaderExtraDataAsync(BytesValue consensusCommandBytes) { if (consensusCommandBytes == null) { return(new AElfConsensusTriggerInformation { Pubkey = PublicKey, Behaviour = AElfConsensusBehaviour.UpdateValue }.ToBytesValue()); } var command = consensusCommandBytes.ToConsensusCommand(); var behaviour = command.Hint.ToAElfConsensusHint().Behaviour; if (behaviour == AElfConsensusBehaviour.UpdateValue || behaviour == AElfConsensusBehaviour.UpdateValueWithoutPreviousInValue) { var bestChainLastBlockHeader = await _blockchainService.GetBestChainLastBlockHeaderAsync(); var bestChainLastBlockHash = bestChainLastBlockHeader.GetHash(); _randomHashCacheService.SetGeneratedBlockPreviousBlockInformation(bestChainLastBlockHash, bestChainLastBlockHeader.Height); var newRandomHash = GetRandomHash(command); _randomHashCacheService.SetRandomHash(bestChainLastBlockHash, newRandomHash); return(new AElfConsensusTriggerInformation { Pubkey = PublicKey, RandomHash = newRandomHash, PreviousRandomHash = _randomHashCacheService.GetLatestGeneratedBlockRandomHash(), Behaviour = behaviour }.ToBytesValue()); } return(new AElfConsensusTriggerInformation { Pubkey = PublicKey, Behaviour = behaviour }.ToBytesValue()); }