public void ListAllStates() { IKeyValueStore keyValueStore = new MemoryKeyValueStore(); MerkleTrie trie = new MerkleTrie(keyValueStore); trie = (MerkleTrie)trie.Set(new KeyBytes(0x01), Null.Value) .Set(new KeyBytes(0x02), Null.Value) .Set(new KeyBytes(0x03), Null.Value) .Set(new KeyBytes(0x04), Null.Value) .Set(new KeyBytes(0xbe, 0xef), Dictionary.Empty); Dictionary <KeyBytes, IValue> states = trie.ListAllStates().ToDictionary(pair => pair.Key, pair => pair.Value); Assert.Equal(5, states.Count); Assert.Equal(Null.Value, states[new KeyBytes(0x01)]); Assert.Equal(Null.Value, states[new KeyBytes(0x02)]); Assert.Equal(Null.Value, states[new KeyBytes(0x03)]); Assert.Equal(Null.Value, states[new KeyBytes(0x04)]); Assert.Equal(Dictionary.Empty, states[new KeyBytes(0xbe, 0xef)]); trie = (MerkleTrie)trie.Commit(); states = trie.ListAllStates().ToDictionary(pair => pair.Key, pair => pair.Value); Assert.Equal(5, states.Count); Assert.Equal(Null.Value, states[new KeyBytes(0x01)]); Assert.Equal(Null.Value, states[new KeyBytes(0x02)]); Assert.Equal(Null.Value, states[new KeyBytes(0x03)]); Assert.Equal(Null.Value, states[new KeyBytes(0x04)]); Assert.Equal(Dictionary.Empty, states[new KeyBytes(0xbe, 0xef)]); }
public void Export( [Argument( Name = "KV-STORE", Description = KVStoreArgumentDescription)] string kvStoreUri, [Argument( Name = "STATE-ROOT-HASH", Description = "The state root hash to compare.")] string stateRootHashHex, [FromService] IConfigurationService <ToolConfiguration> configurationService) { ToolConfiguration toolConfiguration = configurationService.Load(); kvStoreUri = ConvertKVStoreUri(kvStoreUri, toolConfiguration); IKeyValueStore keyValueStore = LoadKVStoreFromURI(kvStoreUri); var trie = new MerkleTrie( keyValueStore, HashDigest <SHA256> .FromString(stateRootHashHex)); var codec = new Codec(); ImmutableDictionary <string, byte[]> decoratedStates = trie.ListAllStates() .ToImmutableDictionary( pair => Encoding.UTF8.GetString(pair.Key.ToArray()), pair => codec.Encode(pair.Value)); Console.WriteLine(JsonSerializer.Serialize(decoratedStates)); }