(t *testing.T)
| 359 | } |
| 360 | |
| 361 | func TestTransactionDoubleNonce(t *testing.T) { |
| 362 | t.Parallel() |
| 363 | |
| 364 | pool, key := setupTxPool() |
| 365 | defer pool.Stop() |
| 366 | |
| 367 | addr := crypto.PubkeyToAddress(key.PublicKey) |
| 368 | resetState := func() { |
| 369 | statedb, _ := state.New(common.Hash{}, state.NewDatabase(database.NewMemDatabase())) |
| 370 | statedb.AddBalance(addr, big.NewInt(100000000000000)) |
| 371 | |
| 372 | pool.chain = &testBlockChain{statedb, 1000000, new(event.Feed)} |
| 373 | pool.lockedReset(nil, nil) |
| 374 | } |
| 375 | resetState() |
| 376 | |
| 377 | signer := types.HomesteadSigner{} |
| 378 | tx1, _ := types.SignTx(types.NewTransaction(0, common.Address{}, big.NewInt(100), 100000, big.NewInt(1), nil), signer, key) |
| 379 | tx2, _ := types.SignTx(types.NewTransaction(0, common.Address{}, big.NewInt(100), 1000000, big.NewInt(2), nil), signer, key) |
| 380 | tx3, _ := types.SignTx(types.NewTransaction(0, common.Address{}, big.NewInt(100), 1000000, big.NewInt(1), nil), signer, key) |
| 381 | |
| 382 | // Add the first two transaction, ensure higher priced stays only |
| 383 | if replace, err := pool.add(tx1, false); err != nil || replace { |
| 384 | t.Errorf("first transaction insert failed (%v) or reported replacement (%v)", err, replace) |
| 385 | } |
| 386 | if replace, err := pool.add(tx2, false); err != nil || !replace { |
| 387 | t.Errorf("second transaction insert failed (%v) or not reported replacement (%v)", err, replace) |
| 388 | } |
| 389 | pool.promoteExecutables([]common.Address{addr}) |
| 390 | if pool.pending[addr].Len() != 1 { |
| 391 | t.Error("expected 1 pending transactions, got", pool.pending[addr].Len()) |
| 392 | } |
| 393 | if tx := pool.pending[addr].txs.items[0]; tx.Hash() != tx2.Hash() { |
| 394 | t.Errorf("transaction mismatch: have %x, want %x", tx.Hash(), tx2.Hash()) |
| 395 | } |
| 396 | // Add the third transaction and ensure it's not saved (smaller price) |
| 397 | pool.add(tx3, false) |
| 398 | pool.promoteExecutables([]common.Address{addr}) |
| 399 | if pool.pending[addr].Len() != 1 { |
| 400 | t.Error("expected 1 pending transactions, got", pool.pending[addr].Len()) |
| 401 | } |
| 402 | if tx := pool.pending[addr].txs.items[0]; tx.Hash() != tx2.Hash() { |
| 403 | t.Errorf("transaction mismatch: have %x, want %x", tx.Hash(), tx2.Hash()) |
| 404 | } |
| 405 | // Ensure the total transaction count is correct |
| 406 | if pool.all.Count() != 1 { |
| 407 | t.Error("expected 1 total transactions, got", pool.all.Count()) |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | func TestTransactionMissingNonce(t *testing.T) { |
| 412 | t.Parallel() |
nothing calls this directly
no test coverage detected