projectx
projectx copied to clipboard
Fix transaction sign
Since transaction's hash function returns the cached version of hash, it won't calculate the latest hash of tracsaction's data. When we temper one transaction's data and call Verify() again, it still pass! Because transaction's Hash function returns the cached version of hash.
func TestTemperTxData(t *testing.T) {
userA := crypto.GeneratePrivateKey()
userB := crypto.GeneratePrivateKey()
tx := &Transaction{
From: userA.PublicKey(),
To: userB.PublicKey(),
Value: 666,
Data: []byte("user a send 666 to user b"),
}
assert.Nil(t, tx.Sign(userA))
assert.Nil(t, tx.Verify())
tx.Data = []byte("hhh")
assert.NotNil(t, tx.Verify())
}