本文整理汇总了C#中Chain.SetTip方法的典型用法代码示例。如果您正苦于以下问题:C# Chain.SetTip方法的具体用法?C# Chain.SetTip怎么用?C# Chain.SetTip使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Chain
的用法示例。
在下文中一共展示了Chain.SetTip方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RunFullBlockTest
public void RunFullBlockTest()
{
var generator = new FullBlockTestGenerator(Network.Main);
ValidationState validation = new ValidationState(Network.Main);
validation.CheckMerkleRoot = false;
validation.CheckProofOfWork = false;
var scan =
new ScanState(new PubKeyHashScanner(generator.CoinbaseKey.PubKey.ID),
new Chain(),
new Account(),
0);
scan.CheckDoubleSpend = true;
var mainChain = new Chain(Network.Main);
var indexed = new IndexedBlockStore(new InMemoryNoSqlRepository(), CreateBlockStore());
indexed.Put(Network.Main.GetGenesis());
foreach(var test in generator.GetBlocksToTest(true, true).list.OfType<BlockAndValidity>())
{
indexed.Put(test.block);
mainChain.GetOrAdd(test.block.Header);
Assert.True(scan.Process(mainChain, indexed) == test.connects);
//if(!)
//{
// Assert.True(test.throwsException);
//}
Assert.Equal(test.heightAfterBlock, scan.Chain.Height);
Assert.Equal(test.hashChainTipAfterBlock, scan.Chain.Tip.HashBlock);
mainChain.SetTip(scan.Chain.Tip);
}
}
示例2: CanForkSidePartialChain
public void CanForkSidePartialChain()
{
var block = TestUtils.CreateFakeBlock();
Chain side = new Chain(block.Header, 10, new StreamObjectStream<ChainChange>());
Chain main = new Chain(block.Header, 10, new StreamObjectStream<ChainChange>());
AppendBlock(side, main);
AppendBlock(side, main);
var common = AppendBlock(side, main);
var sideb = AppendBlock(side);
var mainb1 = AppendBlock(main);
var mainb2 = AppendBlock(main);
var mainb3 = AppendBlock(main);
Assert.Equal(common.HashBlock, side.SetTip(main.Tip).HashBlock);
Assert.NotNull(side.GetBlock(mainb1.HashBlock));
Assert.NotNull(side.GetBlock(mainb2.HashBlock));
Assert.NotNull(side.GetBlock(mainb3.HashBlock));
Assert.NotNull(side.GetBlock(common.HashBlock));
Assert.Null(side.GetBlock(sideb.HashBlock));
Assert.Equal(common.HashBlock, side.SetTip(sideb).HashBlock);
Assert.Null(side.GetBlock(mainb1.HashBlock));
Assert.Null(side.GetBlock(mainb2.HashBlock));
Assert.Null(side.GetBlock(mainb3.HashBlock));
Assert.NotNull(side.GetBlock(sideb.HashBlock));
}
示例3: CanForkSide
public void CanForkSide()
{
Chain side = new Chain(Network.Main);
Chain main = new Chain(Network.Main);
AppendBlock(side, main);
AppendBlock(side, main);
var common = AppendBlock(side, main);
var sideb = AppendBlock(side);
var mainb1 = AppendBlock(main);
var mainb2 = AppendBlock(main);
var mainb3 = AppendBlock(main);
Assert.Equal(common.HashBlock, side.SetTip(main.Tip).HashBlock);
Assert.NotNull(side.GetBlock(mainb1.HashBlock));
Assert.NotNull(side.GetBlock(mainb2.HashBlock));
Assert.NotNull(side.GetBlock(mainb3.HashBlock));
Assert.NotNull(side.GetBlock(common.HashBlock));
Assert.Null(side.GetBlock(sideb.HashBlock));
Assert.Equal(common.HashBlock, side.SetTip(sideb).HashBlock);
Assert.Null(side.GetBlock(mainb1.HashBlock));
Assert.Null(side.GetBlock(mainb2.HashBlock));
Assert.Null(side.GetBlock(mainb3.HashBlock));
Assert.NotNull(side.GetBlock(sideb.HashBlock));
}
示例4: CanForkBackwardPartialChain
public void CanForkBackwardPartialChain()
{
Chain chain = new Chain(TestUtils.CreateFakeBlock().Header, 10, new StreamObjectStream<ChainChange>());
AppendBlock(chain);
AppendBlock(chain);
var fork = AppendBlock(chain);
//Test single block back fork
var last = AppendBlock(chain);
Assert.Equal(14, chain.Height);
Assert.Equal(14, last.Height);
Assert.Equal(last.HashBlock, chain.Tip.HashBlock);
Assert.Equal(fork.HashBlock, chain.SetTip(fork).HashBlock);
Assert.Equal(13, chain.Height);
Assert.Equal(13, fork.Height);
Assert.Equal(fork.HashBlock, chain.Tip.HashBlock);
Assert.Null(chain.GetBlock(last.HashBlock));
Assert.NotNull(chain.GetBlock(fork.HashBlock));
//Test 3 blocks back fork
var b1 = AppendBlock(chain);
var b2 = AppendBlock(chain);
last = AppendBlock(chain);
Assert.Equal(16, chain.Height);
Assert.Equal(16, last.Height);
Assert.Equal(last.HashBlock, chain.Tip.HashBlock);
Assert.Equal(fork.HashBlock, chain.SetTip(fork).HashBlock);
Assert.Equal(13, chain.Height);
Assert.Equal(13, fork.Height);
Assert.Equal(fork.HashBlock, chain.Tip.HashBlock);
Assert.Null(chain.GetBlock(last.HashBlock));
Assert.Null(chain.GetBlock(b1.HashBlock));
Assert.Null(chain.GetBlock(b2.HashBlock));
chain.SetTip(last);
Assert.Equal(16, chain.Height);
Assert.Equal(16, last.Height);
Assert.Equal(last.HashBlock, chain.Tip.HashBlock);
}
示例5: CanForkBackward
public void CanForkBackward()
{
Chain chain = new Chain(Network.Main);
AppendBlock(chain);
AppendBlock(chain);
var fork = AppendBlock(chain);
//Test single block back fork
var last = AppendBlock(chain);
Assert.Equal(4, chain.Height);
Assert.Equal(4, last.Height);
Assert.Equal(last.HashBlock, chain.Tip.HashBlock);
Assert.Equal(fork.HashBlock, chain.SetTip(fork).HashBlock);
Assert.Equal(3, chain.Height);
Assert.Equal(3, fork.Height);
Assert.Equal(fork.HashBlock, chain.Tip.HashBlock);
Assert.Null(chain.GetBlock(last.HashBlock));
Assert.NotNull(chain.GetBlock(fork.HashBlock));
//Test 3 blocks back fork
var b1 = AppendBlock(chain);
var b2 = AppendBlock(chain);
last = AppendBlock(chain);
Assert.Equal(6, chain.Height);
Assert.Equal(6, last.Height);
Assert.Equal(last.HashBlock, chain.Tip.HashBlock);
Assert.Equal(fork.HashBlock, chain.SetTip(fork).HashBlock);
Assert.Equal(3, chain.Height);
Assert.Equal(3, fork.Height);
Assert.Equal(fork.HashBlock, chain.Tip.HashBlock);
Assert.Null(chain.GetBlock(last.HashBlock));
Assert.Null(chain.GetBlock(b1.HashBlock));
Assert.Null(chain.GetBlock(b2.HashBlock));
chain.SetTip(last);
Assert.Equal(6, chain.Height);
Assert.Equal(6, last.Height);
Assert.Equal(last.HashBlock, chain.Tip.HashBlock);
}