add blockchain_test

pull/3/head
Minh Doan 7 years ago
parent 0c41cc4a3b
commit b86c836bb5
  1. 39
      blockchain/blockchain_test.go
  2. 2
      blockchain/transaction.go

@ -0,0 +1,39 @@
package blockchain
import (
"testing"
)
func TestCreateBlockchain(t *testing.T) {
CreateBlockchain("minh")
}
func TestFindSpendableOutputs(t *testing.T) {
requestAmount := 3
bc := CreateBlockchain("minh")
accumulated, unspentOutputs := bc.FindSpendableOutputs("minh", requestAmount)
if accumulated < DefaultCoinbaseValue {
t.Error("Failed to find enough unspent ouptuts")
}
if len(unspentOutputs) <= 0 {
t.Error("Failed to find enough unspent ouptuts")
}
}
func TestFindUTXO(t *testing.T) {
bc := CreateBlockchain("minh")
utxo := bc.FindUTXO("minh")
total := 0
for _, value := range utxo {
total += value.Value
if value.Address != "minh" {
t.Error("FindUTXO failed.")
}
}
if total != DefaultCoinbaseValue {
t.Error("FindUTXO failed.")
}
}

@ -30,7 +30,7 @@ type TXInput struct {
}
// DefaultCoinbaseValue is the default value of coinbase transaction.
const DefaultCoinbaseValue = 10
const DefaultCoinbaseValue = 1000
// SetID sets ID of a transaction
func (tx *Transaction) SetID() {

Loading…
Cancel
Save