2021-06-11 08:34:47 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2021-10-28 14:18:34 +00:00
|
|
|
"fmt"
|
2021-06-11 08:34:47 +00:00
|
|
|
"testing"
|
|
|
|
|
2021-06-27 06:41:21 +00:00
|
|
|
"github.com/holiman/uint256"
|
2021-07-01 21:31:14 +00:00
|
|
|
"github.com/ledgerwatch/erigon-lib/gointerfaces/txpool"
|
2021-10-28 14:18:34 +00:00
|
|
|
txPoolProto "github.com/ledgerwatch/erigon-lib/gointerfaces/txpool"
|
2021-09-29 01:36:25 +00:00
|
|
|
"github.com/ledgerwatch/erigon-lib/kv/kvcache"
|
2021-06-29 10:00:22 +00:00
|
|
|
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/rpcdaemontest"
|
2021-06-11 08:34:47 +00:00
|
|
|
"github.com/ledgerwatch/erigon/common"
|
2021-08-06 02:45:44 +00:00
|
|
|
"github.com/ledgerwatch/erigon/common/hexutil"
|
2021-06-27 06:41:21 +00:00
|
|
|
"github.com/ledgerwatch/erigon/core"
|
|
|
|
"github.com/ledgerwatch/erigon/core/types"
|
|
|
|
"github.com/ledgerwatch/erigon/params"
|
2022-06-10 15:18:43 +00:00
|
|
|
"github.com/ledgerwatch/erigon/turbo/rpchelper"
|
2021-11-14 04:08:52 +00:00
|
|
|
"github.com/ledgerwatch/erigon/turbo/snapshotsync"
|
2021-06-27 06:41:21 +00:00
|
|
|
"github.com/ledgerwatch/erigon/turbo/stages"
|
2021-06-11 08:34:47 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestTxPoolContent(t *testing.T) {
|
2021-10-28 14:18:34 +00:00
|
|
|
m, require := stages.MockWithTxPool(t), require.New(t)
|
2021-06-27 06:41:21 +00:00
|
|
|
chain, err := core.GenerateChain(m.ChainConfig, m.Genesis, m.Engine, m.DB, 1, func(i int, b *core.BlockGen) {
|
|
|
|
b.SetCoinbase(common.Address{1})
|
2022-03-03 15:09:03 +00:00
|
|
|
}, false /* intermediateHashes */)
|
2021-06-27 06:41:21 +00:00
|
|
|
require.NoError(err)
|
2021-10-25 10:15:56 +00:00
|
|
|
err = m.InsertChain(chain)
|
|
|
|
require.NoError(err)
|
2021-06-27 06:41:21 +00:00
|
|
|
|
2021-06-29 10:00:22 +00:00
|
|
|
ctx, conn := rpcdaemontest.CreateTestGrpcConn(t, m)
|
2021-06-11 08:34:47 +00:00
|
|
|
txPool := txpool.NewTxpoolClient(conn)
|
2022-06-10 15:18:43 +00:00
|
|
|
ff := rpchelper.New(ctx, nil, txPool, txpool.NewMiningClient(conn), func() {})
|
2021-11-14 04:08:52 +00:00
|
|
|
api := NewTxPoolAPI(NewBaseApi(ff, kvcache.New(kvcache.DefaultCoherentConfig), snapshotsync.NewBlockReader(), false), m.DB, txPool)
|
2021-06-27 06:41:21 +00:00
|
|
|
|
|
|
|
expectValue := uint64(1234)
|
2021-10-28 14:18:34 +00:00
|
|
|
txn, err := types.SignTx(types.NewTransaction(0, common.Address{1}, uint256.NewInt(expectValue), params.TxGas, uint256.NewInt(10*params.GWei), nil), *types.LatestSignerForChainID(m.ChainConfig.ChainID), m.Key)
|
2021-06-27 06:41:21 +00:00
|
|
|
require.NoError(err)
|
2021-06-11 08:34:47 +00:00
|
|
|
|
|
|
|
buf := bytes.NewBuffer(nil)
|
2021-06-27 06:41:21 +00:00
|
|
|
err = txn.MarshalBinary(buf)
|
|
|
|
require.NoError(err)
|
2021-06-11 08:34:47 +00:00
|
|
|
|
2021-10-28 14:18:34 +00:00
|
|
|
reply, err := txPool.Add(ctx, &txpool.AddRequest{RlpTxs: [][]byte{buf.Bytes()}})
|
2021-06-27 06:41:21 +00:00
|
|
|
require.NoError(err)
|
2021-10-28 14:18:34 +00:00
|
|
|
for _, res := range reply.Imported {
|
|
|
|
require.Equal(res, txPoolProto.ImportResult_SUCCESS, fmt.Sprintf("%s", reply.Errors))
|
|
|
|
}
|
|
|
|
|
2021-06-11 08:34:47 +00:00
|
|
|
content, err := api.Content(ctx)
|
2021-06-27 06:41:21 +00:00
|
|
|
require.NoError(err)
|
2021-06-11 08:34:47 +00:00
|
|
|
|
2021-06-27 06:41:21 +00:00
|
|
|
sender := m.Address.String()
|
|
|
|
require.Equal(1, len(content["pending"][sender]))
|
|
|
|
require.Equal(expectValue, content["pending"][sender]["0"].Value.ToInt().Uint64())
|
2021-08-06 02:45:44 +00:00
|
|
|
|
|
|
|
status, err := api.Status(ctx)
|
|
|
|
require.NoError(err)
|
2021-09-08 05:31:51 +00:00
|
|
|
require.Len(status, 3)
|
2021-08-06 02:45:44 +00:00
|
|
|
require.Equal(status["pending"], hexutil.Uint(1))
|
|
|
|
require.Equal(status["queued"], hexutil.Uint(0))
|
2021-06-11 08:34:47 +00:00
|
|
|
}
|