Unsure if this is a bug, but the following code returns null when chain.Store.GetBlockCommit(block.Hash) is called:
using System;
using System.Collections.Immutable;
using Bencodex.Types;
using Libplanet.Action;
using Libplanet.Action.Sys;
using Libplanet.Blockchain;
using Libplanet.Blockchain.Policies;
using Libplanet.Blocks;
using Libplanet.Consensus;
using Libplanet.Crypto;
using Libplanet.Store;
using Libplanet.Store.Trie;
using Xunit;
namespace Libplanet.Tests
{
public class BlockCommitTest
{
[Fact]
public void CannotGetBlockCommitFromStore()
{
var pk = new PrivateKey();
var chain = BlockChain<Dum>.Create(
new NullBlockPolicy<Dum>(),
new VolatileStagePolicy<Dum>(),
new MemoryStore(),
new TrieStateStore(new MemoryKeyValueStore()),
BlockChain<Dum>.ProposeGenesisBlock(
privateKey: pk,
systemActions: new[]
{
new SetValidator(new Validator(pk.PublicKey, 1)),
}));
var block = chain.ProposeBlock(
pk, lastCommit: chain.GetBlockCommit(chain.Tip.Index));
var blockCommit = new BlockCommit(
chain.Tip.Index + 1,
0,
block.Hash,
ImmutableArray<Vote>.Empty
.Add(
new VoteMetadata(
chain.Tip.Index + 1,
0,
block.Hash,
DateTimeOffset.UtcNow,
pk.PublicKey,
VoteFlag.PreCommit)
.Sign(pk)));
chain.Append(block, blockCommit);
Assert.Equal(blockCommit, chain.GetBlockCommit(block.Hash));
Assert.Equal(blockCommit, chain.Store.GetBlockCommit(block.Hash));
}
private class Dum : IAction
{
public IValue PlainValue => null;
public void LoadPlainValue(IValue plainValue)
{
}
public IAccountStateDelta Execute(IActionContext context) => context.PreviousStates;
}
}
}
Unsure if this is a bug, but the following code returns
null
whenchain.Store.GetBlockCommit(block.Hash)
is called: