public void Ctor_DefaultHashIsGenesisHash() { // Act var bloq = new Bloq <string>(); // Assert Assert.Equal("0000000000000000000000000000000000000000000000000000000000000000", bloq.PreviousHash); }
/// <summary> /// Initializes a new instance of the <see cref="BloqControl"/> class. /// </summary> /// <param name="bloq">The bloq.</param> public BloqControl(Bloq <string> bloq) { InitializeComponent(); this.bloq = bloq ?? throw new ArgumentNullException(nameof(bloq)); this.TextboxIndex.Text = this.bloq.Index.ToString(); this.TextboxNonce.Text = this.bloq.Nonce.ToString(); this.TextboxPreviousHash.Text = this.bloq.PreviousHash; this.TextboxHash.Text = this.bloq.Hash; this.TextboxData.Text = this.bloq.Data; this.TextboxTimestamp.Text = this.bloq.Timestamp.ToString(); }
public void Mine_NegativeDifficulty_Throws() { // Arrange int index = 5; int nonce = 0; string data = "Hello, I'm some data"; DateTime timestamp = DateTime.UtcNow; var bloq = new Bloq <string>(index, nonce, timestamp, data, "Some Hash"); bloq.PreviousHash = "Some Hash"; // Act and Assert int difficulty = -3; Assert.Throws <ArgumentOutOfRangeException>(() => bloq.Mine(difficulty)); }
public void IsGenesisBloq_PreviousHashIsNotGenesisHash_ReturnsTrue() { // Arrange int index = 5; int nonce = 0; string data = "Hello, I'm some data"; DateTime timestamp = DateTime.UtcNow; var bloq = new Bloq <string>(index, nonce, timestamp, data, "Some Hash"); bloq.PreviousHash = "Some Hash"; // Act bool result = bloq.IsGenesisBloq; // Assert Assert.False(result); }
public void CalculateHash_AllSameData_ExceptIndex_GivesDifferentSameHash() { // Arrange int nonce = 0; DateTime timestamp = DateTime.UtcNow; string data = "Hello, I'm some data"; string previousHash = "41aa65db55b7bfd4af15c2945d3943c202ee77728719fed39703a2f03855c703"; var bloq1 = new Bloq <string>(1, nonce, timestamp, data, previousHash); var bloq2 = new Bloq <string>(2, nonce, timestamp, data, previousHash); // Act int difficulty = 0; bloq1.Mine(difficulty); bloq2.Mine(difficulty); string hashOfBLoq1 = bloq1.Hash; string hashOfBLoq2 = bloq2.Hash; // Assert Assert.NotEqual(hashOfBLoq1, hashOfBLoq2); }
public void CalculateHash_AllSameData_ExceptPreviousHash_GivesDifferentSameHash() { // Arrange int index = 5; int nonce = 0; string data = "Hello, I'm some data"; DateTime timestamp = DateTime.UtcNow; var bloq1 = new Bloq <string>(index, nonce, timestamp, data, "Some Hash"); var bloq2 = new Bloq <string>(index, nonce, timestamp, data, "Some Other Hash"); // Act int difficulty = 0; bloq1.Mine(difficulty); bloq2.Mine(difficulty); string hashOfBLoq1 = bloq1.Hash; string hashOfBLoq2 = bloq2.Hash; // Assert Assert.NotEqual(hashOfBLoq1, hashOfBLoq2); }