2021-05-04 01:37:17 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"context"
|
|
|
|
"crypto/ecdsa"
|
|
|
|
"math/big"
|
|
|
|
"testing"
|
2021-05-04 16:12:59 +00:00
|
|
|
"time"
|
2021-05-04 01:37:17 +00:00
|
|
|
|
|
|
|
"github.com/holiman/uint256"
|
2021-05-20 18:25:53 +00:00
|
|
|
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/filters"
|
|
|
|
"github.com/ledgerwatch/erigon/common"
|
|
|
|
"github.com/ledgerwatch/erigon/common/u256"
|
|
|
|
"github.com/ledgerwatch/erigon/core/types"
|
|
|
|
"github.com/ledgerwatch/erigon/crypto"
|
|
|
|
"github.com/ledgerwatch/erigon/gointerfaces/txpool"
|
2021-05-04 01:37:17 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSendRawTransaction(t *testing.T) {
|
2021-05-16 18:09:12 +00:00
|
|
|
t.Skip("Flaky test")
|
2021-05-04 01:37:17 +00:00
|
|
|
db, err := createTestKV()
|
|
|
|
require.NoError(t, err)
|
|
|
|
defer db.Close()
|
|
|
|
conn := createTestGrpcConn()
|
|
|
|
defer conn.Close()
|
|
|
|
txPool := txpool.NewTxpoolClient(conn)
|
2021-05-17 12:15:19 +00:00
|
|
|
ff := filters.New(context.Background(), nil, txPool, nil)
|
|
|
|
api := NewEthAPI(NewBaseApi(ff), db, nil, txPool, nil, 5000000)
|
2021-05-04 01:37:17 +00:00
|
|
|
|
|
|
|
// Call GetTransactionReceipt for un-protected transaction
|
|
|
|
var testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
2021-05-17 12:15:19 +00:00
|
|
|
expect := uint64(40)
|
|
|
|
txn := transaction(expect, 1000000, testKey)
|
2021-05-04 01:37:17 +00:00
|
|
|
buf := bytes.NewBuffer(nil)
|
|
|
|
err = txn.MarshalBinary(buf)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
txsCh := make(chan []types.Transaction, 1)
|
|
|
|
defer close(txsCh)
|
|
|
|
id := api.filters.SubscribePendingTxs(txsCh)
|
|
|
|
defer api.filters.UnsubscribePendingTxs(id)
|
|
|
|
|
|
|
|
_, err = api.SendRawTransaction(context.Background(), buf.Bytes())
|
|
|
|
require.NoError(t, err)
|
|
|
|
select {
|
2021-05-17 12:15:19 +00:00
|
|
|
case got := <-txsCh:
|
|
|
|
require.Equal(t, expect, got[0].GetNonce())
|
2021-05-04 16:12:59 +00:00
|
|
|
case <-time.After(100 * time.Millisecond):
|
|
|
|
t.Fatalf("timeout waiting for expected notification")
|
2021-05-04 01:37:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func transaction(nonce uint64, gaslimit uint64, key *ecdsa.PrivateKey) types.Transaction {
|
|
|
|
return pricedTransaction(nonce, gaslimit, u256.Num1, key)
|
|
|
|
}
|
|
|
|
|
|
|
|
func pricedTransaction(nonce uint64, gaslimit uint64, gasprice *uint256.Int, key *ecdsa.PrivateKey) types.Transaction {
|
2021-06-04 16:25:28 +00:00
|
|
|
tx, _ := types.SignTx(types.NewTransaction(nonce, common.Address{}, uint256.NewInt(100), gaslimit, gasprice, nil), *types.LatestSignerForChainID(big.NewInt(1337)), key)
|
2021-05-04 01:37:17 +00:00
|
|
|
return tx
|
|
|
|
}
|