go-ethereum/rollup/ccc/async_checker_test.go
colin 60cbf64f9c
feat: add EIP-7702 (#1112)
* feat: add EIP-7702

* fix goimport

* add unit tests

* add api test

* sync txpool update

* update generated code

* make code readable

* fix goimport

* fix TestAsyncChecker unit test

* add AuthorizationList in fuzz tests for completeness sake

* add EuclidV2 test, EIP-7702 transaction in TestT8n

* clean up logs

* bump version

* fix TestAsyncChecker

* Revert "fix TestAsyncChecker"

This reverts commit 314478303d4a504a3948bd6595568916ba7d82f0.

* accept eip-7702 txns only after enabling eip-7702

* revert IntrinsicGas param name from setCodeAuthorizations to authList

* fix a bug

* align upstream implementation in Encoding Receipts

* fix one test case

* fix tracer

* return precode copy

* support setcode tx in EstimateGas and add unit tests

* add TestValidateAuthorizations

* poseidon hash fix

* migrate a fix before the fix pr is merged

* support setcode type transactions in TransactionData

* chore: auto version bump [bot]

* add a nonce-gapped-auth-does-not-block-pending-tx unit test

* make the auth invalid

* Apply suggestions from code review

* change usedAndLeftSlots and knownConflicts to util functions

* add comments about different return of applyAuthorization

* remove gencodec:required in transaction signatures

* fix goimport

* update StructLogger and AccessListTracer

* fix a bug

* fix flaky test

---------

Co-authored-by: colinlyguo <colinlyguo@users.noreply.github.com>
Co-authored-by: Péter Garamvölgyi <peter@scroll.io>
2025-02-25 14:56:51 +01:00

85 lines
2.9 KiB
Go

package ccc
import (
"math/big"
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/scroll-tech/go-ethereum/common"
"github.com/scroll-tech/go-ethereum/consensus/ethash"
"github.com/scroll-tech/go-ethereum/core"
"github.com/scroll-tech/go-ethereum/core/rawdb"
"github.com/scroll-tech/go-ethereum/core/types"
"github.com/scroll-tech/go-ethereum/core/vm"
"github.com/scroll-tech/go-ethereum/crypto"
"github.com/scroll-tech/go-ethereum/params"
)
func TestAsyncChecker(t *testing.T) {
// testKey is a private key to use for funding a tester account.
testKey, _ := crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
// testAddr is the Ethereum address of the tester account.
testAddr := crypto.PubkeyToAddress(testKey.PublicKey)
// Create a database pre-initialize with a genesis block
db := rawdb.NewMemoryDatabase()
chainConfig := params.TestChainConfig.Clone()
chainConfig.EuclidTime = nil
chainConfig.EuclidV2Time = nil
chainConfig.Scroll.UseZktrie = true
(&core.Genesis{
Config: chainConfig,
Alloc: core.GenesisAlloc{testAddr: {Balance: new(big.Int).Mul(big.NewInt(1000), big.NewInt(params.Ether))}},
}).MustCommit(db)
chain, _ := core.NewBlockChain(db, nil, chainConfig, ethash.NewFaker(), vm.Config{}, nil, nil)
asyncChecker := NewAsyncChecker(chain, 1, false)
chain.Validator().WithAsyncValidator(asyncChecker.Check)
bs, _ := core.GenerateChain(chainConfig, chain.Genesis(), ethash.NewFaker(), db, 100, func(i int, block *core.BlockGen) {
for i := 0; i < 10; i++ {
signer := types.MakeSigner(chainConfig, block.Number(), block.Time())
tx, err := types.SignTx(types.NewTransaction(block.TxNonce(testAddr), testAddr, big.NewInt(1000), params.TxGas, block.BaseFee(), nil), signer, testKey)
if err != nil {
panic(err)
}
block.AddTx(tx)
}
})
noReorgBlocks := bs[:len(bs)/2]
if _, err := chain.InsertChain(noReorgBlocks); err != nil {
panic(err)
}
time.Sleep(time.Second)
for _, block := range noReorgBlocks {
require.NotNil(t, rawdb.ReadBlockRowConsumption(db, block.Hash()))
}
reorgBlocks := bs[len(bs)/2:]
skippedTxn := reorgBlocks[3].Transactions()[3]
checker := <-asyncChecker.freeCheckers
checker.Skip(skippedTxn.Hash(), ErrBlockRowConsumptionOverflow)
// trigger an error on some later height, we shouldn't get a notification for this
checker.ScheduleError(50, ErrBlockRowConsumptionOverflow)
asyncChecker.freeCheckers <- checker
var failingBlockHash common.Hash
var errWithIdx *ErrorWithTxnIdx
asyncChecker.WithOnFailingBlock(func(b *types.Block, err error) {
failingBlockHash = b.Hash()
require.ErrorAs(t, err, &errWithIdx)
})
if _, err := chain.InsertChain(reorgBlocks); err != nil {
panic(err)
}
time.Sleep(3 * time.Second)
require.Equal(t, reorgBlocks[3].Hash(), failingBlockHash)
require.Equal(t, uint(3), errWithIdx.TxIdx)
require.True(t, errWithIdx.ShouldSkip)
}