public void GetStateRoot(bool secure) { var stateStore = new TrieStateStore(_stateKeyValueStore, secure); ITrie empty = stateStore.GetStateRoot(null); Assert.True(empty.Recorded); Assert.Null(empty.Get(new[] { KeyFoo })[0]); Assert.Null(empty.Get(new[] { KeyBar })[0]); Assert.Null(empty.Get(new[] { KeyBaz })[0]); Assert.Null(empty.Get(new[] { KeyQux })[0]); Assert.Null(empty.Get(new[] { KeyQuux })[0]); 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); HashDigest <SHA256> hash = stateStore.Commit(null, values).Hash; ITrie found = stateStore.GetStateRoot(hash); Assert.True(found.Recorded); AssertBencodexEqual(values["foo"], found.Get(new[] { KeyFoo })[0]); AssertBencodexEqual(values["bar"], found.Get(new[] { KeyBar })[0]); AssertBencodexEqual(values["baz"], found.Get(new[] { KeyBaz })[0]); AssertBencodexEqual(values["qux"], found.Get(new[] { KeyQux })[0]); Assert.Null(found.Get(new[] { KeyQuux })[0]); }
private IList <dynamic> ResolveAllByName(string name, HashSet <Type> previousGrahpNodes) { return(registries.Get(name) .Select(entry => ResolveByRegistry(entry, previousGrahpNodes)) .Where(entryResolved => entryResolved != null) .ToList()); }
public void Commit(int addressCount) { IKeyValueStore keyValueStore = new MemoryKeyValueStore(); var codec = new Codec(); ITrie trieA = new MerkleTrie(keyValueStore); var addresses = new Address[addressCount]; var states = new IValue[addressCount]; for (int i = 0; i < addressCount; ++i) { addresses[i] = new PrivateKey().ToAddress(); states[i] = (Binary)TestUtils.GetRandomBytes(128); trieA = trieA.Set(new KeyBytes(addresses[i].ByteArray), states[i]); } KeyBytes path = new KeyBytes(TestUtils.GetRandomBytes(32)); trieA = trieA.Set(path, (Text)"foo"); Assert.Equal((Text)"foo", trieA.Get(new[] { path })[0]); ITrie trieB = trieA.Commit(); Assert.Equal((Text)"foo", trieB.Get(new[] { path })[0]); trieB = trieB.Set(path, (Text)"bar"); Assert.Equal((Text)"foo", trieA.Get(new[] { path })[0]); Assert.Equal((Text)"bar", trieB.Get(new[] { path })[0]); ITrie trieC = trieB.Commit(); ITrie trieD = trieC.Commit(); Assert.NotEqual(trieA.Hash, trieB.Hash); Assert.NotEqual(trieA.Hash, trieC.Hash); Assert.NotEqual(trieB.Hash, trieC.Hash); Assert.Equal(trieC.Hash, trieD.Hash); }
public IEnumerable <WordEntry> Get(string query, bool wholeWord) => _searchIndex.Get(query, wholeWord);