Skip to content

Commit

Permalink
Fixes issue with incorrect block hash in TestVerifyBlock()
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashy5000 committed Mar 15, 2024
1 parent f82f8c6 commit 693e013
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
"fmt"
"github.com/stretchr/testify/assert"
"math/big"
"strconv"
"testing"
"time"
)

func TestVerifyTransaction(t *testing.T) {
Expand Down Expand Up @@ -91,23 +93,17 @@ func TestVerifyBlock(t *testing.T) {
Append(GenesisBlock())
sender := key.PublicKey
receiver := key.PublicKey
amount := "0"
amount := 0.0
r := big.NewInt(0)
s := big.NewInt(0)
hash := sha256.Sum256([]byte(fmt.Sprintf("%s:%s:%s", sender.Y, receiver.Y, amount)))
hash := sha256.Sum256([]byte(fmt.Sprintf("%s:%s:%s", sender.Y, receiver.Y, strconv.FormatFloat(amount, 'f', -1, 64))))
r, s, err := dsa.Sign(rand.Reader, &key, hash[:])
if err != nil {
panic(err)
}
block := Block{
Sender: sender,
Recipient: receiver,
Amount: 0,
R: *r,
S: *s,
PreviousBlockHash: HashBlock(GenesisBlock()),
Miner: key.PublicKey,
Difficulty: 1,
block, err := CreateBlock(sender, receiver, amount, *r, *s, hash, strconv.FormatInt(time.Now().UnixNano(), 10))
if err != nil {
panic(err)
}
result := VerifyBlock(block)
assert.True(t, result)
Expand Down

0 comments on commit 693e013

Please sign in to comment.