private TrieStateStore MakeTrieStateStoreFixture(bool secure) { var stateStore = new TrieStateStore( _stateKeyValueStore, _stateHashKeyValueStore, secure); stateStore.SetStates(_fx.GenesisBlock, _prestoredValues); return(stateStore); }
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)); }
public TrieStateStoreTest() { _fx = new DefaultStoreFixture(); _stateKeyValueStore = new DefaultKeyValueStore(null); _stateHashKeyValueStore = new DefaultKeyValueStore(null); _prestoredValues = ImmutableDictionary <string, IValue> .Empty .Add("foo", (Binary)TestUtils.GetRandomBytes(32)) .Add("bar", (Text)ByteUtil.Hex(TestUtils.GetRandomBytes(32))) .Add("baz", (Bencodex.Types.Boolean)false) .Add("qux", Bencodex.Types.Dictionary.Empty); _stateStore = new TrieStateStore(_stateKeyValueStore, _stateHashKeyValueStore); _stateStore.SetStates(_fx.GenesisBlock, _prestoredValues); }