@@ -29,6 +29,7 @@ import (
2929 "github.com/ethereum/go-ethereum"
3030 "github.com/ethereum/go-ethereum/accounts/abi"
3131 "github.com/ethereum/go-ethereum/common"
32+ "github.com/ethereum/go-ethereum/common/hexutil"
3233 "github.com/ethereum/go-ethereum/consensus/beacon"
3334 "github.com/ethereum/go-ethereum/consensus/ethash"
3435 "github.com/ethereum/go-ethereum/core"
@@ -1058,3 +1059,76 @@ func genesisAlloc() types.GenesisAlloc {
10581059 alloc [revertContractAddr ] = types.Account {Code : revertCode }
10591060 return alloc
10601061}
1062+
1063+ type blockAccessListTestService struct {
1064+ calls chan rpc.BlockNumberOrHash
1065+ }
1066+
1067+ func (s * blockAccessListTestService ) GetBlockAccessList (ctx context.Context , block rpc.BlockNumberOrHash ) ([]ethclient.BlockAccessListEntry , error ) {
1068+ s .calls <- block
1069+ return []ethclient.BlockAccessListEntry {
1070+ {
1071+ Address : common .HexToAddress ("0x000f3df6d732807ef1319fb7b8bb8522d0beac02" ),
1072+ BalanceChanges : []ethclient.BalanceChangeEntry {},
1073+ CodeChanges : []ethclient.CodeChangeEntry {},
1074+ NonceChanges : []ethclient.NonceChangeEntry {},
1075+ StorageChanges : []ethclient.StorageChangesEntry {
1076+ {
1077+ Key : common .HexToHash ("0x152f" ),
1078+ Changes : []ethclient.StorageChangeEntry {
1079+ {Index : 0 , Value : common .HexToHash ("0x01" )},
1080+ },
1081+ },
1082+ },
1083+ StorageReads : []common.Hash {},
1084+ },
1085+ {
1086+ Address : common .HexToAddress ("0x8943545177806ed17b9f23f0a21ee5948ecaa776" ),
1087+ BalanceChanges : []ethclient.BalanceChangeEntry {
1088+ {Index : 1 , Value : (* hexutil .Big )(big .NewInt (1e18 ))},
1089+ },
1090+ CodeChanges : []ethclient.CodeChangeEntry {},
1091+ NonceChanges : []ethclient.NonceChangeEntry {{Index : 1 , Value : 1 }},
1092+ StorageChanges : []ethclient.StorageChangesEntry {},
1093+ StorageReads : []common.Hash {},
1094+ },
1095+ }, nil
1096+ }
1097+
1098+ func TestGetBlockAccessList (t * testing.T ) {
1099+ srv := rpc .NewServer ()
1100+ service := & blockAccessListTestService {calls : make (chan rpc.BlockNumberOrHash , 1 )}
1101+ if err := srv .RegisterName ("eth" , service ); err != nil {
1102+ t .Fatalf ("failed to register service: %v" , err )
1103+ }
1104+ defer srv .Stop ()
1105+
1106+ client := rpc .DialInProc (srv )
1107+ defer client .Close ()
1108+
1109+ ec := ethclient .NewClient (client )
1110+ defer ec .Close ()
1111+
1112+ hash := common .HexToHash ("0x01" )
1113+ ref := rpc .BlockNumberOrHashWithHash (hash , true )
1114+
1115+ entries , err := ec .GetBlockAccessList (context .Background (), ref )
1116+ if err != nil {
1117+ t .Fatalf ("GetBlockAccessList returned error: %v" , err )
1118+ }
1119+ if len (entries ) != 2 {
1120+ t .Fatalf ("expected 2 entries, got %d" , len (entries ))
1121+ }
1122+ if entries [0 ].Address != common .HexToAddress ("0x000f3df6d732807ef1319fb7b8bb8522d0beac02" ) {
1123+ t .Fatalf ("unexpected first entry address: %s" , entries [0 ].Address )
1124+ }
1125+ if len (entries [0 ].StorageChanges ) != 1 || entries [0 ].StorageChanges [0 ].Changes [0 ].Index != 0 {
1126+ t .Fatalf ("unexpected storage changes: %+v" , entries [0 ].StorageChanges )
1127+ }
1128+ if entries [1 ].BalanceChanges [0 ].Value .ToInt ().Cmp (big .NewInt (1e18 )) != 0 {
1129+ t .Fatalf ("unexpected balance change: %v" , entries [1 ].BalanceChanges [0 ].Value )
1130+ }
1131+ if entries [1 ].NonceChanges [0 ].Value != 1 {
1132+ t .Fatalf ("unexpected nonce change: %+v" , entries [1 ].NonceChanges )
1133+ }
1134+ }
0 commit comments