MCPcopy Create free account
hub / github.com/CPChain/chain / testSendTransactions

Function testSendTransactions

protocols/cpc/protocol_test.go:109–161  ·  view source on GitHub ↗
(t *testing.T, protocol int)

Source from the content-addressed store, hash-verified

107func TestSendTransactionsCpc1(t *testing.T) { testSendTransactions(t, 1) }
108
109func testSendTransactions(t *testing.T, protocol int) {
110 pm, _ := newTestProtocolManagerMust(t, 0, nil, nil)
111 defer pm.Stop()
112
113 // Fill the pool with big transactions.
114 const txsize = txsyncPackSize / 10
115 alltxs := make([]*types.Transaction, 100)
116 for nonce := range alltxs {
117 alltxs[nonce] = newTestTransaction(testAccount, uint64(nonce), txsize)
118 }
119 pm.txpool.AddRemotes(alltxs)
120
121 // Connect several peers. They should all receive the pending transactions.
122 var wg sync.WaitGroup
123 checktxs := func(p *testPeer) {
124 defer wg.Done()
125 defer p.close()
126 seen := make(map[common.Hash]bool)
127 for _, tx := range alltxs {
128 seen[tx.Hash()] = false
129 }
130 for n := 0; n < len(alltxs) && !t.Failed(); {
131 var txs []*types.Transaction
132 msg, err := p.app.ReadMsg()
133 if err != nil {
134 t.Errorf("%v: read error: %v", p.Peer, err)
135 } else if msg.Code != TxMsg {
136 t.Errorf("%v: got code %d, want TxMsg", p.Peer, msg.Code)
137 }
138 if err := msg.Decode(&txs); err != nil {
139 t.Errorf("%v: %v", p.Peer, err)
140 }
141 for _, tx := range txs {
142 hash := tx.Hash()
143 seentx, want := seen[hash]
144 if seentx {
145 t.Errorf("%v: got tx more than once: %x", p.Peer, hash)
146 }
147 if !want {
148 t.Errorf("%v: got unexpected tx: %x", p.Peer, hash)
149 }
150 seen[hash] = true
151 n++
152 }
153 }
154 }
155 for i := 0; i < 3; i++ {
156 p, _ := newTestPeer(fmt.Sprintf("peer #%d", i), protocol, pm, true)
157 wg.Add(1)
158 go checktxs(p)
159 }
160 wg.Wait()
161}
162
163// Tests that the custom union field encoder and decoder works correctly.
164func TestGetBlockHeadersDataEncodeDecode(t *testing.T) {

Callers 1

TestSendTransactionsCpc1Function · 0.85

Calls 10

newTestTransactionFunction · 0.85
newTestPeerFunction · 0.85
WaitMethod · 0.80
StopMethod · 0.65
AddRemotesMethod · 0.65
HashMethod · 0.65
AddMethod · 0.65
closeMethod · 0.45
ReadMsgMethod · 0.45

Tested by

no test coverage detected