(t *testing.T, protocol int)
| 376 | func TestGetReceipt64(t *testing.T) { testGetReceipt(t, 64) } |
| 377 | |
| 378 | func testGetReceipt(t *testing.T, protocol int) { |
| 379 | // Define three accounts to simulate transactions with |
| 380 | acc1Key, _ := crypto.HexToECDSA("8a1f9a8f95be41cd7ccb6168179afb4504aefe388d1e14474d32c45c72ce7b7a") |
| 381 | acc2Key, _ := crypto.HexToECDSA("49a7b37aa6f6645917e7b807e9d1c00d4fa71f18343b0d4122a4d2df64dd6fee") |
| 382 | acc1Addr := crypto.PubkeyToAddress(acc1Key.PublicKey) |
| 383 | acc2Addr := crypto.PubkeyToAddress(acc2Key.PublicKey) |
| 384 | |
| 385 | signer := types.HomesteadSigner{} |
| 386 | // Create a chain generator with some simple transactions (blatantly stolen from @fjl/chain_markets_test) |
| 387 | generator := func(i int, block *core.BlockGen) { |
| 388 | switch i { |
| 389 | case 0: |
| 390 | // In block 1, the test bank sends account #1 some ether. |
| 391 | tx, _ := types.SignTx(types.NewTransaction(block.TxNonce(testBank), acc1Addr, big.NewInt(10000), configs.TxGas, nil, nil), signer, testBankKey) |
| 392 | block.AddTx(tx) |
| 393 | case 1: |
| 394 | // In block 2, the test bank sends some more ether to account #1. |
| 395 | // acc1Addr passes it on to account #2. |
| 396 | tx1, _ := types.SignTx(types.NewTransaction(block.TxNonce(testBank), acc1Addr, big.NewInt(1000), configs.TxGas, nil, nil), signer, testBankKey) |
| 397 | tx2, _ := types.SignTx(types.NewTransaction(block.TxNonce(acc1Addr), acc2Addr, big.NewInt(1000), configs.TxGas, nil, nil), signer, acc1Key) |
| 398 | block.AddTx(tx1) |
| 399 | block.AddTx(tx2) |
| 400 | case 2: |
| 401 | // Block 3 is empty but was mined by account #2. |
| 402 | block.SetCoinbase(acc2Addr) |
| 403 | } |
| 404 | } |
| 405 | // Assemble the test environment |
| 406 | pm, _ := newTestProtocolManagerMust(t, 4, generator, nil) |
| 407 | peer, _ := newTestPeer("peer", protocol, pm, true) |
| 408 | defer peer.close() |
| 409 | |
| 410 | // Collect the hashes to request, and the response to expect |
| 411 | hashes, receipts := []common.Hash{}, []types.Receipts{} |
| 412 | for i := uint64(0); i <= pm.blockchain.CurrentBlock().NumberU64(); i++ { |
| 413 | block := pm.blockchain.GetBlockByNumber(i) |
| 414 | |
| 415 | hashes = append(hashes, block.Hash()) |
| 416 | receipts = append(receipts, pm.blockchain.GetReceiptsByHash(block.Hash())) |
| 417 | } |
| 418 | // Send the hash request and verify the response |
| 419 | p2p.Send(peer.app, 0x0f, hashes) |
| 420 | if err := p2p.ExpectMsg(peer.app, 0x10, receipts); err != nil { |
| 421 | t.Errorf("receipts mismatch: %v", err) |
| 422 | } |
| 423 | } |
no test coverage detected