Ejemplo n.º 1
0
        public void PruneStates(bool secure)
        {
            var values = ImmutableDictionary <string, IValue> .Empty
                         .Add("foo", (Binary)GetRandomBytes(4096))
                         .Add("bar", (Text)ByteUtil.Hex(GetRandomBytes(2048)))
                         .Add("baz", (Bencodex.Types.Boolean)false)
                         .Add("qux", Bencodex.Types.Dictionary.Empty)
                         .Add(
                "zzz",
                Bencodex.Types.Dictionary.Empty
                .Add("binary", GetRandomBytes(4096))
                .Add("text", ByteUtil.Hex(GetRandomBytes(2048))));

            var   stateStore = new TrieStateStore(_stateKeyValueStore, secure);
            ITrie first      = stateStore.Commit(null, values);

            int prevStatesCount = _stateKeyValueStore.ListKeys().Count();
            ImmutableDictionary <string, IValue> nextStates =
                values.SetItem("foo", (Binary)GetRandomBytes(4096));
            ITrie second = stateStore.Commit(first.Hash, nextStates);

            // foo = 0x666f6f
            // updated branch node (0x6, aka root) + updated branch node (0x66) +
            // updated short node + new value nodes
            Assert.Equal(prevStatesCount + 4, _stateKeyValueStore.ListKeys().Count());

            stateStore.PruneStates(ImmutableHashSet <HashDigest <SHA256> > .Empty.Add(second.Hash));

            // It will stay at the same count of nodes.
            // FIXME: Bencodex fingerprints also should be tracked.
            //        https://github.com/planetarium/libplanet/issues/1653
            Assert.Equal(prevStatesCount, _stateKeyValueStore.ListKeys().Count());
        }
Ejemplo n.º 2
0
        public void PruneStates(bool secure)
        {
            var values = ImmutableDictionary <string, IValue> .Empty
                         .Add("foo", (Binary)GetRandomBytes(32))
                         .Add("bar", (Text)ByteUtil.Hex(GetRandomBytes(32)))
                         .Add("baz", (Bencodex.Types.Boolean)false)
                         .Add("qux", Bencodex.Types.Dictionary.Empty);

            var   stateStore = new TrieStateStore(_stateKeyValueStore, secure);
            ITrie first      = stateStore.Commit(null, values);

            int prevStatesCount = _stateKeyValueStore.ListKeys().Count();
            ImmutableDictionary <string, IValue> nextStates =
                values.SetItem("foo", (Binary)GetRandomBytes(32));
            ITrie second = stateStore.Commit(first.Hash, nextStates);

            // foo = 0x666f6f
            // updated branch node (0x6, aka root) + updated branch node (0x66) +
            // updated short node + new value node
            Assert.Equal(prevStatesCount + 4, _stateKeyValueStore.ListKeys().Count());

            stateStore.PruneStates(ImmutableHashSet <HashDigest <SHA256> > .Empty.Add(second.Hash));

            // It will stay at the same count of nodes.
            Assert.Equal(prevStatesCount, _stateKeyValueStore.ListKeys().Count());
        }
Ejemplo n.º 3
0
        public void PruneStates()
        {
            int prevStateHashesCount = _stateHashKeyValueStore.ListKeys().Count(),
                prevStatesCount      = _stateKeyValueStore.ListKeys().Count();
            var nextStates           = _prestoredValues.SetItem("foo", (Binary)TestUtils.GetRandomBytes(32));

            _stateStore.SetStates(_fx.Block1, nextStates);

            // Hash of _fx.Block1
            Assert.Equal(prevStateHashesCount + 1, _stateHashKeyValueStore.ListKeys().Count());
            // foo = 0x666f6f
            // updated branch node (0x6, aka root) + updated branch node (0x66) +
            // updated short node + new value node
            Assert.Equal(prevStatesCount + 4, _stateKeyValueStore.ListKeys().Count());

            _stateStore.PruneStates(
                ImmutableHashSet <HashDigest <SHA256> > .Empty.Add(_fx.Block1.Hash));
            Assert.Single(_stateHashKeyValueStore.ListKeys());
            // It will stay at the same count of nodes.
            Assert.Equal(prevStatesCount, _stateKeyValueStore.ListKeys().Count());
        }