Refactor tx generator methods and add more comments

pull/17/head
Rongjian Lan 7 years ago
parent 8cee77e82e
commit c8627fa32a
  1. 2
      benchmark_main.go
  2. 8
      node/node.go
  3. 2
      node/node_test.go

@ -107,7 +107,7 @@ func main() {
consensus.OnConsensusDone = node.PostConsensusProcessing consensus.OnConsensusDone = node.PostConsensusProcessing
// Temporary testing code, to be removed. // Temporary testing code, to be removed.
node.AddMoreFakeTransactions(10000) node.AddTestingAddresses(10000)
if consensus.IsLeader { if consensus.IsLeader {
// Let consensus run // Let consensus run

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

@ -39,7 +39,7 @@ func TestCountNumTransactionsInBlockchain(test *testing.T) {
consensus := consensus.NewConsensus("1", "2", "0", []p2p.Peer{leader, validator}, leader) consensus := consensus.NewConsensus("1", "2", "0", []p2p.Peer{leader, validator}, leader)
node := NewNode(&consensus) node := NewNode(&consensus)
node.AddMoreFakeTransactions(1000) node.AddTestingAddresses(1000)
if node.countNumTransactionsInBlockchain() != 1001 { if node.countNumTransactionsInBlockchain() != 1001 {
test.Error("Count of transactions in the blockchain is incorrect") test.Error("Count of transactions in the blockchain is incorrect")
} }

Loading…
Cancel
Save