Skip to content

Commit

Permalink
testgen: added EIP 7702 transaction receipt test and SignAuth (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
PelleKrab authored Jan 5, 2025
1 parent 321d235 commit 3d29578
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
15 changes: 15 additions & 0 deletions testgen/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,21 @@ func (c *Chain) MustSignTx(from common.Address, txdata types.TxData) *types.Tran
return types.MustSignNewTx(acc.Key, signer, txdata)
}

// SignAuth signs a SetCode Authorization for the specified from account, so long as that
// account was in the hivechain accounts dump.
func (c *Chain) SignAuth(from common.Address, auth types.SetCodeAuthorization) (types.SetCodeAuthorization, error) {
acc, ok := c.senders[from]
if !ok {
panic(fmt.Errorf("account not available for signing: %s", from))
}

signedAuth, err := types.SignSetCode(acc.Key, auth)
if err != nil {
return types.SetCodeAuthorization{}, err
}
return signedAuth, nil
}

func loadGenesis(genesisFile string) (core.Genesis, error) {
chainConfig, err := os.ReadFile(genesisFile)
if err != nil {
Expand Down
18 changes: 18 additions & 0 deletions testgen/generators.go
Original file line number Diff line number Diff line change
Expand Up @@ -1264,6 +1264,24 @@ var EthGetTransactionReceipt = MethodTests{
return nil
},
},
{
Name: "get-setcode-tx",
About: "gets the receipt for a EIP-7702 setcode transaction",
Run: func(ctx context.Context, t *T) error {
txhash := t.chain.txinfo.EIP7702.AuthorizeTx
receipt, err := t.eth.TransactionReceipt(ctx, txhash)
if err != nil {
return err
}
if receipt.TxHash != txhash {
return fmt.Errorf("wrong receipt returned")
}
if receipt.Type != types.SetCodeTxType {
return fmt.Errorf("wrong tx type in receipt")
}
return nil
},
},
{
Name: "get-empty-tx",
About: "requests the receipt for the zero tx hash",
Expand Down

0 comments on commit 3d29578

Please sign in to comment.