Merge branch 'ethereum:master' into fix/linter-usetesting

This commit is contained in:
levisyin 2025-02-21 10:44:43 +08:00 committed by GitHub
commit afb9691bb6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 123 additions and 61 deletions

View file

@ -23,7 +23,7 @@ jobs:
- name: Set up Go - name: Set up Go
uses: actions/setup-go@v5 uses: actions/setup-go@v5
with: with:
go-version: 1.24.0 go-version: 1.23.0
cache: false cache: false
- name: Run linters - name: Run linters

View file

@ -149,6 +149,10 @@ func pricedSetCodeTx(nonce uint64, gaslimit uint64, gasFee, tip *uint256.Int, ke
}) })
authList = append(authList, auth) authList = append(authList, auth)
} }
return pricedSetCodeTxWithAuth(nonce, gaslimit, gasFee, tip, key, authList)
}
func pricedSetCodeTxWithAuth(nonce uint64, gaslimit uint64, gasFee, tip *uint256.Int, key *ecdsa.PrivateKey, authList []types.SetCodeAuthorization) *types.Transaction {
return types.MustSignNewTx(key, types.LatestSignerForChainID(params.TestChainConfig.ChainID), &types.SetCodeTx{ return types.MustSignNewTx(key, types.LatestSignerForChainID(params.TestChainConfig.ChainID), &types.SetCodeTx{
ChainID: uint256.MustFromBig(params.TestChainConfig.ChainID), ChainID: uint256.MustFromBig(params.TestChainConfig.ChainID),
Nonce: nonce, Nonce: nonce,
@ -2393,6 +2397,65 @@ func TestSetCodeTransactions(t *testing.T) {
} }
} }
func TestSetCodeTransactionsReorg(t *testing.T) {
t.Parallel()
// Create the pool to test the status retrievals with
statedb, _ := state.New(types.EmptyRootHash, state.NewDatabaseForTesting())
blockchain := newTestBlockChain(params.MergedTestChainConfig, 1000000, statedb, new(event.Feed))
pool := New(testTxPoolConfig, blockchain)
pool.Init(testTxPoolConfig.PriceLimit, blockchain.CurrentBlock(), makeAddressReserver())
defer pool.Close()
// Create the test accounts
var (
keyA, _ = crypto.GenerateKey()
addrA = crypto.PubkeyToAddress(keyA.PublicKey)
)
testAddBalance(pool, addrA, big.NewInt(params.Ether))
// Send an authorization for 0x42
var authList []types.SetCodeAuthorization
auth, _ := types.SignSetCode(keyA, types.SetCodeAuthorization{
ChainID: *uint256.MustFromBig(params.TestChainConfig.ChainID),
Address: common.Address{0x42},
Nonce: 0,
})
authList = append(authList, auth)
if err := pool.addRemoteSync(pricedSetCodeTxWithAuth(0, 250000, uint256.NewInt(10), uint256.NewInt(3), keyA, authList)); err != nil {
t.Fatalf("failed to add with remote setcode transaction: %v", err)
}
// Simulate the chain moving
blockchain.statedb.SetNonce(addrA, 1, tracing.NonceChangeAuthorization)
blockchain.statedb.SetCode(addrA, types.AddressToDelegation(auth.Address))
<-pool.requestReset(nil, nil)
// Set an authorization for 0x00
auth, _ = types.SignSetCode(keyA, types.SetCodeAuthorization{
ChainID: *uint256.MustFromBig(params.TestChainConfig.ChainID),
Address: common.Address{},
Nonce: 0,
})
authList = append(authList, auth)
if err := pool.addRemoteSync(pricedSetCodeTxWithAuth(1, 250000, uint256.NewInt(10), uint256.NewInt(3), keyA, authList)); err != nil {
t.Fatalf("failed to add with remote setcode transaction: %v", err)
}
// Try to add a transactions in
if err := pool.addRemoteSync(pricedTransaction(2, 100000, big.NewInt(1000), keyA)); !errors.Is(err, txpool.ErrAccountLimitExceeded) {
t.Fatalf("unexpected error %v, expecting %v", err, txpool.ErrAccountLimitExceeded)
}
// Simulate the chain moving
blockchain.statedb.SetNonce(addrA, 2, tracing.NonceChangeAuthorization)
blockchain.statedb.SetCode(addrA, nil)
<-pool.requestReset(nil, nil)
// Now send two transactions from addrA
if err := pool.addRemoteSync(pricedTransaction(2, 100000, big.NewInt(1000), keyA)); err != nil {
t.Fatalf("failed to added single transaction: %v", err)
}
if err := pool.addRemoteSync(pricedTransaction(3, 100000, big.NewInt(1000), keyA)); err != nil {
t.Fatalf("failed to added single transaction: %v", err)
}
}
// Benchmarks the speed of validating the contents of the pending queue of the // Benchmarks the speed of validating the contents of the pending queue of the
// transaction pool. // transaction pool.
func BenchmarkPendingDemotion100(b *testing.B) { benchmarkPendingDemotion(b, 100) } func BenchmarkPendingDemotion100(b *testing.B) { benchmarkPendingDemotion(b, 100) }

View file

@ -65,10 +65,7 @@ type callTrace struct {
// callTracerTest defines a single test to check the call tracer against. // callTracerTest defines a single test to check the call tracer against.
type callTracerTest struct { type callTracerTest struct {
Genesis *core.Genesis `json:"genesis"` tracerTestEnv
Context *callContext `json:"context"`
Input string `json:"input"`
TracerConfig json.RawMessage `json:"tracerConfig"`
Result *callTrace `json:"result"` Result *callTrace `json:"result"`
} }

View file

@ -77,10 +77,7 @@ type flatCallTraceResult struct {
// flatCallTracerTest defines a single test to check the call tracer against. // flatCallTracerTest defines a single test to check the call tracer against.
type flatCallTracerTest struct { type flatCallTracerTest struct {
Genesis *core.Genesis `json:"genesis"` tracerTestEnv
Context *callContext `json:"context"`
Input string `json:"input"`
TracerConfig json.RawMessage `json:"tracerConfig"`
Result []flatCallTrace `json:"result"` Result []flatCallTrace `json:"result"`
} }

View file

@ -31,6 +31,9 @@ var makeTest = function(tx, traceConfig) {
delete genesis.transactions; delete genesis.transactions;
delete genesis.transactionsRoot; delete genesis.transactionsRoot;
delete genesis.uncles; delete genesis.uncles;
delete genesis.withdrawals;
delete genesis.withdrawalsRoot;
delete genesis.baseFeePerGas;
genesis.gasLimit = genesis.gasLimit.toString(); genesis.gasLimit = genesis.gasLimit.toString();
genesis.number = genesis.number.toString(); genesis.number = genesis.number.toString();
@ -60,11 +63,15 @@ var makeTest = function(tx, traceConfig) {
context.baseFeePerGas = block.baseFeePerGas.toString(); context.baseFeePerGas = block.baseFeePerGas.toString();
} }
console.log(JSON.stringify({ var data = {
genesis: genesis, genesis: genesis,
context: context, context: context,
input: eth.getRawTransaction(tx), input: eth.getRawTransaction(tx),
result: result, result: result,
tracerConfig: traceConfig.tracerConfig, };
}, null, 2)); if (traceConfig && traceConfig.tracerConfig) {
data.tracerConfig = traceConfig.tracerConfig;
}
console.log(JSON.stringify(data, null, 2));
} }

View file

@ -43,28 +43,25 @@ type account struct {
Storage map[common.Hash]common.Hash `json:"storage"` Storage map[common.Hash]common.Hash `json:"storage"`
} }
// testcase defines a single test to check the stateDiff tracer against. // prestateTracerTest defines a single test to check the stateDiff tracer against.
type testcase struct { type prestateTracerTest struct {
Genesis *core.Genesis `json:"genesis"` tracerTestEnv
Context *callContext `json:"context"`
Input string `json:"input"`
TracerConfig json.RawMessage `json:"tracerConfig"`
Result interface{} `json:"result"` Result interface{} `json:"result"`
} }
func TestPrestateTracerLegacy(t *testing.T) { func TestPrestateTracerLegacy(t *testing.T) {
testPrestateDiffTracer("prestateTracerLegacy", "prestate_tracer_legacy", t) testPrestateTracer("prestateTracerLegacy", "prestate_tracer_legacy", t)
} }
func TestPrestateTracer(t *testing.T) { func TestPrestateTracer(t *testing.T) {
testPrestateDiffTracer("prestateTracer", "prestate_tracer", t) testPrestateTracer("prestateTracer", "prestate_tracer", t)
} }
func TestPrestateWithDiffModeTracer(t *testing.T) { func TestPrestateWithDiffModeTracer(t *testing.T) {
testPrestateDiffTracer("prestateTracer", "prestate_tracer_with_diff_mode", t) testPrestateTracer("prestateTracer", "prestate_tracer_with_diff_mode", t)
} }
func testPrestateDiffTracer(tracerName string, dirPath string, t *testing.T) { func testPrestateTracer(tracerName string, dirPath string, t *testing.T) {
files, err := os.ReadDir(filepath.Join("testdata", dirPath)) files, err := os.ReadDir(filepath.Join("testdata", dirPath))
if err != nil { if err != nil {
t.Fatalf("failed to retrieve tracer test suite: %v", err) t.Fatalf("failed to retrieve tracer test suite: %v", err)
@ -77,7 +74,7 @@ func testPrestateDiffTracer(tracerName string, dirPath string, t *testing.T) {
t.Parallel() t.Parallel()
var ( var (
test = new(testcase) test = new(prestateTracerTest)
tx = new(types.Transaction) tx = new(types.Transaction)
) )
// Call tracer test found, read if from disk // Call tracer test found, read if from disk

View file

@ -14,8 +14,6 @@
"parentBeaconBlockRoot": "0x0000000000000000000000000000000000000000000000000000000000000000", "parentBeaconBlockRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
"stateRoot": "0x577f42ab21ccfd946511c57869ace0bdf7c217c36f02b7cd3459df0ed1cffc1a", "stateRoot": "0x577f42ab21ccfd946511c57869ace0bdf7c217c36f02b7cd3459df0ed1cffc1a",
"timestamp": "1709626771", "timestamp": "1709626771",
"withdrawals": [],
"withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"alloc": { "alloc": {
"0x0000000000000000000000000000000000000000": { "0x0000000000000000000000000000000000000000": {
"balance": "0x272e0528" "balance": "0x272e0528"

View file

@ -14,8 +14,6 @@
"parentBeaconBlockRoot": "0x0000000000000000000000000000000000000000000000000000000000000000", "parentBeaconBlockRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
"stateRoot": "0x577f42ab21ccfd946511c57869ace0bdf7c217c36f02b7cd3459df0ed1cffc1a", "stateRoot": "0x577f42ab21ccfd946511c57869ace0bdf7c217c36f02b7cd3459df0ed1cffc1a",
"timestamp": "1709626771", "timestamp": "1709626771",
"withdrawals": [],
"withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"alloc": { "alloc": {
"0x0000000000000000000000000000000000000000": { "0x0000000000000000000000000000000000000000": {
"balance": "0x272e0528" "balance": "0x272e0528"

View file

@ -11,8 +11,6 @@
"number": "1", "number": "1",
"stateRoot": "0xd2ebe0a7f3572ffe3e5b4c78147376d3fca767f236e4dd23f9151acfec7cb0d1", "stateRoot": "0xd2ebe0a7f3572ffe3e5b4c78147376d3fca767f236e4dd23f9151acfec7cb0d1",
"timestamp": "1699617692", "timestamp": "1699617692",
"withdrawals": [],
"withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"alloc": { "alloc": {
"0x0000000000000000000000000000000000000000": { "0x0000000000000000000000000000000000000000": {
"balance": "0x5208" "balance": "0x5208"

View file

@ -17,6 +17,7 @@
package tracetest package tracetest
import ( import (
"encoding/json"
"math/big" "math/big"
"strings" "strings"
"unicode" "unicode"
@ -42,7 +43,8 @@ func camel(str string) string {
return strings.Join(pieces, "") return strings.Join(pieces, "")
} }
type callContext struct { // traceContext defines a context used to construct the block context
type traceContext struct {
Number math.HexOrDecimal64 `json:"number"` Number math.HexOrDecimal64 `json:"number"`
Difficulty *math.HexOrDecimal256 `json:"difficulty"` Difficulty *math.HexOrDecimal256 `json:"difficulty"`
Time math.HexOrDecimal64 `json:"timestamp"` Time math.HexOrDecimal64 `json:"timestamp"`
@ -51,7 +53,7 @@ type callContext struct {
BaseFee *math.HexOrDecimal256 `json:"baseFeePerGas"` BaseFee *math.HexOrDecimal256 `json:"baseFeePerGas"`
} }
func (c *callContext) toBlockContext(genesis *core.Genesis) vm.BlockContext { func (c *traceContext) toBlockContext(genesis *core.Genesis) vm.BlockContext {
context := vm.BlockContext{ context := vm.BlockContext{
CanTransfer: core.CanTransfer, CanTransfer: core.CanTransfer,
Transfer: core.Transfer, Transfer: core.Transfer,
@ -77,3 +79,11 @@ func (c *callContext) toBlockContext(genesis *core.Genesis) vm.BlockContext {
} }
return context return context
} }
// tracerTestEnv defines a tracer test required fields
type tracerTestEnv struct {
Genesis *core.Genesis `json:"genesis"`
Context *traceContext `json:"context"`
Input string `json:"input"`
TracerConfig json.RawMessage `json:"tracerConfig"`
}

View file

@ -194,6 +194,10 @@ func (sim *simulator) processBlock(ctx context.Context, block *simBlock, header,
if precompiles != nil { if precompiles != nil {
evm.SetPrecompiles(precompiles) evm.SetPrecompiles(precompiles)
} }
if sim.chainConfig.IsPrague(header.Number, header.Time) || sim.chainConfig.IsVerkle(header.Number, header.Time) {
core.ProcessParentBlockHash(header.ParentHash, evm)
}
var allLogs []*types.Log
for i, call := range block.Calls { for i, call := range block.Calls {
if err := ctx.Err(); err != nil { if err := ctx.Err(); err != nil {
return nil, nil, err return nil, nil, err
@ -234,9 +238,23 @@ func (sim *simulator) processBlock(ctx context.Context, block *simBlock, header,
} }
} else { } else {
callRes.Status = hexutil.Uint64(types.ReceiptStatusSuccessful) callRes.Status = hexutil.Uint64(types.ReceiptStatusSuccessful)
allLogs = append(allLogs, callRes.Logs...)
} }
callResults[i] = callRes callResults[i] = callRes
} }
var requests [][]byte
// Process EIP-7685 requests
if sim.chainConfig.IsPrague(header.Number, header.Time) {
requests = [][]byte{}
// EIP-6110
if err := core.ParseDepositLogs(&requests, allLogs, sim.chainConfig); err != nil {
return nil, nil, err
}
// EIP-7002
core.ProcessWithdrawalQueue(&requests, evm)
// EIP-7251
core.ProcessConsolidationQueue(&requests, evm)
}
header.Root = sim.state.IntermediateRoot(true) header.Root = sim.state.IntermediateRoot(true)
header.GasUsed = gasUsed header.GasUsed = gasUsed
if sim.chainConfig.IsCancun(header.Number, header.Time) { if sim.chainConfig.IsCancun(header.Number, header.Time) {
@ -246,6 +264,10 @@ func (sim *simulator) processBlock(ctx context.Context, block *simBlock, header,
if sim.chainConfig.IsShanghai(header.Number, header.Time) { if sim.chainConfig.IsShanghai(header.Number, header.Time) {
withdrawals = make([]*types.Withdrawal, 0) withdrawals = make([]*types.Withdrawal, 0)
} }
if requests != nil {
reqHash := types.CalcRequestsHash(requests)
header.RequestsHash = &reqHash
}
b := types.NewBlock(header, &types.Body{Transactions: txes, Withdrawals: withdrawals}, receipts, trie.NewStackTrie(nil)) b := types.NewBlock(header, &types.Body{Transactions: txes, Withdrawals: withdrawals}, receipts, trie.NewStackTrie(nil))
repairLogs(callResults, b.Hash()) repairLogs(callResults, b.Hash())
return b, callResults, nil return b, callResults, nil

View file

@ -160,14 +160,6 @@ compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \
FuzzG1Add fuzz_g1_add\ FuzzG1Add fuzz_g1_add\
$repo/tests/fuzzers/bls12381/bls12381_test.go $repo/tests/fuzzers/bls12381/bls12381_test.go
compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \
FuzzCrossG1Mul fuzz_cross_g1_mul\
$repo/tests/fuzzers/bls12381/bls12381_test.go
compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \
FuzzG1Mul fuzz_g1_mul\
$repo/tests/fuzzers/bls12381/bls12381_test.go
compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \ compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \
FuzzG1MultiExp fuzz_g1_multiexp \ FuzzG1MultiExp fuzz_g1_multiexp \
$repo/tests/fuzzers/bls12381/bls12381_test.go $repo/tests/fuzzers/bls12381/bls12381_test.go
@ -176,14 +168,6 @@ compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \
FuzzG2Add fuzz_g2_add \ FuzzG2Add fuzz_g2_add \
$repo/tests/fuzzers/bls12381/bls12381_test.go $repo/tests/fuzzers/bls12381/bls12381_test.go
compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \
FuzzCrossG2Mul fuzz_cross_g2_mul\
$repo/tests/fuzzers/bls12381/bls12381_test.go
compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \
FuzzG2Mul fuzz_g2_mul\
$repo/tests/fuzzers/bls12381/bls12381_test.go
compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \ compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \
FuzzG2MultiExp fuzz_g2_multiexp \ FuzzG2MultiExp fuzz_g2_multiexp \
$repo/tests/fuzzers/bls12381/bls12381_test.go $repo/tests/fuzzers/bls12381/bls12381_test.go

View file

@ -18,17 +18,8 @@ package nat
import ( import (
"testing" "testing"
"github.com/stretchr/testify/assert"
) )
func TestNatStun(t *testing.T) {
nat, err := newSTUN("")
assert.NoError(t, err)
_, err = nat.ExternalIP()
assert.NoError(t, err)
}
func TestUnreachedNatServer(t *testing.T) { func TestUnreachedNatServer(t *testing.T) {
stun := &stun{ stun := &stun{
serverList: []string{"198.51.100.2:1234", "198.51.100.5"}, serverList: []string{"198.51.100.2:1234", "198.51.100.5"},