Пример #1
0
        public void WalletStore_Get_And_Set_And_Remove()
        {
            DataFolder dataFolder = CreateDataFolder(this);

            WalletStore store = new WalletStore(this.Network, dataFolder, new Types.Wallet {
                Name = "wallet1", EncryptedSeed = "EncryptedSeed1"
            });

            var utxo    = new OutPoint(new uint256(10), 1);
            var address = new Key().PubKey.GetAddress(this.Network).ScriptPubKey.ToString();

            var trx = Create(utxo, address);

            // insert the document then fetch it and compare with source
            store.InsertOrUpdate(trx);
            var trxRes        = store.GetForOutput(utxo);
            var jsonStringTrx = JsonConvert.SerializeObject(trx, new JsonSerializerSettings {
                Converters = new List <JsonConverter> {
                    new MoneyJsonConverter(), new ScriptJsonConverter()
                }
            });
            var jsonStringTrxRes = JsonConvert.SerializeObject(trxRes, new JsonSerializerSettings {
                Converters = new List <JsonConverter> {
                    new MoneyJsonConverter(), new ScriptJsonConverter()
                }
            });

            jsonStringTrx.Should().Be(jsonStringTrxRes);

            trx.BlockHash   = null;
            trx.BlockHeight = null;
            trx.BlockIndex  = null;

            // update the changed document then fetch it and compare with source
            store.InsertOrUpdate(trx);
            trxRes        = store.GetForOutput(utxo);
            jsonStringTrx = JsonConvert.SerializeObject(trx, new JsonSerializerSettings {
                Converters = new List <JsonConverter> {
                    new MoneyJsonConverter(), new ScriptJsonConverter()
                }
            });
            jsonStringTrxRes = JsonConvert.SerializeObject(trxRes, new JsonSerializerSettings {
                Converters = new List <JsonConverter> {
                    new MoneyJsonConverter(), new ScriptJsonConverter()
                }
            });
            jsonStringTrx.Should().Be(jsonStringTrxRes);

            store.Remove(trx.OutPoint);
            var removed = store.GetForOutput(trx.OutPoint);

            removed.Should().BeNull();
        }