mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 11:41:19 +00:00
Remove chain id check for non-eip155 and fix a test (#8404)
Correcting a mistake in PR #8400 and a workaround for TestSendRawTransaction
This commit is contained in:
parent
57cc5ccc6d
commit
73e2bad897
@ -45,11 +45,12 @@ func (api *APIImpl) SendRawTransaction(ctx context.Context, encodedTx hexutility
|
||||
return common.Hash{}, err
|
||||
}
|
||||
|
||||
txnChainId := txn.GetChainID()
|
||||
chainId := cc.ChainID
|
||||
|
||||
if (txn.Protected() || !api.AllowUnprotectedTxs) && chainId.Cmp(txnChainId.ToBig()) != 0 {
|
||||
return common.Hash{}, fmt.Errorf("invalid chain id, expected: %d got: %d", chainId, *txnChainId)
|
||||
if txn.Protected() {
|
||||
txnChainId := txn.GetChainID()
|
||||
chainId := cc.ChainID
|
||||
if chainId.Cmp(txnChainId.ToBig()) != 0 {
|
||||
return common.Hash{}, fmt.Errorf("invalid chain id, expected: %d got: %d", chainId, *txnChainId)
|
||||
}
|
||||
}
|
||||
|
||||
hash := txn.Hash()
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"crypto/ecdsa"
|
||||
"math/big"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/holiman/uint256"
|
||||
"github.com/ledgerwatch/erigon-lib/common"
|
||||
@ -80,8 +81,8 @@ func TestSendRawTransaction(t *testing.T) {
|
||||
|
||||
oneBlockStep(mockSentry, require, t)
|
||||
|
||||
expectValue := uint64(1234)
|
||||
txn, err := types.SignTx(types.NewTransaction(0, common.Address{1}, uint256.NewInt(expectValue), params.TxGas, uint256.NewInt(10*params.GWei), nil), *types.LatestSignerForChainID(mockSentry.ChainConfig.ChainID), mockSentry.Key)
|
||||
expectedValue := uint64(1234)
|
||||
txn, err := types.SignTx(types.NewTransaction(0, common.Address{1}, uint256.NewInt(expectedValue), params.TxGas, uint256.NewInt(10*params.GWei), nil), *types.LatestSignerForChainID(mockSentry.ChainConfig.ChainID), mockSentry.Key)
|
||||
require.NoError(err)
|
||||
|
||||
ctx, conn := rpcdaemontest.CreateTestGrpcConn(t, mockSentry)
|
||||
@ -96,11 +97,18 @@ func TestSendRawTransaction(t *testing.T) {
|
||||
txsCh, id := ff.SubscribePendingTxs(1)
|
||||
defer ff.UnsubscribePendingTxs(id)
|
||||
|
||||
_, err = api.SendRawTransaction(ctx, buf.Bytes())
|
||||
txHash, err := api.SendRawTransaction(ctx, buf.Bytes())
|
||||
require.NoError(err)
|
||||
|
||||
got := <-txsCh
|
||||
require.Equal(expectValue, got[0].GetValue().Uint64())
|
||||
select {
|
||||
case got := <-txsCh:
|
||||
require.Equal(expectedValue, got[0].GetValue().Uint64())
|
||||
case <-time.After(20 * time.Second): // Sometimes the channel times out on github actions
|
||||
t.Log("Timeout waiting for txn from channel")
|
||||
jsonTx, err := api.GetTransactionByHash(ctx, txHash)
|
||||
require.NoError(err)
|
||||
require.Equal(expectedValue+1, jsonTx.Value.Uint64())
|
||||
}
|
||||
|
||||
//send same tx second time and expect error
|
||||
_, err = api.SendRawTransaction(ctx, buf.Bytes())
|
||||
@ -144,11 +152,18 @@ func TestSendRawTransactionUnprotected(t *testing.T) {
|
||||
txsCh, id := ff.SubscribePendingTxs(1)
|
||||
defer ff.UnsubscribePendingTxs(id)
|
||||
|
||||
_, err = api.SendRawTransaction(ctx, buf.Bytes())
|
||||
txHash, err := api.SendRawTransaction(ctx, buf.Bytes())
|
||||
require.NoError(err)
|
||||
|
||||
got := <-txsCh
|
||||
require.Equal(expectedTxValue, got[0].GetValue().Uint64())
|
||||
select {
|
||||
case got := <-txsCh:
|
||||
require.Equal(expectedTxValue, got[0].GetValue().Uint64())
|
||||
case <-time.After(20 * time.Second): // Sometimes the channel times out on github actions
|
||||
t.Log("Timeout waiting for txn from channel")
|
||||
jsonTx, err := api.GetTransactionByHash(ctx, txHash)
|
||||
require.NoError(err)
|
||||
require.Equal(expectedTxValue, jsonTx.Value.Uint64())
|
||||
}
|
||||
}
|
||||
|
||||
func transaction(nonce uint64, gaslimit uint64, key *ecdsa.PrivateKey) types.Transaction {
|
||||
|
Loading…
Reference in New Issue
Block a user