Esempio n. 1
0
        public void SetStates()
        {
            // Check to set and to get.
            Assert.Throws <KeyNotFoundException>(() => _stateStore.GetRootHash(_fx.Block1.Hash));
            Assert.False(_stateStore.ContainsBlockStates(_fx.Block1.Hash));
            var states = ImmutableDictionary <string, IValue> .Empty
                         .Add("foo", (Text)"value");

            _stateStore.SetStates(_fx.Block1, states);
            Assert.Equal((Text)"value", _stateStore.GetState("foo", _fx.Block1.Hash));
            Assert.IsType <HashDigest <SHA256> >(_stateStore.GetRootHash(_fx.Block1.Hash));
            Assert.True(_stateStore.ContainsBlockStates(_fx.Block1.Hash));

            _stateStore.SetStates(_fx.Block2, _prestoredValues);

            // Check same states have same state hash.
            Assert.NotEqual(
                _stateStore.GetRootHash(_fx.GenesisBlock.Hash),
                _stateStore.GetRootHash(_fx.Block1.Hash));
            Assert.Equal(
                _stateStore.GetRootHash(_fx.GenesisBlock.Hash),
                _stateStore.GetRootHash(_fx.Block2.Hash));
        }