Ejemplo n.º 1
0
        public async Task CanResolveConflictsOnEmptyChains()
        {
            var application = new FakeApplicationContext();

            var blockchain = application.GetService <Blockchain>();

            var actual = await blockchain.ResolveConflictsAsync();

            Assert.False(actual);
        }
Ejemplo n.º 2
0
        public void CanValidateChain()
        {
            var application = new FakeApplicationContext();

            var blockchain = application.GetService <Blockchain>();

            var actual = blockchain.IsValidChain(blockchain.Chain);

            Assert.True(actual);
        }
Ejemplo n.º 3
0
        public void CanValidateProof()
        {
            var application = new FakeApplicationContext();

            var blockchain = application.GetService <Blockchain>();

            var actual = blockchain.IsValidProof(100, 33575);

            Assert.True(actual);
        }
Ejemplo n.º 4
0
        public void CanComputeProofOfWork()
        {
            var application = new FakeApplicationContext();

            var blockchain = application.GetService <Blockchain>();

            var actual = blockchain.ComputeProofOfWork();

            Assert.Equal(33575, actual);
        }
Ejemplo n.º 5
0
        public async Task CanGetHttpResponse()
        {
            var application = new FakeApplicationContext();

            var response = await application.Client.GetAsync("/");

            var value = await response.Content.ReadAsStringAsync();

            var actual = JsonConvert.DeserializeObject <List <Block> >(value);

            Assert.NotNull(actual);
            Assert.Equal("7F83B1657FF1FC53B92DC18148A1D65DFC2D4B1FA3D677284ADDD200126D9069", actual.First().PreviousHash);
        }
Ejemplo n.º 6
0
        public void CanRegisterNode()
        {
            var application = new FakeApplicationContext();

            var blockchain = application.GetService <Blockchain>();

            Assert.Empty(blockchain.Nodes);

            var actual = blockchain.RegisterNode("http://localhost:8080/");

            Assert.True(actual);
            Assert.NotEmpty(blockchain.Nodes);
        }
Ejemplo n.º 7
0
        public void CanHashBlock()
        {
            var application = new FakeApplicationContext();

            var blockchain = application.GetService <Blockchain>();

            var block = new Block()
            {
                Index        = 1,
                Timestamp    = 10,
                Transactions = new List <Transaction>(),
                Proof        = 100,
                PreviousHash = "7F83B1657FF1FC53B92DC18148A1D65DFC2D4B1FA3D677284ADDD200126D9069"
            };

            var actual = blockchain.HashBlock(block);

            Assert.NotNull(actual);
            Assert.Equal("4B3E01D751A9B74F46FB85757177FD6E17C8E7201A0F1193E1EF3B57FCE8264B", actual);
        }