(t *testing.T, protocol int)
| 107 | func TestSendTransactionsCpc1(t *testing.T) { testSendTransactions(t, 1) } |
| 108 | |
| 109 | func 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. |
| 164 | func TestGetBlockHeadersDataEncodeDecode(t *testing.T) { |
no test coverage detected