mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-17 18:30:45 +00:00
core, les: fix les unit tests (#19823)
This commit is contained in:
parent
edaed4fd92
commit
b708614470
3 changed files with 20 additions and 19 deletions
|
|
@ -884,13 +884,13 @@ func (pool *TxPool) AddRemotes(txs []*types.Transaction) []error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is like AddRemotes, but waits for pool reorganization. Tests use this method.
|
// This is like AddRemotes, but waits for pool reorganization. Tests use this method.
|
||||||
func (pool *TxPool) addRemotesSync(txs []*types.Transaction) []error {
|
func (pool *TxPool) AddRemotesSync(txs []*types.Transaction) []error {
|
||||||
return pool.addTxs(txs, false, true)
|
return pool.addTxs(txs, false, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is like AddRemotes with a single transaction, but waits for pool reorganization. Tests use this method.
|
// This is like AddRemotes with a single transaction, but waits for pool reorganization. Tests use this method.
|
||||||
func (pool *TxPool) addRemoteSync(tx *types.Transaction) error {
|
func (pool *TxPool) AddRemoteSync(tx *types.Transaction) error {
|
||||||
errs := pool.addRemotesSync([]*types.Transaction{tx})
|
errs := pool.AddRemotesSync([]*types.Transaction{tx})
|
||||||
return errs[0]
|
return errs[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -220,7 +220,7 @@ func TestStateChangeDuringTransactionPoolReset(t *testing.T) {
|
||||||
t.Fatalf("Invalid nonce, want 0, got %d", nonce)
|
t.Fatalf("Invalid nonce, want 0, got %d", nonce)
|
||||||
}
|
}
|
||||||
|
|
||||||
pool.addRemotesSync([]*types.Transaction{tx0, tx1})
|
pool.AddRemotesSync([]*types.Transaction{tx0, tx1})
|
||||||
|
|
||||||
nonce = pool.Nonce(address)
|
nonce = pool.Nonce(address)
|
||||||
if nonce != 2 {
|
if nonce != 2 {
|
||||||
|
|
@ -611,7 +611,7 @@ func TestTransactionPostponing(t *testing.T) {
|
||||||
txs = append(txs, tx)
|
txs = append(txs, tx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for i, err := range pool.addRemotesSync(txs) {
|
for i, err := range pool.AddRemotesSync(txs) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("tx %d: failed to add transactions: %v", i, err)
|
t.Fatalf("tx %d: failed to add transactions: %v", i, err)
|
||||||
}
|
}
|
||||||
|
|
@ -707,7 +707,7 @@ func TestTransactionGapFilling(t *testing.T) {
|
||||||
defer sub.Unsubscribe()
|
defer sub.Unsubscribe()
|
||||||
|
|
||||||
// Create a pending and a queued transaction with a nonce-gap in between
|
// Create a pending and a queued transaction with a nonce-gap in between
|
||||||
pool.addRemotesSync([]*types.Transaction{
|
pool.AddRemotesSync([]*types.Transaction{
|
||||||
transaction(0, 100000, key),
|
transaction(0, 100000, key),
|
||||||
transaction(2, 100000, key),
|
transaction(2, 100000, key),
|
||||||
})
|
})
|
||||||
|
|
@ -725,7 +725,7 @@ func TestTransactionGapFilling(t *testing.T) {
|
||||||
t.Fatalf("pool internal state corrupted: %v", err)
|
t.Fatalf("pool internal state corrupted: %v", err)
|
||||||
}
|
}
|
||||||
// Fill the nonce gap and ensure all transactions become pending
|
// Fill the nonce gap and ensure all transactions become pending
|
||||||
if err := pool.addRemoteSync(transaction(1, 100000, key)); err != nil {
|
if err := pool.AddRemoteSync(transaction(1, 100000, key)); err != nil {
|
||||||
t.Fatalf("failed to add gapped transaction: %v", err)
|
t.Fatalf("failed to add gapped transaction: %v", err)
|
||||||
}
|
}
|
||||||
pending, queued = pool.Stats()
|
pending, queued = pool.Stats()
|
||||||
|
|
@ -757,7 +757,7 @@ func TestTransactionQueueAccountLimiting(t *testing.T) {
|
||||||
testTxPoolConfig.AccountQueue = 10
|
testTxPoolConfig.AccountQueue = 10
|
||||||
// Keep queuing up transactions and make sure all above a limit are dropped
|
// Keep queuing up transactions and make sure all above a limit are dropped
|
||||||
for i := uint64(1); i <= testTxPoolConfig.AccountQueue; i++ {
|
for i := uint64(1); i <= testTxPoolConfig.AccountQueue; i++ {
|
||||||
if err := pool.addRemoteSync(transaction(i, 100000, key)); err != nil {
|
if err := pool.AddRemoteSync(transaction(i, 100000, key)); err != nil {
|
||||||
t.Fatalf("tx %d: failed to add transaction: %v", i, err)
|
t.Fatalf("tx %d: failed to add transaction: %v", i, err)
|
||||||
}
|
}
|
||||||
if len(pool.pending) != 0 {
|
if len(pool.pending) != 0 {
|
||||||
|
|
@ -826,7 +826,7 @@ func testTransactionQueueGlobalLimiting(t *testing.T, nolocals bool) {
|
||||||
nonces[addr]++
|
nonces[addr]++
|
||||||
}
|
}
|
||||||
// Import the batch and verify that limits have been enforced
|
// Import the batch and verify that limits have been enforced
|
||||||
pool.addRemotesSync(txs)
|
pool.AddRemotesSync(txs)
|
||||||
|
|
||||||
queued := 0
|
queued := 0
|
||||||
for addr, list := range pool.queue {
|
for addr, list := range pool.queue {
|
||||||
|
|
@ -963,7 +963,7 @@ func TestTransactionPendingLimiting(t *testing.T) {
|
||||||
|
|
||||||
// Keep queuing up transactions and make sure all above a limit are dropped
|
// Keep queuing up transactions and make sure all above a limit are dropped
|
||||||
for i := uint64(0); i < testTxPoolConfig.AccountQueue; i++ {
|
for i := uint64(0); i < testTxPoolConfig.AccountQueue; i++ {
|
||||||
if err := pool.addRemoteSync(transaction(i, 100000, key)); err != nil {
|
if err := pool.AddRemoteSync(transaction(i, 100000, key)); err != nil {
|
||||||
t.Fatalf("tx %d: failed to add transaction: %v", i, err)
|
t.Fatalf("tx %d: failed to add transaction: %v", i, err)
|
||||||
}
|
}
|
||||||
if pool.pending[account].Len() != int(i)+1 {
|
if pool.pending[account].Len() != int(i)+1 {
|
||||||
|
|
@ -1019,7 +1019,7 @@ func TestTransactionPendingGlobalLimiting(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Import the batch and verify that limits have been enforced
|
// Import the batch and verify that limits have been enforced
|
||||||
pool.addRemotesSync(txs)
|
pool.AddRemotesSync(txs)
|
||||||
|
|
||||||
pending := 0
|
pending := 0
|
||||||
for _, list := range pool.pending {
|
for _, list := range pool.pending {
|
||||||
|
|
@ -1101,7 +1101,7 @@ func TestTransactionPendingMinimumAllowance(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Import the batch and verify that limits have been enforced
|
// Import the batch and verify that limits have been enforced
|
||||||
pool.addRemotesSync(txs)
|
pool.AddRemotesSync(txs)
|
||||||
|
|
||||||
for addr, list := range pool.pending {
|
for addr, list := range pool.pending {
|
||||||
if list.Len() != int(config.AccountSlots) {
|
if list.Len() != int(config.AccountSlots) {
|
||||||
|
|
@ -1158,7 +1158,7 @@ func TestTransactionPoolRepricing(t *testing.T) {
|
||||||
ltx := pricedTransaction(0, 100000, big.NewInt(1), keys[3])
|
ltx := pricedTransaction(0, 100000, big.NewInt(1), keys[3])
|
||||||
|
|
||||||
// Import the batch and that both pending and queued transactions match up
|
// Import the batch and that both pending and queued transactions match up
|
||||||
pool.addRemotesSync(txs)
|
pool.AddRemotesSync(txs)
|
||||||
pool.AddLocal(ltx)
|
pool.AddLocal(ltx)
|
||||||
|
|
||||||
pending, queued := pool.Stats()
|
pending, queued := pool.Stats()
|
||||||
|
|
@ -1442,7 +1442,7 @@ func TestTransactionPoolStableUnderpricing(t *testing.T) {
|
||||||
for i := uint64(0); i < config.GlobalSlots; i++ {
|
for i := uint64(0); i < config.GlobalSlots; i++ {
|
||||||
txs = append(txs, pricedTransaction(i, 100000, big.NewInt(1), keys[0]))
|
txs = append(txs, pricedTransaction(i, 100000, big.NewInt(1), keys[0]))
|
||||||
}
|
}
|
||||||
pool.addRemotesSync(txs)
|
pool.AddRemotesSync(txs)
|
||||||
|
|
||||||
pending, queued := pool.Stats()
|
pending, queued := pool.Stats()
|
||||||
if pending != int(config.GlobalSlots) {
|
if pending != int(config.GlobalSlots) {
|
||||||
|
|
@ -1458,7 +1458,7 @@ func TestTransactionPoolStableUnderpricing(t *testing.T) {
|
||||||
t.Fatalf("pool internal state corrupted: %v", err)
|
t.Fatalf("pool internal state corrupted: %v", err)
|
||||||
}
|
}
|
||||||
// Ensure that adding high priced transactions drops a cheap, but doesn't produce a gap
|
// Ensure that adding high priced transactions drops a cheap, but doesn't produce a gap
|
||||||
if err := pool.addRemoteSync(pricedTransaction(0, 100000, big.NewInt(3), keys[1])); err != nil {
|
if err := pool.AddRemoteSync(pricedTransaction(0, 100000, big.NewInt(3), keys[1])); err != nil {
|
||||||
t.Fatalf("failed to add well priced transaction: %v", err)
|
t.Fatalf("failed to add well priced transaction: %v", err)
|
||||||
}
|
}
|
||||||
pending, queued = pool.Stats()
|
pending, queued = pool.Stats()
|
||||||
|
|
@ -1502,7 +1502,7 @@ func TestTransactionReplacement(t *testing.T) {
|
||||||
price := int64(100)
|
price := int64(100)
|
||||||
threshold := (price * (100 + int64(testTxPoolConfig.PriceBump))) / 100
|
threshold := (price * (100 + int64(testTxPoolConfig.PriceBump))) / 100
|
||||||
|
|
||||||
if err := pool.addRemoteSync(pricedTransaction(0, 100000, big.NewInt(1), key)); err != nil {
|
if err := pool.AddRemoteSync(pricedTransaction(0, 100000, big.NewInt(1), key)); err != nil {
|
||||||
t.Fatalf("failed to add original cheap pending transaction: %v", err)
|
t.Fatalf("failed to add original cheap pending transaction: %v", err)
|
||||||
}
|
}
|
||||||
if err := pool.AddRemote(pricedTransaction(0, 100001, big.NewInt(1), key)); err != ErrReplaceUnderpriced {
|
if err := pool.AddRemote(pricedTransaction(0, 100001, big.NewInt(1), key)); err != ErrReplaceUnderpriced {
|
||||||
|
|
@ -1515,7 +1515,7 @@ func TestTransactionReplacement(t *testing.T) {
|
||||||
t.Fatalf("cheap replacement event firing failed: %v", err)
|
t.Fatalf("cheap replacement event firing failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := pool.addRemoteSync(pricedTransaction(0, 100000, big.NewInt(price), key)); err != nil {
|
if err := pool.AddRemoteSync(pricedTransaction(0, 100000, big.NewInt(price), key)); err != nil {
|
||||||
t.Fatalf("failed to add original proper pending transaction: %v", err)
|
t.Fatalf("failed to add original proper pending transaction: %v", err)
|
||||||
}
|
}
|
||||||
if err := pool.AddRemote(pricedTransaction(0, 100001, big.NewInt(threshold-1), key)); err != ErrReplaceUnderpriced {
|
if err := pool.AddRemote(pricedTransaction(0, 100001, big.NewInt(threshold-1), key)); err != ErrReplaceUnderpriced {
|
||||||
|
|
@ -1606,7 +1606,7 @@ func testTransactionJournaling(t *testing.T, nolocals bool) {
|
||||||
if err := pool.AddLocal(pricedTransaction(2, 100000, big.NewInt(1), local)); err != nil {
|
if err := pool.AddLocal(pricedTransaction(2, 100000, big.NewInt(1), local)); err != nil {
|
||||||
t.Fatalf("failed to add local transaction: %v", err)
|
t.Fatalf("failed to add local transaction: %v", err)
|
||||||
}
|
}
|
||||||
if err := pool.addRemoteSync(pricedTransaction(0, 100000, big.NewInt(1), remote)); err != nil {
|
if err := pool.AddRemoteSync(pricedTransaction(0, 100000, big.NewInt(1), remote)); err != nil {
|
||||||
t.Fatalf("failed to add remote transaction: %v", err)
|
t.Fatalf("failed to add remote transaction: %v", err)
|
||||||
}
|
}
|
||||||
pending, queued := pool.Stats()
|
pending, queued := pool.Stats()
|
||||||
|
|
@ -1699,7 +1699,7 @@ func TestTransactionStatusCheck(t *testing.T) {
|
||||||
txs = append(txs, pricedTransaction(2, 100000, big.NewInt(1), keys[2])) // Queued only
|
txs = append(txs, pricedTransaction(2, 100000, big.NewInt(1), keys[2])) // Queued only
|
||||||
|
|
||||||
// Import the transaction and ensure they are correctly added
|
// Import the transaction and ensure they are correctly added
|
||||||
pool.addRemotesSync(txs)
|
pool.AddRemotesSync(txs)
|
||||||
|
|
||||||
pending, queued := pool.Stats()
|
pending, queued := pool.Stats()
|
||||||
if pending != 2 {
|
if pending != 2 {
|
||||||
|
|
|
||||||
|
|
@ -91,6 +91,7 @@ type BlockChain interface {
|
||||||
|
|
||||||
type txPool interface {
|
type txPool interface {
|
||||||
AddRemotes(txs []*types.Transaction) []error
|
AddRemotes(txs []*types.Transaction) []error
|
||||||
|
AddRemotesSync(txs []*types.Transaction) []error
|
||||||
Status(hashes []common.Hash) []core.TxStatus
|
Status(hashes []common.Hash) []core.TxStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue