The core protocol of WoopChain
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
woop/blockchain/utxopool_test.go

51 lines
1.3 KiB

package blockchain
import (
"testing"
)
6 years ago
func TestVerifyOneTransactionAndUpdate(t *testing.T) {
bc := CreateBlockchain("minh", 0)
6 years ago
utxoPool := CreateUTXOPoolFromGenesisBlockChain(bc)
bc.AddNewUserTransfer(utxoPool, "minh", "alok", 3, 0)
bc.AddNewUserTransfer(utxoPool, "minh", "rj", 100, 0)
6 years ago
tx := bc.NewUTXOTransaction("minh", "mark", 10, 0)
6 years ago
if tx == nil {
t.Error("failed to create a new transaction.")
}
6 years ago
6 years ago
if !utxoPool.VerifyOneTransaction(tx) {
t.Error("failed to verify a valid transaction.")
}
6 years ago
utxoPool.VerifyOneTransactionAndUpdate(tx)
}
func TestDeleteOneBalanceItem(t *testing.T) {
bc := CreateBlockchain("minh", 0)
utxoPool := CreateUTXOPoolFromGenesisBlockChain(bc)
bc.AddNewUserTransfer(utxoPool, "minh", "alok", 3, 0)
bc.AddNewUserTransfer(utxoPool, "alok", "rj", 3, 0)
if _, ok := utxoPool.UtxoMap["alok"]; ok {
t.Errorf("alok should not be contained in the balance map")
}
}
func TestCleanUp(t *testing.T) {
var utxoPool UTXOPool
utxoPool.UtxoMap = make(map[string]map[string]map[int]int)
utxoPool.UtxoMap["minh"] = make(map[string]map[int]int)
utxoPool.UtxoMap["rj"] = map[string]map[int]int{
"abcd": {
0: 1,
},
}
utxoPool.CleanUp()
if _, ok := utxoPool.UtxoMap["minh"]; ok {
t.Errorf("minh should not be contained in the balance map")
}
}