diff --git a/internal/ethapi/api_test.go b/internal/ethapi/api_test.go index b086d1a6d5..be7e796b98 100644 --- a/internal/ethapi/api_test.go +++ b/internal/ethapi/api_test.go @@ -3278,7 +3278,7 @@ func setupReceiptBackend(t *testing.T, genBlocks int) (*testBackend, []common.Ha // return true; // } // } - contract: {Balance: big.NewInt(params.Ether), Code: common.FromHex("0x608060405234801561001057600080fd5b506004361061002b5760003560e01c8063a9059cbb14610030575b600080fd5b61004a6004803603810190610045919061016a565b610060565b60405161005791906101c5565b60405180910390f35b60008273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516100bf91906101ef565b60405180910390a36001905092915050565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610101826100d6565b9050919050565b610111816100f6565b811461011c57600080fd5b50565b60008135905061012e81610108565b92915050565b6000819050919050565b61014781610134565b811461015257600080fd5b50565b6000813590506101648161013e565b92915050565b60008060408385031215610181576101806100d1565b5b600061018f8582860161011f565b92505060206101a085828601610155565b9150509250929050565b60008115159050919050565b6101bf816101aa565b82525050565b60006020820190506101da60008301846101b6565b92915050565b6101e981610134565b82525050565b600060208201905061020460008301846101e0565b9291505056fea2646970667358221220b469033f4b77b9565ee84e0a2f04d496b18160d26034d54f9487e57788fd36d564736f6c63430008120033")}, + contract: {Balance: big.NewInt(params.Ether), Code: common.FromHex("0x608060405234801561001057600080fd5b506004361061002b5760003560e01c8063a9059cbb14610030575b600080fd5b61004a6004803603810190610045919061016a565b610060565b60405161005791906101c5565b60405180910390f35b60008273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516100bf91906101ef565b60405180910390a36001905092915050565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610101826100d6565b9050919050565b610111816100f6565b811461011c57600080fd5b50565b60008135905061012e81610108565b92915050565b61014781610134565b811461015257600080fd5b50565b6000813590506101648161013e565b92915050565b60008060408385031215610181576101806100d1565b5b600061018f8582860161011f565b92505060206101a085828601610155565b9150509250929050565b60008115159050919050565b6101bf816101aa565b82525050565b60006020820190506101da60008301846101b6565b92915050565b6101e981610134565b82525050565b600060208201905061020460008301846101e0565b9291505056fea2646970667358221220b469033f4b77b9565ee84e0a2f04d496b18160d26034d54f9487e57788fd36d564736f6c63430008120033")}, }, } signer = types.LatestSignerForChainID(params.TestChainConfig.ChainID) @@ -3529,3 +3529,67 @@ func testRPCResponseWithFile(t *testing.T, testid int, result interface{}, rpc s func addressToHash(a common.Address) common.Hash { return common.BytesToHash(a.Bytes()) } + +func TestCreateAccessListWithStateOverrides(t *testing.T) { + // Initialize test backend + genesis := &core.Genesis{ + Config: params.TestChainConfig, + Alloc: core.GenesisAlloc{ + common.HexToAddress("0x71562b71999873db5b286df957af199ec94617f7"): {Balance: big.NewInt(1000000000000000000)}, + }, + } + backend := newTestBackend(t, 1, genesis, ethash.NewFaker(), nil) + + // Create a new BlockChainAPI instance + api := NewBlockChainAPI(backend) + + // Create test contract code + contractCode := common.Hex2Bytes("608060405234801561001057600080fd5b506004361061002b5760003560e01c806360fe47b114610030575b600080fd5b61004a6004803603810190610045919061009d565b61004c565b005b8060008190555050565b600080fd5b6000819050919050565b61007a81610067565b811461008557600080fd5b50565b60008135905061009781610071565b92915050565b6000602082840312156100b3576100b2610062565b5b60006100c184828501610088565b9150509291505056") + codeBytes := hexutil.Bytes(contractCode) + + // Create state overrides + overrides := &override.StateOverride{ + common.HexToAddress("0x1234567890123456789012345678901234567890"): override.OverrideAccount{ + Code: &codeBytes, + }, + } + + // Create transaction arguments + from := common.HexToAddress("0x71562b71999873db5b286df957af199ec94617f7") + to := common.HexToAddress("0x1234567890123456789012345678901234567890") + data := hexutil.Bytes(common.Hex2Bytes("60fe47b1000000000000000000000000000000000000000000000000000000000000002a")) // set(42) + args := TransactionArgs{ + From: &from, + To: &to, + Data: &data, + } + + // Call CreateAccessList + result, err := api.CreateAccessList(context.Background(), args, nil, overrides) + if err != nil { + t.Fatalf("Failed to create access list: %v", err) + } + + // Verify the result + if result == nil { + t.Fatal("Expected non-nil result") + } + if result.Accesslist == nil { + t.Fatal("Expected non-nil access list") + } + if result.GasUsed == 0 { + t.Fatal("Expected non-zero gas used") + } + + // Verify access list contains the overridden contract address + found := false + for _, tuple := range *result.Accesslist { + if tuple.Address == common.HexToAddress("0x1234567890123456789012345678901234567890") { + found = true + break + } + } + if !found { + t.Fatal("Access list should contain the overridden contract address") + } +}