Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
igorcrevar committed Sep 1, 2023
1 parent 1799b28 commit ddd4963
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
3 changes: 2 additions & 1 deletion txpool/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type defaultMockStore struct {

getBlockByHashFn func(types.Hash, bool) (*types.Block, bool)
calculateBaseFeeFn func(*types.Header) uint64
nonce uint64
}

func NewDefaultMockStore(header *types.Header) defaultMockStore {
Expand All @@ -34,7 +35,7 @@ func (m defaultMockStore) Header() *types.Header {
}

func (m defaultMockStore) GetNonce(types.Hash, types.Address) uint64 {
return 0
return m.nonce
}

func (m defaultMockStore) GetBlockByHash(hash types.Hash, full bool) (*types.Block, bool) {
Expand Down
45 changes: 45 additions & 0 deletions txpool/txpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2055,6 +2055,51 @@ func Test_updateAccountSkipsCounts(t *testing.T) {
assert.Equal(t, slotsRequired(tx), pool.gauge.read())
checkTxExistence(t, pool, tx.Hash, true)
})

t.Run("drop should set nonce to current account nonce from store", func(t *testing.T) {
t.Parallel()

const storeNonce = uint64(10)

// create pool
store := defaultMockStore{
DefaultHeader: mockHeader,
nonce: storeNonce,
}

pool, err := newTestPool(store)
assert.NoError(t, err)

pool.SetSigner(&mockSigner{})

accountMap := pool.accounts.initOnce(addr1, storeNonce)
accountMap.enqueued.push(&types.Transaction{
Nonce: storeNonce + 2,
Hash: types.StringToHash("0xffa"),
})
accountMap.enqueued.push(&types.Transaction{
Nonce: storeNonce + 4,
Hash: types.StringToHash("0xff1"),
})
accountMap.promoted.push(&types.Transaction{
Nonce: storeNonce,
Hash: types.StringToHash("0xff2"),
})
accountMap.promoted.push(&types.Transaction{
Nonce: storeNonce + 1,
Hash: types.StringToHash("0xff3"),
})
accountMap.setNonce(storeNonce + 3)
accountMap.skips = maxAccountSkips - 1

pool.updateAccountSkipsCounts(map[types.Address]uint64{})

// make sure the account queue is empty and skips is reset
assert.Zero(t, accountMap.enqueued.length())
assert.Equal(t, uint64(0), accountMap.promoted.length())
assert.Equal(t, uint64(0), accountMap.skips)
assert.Equal(t, storeNonce, accountMap.getNonce())
})
}

func Test_TxPool_validateTx(t *testing.T) {
Expand Down

0 comments on commit ddd4963

Please sign in to comment.