Add test for countNumTransactionsInBlockchain()

pull/10/head
Rongjian Lan 7 years ago
parent 71d1a819a4
commit 600ad2b5e4
  1. 2
      aws-code/transaction_generator.go
  2. 2
      benchmark_main.go
  3. 4
      node/node.go
  4. 12
      node/node_test.go

@ -122,7 +122,7 @@ func main() {
// Testing node to mirror the node data in consensus
dataNode := node.NewNode(&consensus.Consensus{})
dataNode.AddMoreFakeTransactions()
dataNode.AddMoreFakeTransactions(1000)
start := time.Now()
totalTime := 60.0

@ -88,7 +88,7 @@ func main() {
consensus.OnConsensusDone = node.AddNewBlockToBlockchain
// Temporary testing code, to be removed.
node.AddMoreFakeTransactions()
node.AddMoreFakeTransactions(1000)
if consensus.IsLeader {
// Let consensus run

@ -73,8 +73,8 @@ func (node *Node) String() string {
// [Testing code] Should be deleted for production
// Create in genesis block 1000 transactions which assign 1000 token to each address in [1 - 1000]
func (node *Node) AddMoreFakeTransactions() {
txs := make([]*blockchain.Transaction, 1000)
func (node *Node) AddMoreFakeTransactions(numTxs int) {
txs := make([]*blockchain.Transaction, numTxs)
for i := range txs {
txs[i] = blockchain.NewCoinbaseTX(strconv.Itoa(i), "")
}

@ -32,3 +32,15 @@ func TestNewNewNode(test *testing.T) {
test.Error("Utxo pool is not initialized for the node")
}
}
func TestCountNumTransactionsInBlockchain(test *testing.T) {
leader := p2p.Peer{Ip: "1", Port: "2"}
validator := p2p.Peer{Ip: "3", Port: "5"}
consensus := consensus.NewConsensus("1", "2", "0", []p2p.Peer{leader, validator}, leader)
node := NewNode(&consensus)
node.AddMoreFakeTransactions(1000)
if node.countNumTransactionsInBlockchain() != 1001 {
test.Error("Count of transactions in the blockchain is incorrect")
}
}

Loading…
Cancel
Save