|
|
@ -17,10 +17,12 @@
|
|
|
|
package core
|
|
|
|
package core
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
|
|
|
|
"crypto/ecdsa"
|
|
|
|
"math/big"
|
|
|
|
"math/big"
|
|
|
|
"testing"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common/math"
|
|
|
|
"github.com/ethereum/go-ethereum/consensus"
|
|
|
|
"github.com/ethereum/go-ethereum/consensus"
|
|
|
|
"github.com/ethereum/go-ethereum/consensus/ethash"
|
|
|
|
"github.com/ethereum/go-ethereum/consensus/ethash"
|
|
|
|
"github.com/ethereum/go-ethereum/consensus/misc"
|
|
|
|
"github.com/ethereum/go-ethereum/consensus/misc"
|
|
|
@ -54,11 +56,12 @@ func TestStateProcessorErrors(t *testing.T) {
|
|
|
|
LondonBlock: big.NewInt(0),
|
|
|
|
LondonBlock: big.NewInt(0),
|
|
|
|
Ethash: new(params.EthashConfig),
|
|
|
|
Ethash: new(params.EthashConfig),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
signer = types.LatestSigner(config)
|
|
|
|
signer = types.LatestSigner(config)
|
|
|
|
testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
|
|
|
key1, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
|
|
|
|
|
|
|
key2, _ = crypto.HexToECDSA("0202020202020202020202020202020202020202020202020202002020202020")
|
|
|
|
)
|
|
|
|
)
|
|
|
|
var makeTx = func(nonce uint64, to common.Address, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte) *types.Transaction {
|
|
|
|
var makeTx = func(key *ecdsa.PrivateKey, nonce uint64, to common.Address, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte) *types.Transaction {
|
|
|
|
tx, _ := types.SignTx(types.NewTransaction(nonce, to, amount, gasLimit, gasPrice, data), signer, testKey)
|
|
|
|
tx, _ := types.SignTx(types.NewTransaction(nonce, to, amount, gasLimit, gasPrice, data), signer, key)
|
|
|
|
return tx
|
|
|
|
return tx
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var mkDynamicTx = func(nonce uint64, to common.Address, gasLimit uint64, gasTipCap, gasFeeCap *big.Int) *types.Transaction {
|
|
|
|
var mkDynamicTx = func(nonce uint64, to common.Address, gasLimit uint64, gasTipCap, gasFeeCap *big.Int) *types.Transaction {
|
|
|
@ -69,7 +72,7 @@ func TestStateProcessorErrors(t *testing.T) {
|
|
|
|
Gas: gasLimit,
|
|
|
|
Gas: gasLimit,
|
|
|
|
To: &to,
|
|
|
|
To: &to,
|
|
|
|
Value: big.NewInt(0),
|
|
|
|
Value: big.NewInt(0),
|
|
|
|
}), signer, testKey)
|
|
|
|
}), signer, key1)
|
|
|
|
return tx
|
|
|
|
return tx
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{ // Tests against a 'recent' chain definition
|
|
|
|
{ // Tests against a 'recent' chain definition
|
|
|
@ -82,6 +85,10 @@ func TestStateProcessorErrors(t *testing.T) {
|
|
|
|
Balance: big.NewInt(1000000000000000000), // 1 ether
|
|
|
|
Balance: big.NewInt(1000000000000000000), // 1 ether
|
|
|
|
Nonce: 0,
|
|
|
|
Nonce: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
common.HexToAddress("0xfd0810DD14796680f72adf1a371963d0745BCc64"): GenesisAccount{
|
|
|
|
|
|
|
|
Balance: big.NewInt(1000000000000000000), // 1 ether
|
|
|
|
|
|
|
|
Nonce: math.MaxUint64,
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
genesis = gspec.MustCommit(db)
|
|
|
|
genesis = gspec.MustCommit(db)
|
|
|
@ -97,32 +104,38 @@ func TestStateProcessorErrors(t *testing.T) {
|
|
|
|
}{
|
|
|
|
}{
|
|
|
|
{ // ErrNonceTooLow
|
|
|
|
{ // ErrNonceTooLow
|
|
|
|
txs: []*types.Transaction{
|
|
|
|
txs: []*types.Transaction{
|
|
|
|
makeTx(0, common.Address{}, big.NewInt(0), params.TxGas, big.NewInt(875000000), nil),
|
|
|
|
makeTx(key1, 0, common.Address{}, big.NewInt(0), params.TxGas, big.NewInt(875000000), nil),
|
|
|
|
makeTx(0, common.Address{}, big.NewInt(0), params.TxGas, big.NewInt(875000000), nil),
|
|
|
|
makeTx(key1, 0, common.Address{}, big.NewInt(0), params.TxGas, big.NewInt(875000000), nil),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: "could not apply tx 1 [0x0026256b3939ed97e2c4a6f3fce8ecf83bdcfa6d507c47838c308a1fb0436f62]: nonce too low: address 0x71562b71999873DB5b286dF957af199Ec94617F7, tx: 0 state: 1",
|
|
|
|
want: "could not apply tx 1 [0x0026256b3939ed97e2c4a6f3fce8ecf83bdcfa6d507c47838c308a1fb0436f62]: nonce too low: address 0x71562b71999873DB5b286dF957af199Ec94617F7, tx: 0 state: 1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{ // ErrNonceTooHigh
|
|
|
|
{ // ErrNonceTooHigh
|
|
|
|
txs: []*types.Transaction{
|
|
|
|
txs: []*types.Transaction{
|
|
|
|
makeTx(100, common.Address{}, big.NewInt(0), params.TxGas, big.NewInt(875000000), nil),
|
|
|
|
makeTx(key1, 100, common.Address{}, big.NewInt(0), params.TxGas, big.NewInt(875000000), nil),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: "could not apply tx 0 [0xdebad714ca7f363bd0d8121c4518ad48fa469ca81b0a081be3d10c17460f751b]: nonce too high: address 0x71562b71999873DB5b286dF957af199Ec94617F7, tx: 100 state: 0",
|
|
|
|
want: "could not apply tx 0 [0xdebad714ca7f363bd0d8121c4518ad48fa469ca81b0a081be3d10c17460f751b]: nonce too high: address 0x71562b71999873DB5b286dF957af199Ec94617F7, tx: 100 state: 0",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{ // ErrNonceMax
|
|
|
|
|
|
|
|
txs: []*types.Transaction{
|
|
|
|
|
|
|
|
makeTx(key2, math.MaxUint64, common.Address{}, big.NewInt(0), params.TxGas, big.NewInt(875000000), nil),
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
want: "could not apply tx 0 [0x84ea18d60eb2bb3b040e3add0eb72f757727122cc257dd858c67cb6591a85986]: nonce has max value: address 0xfd0810DD14796680f72adf1a371963d0745BCc64, nonce: 18446744073709551615",
|
|
|
|
|
|
|
|
},
|
|
|
|
{ // ErrGasLimitReached
|
|
|
|
{ // ErrGasLimitReached
|
|
|
|
txs: []*types.Transaction{
|
|
|
|
txs: []*types.Transaction{
|
|
|
|
makeTx(0, common.Address{}, big.NewInt(0), 21000000, big.NewInt(875000000), nil),
|
|
|
|
makeTx(key1, 0, common.Address{}, big.NewInt(0), 21000000, big.NewInt(875000000), nil),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: "could not apply tx 0 [0xbd49d8dadfd47fb846986695f7d4da3f7b2c48c8da82dbc211a26eb124883de9]: gas limit reached",
|
|
|
|
want: "could not apply tx 0 [0xbd49d8dadfd47fb846986695f7d4da3f7b2c48c8da82dbc211a26eb124883de9]: gas limit reached",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{ // ErrInsufficientFundsForTransfer
|
|
|
|
{ // ErrInsufficientFundsForTransfer
|
|
|
|
txs: []*types.Transaction{
|
|
|
|
txs: []*types.Transaction{
|
|
|
|
makeTx(0, common.Address{}, big.NewInt(1000000000000000000), params.TxGas, big.NewInt(875000000), nil),
|
|
|
|
makeTx(key1, 0, common.Address{}, big.NewInt(1000000000000000000), params.TxGas, big.NewInt(875000000), nil),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: "could not apply tx 0 [0x98c796b470f7fcab40aaef5c965a602b0238e1034cce6fb73823042dd0638d74]: insufficient funds for gas * price + value: address 0x71562b71999873DB5b286dF957af199Ec94617F7 have 1000000000000000000 want 1000018375000000000",
|
|
|
|
want: "could not apply tx 0 [0x98c796b470f7fcab40aaef5c965a602b0238e1034cce6fb73823042dd0638d74]: insufficient funds for gas * price + value: address 0x71562b71999873DB5b286dF957af199Ec94617F7 have 1000000000000000000 want 1000018375000000000",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{ // ErrInsufficientFunds
|
|
|
|
{ // ErrInsufficientFunds
|
|
|
|
txs: []*types.Transaction{
|
|
|
|
txs: []*types.Transaction{
|
|
|
|
makeTx(0, common.Address{}, big.NewInt(0), params.TxGas, big.NewInt(900000000000000000), nil),
|
|
|
|
makeTx(key1, 0, common.Address{}, big.NewInt(0), params.TxGas, big.NewInt(900000000000000000), nil),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: "could not apply tx 0 [0x4a69690c4b0cd85e64d0d9ea06302455b01e10a83db964d60281739752003440]: insufficient funds for gas * price + value: address 0x71562b71999873DB5b286dF957af199Ec94617F7 have 1000000000000000000 want 18900000000000000000000",
|
|
|
|
want: "could not apply tx 0 [0x4a69690c4b0cd85e64d0d9ea06302455b01e10a83db964d60281739752003440]: insufficient funds for gas * price + value: address 0x71562b71999873DB5b286dF957af199Ec94617F7 have 1000000000000000000 want 18900000000000000000000",
|
|
|
|
},
|
|
|
|
},
|
|
|
@ -132,13 +145,13 @@ func TestStateProcessorErrors(t *testing.T) {
|
|
|
|
// multiplication len(data) +gas_per_byte overflows uint64. Not testable at the moment
|
|
|
|
// multiplication len(data) +gas_per_byte overflows uint64. Not testable at the moment
|
|
|
|
{ // ErrIntrinsicGas
|
|
|
|
{ // ErrIntrinsicGas
|
|
|
|
txs: []*types.Transaction{
|
|
|
|
txs: []*types.Transaction{
|
|
|
|
makeTx(0, common.Address{}, big.NewInt(0), params.TxGas-1000, big.NewInt(875000000), nil),
|
|
|
|
makeTx(key1, 0, common.Address{}, big.NewInt(0), params.TxGas-1000, big.NewInt(875000000), nil),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: "could not apply tx 0 [0xcf3b049a0b516cb4f9274b3e2a264359e2ba53b2fb64b7bda2c634d5c9d01fca]: intrinsic gas too low: have 20000, want 21000",
|
|
|
|
want: "could not apply tx 0 [0xcf3b049a0b516cb4f9274b3e2a264359e2ba53b2fb64b7bda2c634d5c9d01fca]: intrinsic gas too low: have 20000, want 21000",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{ // ErrGasLimitReached
|
|
|
|
{ // ErrGasLimitReached
|
|
|
|
txs: []*types.Transaction{
|
|
|
|
txs: []*types.Transaction{
|
|
|
|
makeTx(0, common.Address{}, big.NewInt(0), params.TxGas*1000, big.NewInt(875000000), nil),
|
|
|
|
makeTx(key1, 0, common.Address{}, big.NewInt(0), params.TxGas*1000, big.NewInt(875000000), nil),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: "could not apply tx 0 [0xbd49d8dadfd47fb846986695f7d4da3f7b2c48c8da82dbc211a26eb124883de9]: gas limit reached",
|
|
|
|
want: "could not apply tx 0 [0xbd49d8dadfd47fb846986695f7d4da3f7b2c48c8da82dbc211a26eb124883de9]: gas limit reached",
|
|
|
|
},
|
|
|
|
},
|
|
|
|