@ -5,14 +5,14 @@ import (
)
func TestCreateBlockchain ( t * testing . T ) {
if bc := CreateBlockchain ( "minh" ) ; bc == nil {
if bc := CreateBlockchain ( "minh" , 0 ) ; bc == nil {
t . Errorf ( "failed to create a blockchain" )
}
}
func TestFindSpendableOutputs ( t * testing . T ) {
requestAmount := 3
bc := CreateBlockchain ( "minh" )
bc := CreateBlockchain ( "minh" , 0 )
accumulated , unspentOutputs := bc . FindSpendableOutputs ( "minh" , requestAmount )
if accumulated < DefaultCoinbaseValue {
t . Error ( "Failed to find enough unspent ouptuts" )
@ -24,7 +24,7 @@ func TestFindSpendableOutputs(t *testing.T) {
}
func TestFindUTXO ( t * testing . T ) {
bc := CreateBlockchain ( "minh" )
bc := CreateBlockchain ( "minh" , 0 )
utxo := bc . FindUTXO ( "minh" )
total := 0
@ -41,34 +41,34 @@ func TestFindUTXO(t *testing.T) {
}
func TestAddNewUserTransfer ( t * testing . T ) {
bc := CreateBlockchain ( "minh" )
bc := CreateBlockchain ( "minh" , 0 )
utxoPool := CreateUTXOPoolFromGenesisBlockChain ( bc )
if ! bc . AddNewUserTransfer ( utxoPool , "minh" , "alok" , 3 ) {
if ! bc . AddNewUserTransfer ( utxoPool , "minh" , "alok" , 3 , 0 ) {
t . Error ( "Failed to add new transfer to alok." )
}
if ! bc . AddNewUserTransfer ( utxoPool , "minh" , "rj" , 100 ) {
if ! bc . AddNewUserTransfer ( utxoPool , "minh" , "rj" , 100 , 0 ) {
t . Error ( "Failed to add new transfer to rj." )
}
if bc . AddNewUserTransfer ( utxoPool , "minh" , "stephen" , DefaultCoinbaseValue - 102 ) {
if bc . AddNewUserTransfer ( utxoPool , "minh" , "stephen" , DefaultCoinbaseValue - 102 , 0 ) {
t . Error ( "minh should not have enough fun to make the transfer." )
}
}
func TestVerifyNewBlock ( t * testing . T ) {
bc := CreateBlockchain ( "minh" )
bc := CreateBlockchain ( "minh" , 0 )
utxoPool := CreateUTXOPoolFromGenesisBlockChain ( bc )
bc . AddNewUserTransfer ( utxoPool , "minh" , "alok" , 3 )
bc . AddNewUserTransfer ( utxoPool , "minh" , "rj" , 100 )
bc . AddNewUserTransfer ( utxoPool , "minh" , "alok" , 3 , 0 )
bc . AddNewUserTransfer ( utxoPool , "minh" , "rj" , 100 , 0 )
tx := bc . NewUTXOTransaction ( "minh" , "mark" , 10 )
tx := bc . NewUTXOTransaction ( "minh" , "mark" , 10 , 0 )
if tx == nil {
t . Error ( "failed to create a new transaction." )
}
newBlock := NewBlock ( [ ] * Transaction { tx } , bc . Blocks [ len ( bc . Blocks ) - 1 ] . Hash )
newBlock := NewBlock ( [ ] * Transaction { tx } , bc . Blocks [ len ( bc . Blocks ) - 1 ] . Hash , 0 )
if ! bc . VerifyNewBlockAndUpdate ( utxoPool , newBlock ) {
t . Error ( "failed to add a new valid block." )