mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
add eth_call tests
This commit is contained in:
parent
61eb793205
commit
28516b0314
4 changed files with 39 additions and 4 deletions
|
|
@ -104,4 +104,8 @@ var (
|
||||||
// ErrBlobFeeCapTooLow is returned if the transaction fee cap is less than the
|
// ErrBlobFeeCapTooLow is returned if the transaction fee cap is less than the
|
||||||
// blob gas fee of the block.
|
// blob gas fee of the block.
|
||||||
ErrBlobFeeCapTooLow = errors.New("max fee per blob gas less than block blob gas fee")
|
ErrBlobFeeCapTooLow = errors.New("max fee per blob gas less than block blob gas fee")
|
||||||
|
|
||||||
|
// ErrMissingBlobHashes is returned if a blob transaction has 0 blob hashes.
|
||||||
|
ErrMissingBlobHashes = errors.New("blob transaction missing blob hashes")
|
||||||
|
ErrBlobTxCreate = errors.New("blob transaction of type create")
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@
|
||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
@ -315,8 +314,11 @@ func (st *StateTransition) preCheck() error {
|
||||||
}
|
}
|
||||||
// Check the blob version validity
|
// Check the blob version validity
|
||||||
if msg.BlobHashes != nil {
|
if msg.BlobHashes != nil {
|
||||||
|
if msg.To == nil {
|
||||||
|
return ErrBlobTxCreate
|
||||||
|
}
|
||||||
if len(msg.BlobHashes) == 0 {
|
if len(msg.BlobHashes) == 0 {
|
||||||
return errors.New("blob transaction missing blob hashes")
|
return ErrMissingBlobHashes
|
||||||
}
|
}
|
||||||
for i, hash := range msg.BlobHashes {
|
for i, hash := range msg.BlobHashes {
|
||||||
if hash[0] != params.BlobTxHashVersion {
|
if hash[0] != params.BlobTxHashVersion {
|
||||||
|
|
|
||||||
|
|
@ -747,7 +747,7 @@ func TestCall(t *testing.T) {
|
||||||
var (
|
var (
|
||||||
accounts = newAccounts(3)
|
accounts = newAccounts(3)
|
||||||
genesis = &core.Genesis{
|
genesis = &core.Genesis{
|
||||||
Config: params.TestChainConfig,
|
Config: params.MergedTestChainConfig,
|
||||||
Alloc: core.GenesisAlloc{
|
Alloc: core.GenesisAlloc{
|
||||||
accounts[0].addr: {Balance: big.NewInt(params.Ether)},
|
accounts[0].addr: {Balance: big.NewInt(params.Ether)},
|
||||||
accounts[1].addr: {Balance: big.NewInt(params.Ether)},
|
accounts[1].addr: {Balance: big.NewInt(params.Ether)},
|
||||||
|
|
@ -757,12 +757,13 @@ func TestCall(t *testing.T) {
|
||||||
genBlocks = 10
|
genBlocks = 10
|
||||||
signer = types.HomesteadSigner{}
|
signer = types.HomesteadSigner{}
|
||||||
)
|
)
|
||||||
api := NewBlockChainAPI(newTestBackend(t, genBlocks, genesis, ethash.NewFaker(), func(i int, b *core.BlockGen) {
|
api := NewBlockChainAPI(newTestBackend(t, genBlocks, genesis, beacon.New(ethash.NewFaker()), func(i int, b *core.BlockGen) {
|
||||||
// Transfer from account[0] to account[1]
|
// Transfer from account[0] to account[1]
|
||||||
// value: 1000 wei
|
// value: 1000 wei
|
||||||
// fee: 0 wei
|
// fee: 0 wei
|
||||||
tx, _ := types.SignTx(types.NewTx(&types.LegacyTx{Nonce: uint64(i), To: &accounts[1].addr, Value: big.NewInt(1000), Gas: params.TxGas, GasPrice: b.BaseFee(), Data: nil}), signer, accounts[0].key)
|
tx, _ := types.SignTx(types.NewTx(&types.LegacyTx{Nonce: uint64(i), To: &accounts[1].addr, Value: big.NewInt(1000), Gas: params.TxGas, GasPrice: b.BaseFee(), Data: nil}), signer, accounts[0].key)
|
||||||
b.AddTx(tx)
|
b.AddTx(tx)
|
||||||
|
b.SetPoS()
|
||||||
}))
|
}))
|
||||||
randomAccounts := newAccounts(3)
|
randomAccounts := newAccounts(3)
|
||||||
var testSuite = []struct {
|
var testSuite = []struct {
|
||||||
|
|
@ -884,6 +885,32 @@ func TestCall(t *testing.T) {
|
||||||
blockOverrides: BlockOverrides{Number: (*hexutil.Big)(big.NewInt(11))},
|
blockOverrides: BlockOverrides{Number: (*hexutil.Big)(big.NewInt(11))},
|
||||||
want: "0x000000000000000000000000000000000000000000000000000000000000000b",
|
want: "0x000000000000000000000000000000000000000000000000000000000000000b",
|
||||||
},
|
},
|
||||||
|
// Invalid blob-tx
|
||||||
|
{
|
||||||
|
blockNumber: rpc.LatestBlockNumber,
|
||||||
|
call: TransactionArgs{
|
||||||
|
From: &accounts[1].addr,
|
||||||
|
Input: &hexutil.Bytes{0x00},
|
||||||
|
BlobVersionedHashes: []common.Hash{},
|
||||||
|
},
|
||||||
|
expectErr: core.ErrBlobTxCreate,
|
||||||
|
},
|
||||||
|
// BLOBHASH opcode
|
||||||
|
{
|
||||||
|
blockNumber: rpc.LatestBlockNumber,
|
||||||
|
call: TransactionArgs{
|
||||||
|
From: &accounts[1].addr,
|
||||||
|
To: &randomAccounts[2].addr,
|
||||||
|
BlobVersionedHashes: []common.Hash{common.Hash{0x01, 0x22}},
|
||||||
|
MaxFeePerBlobGas: (*hexutil.Big)(big.NewInt(1)),
|
||||||
|
},
|
||||||
|
overrides: StateOverride{
|
||||||
|
randomAccounts[2].addr: {
|
||||||
|
Code: hex2Bytes("60004960005260206000f3"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
want: "0x0122000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for i, tc := range testSuite {
|
for i, tc := range testSuite {
|
||||||
result, err := api.Call(context.Background(), tc.call, &rpc.BlockNumberOrHash{BlockNumber: &tc.blockNumber}, &tc.overrides, &tc.blockOverrides)
|
result, err := api.Call(context.Background(), tc.call, &rpc.BlockNumberOrHash{BlockNumber: &tc.blockNumber}, &tc.overrides, &tc.blockOverrides)
|
||||||
|
|
|
||||||
|
|
@ -311,6 +311,8 @@ func (args *TransactionArgs) ToMessage(globalGasCap uint64, baseFee *big.Int) (*
|
||||||
}
|
}
|
||||||
if args.MaxFeePerBlobGas != nil {
|
if args.MaxFeePerBlobGas != nil {
|
||||||
blobGasFeeCap = args.MaxFeePerBlobGas.ToInt()
|
blobGasFeeCap = args.MaxFeePerBlobGas.ToInt()
|
||||||
|
} else if args.BlobVersionedHashes != nil {
|
||||||
|
blobGasFeeCap = new(big.Int)
|
||||||
}
|
}
|
||||||
value := new(big.Int)
|
value := new(big.Int)
|
||||||
if args.Value != nil {
|
if args.Value != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue