erigon-pulse/cmd/rpcdaemon/commands/txpool_api_test.go
Alex Sharov eedabfca85
txpool_content (#2127)
* txpool_content

* txpool_content

* txpool_content

* txpool_content

* Squashed 'interfaces/' content from commit 1e916d013

git-subtree-dir: interfaces
git-subtree-split: 1e916d0137aff7bd9e9356cc203cea5f0ea9c7f1

* add test

* add test

* add test

* merge devel

* save
2021-06-11 09:34:47 +01:00

38 lines
1.2 KiB
Go

package commands
import (
"bytes"
"testing"
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/filters"
"github.com/ledgerwatch/erigon/common"
"github.com/ledgerwatch/erigon/crypto"
"github.com/ledgerwatch/erigon/gointerfaces/txpool"
"github.com/stretchr/testify/require"
)
func TestTxPoolContent(t *testing.T) {
db := createTestKV(t)
ctx, conn := createTestGrpcConn(t)
txPool := txpool.NewTxpoolClient(conn)
ff := filters.New(ctx, nil, txPool, txpool.NewMiningClient(conn))
api := NewTxPoolAPI(NewBaseApi(ff), db, txPool)
// Call GetTransactionReceipt for un-protected transaction
var testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
expect := uint64(40)
txn := transaction(expect, 1000000, testKey)
buf := bytes.NewBuffer(nil)
err := txn.MarshalBinary(buf)
require.NoError(t, err)
_, err = txPool.Add(ctx, &txpool.AddRequest{RlpTxs: [][]byte{buf.Bytes()}})
require.NoError(t, err)
content, err := api.Content(ctx)
require.NoError(t, err)
sender := (common.Address{}).String()
require.Equal(t, 1, len(content["pending"][sender]))
require.Equal(t, expect, uint64(content["pending"][sender]["40"].Nonce))
}