public async Task CanDoOperationsAsync()
        {
            var txStore = new TransactionStoreMock();
            var network = Network.Main;
            await txStore.InitializeAsync(network);

            Assert.True(txStore.IsEmpty());

            var stx     = Global.GenerateRandomSmartTransaction();
            var isAdded = txStore.TryAdd(stx);

            Assert.True(isAdded);
            var isRemoved = txStore.TryRemove(stx.GetHash(), out SmartTransaction removed);

            Assert.True(isRemoved);
            Assert.Equal(stx, removed);
            isAdded = txStore.TryAdd(stx);
            Assert.True(isAdded);
            isAdded = txStore.TryAdd(stx);
            Assert.False(isAdded);
            Assert.False(txStore.TryAdd(stx));
            Assert.False(txStore.IsEmpty());
            Assert.True(txStore.TryGetTransaction(stx.GetHash(), out SmartTransaction sameStx));
            Assert.True(txStore.Contains(stx.GetHash()));
            Assert.Equal(stx, sameStx);

            txStore.TryRemove(stx.GetHash(), out _);
            Assert.True(txStore.IsEmpty());
            Assert.Empty(txStore.GetTransactions());
            txStore.TryAdd(stx);

            txStore.TryAdd(stx);
            Assert.Equal(1, txStore.GetTransactions().Count);
            Assert.Equal(1, txStore.GetTransactionHashes().Count);
        }
Exemplo n.º 2
0
        public async Task CanDoOperationsAsync()
        {
            var txStore = new TransactionStoreMock();
            var network = Network.Main;
            await txStore.InitializeAsync(network);

            Assert.True(txStore.IsEmpty());

            var stx       = Global.GenerateRandomSmartTransaction();
            var operation = txStore.TryAddOrUpdate(stx);

            Assert.True(operation.isAdded);
            Assert.False(operation.isUpdated);
            var isRemoved = txStore.TryRemove(stx.GetHash(), out SmartTransaction removed);

            Assert.True(isRemoved);
            Assert.Equal(stx, removed);
            operation = txStore.TryAddOrUpdate(stx);
            Assert.True(operation.isAdded);
            Assert.False(operation.isUpdated);
            operation = txStore.TryAddOrUpdate(stx);
            Assert.False(operation.isAdded);
            Assert.False(operation.isUpdated);

            operation = txStore.TryAddOrUpdate(
                new SmartTransaction(
                    stx.Transaction,
                    height: stx.Height,
                    stx.BlockHash,
                    stx.BlockIndex,
                    "totally random new label",
                    stx.IsReplacement,
                    stx.FirstSeen));
            Assert.False(operation.isAdded);
            Assert.True(operation.isUpdated);

            operation = txStore.TryAddOrUpdate(stx);
            Assert.False(operation.isAdded);
            Assert.False(operation.isUpdated);

            Assert.False(txStore.IsEmpty());
            Assert.True(txStore.TryGetTransaction(stx.GetHash(), out SmartTransaction sameStx));
            Assert.True(txStore.Contains(stx.GetHash()));
            Assert.Equal(stx, sameStx);

            txStore.TryRemove(stx.GetHash(), out _);
            Assert.True(txStore.IsEmpty());
            Assert.Empty(txStore.GetTransactions());
            txStore.TryAddOrUpdate(stx);

            txStore.TryAddOrUpdate(stx);
            Assert.Single(txStore.GetTransactions());
            Assert.Single(txStore.GetTransactionHashes());
        }