mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 01:13:45 +00:00
Merge branch 'ethereum:master' into fix/linter-usetesting
This commit is contained in:
commit
afb9691bb6
13 changed files with 123 additions and 61 deletions
2
.github/workflows/go.yml
vendored
2
.github/workflows/go.yml
vendored
|
|
@ -23,7 +23,7 @@ jobs:
|
|||
- name: Set up Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: 1.24.0
|
||||
go-version: 1.23.0
|
||||
cache: false
|
||||
|
||||
- name: Run linters
|
||||
|
|
|
|||
|
|
@ -149,6 +149,10 @@ func pricedSetCodeTx(nonce uint64, gaslimit uint64, gasFee, tip *uint256.Int, ke
|
|||
})
|
||||
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{
|
||||
ChainID: uint256.MustFromBig(params.TestChainConfig.ChainID),
|
||||
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
|
||||
// transaction pool.
|
||||
func BenchmarkPendingDemotion100(b *testing.B) { benchmarkPendingDemotion(b, 100) }
|
||||
|
|
|
|||
|
|
@ -65,11 +65,8 @@ type callTrace struct {
|
|||
|
||||
// callTracerTest defines a single test to check the call tracer against.
|
||||
type callTracerTest struct {
|
||||
Genesis *core.Genesis `json:"genesis"`
|
||||
Context *callContext `json:"context"`
|
||||
Input string `json:"input"`
|
||||
TracerConfig json.RawMessage `json:"tracerConfig"`
|
||||
Result *callTrace `json:"result"`
|
||||
tracerTestEnv
|
||||
Result *callTrace `json:"result"`
|
||||
}
|
||||
|
||||
// Iterates over all the input-output datasets in the tracer test harness and
|
||||
|
|
|
|||
|
|
@ -77,11 +77,8 @@ type flatCallTraceResult struct {
|
|||
|
||||
// flatCallTracerTest defines a single test to check the call tracer against.
|
||||
type flatCallTracerTest struct {
|
||||
Genesis *core.Genesis `json:"genesis"`
|
||||
Context *callContext `json:"context"`
|
||||
Input string `json:"input"`
|
||||
TracerConfig json.RawMessage `json:"tracerConfig"`
|
||||
Result []flatCallTrace `json:"result"`
|
||||
tracerTestEnv
|
||||
Result []flatCallTrace `json:"result"`
|
||||
}
|
||||
|
||||
func flatCallTracerTestRunner(tracerName string, filename string, dirPath string, t testing.TB) error {
|
||||
|
|
|
|||
|
|
@ -31,6 +31,9 @@ var makeTest = function(tx, traceConfig) {
|
|||
delete genesis.transactions;
|
||||
delete genesis.transactionsRoot;
|
||||
delete genesis.uncles;
|
||||
delete genesis.withdrawals;
|
||||
delete genesis.withdrawalsRoot;
|
||||
delete genesis.baseFeePerGas;
|
||||
|
||||
genesis.gasLimit = genesis.gasLimit.toString();
|
||||
genesis.number = genesis.number.toString();
|
||||
|
|
@ -60,11 +63,15 @@ var makeTest = function(tx, traceConfig) {
|
|||
context.baseFeePerGas = block.baseFeePerGas.toString();
|
||||
}
|
||||
|
||||
console.log(JSON.stringify({
|
||||
var data = {
|
||||
genesis: genesis,
|
||||
context: context,
|
||||
input: eth.getRawTransaction(tx),
|
||||
result: result,
|
||||
tracerConfig: traceConfig.tracerConfig,
|
||||
}, null, 2));
|
||||
input: eth.getRawTransaction(tx),
|
||||
result: result,
|
||||
};
|
||||
if (traceConfig && traceConfig.tracerConfig) {
|
||||
data.tracerConfig = traceConfig.tracerConfig;
|
||||
}
|
||||
|
||||
console.log(JSON.stringify(data, null, 2));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,28 +43,25 @@ type account struct {
|
|||
Storage map[common.Hash]common.Hash `json:"storage"`
|
||||
}
|
||||
|
||||
// testcase defines a single test to check the stateDiff tracer against.
|
||||
type testcase struct {
|
||||
Genesis *core.Genesis `json:"genesis"`
|
||||
Context *callContext `json:"context"`
|
||||
Input string `json:"input"`
|
||||
TracerConfig json.RawMessage `json:"tracerConfig"`
|
||||
Result interface{} `json:"result"`
|
||||
// prestateTracerTest defines a single test to check the stateDiff tracer against.
|
||||
type prestateTracerTest struct {
|
||||
tracerTestEnv
|
||||
Result interface{} `json:"result"`
|
||||
}
|
||||
|
||||
func TestPrestateTracerLegacy(t *testing.T) {
|
||||
testPrestateDiffTracer("prestateTracerLegacy", "prestate_tracer_legacy", t)
|
||||
testPrestateTracer("prestateTracerLegacy", "prestate_tracer_legacy", t)
|
||||
}
|
||||
|
||||
func TestPrestateTracer(t *testing.T) {
|
||||
testPrestateDiffTracer("prestateTracer", "prestate_tracer", t)
|
||||
testPrestateTracer("prestateTracer", "prestate_tracer", 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))
|
||||
if err != nil {
|
||||
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()
|
||||
|
||||
var (
|
||||
test = new(testcase)
|
||||
test = new(prestateTracerTest)
|
||||
tx = new(types.Transaction)
|
||||
)
|
||||
// Call tracer test found, read if from disk
|
||||
|
|
|
|||
|
|
@ -14,8 +14,6 @@
|
|||
"parentBeaconBlockRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"stateRoot": "0x577f42ab21ccfd946511c57869ace0bdf7c217c36f02b7cd3459df0ed1cffc1a",
|
||||
"timestamp": "1709626771",
|
||||
"withdrawals": [],
|
||||
"withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
|
||||
"alloc": {
|
||||
"0x0000000000000000000000000000000000000000": {
|
||||
"balance": "0x272e0528"
|
||||
|
|
|
|||
|
|
@ -14,8 +14,6 @@
|
|||
"parentBeaconBlockRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"stateRoot": "0x577f42ab21ccfd946511c57869ace0bdf7c217c36f02b7cd3459df0ed1cffc1a",
|
||||
"timestamp": "1709626771",
|
||||
"withdrawals": [],
|
||||
"withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
|
||||
"alloc": {
|
||||
"0x0000000000000000000000000000000000000000": {
|
||||
"balance": "0x272e0528"
|
||||
|
|
|
|||
|
|
@ -11,8 +11,6 @@
|
|||
"number": "1",
|
||||
"stateRoot": "0xd2ebe0a7f3572ffe3e5b4c78147376d3fca767f236e4dd23f9151acfec7cb0d1",
|
||||
"timestamp": "1699617692",
|
||||
"withdrawals": [],
|
||||
"withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
|
||||
"alloc": {
|
||||
"0x0000000000000000000000000000000000000000": {
|
||||
"balance": "0x5208"
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package tracetest
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"math/big"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
|
@ -42,7 +43,8 @@ func camel(str string) string {
|
|||
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"`
|
||||
Difficulty *math.HexOrDecimal256 `json:"difficulty"`
|
||||
Time math.HexOrDecimal64 `json:"timestamp"`
|
||||
|
|
@ -51,7 +53,7 @@ type callContext struct {
|
|||
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{
|
||||
CanTransfer: core.CanTransfer,
|
||||
Transfer: core.Transfer,
|
||||
|
|
@ -77,3 +79,11 @@ func (c *callContext) toBlockContext(genesis *core.Genesis) vm.BlockContext {
|
|||
}
|
||||
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"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -194,6 +194,10 @@ func (sim *simulator) processBlock(ctx context.Context, block *simBlock, header,
|
|||
if precompiles != nil {
|
||||
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 {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return nil, nil, err
|
||||
|
|
@ -234,9 +238,23 @@ func (sim *simulator) processBlock(ctx context.Context, block *simBlock, header,
|
|||
}
|
||||
} else {
|
||||
callRes.Status = hexutil.Uint64(types.ReceiptStatusSuccessful)
|
||||
allLogs = append(allLogs, callRes.Logs...)
|
||||
}
|
||||
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.GasUsed = gasUsed
|
||||
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) {
|
||||
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))
|
||||
repairLogs(callResults, b.Hash())
|
||||
return b, callResults, nil
|
||||
|
|
|
|||
16
oss-fuzz.sh
16
oss-fuzz.sh
|
|
@ -160,14 +160,6 @@ compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \
|
|||
FuzzG1Add fuzz_g1_add\
|
||||
$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 \
|
||||
FuzzG1MultiExp fuzz_g1_multiexp \
|
||||
$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 \
|
||||
$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 \
|
||||
FuzzG2MultiExp fuzz_g2_multiexp \
|
||||
$repo/tests/fuzzers/bls12381/bls12381_test.go
|
||||
|
|
|
|||
|
|
@ -18,17 +18,8 @@ package nat
|
|||
|
||||
import (
|
||||
"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) {
|
||||
stun := &stun{
|
||||
serverList: []string{"198.51.100.2:1234", "198.51.100.5"},
|
||||
|
|
|
|||
Loading…
Reference in a new issue