Skip to content

Commit

Permalink
testgen: add some tests for prague
Browse files Browse the repository at this point in the history
  • Loading branch information
fjl committed Dec 17, 2024
1 parent bfb03d8 commit bef79e3
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
13 changes: 13 additions & 0 deletions testgen/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ type ChainTxInfo struct {
CallMeContract *ContractInfo `json:"deploy-callme"`
CallEnvContract *ContractInfo `json:"deploy-callenv"`
CallRevertContract *ContractInfo `json:"deploy-callrevert"`
EIP7702 *EIP7702Info `json:"tx-eip7702"`
EIP7002 *EIP7002Info `json:"tx-request-eip7002"`
}

// TxInfo is a transaction record created by hivechain.
Expand All @@ -64,6 +66,17 @@ type ContractInfo struct {
Block hexutil.Uint64 `json:"block"`
}

type EIP7702Info struct {
Account common.Address `json:"account"`
ProxyAddr common.Address `json:"proxyAddr"`
AuthorizeTx common.Hash `json:"authorizeTx"`
}

type EIP7002Info struct {
TxHash common.Hash `json:"txhash"`
Block hexutil.Uint64 `json:"block"`
}

// NewChain takes the given chain.rlp file, decodes it, and returns
// the blocks from the file.
func NewChain(dir string) (*Chain, error) {
Expand Down
75 changes: 75 additions & 0 deletions testgen/generators.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,24 @@ var EthGetCode = MethodTests{
return nil
},
},
{
Name: "get-code-eip7702-delegation",
About: `requests code of an account that has an EIP-7702 delegation. the server is expected to return
the delegation designator.`,
Run: func(ctx context.Context, t *T) error {
account := t.chain.txinfo.EIP7702.Account
var got hexutil.Bytes
err := t.rpc.CallContext(ctx, &got, "eth_getCode", account, "latest")
if err != nil {
return err
}
want := t.chain.state[account].Code
if !bytes.Equal(got, want) {
return fmt.Errorf("unexpected code (got: %s, want %s)", got, want)
}
return nil
},
},
{
Name: "get-code-unknown-account",
About: "requests code of a non-existent account",
Expand Down Expand Up @@ -472,6 +490,21 @@ var EthGetBlockByNumber = MethodTests{
return nil
},
},
{
Name: "get-block-eip7685-requests",
About: "retrieves a block containing non-empty EIP-7685 requests",
Run: func(ctx context.Context, t *T) error {
blocknum := t.chain.txinfo.EIP7002.Block
b, err := t.eth.BlockByNumber(ctx, big.NewInt(int64(blocknum)))
if err != nil {
return err
}
if b.RequestsHash() == nil || *b.RequestsHash() == types.EmptyRequestsHash {
return fmt.Errorf("block hash empty or missing requestsHash")
}
return nil
},
},
{
Name: "get-block-notfound",
About: "gets block notfound",
Expand Down Expand Up @@ -557,6 +590,33 @@ See https://github.com/ethereum/hive/tree/master/cmd/hivechain/contracts/callenv
return nil
},
},
{
Name: "call-eip7702-delegation",
About: `Performs a call to an account that has an EIP-7702 code delegation.`,
Run: func(ctx context.Context, t *T) error {
msg := ethereum.CallMsg{
To: &t.chain.txinfo.EIP7702.Account,
Gas: 100000,
}
result, err := t.eth.CallContract(ctx, msg, nil)
if err != nil {
return err
}
if len(result) == 0 {
return fmt.Errorf("empty call result")
}
expectedOutput := slices.Concat(
make([]byte, 12),
t.chain.txinfo.EIP7702.Account[:],
[]byte("invoked"),
make([]byte, 25),
)
if !bytes.Equal(result, expectedOutput) {
return fmt.Errorf("wrong return value: %x", result)
}
return nil
},
},
{
Name: "call-revert-abi-panic",
About: "calls a contract that reverts with an ABI-encoded Panic(uint) value",
Expand Down Expand Up @@ -1051,6 +1111,21 @@ var EthGetTransactionByHash = MethodTests{
return nil
},
},
{
Name: "get-setcode-tx",
About: "retrieves an EIP-7702 transaction",
Run: func(ctx context.Context, t *T) error {
txhash := t.chain.txinfo.EIP7702.AuthorizeTx
got, _, err := t.eth.TransactionByHash(ctx, txhash)
if err != nil {
return err
}
if len(got.AuthList()) == 0 {
return fmt.Errorf("missing auth list in transaction")
}
return nil
},
},
{
Name: "get-empty-tx",
About: "requests the zero transaction hash",
Expand Down

0 comments on commit bef79e3

Please sign in to comment.