Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testgen: added EIP 7702 transaction receipt test and SignAuth #38

Merged
merged 8 commits into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions testgen/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,17 @@ func (c *Chain) GetSender(idx int) (common.Address, uint64) {
return addr, c.senders[addr].Nonce
}

func (c *Chain) GetPrivateKey(addr common.Address) (*ecdsa.PrivateKey, error) {
sender, exists := c.senders[addr]
if !exists {
return nil, fmt.Errorf("address %s not found in senders", addr.Hex())
}
if sender.Key == nil {
return nil, fmt.Errorf("no private key available for address %s", addr.Hex())
}
return sender.Key, nil
}

// IncNonce increases the specified signing account's pending nonce.
func (c *Chain) IncNonce(addr common.Address, amt uint64) {
if _, ok := c.senders[addr]; !ok {
Expand Down
93 changes: 93 additions & 0 deletions testgen/generators.go
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,23 @@ var EthGetTransactionByHash = MethodTests{
return nil
},
},
{
Name: "get-authlist-tx",
About: "gets a authorization list transaction",
Run: func(ctx context.Context, t *T) error {
tx := t.chain.FindTransaction("authlist tx", func(i int, tx *types.Transaction) bool {
return tx.Type() == types.SetCodeTxType
})
got, _, err := t.eth.TransactionByHash(ctx, tx.Hash())
if err != nil {
return err
}
if got.Hash() != tx.Hash() {
return fmt.Errorf("tx mismatch (got: %s, want: %s)", got.Hash(), tx.Hash())
}
return nil
},
},
},
}

Expand Down Expand Up @@ -1210,6 +1227,26 @@ var EthGetTransactionReceipt = MethodTests{
return nil
},
},
{
Name: "get-auth-list",
About: "gets an authorization list transaction",
Run: func(ctx context.Context, t *T) error {
tx := t.chain.FindTransaction("auth list tx", func(i int, tx *types.Transaction) bool {
return tx.Type() == types.SetCodeTxType
})
receipt, err := t.eth.TransactionReceipt(ctx, tx.Hash())
if err != nil {
return err
}
if receipt.TxHash != tx.Hash() {
return fmt.Errorf("wrong receipt returned")
}
if receipt.Type != types.SetCodeTxType {
return fmt.Errorf("wrong tx type in receipt")
}
return nil
},
},
},
}

Expand Down Expand Up @@ -1464,6 +1501,62 @@ var EthSendRawTransaction = MethodTests{
return nil
},
},
{
Name: "send-authorization-list-tx",
About: "sends a authorization list transaction",
Run: func(ctx context.Context, t *T) error {
var (
sender, nonce = t.chain.GetSender(4)
basefee = uint256.MustFromBig(t.chain.Head().BaseFee())
fee = uint256.NewInt(500)
)
fee.Add(basefee, fee)


auth := &types.Authorization{
ChainID: t.chain.Config().ChainID,
Address: emitContract,
Nonce: uint64(0),
V: big.NewInt(1),
R: big.NewInt(1),
S: big.NewInt(1),
}

privateKey, err := t.chain.GetPrivateKey(sender)
if err != nil {
return err
}

signedAuth, err := types.SignAuth(auth, privateKey)
if err != nil {
return err
}

authList := types.AuthorizationList{signedAuth}

txdata := &types.SetCodeTx{
Nonce: nonce,
To: emitContract,
Gas: 80000,
GasTipCap: uint256.NewInt(500),
GasFeeCap: fee,
Data: common.FromHex("0x"),
AccessList: types.AccessList{
{Address: emitContract, StorageKeys: []common.Hash{{0}, {1}}},
},
AuthList: authList,
V: uint256.NewInt(1),
R: uint256.NewInt(1),
S: uint256.NewInt(1),
}
tx := t.chain.MustSignTx(sender, txdata)
if err := t.eth.SendTransaction(ctx, tx); err != nil {
return err
}
t.chain.IncNonce(sender, 1)
return nil
},
},
},
}

Expand Down