diff --git a/blockchain/blockchain_test.go b/blockchain/blockchain_test.go new file mode 100644 index 000000000..08e7ef077 --- /dev/null +++ b/blockchain/blockchain_test.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.") + } +} diff --git a/blockchain/transaction.go b/blockchain/transaction.go index 303aa28aa..d8bce39e4 100644 --- a/blockchain/transaction.go +++ b/blockchain/transaction.go @@ -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() {