public void ShouldEvictWithDependencies() { var key = Key.Create(); var tx = Utils .GetTx().AddOutput(Key.Create().Address, Consensus.Tests.zhash, 100) .Sign(key.Private).Tag("tx"); var tx1 = Utils.GetTx().AddInput(tx, 0).AddOutput(Key.Create().Address, Consensus.Tests.zhash, 1).Sign(key.Private).Tag("tx1"); var tx2 = Utils.GetTx().AddInput(tx, 0).AddOutput(Key.Create().Address, Consensus.Tests.zhash, 2).Sign(key.Private).Tag("tx2"); var contractHash = new byte[] { }; BlockChainTrace.SetTag(contractHash, "mock contract"); _BlockChain.memPool.ContractPool.AddRef(tx1.Key(), new ACSItem() { Hash = contractHash }); HandleBlock(_GenesisBlock.AddTx(tx).Tag("genesis")); Assert.That(TxState(tx), Is.EqualTo(TxStateEnum.Confirmed)); HandleBlock(_GenesisBlock.Child().AddTx(tx1).Tag("main")); Assert.That(TxState(tx1), Is.EqualTo(TxStateEnum.Confirmed)); var branch = _GenesisBlock.Child().Tag("branch"); HandleBlock(branch.Child().Tag("branch orphan")); HandleBlock(branch.AddTx(tx2).Tag("branch child")); System.Threading.Thread.Sleep(1000); Assert.That(TxState(tx2), Is.EqualTo(TxStateEnum.Confirmed)); Assert.That(TxState(tx1), Is.EqualTo(TxStateEnum.Invalid)); Assert.That(_BlockChain.memPool.TxPool.ContainsKey(tx1.Key()), Is.False); }
public void ShouldRemoveConfirmedFromMempoolWithDependencies() { var key = Key.Create(); var tx = Utils .GetTx().AddOutput(Key.Create().Address, Consensus.Tests.zhash, 100) .Sign(key.Private).Tag("tx"); var mempoolTx = Utils.GetTx().AddInput(tx, 0).AddOutput(Key.Create().Address, Consensus.Tests.zhash, 1).Sign(key.Private) .Tag("mempoolTx"); var contractHash = new byte[] { }; BlockChainTrace.SetTag(contractHash, "mock contract"); HandleBlock(_GenesisBlock.AddTx(tx).Tag("genesis")); HandleTransaction(mempoolTx); _BlockChain.memPool.ContractPool.AddRef(mempoolTx.Key(), new ACSItem() { Hash = contractHash }); Assert.That(_BlockChain.memPool.TxPool.Count, Is.EqualTo(1)); Assert.That(_BlockChain.memPool.ContractPool.Count, Is.EqualTo(1)); HandleBlock(_GenesisBlock.Child().AddTx(mempoolTx).Tag("genesis")); Assert.That(_BlockChain.memPool.TxPool.Count, Is.EqualTo(0)); Assert.That(_BlockChain.memPool.ContractPool.Count, Is.EqualTo(0)); }
public static Types.Transaction Tag(this Types.Transaction tx, string value) { BlockChainTrace.SetTag(tx, value); return(tx); }
public static Types.Block Tag(this Types.Block block, string value) { BlockChainTrace.SetTag(block, value); return(block); }