Skip to content

Commit 68bfda5

Browse files
internal, graphql, test: remaining components of 7702 (#41)
* tests: adapt TestState to Prague hardfork * internal, graphql: update AuthList in the Tx interface * fixup! tests: adapt TestState to Prague hardfork --------- Co-authored-by: sonhv0212 <[email protected]>
1 parent 9d3fd67 commit 68bfda5

File tree

9 files changed

+260
-57
lines changed

9 files changed

+260
-57
lines changed

accounts/external/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ func (api *ExternalSigner) SignTx(account accounts.Account, tx *types.Transactio
218218
switch tx.Type() {
219219
case types.LegacyTxType, types.AccessListTxType:
220220
args.GasPrice = (*hexutil.Big)(tx.GasPrice())
221-
case types.DynamicFeeTxType:
221+
case types.DynamicFeeTxType, types.BlobTxType, types.SetCodeTxType:
222222
args.MaxFeePerGas = (*hexutil.Big)(tx.GasFeeCap())
223223
args.MaxPriorityFeePerGas = (*hexutil.Big)(tx.GasTipCap())
224224
default:

graphql/graphql.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ func (t *Transaction) MaxFeePerGas(ctx context.Context) (*hexutil.Big, error) {
263263
switch tx.Type() {
264264
case types.AccessListTxType:
265265
return nil, nil
266-
case types.DynamicFeeTxType:
266+
case types.DynamicFeeTxType, types.BlobTxType, types.SetCodeTxType:
267267
return (*hexutil.Big)(tx.GasFeeCap()), nil
268268
default:
269269
return nil, nil
@@ -278,7 +278,7 @@ func (t *Transaction) MaxPriorityFeePerGas(ctx context.Context) (*hexutil.Big, e
278278
switch tx.Type() {
279279
case types.AccessListTxType:
280280
return nil, nil
281-
case types.DynamicFeeTxType:
281+
case types.DynamicFeeTxType, types.BlobTxType, types.SetCodeTxType:
282282
return (*hexutil.Big)(tx.GasTipCap()), nil
283283
default:
284284
return nil, nil

internal/ethapi/api.go

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,32 +1366,34 @@ func (s *PublicBlockChainAPI) rpcMarshalBlock(ctx context.Context, b *types.Bloc
13661366

13671367
// RPCTransaction represents a transaction that will serialize to the RPC representation of a transaction
13681368
type RPCTransaction struct {
1369-
BlockHash *common.Hash `json:"blockHash"`
1370-
BlockNumber *hexutil.Big `json:"blockNumber"`
1371-
From common.Address `json:"from"`
1372-
Gas hexutil.Uint64 `json:"gas"`
1373-
GasPrice *hexutil.Big `json:"gasPrice"`
1374-
GasFeeCap *hexutil.Big `json:"maxFeePerGas,omitempty"`
1375-
GasTipCap *hexutil.Big `json:"maxPriorityFeePerGas,omitempty"`
1376-
MaxFeePerBlobGas *hexutil.Big `json:"maxFeePerBlobGas,omitempty"`
1377-
Hash common.Hash `json:"hash"`
1378-
Input hexutil.Bytes `json:"input"`
1379-
Nonce hexutil.Uint64 `json:"nonce"`
1380-
To *common.Address `json:"to"`
1381-
TransactionIndex *hexutil.Uint64 `json:"transactionIndex"`
1382-
Value *hexutil.Big `json:"value"`
1383-
Type hexutil.Uint64 `json:"type"`
1384-
Accesses *types.AccessList `json:"accessList,omitempty"`
1385-
ChainID *hexutil.Big `json:"chainId,omitempty"`
1386-
BlobVersionedHashes []common.Hash `json:"blobVersionedHashes,omitempty"`
1387-
V *hexutil.Big `json:"v"`
1388-
R *hexutil.Big `json:"r"`
1389-
S *hexutil.Big `json:"s"`
1390-
Payer *common.Address `json:"payer,omitempty"`
1391-
ExpiredTime *hexutil.Uint64 `json:"expiredTime,omitempty"`
1392-
PayerV *hexutil.Big `json:"payerV,omitempty"`
1393-
PayerR *hexutil.Big `json:"payerR,omitempty"`
1394-
PayerS *hexutil.Big `json:"payerS,omitempty"`
1369+
BlockHash *common.Hash `json:"blockHash"`
1370+
BlockNumber *hexutil.Big `json:"blockNumber"`
1371+
From common.Address `json:"from"`
1372+
Gas hexutil.Uint64 `json:"gas"`
1373+
GasPrice *hexutil.Big `json:"gasPrice"`
1374+
GasFeeCap *hexutil.Big `json:"maxFeePerGas,omitempty"`
1375+
GasTipCap *hexutil.Big `json:"maxPriorityFeePerGas,omitempty"`
1376+
MaxFeePerBlobGas *hexutil.Big `json:"maxFeePerBlobGas,omitempty"`
1377+
Hash common.Hash `json:"hash"`
1378+
Input hexutil.Bytes `json:"input"`
1379+
Nonce hexutil.Uint64 `json:"nonce"`
1380+
To *common.Address `json:"to"`
1381+
TransactionIndex *hexutil.Uint64 `json:"transactionIndex"`
1382+
Value *hexutil.Big `json:"value"`
1383+
Type hexutil.Uint64 `json:"type"`
1384+
Accesses *types.AccessList `json:"accessList,omitempty"`
1385+
ChainID *hexutil.Big `json:"chainId,omitempty"`
1386+
BlobVersionedHashes []common.Hash `json:"blobVersionedHashes,omitempty"`
1387+
AuthorizationList []types.Authorization `json:"authorizationList,omitempty"`
1388+
V *hexutil.Big `json:"v"`
1389+
R *hexutil.Big `json:"r"`
1390+
S *hexutil.Big `json:"s"`
1391+
YParity *hexutil.Uint64 `json:"yParity,omitempty"`
1392+
Payer *common.Address `json:"payer,omitempty"`
1393+
ExpiredTime *hexutil.Uint64 `json:"expiredTime,omitempty"`
1394+
PayerV *hexutil.Big `json:"payerV,omitempty"`
1395+
PayerR *hexutil.Big `json:"payerR,omitempty"`
1396+
PayerS *hexutil.Big `json:"payerS,omitempty"`
13951397
}
13961398

13971399
// newRPCTransaction returns a transaction that will serialize to the RPC
@@ -1478,6 +1480,21 @@ func newRPCTransaction(tx *types.Transaction, blockHash common.Hash, blockNumber
14781480
}
14791481
result.MaxFeePerBlobGas = (*hexutil.Big)(tx.BlobGasFeeCap())
14801482
result.BlobVersionedHashes = tx.BlobHashes()
1483+
case types.SetCodeTxType:
1484+
al := tx.AccessList()
1485+
yparity := hexutil.Uint64(v.Sign())
1486+
result.Accesses = &al
1487+
result.ChainID = (*hexutil.Big)(tx.ChainId())
1488+
result.YParity = &yparity
1489+
result.GasFeeCap = (*hexutil.Big)(tx.GasFeeCap())
1490+
result.GasTipCap = (*hexutil.Big)(tx.GasTipCap())
1491+
// if the transaction has been mined, compute the effective gas price
1492+
if baseFee != nil && blockHash != (common.Hash{}) {
1493+
result.GasPrice = (*hexutil.Big)(effectiveGasPrice(tx, baseFee))
1494+
} else {
1495+
result.GasPrice = (*hexutil.Big)(tx.GasFeeCap())
1496+
}
1497+
result.AuthorizationList = tx.AuthList()
14811498
}
14821499
return result
14831500
}

internal/ethapi/api_test.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,12 +638,13 @@ func TestEstimateGas(t *testing.T) {
638638
t.Parallel()
639639
// Initialize test accounts
640640
var (
641-
accounts = newAccounts(2)
641+
accounts = newAccounts(4)
642642
genesis = &core.Genesis{
643643
Config: params.TestChainConfig,
644644
Alloc: core.GenesisAlloc{
645645
accounts[0].addr: {Balance: big.NewInt(params.Ether)},
646646
accounts[1].addr: {Balance: big.NewInt(params.Ether)},
647+
accounts[2].addr: {Balance: big.NewInt(params.Ether), Code: append(types.DelegationPrefix, accounts[3].addr.Bytes()...)},
647648
},
648649
}
649650
genBlocks = 10
@@ -726,6 +727,26 @@ func TestEstimateGas(t *testing.T) {
726727
},
727728
want: 21000,
728729
},
730+
// Should be able to send to an EIP-7702 delegated account.
731+
{
732+
blockNumber: rpc.LatestBlockNumber,
733+
call: TransactionArgs{
734+
From: &accounts[0].addr,
735+
To: &accounts[2].addr,
736+
Value: (*hexutil.Big)(big.NewInt(1)),
737+
},
738+
want: 21000,
739+
},
740+
// Should be able to send as EIP-7702 delegated account.
741+
{
742+
blockNumber: rpc.LatestBlockNumber,
743+
call: TransactionArgs{
744+
From: &accounts[2].addr,
745+
To: &accounts[1].addr,
746+
Value: (*hexutil.Big)(big.NewInt(1)),
747+
},
748+
want: 21000,
749+
},
729750
}
730751
for i, tc := range testSuite {
731752
result, err := api.EstimateGas(context.Background(), tc.call, &rpc.BlockNumberOrHash{BlockNumber: &tc.blockNumber}, &tc.overrides)

tests/gen_stauthorization.go

Lines changed: 75 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/gen_stenv.go

Lines changed: 20 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/gen_sttransaction.go

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/init.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,25 @@ var Forks = map[string]*params.ChainConfig{
197197
LondonBlock: big.NewInt(0),
198198
ArrowGlacierBlock: big.NewInt(0),
199199
},
200+
"Prague": {
201+
ChainID: big.NewInt(1),
202+
HomesteadBlock: big.NewInt(0),
203+
EIP150Block: big.NewInt(0),
204+
EIP155Block: big.NewInt(0),
205+
EIP158Block: big.NewInt(0),
206+
ByzantiumBlock: big.NewInt(0),
207+
ConstantinopleBlock: big.NewInt(0),
208+
PetersburgBlock: big.NewInt(0),
209+
IstanbulBlock: big.NewInt(0),
210+
MuirGlacierBlock: big.NewInt(0),
211+
BerlinBlock: big.NewInt(0),
212+
LondonBlock: big.NewInt(0),
213+
ArrowGlacierBlock: big.NewInt(0),
214+
ShanghaiBlock: big.NewInt(0),
215+
CancunBlock: big.NewInt(0),
216+
VenokiBlock: big.NewInt(0),
217+
PragueBlock: big.NewInt(0),
218+
},
200219
}
201220

202221
// Returns the set of defined fork names

0 commit comments

Comments
 (0)