Skip to content
Permalink
Browse files

Merge pull request #759 from moreal/avoid-execute-genesis-block-many-…

…times

Fix a bug to have invalid state references cache
  • Loading branch information
moreal committed Jan 14, 2020
2 parents 25a97f5 + 11bb64c commit 1c7ac4f078b206e354e6f039a5753722b1637995
Showing with 32 additions and 0 deletions.
  1. +3 −0 CHANGES.md
  2. +27 −0 Libplanet.Tests/Blockchain/BlockChainTest.cs
  3. +2 −0 Libplanet/Store/DefaultStore.cs
@@ -141,6 +141,8 @@ To be released.
[[#744]]
- Fixed a bug where `Swarm<T>` had failed to request a TURN relay when it has
an IPv6 address. [[#744]]
- Fixed a bug where `DefaultStore` had invalid state references cache after fork.
[[#759]]

[#570]: https://github.com/planetarium/libplanet/issues/570
[#580]: https://github.com/planetarium/libplanet/pull/580
@@ -181,6 +183,7 @@ To be released.
[#751]: https://github.com/planetarium/libplanet/pull/751
[#753]: https://github.com/planetarium/libplanet/pull/753
[#758]: https://github.com/planetarium/libplanet/pull/758
[#759]: https://github.com/planetarium/libplanet/pull/759


Version 0.7.0
@@ -1219,6 +1219,33 @@ public void GetStateThrowsIncompleteBlockStatesException()
}
}

[Fact]
public async void GetStateReturnsValidStateAfterFork()
{
var genesisBlock = BlockChain<DumbAction>.MakeGenesisBlock(
new[]
{
new DumbAction(_fx.Address1, "item0.0", idempotent: true),
});
var privateKey = new PrivateKey();
var store = new DefaultStore(path: null);

var chain =
new BlockChain<DumbAction>(new NullPolicy<DumbAction>(), store, genesisBlock);
Assert.Equal("item0.0", (Text)chain.GetState(_fx.Address1));

chain.MakeTransaction(
privateKey,
new[] { new DumbAction(_fx.Address1, "item1.0"), }
);
await chain.MineBlock(_fx.Address1);
Assert.Equal("item0.0,item1.0", (Text)chain.GetState(_fx.Address1));

var forked = chain.Fork(chain.Tip.Hash);
Assert.Equal(2, forked.Count);
Assert.Equal("item0.0,item1.0", (Text)forked.GetState(_fx.Address1));
}

[Fact]
public void GetStateWithCompletingStates()
{
@@ -729,6 +729,8 @@ HashDigest<SHA256> blockHash

dstColl.EnsureIndex("AddressString");
dstColl.EnsureIndex("BlockIndex");

_lastStateRefCaches.Remove(destinationChainId);
}

/// <inheritdoc/>

0 comments on commit 1c7ac4f

Please sign in to comment.
You can’t perform that action at this time.