Beispiel #1
0
        public void GivingSameHeaderDoesNotReset()
        {
            var uut = new WorkGenerator();

            uut.SetHeader(DummySubmit, new byte[] { 1 });
            uut.SetTarget(new DifficultyTarget());
            uut.WannaConsume(ulong.MaxValue - 2);
            uut.SetHeader(DummySubmit, new byte[] { 1 });                 // it compares by value!
            Assert.Throws <ArgumentException>(() => uut.WannaConsume(3)); // you must roll a new nonce2 and feed me a new header.
        }
Beispiel #2
0
        public void GivingNewHeaderResetsConsumedCount()
        {
            var uut = new WorkGenerator();

            uut.SetHeader(DummySubmit, new byte[] { 1 });
            uut.SetTarget(new DifficultyTarget());
            uut.WannaConsume(ulong.MaxValue - 50);
            uut.SetHeader(DummySubmit, new byte[] { 2 });
            Assert.Equal(0u, uut.ConsumedNonces);
        }
Beispiel #3
0
        public void InterruptedIsReadyWithJustHeader()
        {
            var uut    = new WorkGenerator();
            var target = new DifficultyTarget();

            uut.SetHeader(DummySubmit, new byte[] { 1 });
            uut.SetTarget(target);
            uut.Stop();
            uut.SetHeader(DummySubmit, new byte[] { 2 });
            Assert.False(uut.Empty);
        }
Beispiel #4
0
        public void GivingHeaderIsNotEnough()
        {
            var uut = new WorkGenerator();

            uut.SetHeader(DummySubmit, new byte[] { 1 }); // that's certainly not a good header but it's not its concern
            Assert.Throws <InvalidOperationException>(() => uut.WannaConsume(0));
        }
Beispiel #5
0
        public void ConsumingToExhaustationThrows()
        {
            var uut = new WorkGenerator();

            uut.SetHeader(DummySubmit, new byte[] { 1 });
            uut.SetTarget(new DifficultyTarget());
            uut.WannaConsume(ulong.MaxValue - 1);
            Assert.Throws <ArgumentException>(() => uut.WannaConsume(2)); // you must roll a new nonce2 and feed me a new header.
        }
Beispiel #6
0
        public void ConsumingZeroThrows()
        {
            var uut    = new WorkGenerator();
            var target = new DifficultyTarget();

            uut.SetHeader(DummySubmit, new byte[] { 1 });
            uut.SetTarget(target);
            Assert.Throws <ArgumentException>(() => uut.WannaConsume(0));
        }
Beispiel #7
0
        public void ReadyWhenHeaderAndDiffProvided()
        {
            var uut    = new WorkGenerator();
            var target = new DifficultyTarget();

            uut.SetHeader(DummySubmit, new byte[] { 1 });
            uut.SetTarget(target);
            Assert.False(uut.Empty);
        }
Beispiel #8
0
        static WorkGenerator MakeFedWorkGenerator()
        {
            var gen    = new WorkGenerator();
            var target = new DifficultyTarget();

            gen.SetHeader(DummySubmit, new byte[] { 1 });
            gen.SetTarget(target);
            return(gen);
        }
Beispiel #9
0
        public void ReadyCanBeInterrupted()
        {
            var uut    = new WorkGenerator();
            var target = new DifficultyTarget();

            uut.SetHeader(DummySubmit, new byte[] { 1 });
            uut.SetTarget(target);
            uut.Stop();
            Assert.True(uut.Empty);
        }
Beispiel #10
0
        public void ConsumingBurnsRequestedNonces()
        {
            var target = new DifficultyTarget();
            var uut    = new WorkGenerator();
            var hdr    = new byte[] { 1 };
            var info   = DummySubmit;

            uut.SetHeader(info, hdr);
            uut.SetTarget(target);
            var work = uut.WannaConsume(1);

            Assert.Equal(1u, uut.ConsumedNonces);
            Assert.Same(work.target, target);
            Assert.Same(work.header, hdr); // and be careful, to save on copies it takes references to everything.
            Assert.Same(work.info, info);
        }