public void AppendManyWithOffset() { var rand = new Random(42); var pack1 = new CoinPack(new byte[4096]); pack1.SetOutpointSigs(GetSigs(rand)); var coin1 = GetCoin(rand); var coin2 = GetCoin(rand); var coin3 = GetCoin(rand); pack1.Append(coin1); pack1.Append(coin2); pack1.Append(coin3); var pack2 = new CoinPack(new byte[4096]); pack2.Append(pack1, 1, 2); Assert.Equal(2, pack2.CoinCount); pack2.TryGet(ref coin1.Outpoint, out Coin g1); Assert.True(g1.IsEmpty); pack2.TryGet(ref coin2.Outpoint, out Coin g2); Assert.True(coin2.Span.SequenceEqual(g2.Span)); pack2.TryGet(ref coin3.Outpoint, out Coin g3); Assert.True(coin3.Span.SequenceEqual(g3.Span)); }
public void CoinCountAfterAppend() { var pack = new CoinPack(new byte[4096]); var coin = new Coin(new byte[128]); pack.Append(coin); Assert.Equal(1, pack.CoinCount); pack.Append(coin); Assert.Equal(2, pack.CoinCount); }
public void GetSpan() { var rand = new Random(42); var pack = new CoinPack(new byte[4096]); pack.SetOutpointSigs(GetSigs(rand)); var coin1 = GetCoin(rand); var coin2 = GetCoin(rand); pack.Append(coin1); pack.Append(coin2); var shallow = new CoinPack(pack.Span); shallow.TryGet(ref coin2.Outpoint, out Coin g2); Assert.True(coin2.Span.SequenceEqual(g2.Span)); }
public void AppendCoin() { var rand = new Random(42); var pack = new CoinPack(new byte[4096]); pack.SetOutpointSigs(GetSigs(rand)); var coin1 = GetCoin(rand); var coin2 = GetCoin(rand); var coin3 = GetCoin(rand); pack.Append(coin1); Assert.Equal(1, pack.CoinCount); pack.Append(coin2); Assert.Equal(2, pack.CoinCount); pack.Append(coin3); Assert.Equal(3, pack.CoinCount); pack.TryGet(ref coin1.Outpoint, out Coin g1); Assert.True(coin1.Span.SequenceEqual(g1.Span)); pack.TryGet(ref coin2.Outpoint, out Coin g2); Assert.True(coin2.Span.SequenceEqual(g2.Span)); pack.TryGet(ref coin3.Outpoint, out Coin g3); Assert.True(coin3.Span.SequenceEqual(g3.Span)); // should not be found var coin4 = GetCoin(rand); pack.TryGet(ref coin4.Outpoint, out Coin g4); Assert.True(g4.IsEmpty); }
public void CountCoinsAbove() { var rand = new Random(42); var pack = new CoinPack(new byte[4096]); pack.SetOutpointSigs(GetSigs(rand)); for (var i = 0; i < 10; i++) { pack.Append(GetCoin(rand)); } Assert.Equal(1, pack.CountCoinsAbove(10)); Assert.Equal(3, pack.CountCoinsAbove(500)); Assert.Equal(10, pack.CountCoinsAbove(10000)); }