mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
refactor test
This commit is contained in:
parent
62a07266b3
commit
6f8df04a3e
1 changed files with 39 additions and 65 deletions
|
|
@ -3534,7 +3534,7 @@ func TestCreateAccessListWithStateOverrides(t *testing.T) {
|
||||||
// Initialize test backend
|
// Initialize test backend
|
||||||
genesis := &core.Genesis{
|
genesis := &core.Genesis{
|
||||||
Config: params.TestChainConfig,
|
Config: params.TestChainConfig,
|
||||||
Alloc: core.GenesisAlloc{
|
Alloc: types.GenesisAlloc{
|
||||||
common.HexToAddress("0x71562b71999873db5b286df957af199ec94617f7"): {Balance: big.NewInt(1000000000000000000)},
|
common.HexToAddress("0x71562b71999873db5b286df957af199ec94617f7"): {Balance: big.NewInt(1000000000000000000)},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -3555,78 +3555,52 @@ func TestCreateAccessListWithStateOverrides(t *testing.T) {
|
||||||
// return value;
|
// return value;
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
contractCode := common.Hex2Bytes("6080604052348015600f57600080fd5b506004361060285760003560e01c80632e64cec114602d575b600080fd5b60336047565b604051603e91906067565b60405180910390f35b60008054905090565b6000819050919050565b6061816050565b82525050565b6000602082019050607a6000830184605a565b9291505056")
|
var (
|
||||||
codeBytes := hexutil.Bytes(contractCode)
|
contractCode = hexutil.Bytes(common.Hex2Bytes("6080604052348015600f57600080fd5b506004361060285760003560e01c80632e64cec114602d575b600080fd5b60336047565b604051603e91906067565b60405180910390f35b60008054905090565b6000819050919050565b6061816050565b82525050565b6000602082019050607a6000830184605a565b9291505056"))
|
||||||
|
// Create state overrides with more complete state
|
||||||
// Create state overrides with more complete state
|
contractAddr = common.HexToAddress("0x1234567890123456789012345678901234567890")
|
||||||
contractAddr := common.HexToAddress("0x1234567890123456789012345678901234567890")
|
nonce = hexutil.Uint64(1)
|
||||||
balance := (*hexutil.Big)(big.NewInt(1000000000000000000))
|
overrides = &override.StateOverride{
|
||||||
nonce := hexutil.Uint64(1)
|
contractAddr: override.OverrideAccount{
|
||||||
|
Code: &contractCode,
|
||||||
// Add initial storage values
|
Balance: (*hexutil.Big)(big.NewInt(1000000000000000000)),
|
||||||
storage := map[common.Hash]common.Hash{
|
Nonce: &nonce,
|
||||||
common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"): common.HexToHash("0x000000000000000000000000000000000000000000000000000000000000002a"),
|
State: map[common.Hash]common.Hash{
|
||||||
}
|
common.Hash{}: common.HexToHash("0x000000000000000000000000000000000000000000000000000000000000002a"),
|
||||||
|
},
|
||||||
overrides := &override.StateOverride{
|
},
|
||||||
contractAddr: override.OverrideAccount{
|
}
|
||||||
Code: &codeBytes,
|
)
|
||||||
Balance: balance,
|
|
||||||
Nonce: &nonce,
|
|
||||||
State: storage,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create transaction arguments with gas and value
|
// Create transaction arguments with gas and value
|
||||||
from := common.HexToAddress("0x71562b71999873db5b286df957af199ec94617f7")
|
var (
|
||||||
to := contractAddr
|
from = common.HexToAddress("0x71562b71999873db5b286df957af199ec94617f7")
|
||||||
data := hexutil.Bytes(common.Hex2Bytes("2e64cec1")) // retrieve()
|
data = hexutil.Bytes(common.Hex2Bytes("2e64cec1")) // retrieve()
|
||||||
gas := hexutil.Uint64(100000)
|
gas = hexutil.Uint64(100000)
|
||||||
value := (*hexutil.Big)(big.NewInt(0))
|
args = TransactionArgs{
|
||||||
args := TransactionArgs{
|
From: &from,
|
||||||
From: &from,
|
To: &contractAddr,
|
||||||
To: &to,
|
Data: &data,
|
||||||
Data: &data,
|
Gas: &gas,
|
||||||
Gas: &gas,
|
Value: new(hexutil.Big),
|
||||||
Value: value,
|
}
|
||||||
}
|
)
|
||||||
|
|
||||||
// Call CreateAccessList
|
// Call CreateAccessList
|
||||||
result, err := api.CreateAccessList(context.Background(), args, nil, overrides)
|
result, err := api.CreateAccessList(context.Background(), args, nil, overrides)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to create access list: %v", err)
|
t.Fatalf("Failed to create access list: %v", err)
|
||||||
}
|
}
|
||||||
|
if err != nil || result == nil {
|
||||||
// Verify the result
|
t.Fatalf("Failed to create access list: %v", err)
|
||||||
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")
|
|
||||||
}
|
}
|
||||||
|
require.NotNil(t, result.Accesslist)
|
||||||
|
|
||||||
// Verify access list contains the contract address and storage slot
|
// Verify access list contains the contract address and storage slot
|
||||||
foundAddr := false
|
expected := &types.AccessList{{
|
||||||
foundSlot := false
|
Address: contractAddr,
|
||||||
for _, tuple := range *result.Accesslist {
|
StorageKeys: []common.Hash{
|
||||||
if tuple.Address == contractAddr {
|
common.Hash{},
|
||||||
foundAddr = true
|
},
|
||||||
for _, slot := range tuple.StorageKeys {
|
}}
|
||||||
if slot == common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000") {
|
require.Equal(t, expected, result.Accesslist)
|
||||||
foundSlot = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !foundAddr {
|
|
||||||
t.Fatal("Access list should contain the contract address")
|
|
||||||
}
|
|
||||||
if !foundSlot {
|
|
||||||
t.Fatal("Access list should contain the storage slot")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue