Skip to content

Commit d07277e

Browse files
authored
Merge branch 'main' into peter/allow-specifying-build-tag
2 parents 9d8291f + 4481ad0 commit d07277e

20 files changed

+519
-124
lines changed

api/api.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,11 @@ func (b *BlockChainAPI) EstimateGas(
723723
return handleError[hexutil.Uint64](err, b.logger, b.collector)
724724
}
725725

726+
blockOverridesArgs, err := json.Marshal(blockOverrides)
727+
if err != nil {
728+
return handleError[hexutil.Uint64](err, b.logger, b.collector)
729+
}
730+
726731
txArgs, err := json.Marshal(args)
727732
if err != nil {
728733
return handleError[hexutil.Uint64](err, b.logger, b.collector)
@@ -733,6 +738,7 @@ func (b *BlockChainAPI) EstimateGas(
733738
RawJSON("args", txArgs).
734739
Str("blockTag", fmt.Sprintf("%v", blockNumberOrHash)).
735740
RawJSON("stateOverrides", stateOverridesArgs).
741+
RawJSON("blockOverrides", blockOverridesArgs).
736742
Logger()
737743

738744
if err := b.rateLimiter.Apply(ctx, EthEstimateGas); err != nil {

api/debug.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,10 @@ func (d *DebugAPI) TraceCall(
181181

182182
if config.BlockOverrides != nil {
183183
blocksProvider = blocksProvider.WithBlockOverrides(&ethTypes.BlockOverrides{
184-
Number: config.BlockOverrides.Number,
185-
Time: config.BlockOverrides.Time,
186-
Coinbase: config.BlockOverrides.FeeRecipient,
187-
Random: config.BlockOverrides.PrevRandao,
184+
Number: config.BlockOverrides.Number,
185+
Time: config.BlockOverrides.Time,
186+
FeeRecipient: config.BlockOverrides.FeeRecipient,
187+
PrevRandao: config.BlockOverrides.PrevRandao,
188188
})
189189
}
190190
viewProvider := query.NewViewProvider(

eth/types/types.go

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -433,29 +433,32 @@ type SignTransactionResult struct {
433433
// of a message call.
434434
// Note, state and stateDiff can't be specified at the same time. If state is
435435
// set, message execution will only use the data in the given state. Otherwise
436-
// if statDiff is set, all diff will be applied first and then execute the call
436+
// if stateDiff is set, all diff will be applied first and then execute the call
437437
// message.
438438
type OverrideAccount struct {
439-
Nonce *hexutil.Uint64 `json:"nonce"`
440-
Code *hexutil.Bytes `json:"code"`
441-
Balance **hexutil.Big `json:"balance"`
442-
State *map[common.Hash]common.Hash `json:"state"`
443-
StateDiff *map[common.Hash]common.Hash `json:"stateDiff"`
439+
Nonce *hexutil.Uint64 `json:"nonce"`
440+
Code *hexutil.Bytes `json:"code"`
441+
Balance *hexutil.Big `json:"balance"`
442+
State map[common.Hash]common.Hash `json:"state"`
443+
StateDiff map[common.Hash]common.Hash `json:"stateDiff"`
444+
MovePrecompileTo *common.Address `json:"movePrecompileToAddress"`
444445
}
445446

446447
// StateOverride is the collection of overridden accounts.
447448
type StateOverride map[common.Address]OverrideAccount
448449

449450
// BlockOverrides is a set of header fields to override.
450451
type BlockOverrides struct {
451-
Number *hexutil.Big
452-
Difficulty *hexutil.Big
453-
Time *hexutil.Uint64
454-
GasLimit *hexutil.Uint64
455-
Coinbase *common.Address
456-
Random *common.Hash
457-
BaseFee *hexutil.Big
458-
BlobBaseFee *hexutil.Big
452+
Number *hexutil.Big
453+
Difficulty *hexutil.Big // No-op if we're simulating post-merge calls.
454+
Time *hexutil.Uint64
455+
GasLimit *hexutil.Uint64
456+
FeeRecipient *common.Address
457+
PrevRandao *common.Hash
458+
BaseFeePerGas *hexutil.Big
459+
BlobBaseFee *hexutil.Big
460+
BeaconRoot *common.Hash
461+
Withdrawals *types.Withdrawals
459462
}
460463

461464
type Block struct {

services/requester/overridable_blocks_provider.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ func (bs *blockSnapshot) BlockContext() (evmTypes.BlockContext, error) {
5454
blockContext.BlockTimestamp = uint64(*bs.blockOverrides.Time)
5555
}
5656

57-
if bs.blockOverrides.Random != nil {
58-
blockContext.Random = *bs.blockOverrides.Random
57+
if bs.blockOverrides.PrevRandao != nil {
58+
blockContext.Random = *bs.blockOverrides.PrevRandao
5959
}
6060

61-
if bs.blockOverrides.Coinbase != nil {
62-
blockContext.GasFeeCollector = evmTypes.NewAddress(*bs.blockOverrides.Coinbase)
61+
if bs.blockOverrides.FeeRecipient != nil {
62+
blockContext.GasFeeCollector = evmTypes.NewAddress(*bs.blockOverrides.FeeRecipient)
6363
}
6464

6565
return blockContext, nil

services/requester/requester.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -538,18 +538,18 @@ func (e *EVM) dryRunTx(
538538
}
539539
// Override account balance.
540540
if account.Balance != nil {
541-
opts = append(opts, query.WithStateOverrideBalance(addr, (*big.Int)(*account.Balance)))
541+
opts = append(opts, query.WithStateOverrideBalance(addr, (*big.Int)(account.Balance)))
542542
}
543543
if account.State != nil && account.StateDiff != nil {
544544
return nil, fmt.Errorf("account %s has both 'state' and 'stateDiff'", addr.Hex())
545545
}
546546
// Replace entire state if caller requires.
547547
if account.State != nil {
548-
opts = append(opts, query.WithStateOverrideState(addr, *account.State))
548+
opts = append(opts, query.WithStateOverrideState(addr, account.State))
549549
}
550550
// Apply state diff into specified accounts.
551551
if account.StateDiff != nil {
552-
opts = append(opts, query.WithStateOverrideStateDiff(addr, *account.StateDiff))
552+
opts = append(opts, query.WithStateOverrideStateDiff(addr, account.StateDiff))
553553
}
554554
}
555555
}

tests/e2e_web3js_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ func TestWeb3_E2E(t *testing.T) {
7878
runWeb3Test(t, "eth_deploy_contract_and_interact_test")
7979
})
8080

81+
t.Run("apply state overrides", func(t *testing.T) {
82+
runWeb3Test(t, "eth_state_overrides_test")
83+
})
84+
8185
t.Run("test retrieval of contract storage slots", func(t *testing.T) {
8286
runWeb3Test(t, "eth_get_storage_at_test")
8387
})

tests/fixtures/storage.byte

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

tests/fixtures/storage.sol

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ contract Storage {
1111
error MyCustomError(uint value, string message);
1212

1313
uint256 number;
14+
address deployer = 0xea02F564664A477286B93712829180be4764fAe2;
1415

1516
constructor() payable {
1617
number = 1337;
@@ -30,10 +31,18 @@ contract Storage {
3031
revert();
3132
}
3233

33-
function retrieve() public view returns (uint256){
34+
function retrieve() public view returns (uint256) {
3435
return number;
3536
}
3637

38+
function getDeployer() public view returns (address) {
39+
return deployer;
40+
}
41+
42+
function getBalance(address addr) public view returns (uint256) {
43+
return addr.balance;
44+
}
45+
3746
function sum(int A, int B) public returns (int) {
3847
int s = A+B;
3948
emit Calculated(msg.sender, A, B, s);
@@ -64,11 +73,11 @@ contract Storage {
6473
selfdestruct(payable(msg.sender));
6574
}
6675

67-
function assertError() public pure{
76+
function assertError() public pure {
6877
require(false, "Assert Error Message");
6978
}
7079

71-
function customError() public pure{
80+
function customError() public pure {
7281
revert MyCustomError(5, "Value is too low");
7382
}
7483

@@ -86,14 +95,14 @@ contract Storage {
8695
return output;
8796
}
8897

89-
function verifyArchCallToFlowBlockHeight() public view returns (uint64){
98+
function verifyArchCallToFlowBlockHeight() public view returns (uint64) {
9099
(bool ok, bytes memory data) = cadenceArch.staticcall(abi.encodeWithSignature("flowBlockHeight()"));
91100
require(ok, "unsuccessful call to arch ");
92101
uint64 output = abi.decode(data, (uint64));
93102
return output;
94103
}
95104

96-
function verifyArchCallToVerifyCOAOwnershipProof(address arg0 , bytes32 arg1 , bytes memory arg2 ) public view returns (bool){
105+
function verifyArchCallToVerifyCOAOwnershipProof(address arg0, bytes32 arg1, bytes memory arg2) public view returns (bool) {
97106
(bool ok, bytes memory data) = cadenceArch.staticcall(abi.encodeWithSignature("verifyCOAOwnershipProof(address,bytes32,bytes)", arg0, arg1, arg2));
98107
require(ok, "unsuccessful call to arch");
99108
bool output = abi.decode(data, (bool));

tests/fixtures/storageABI.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,38 @@
162162
"stateMutability": "nonpayable",
163163
"type": "function"
164164
},
165+
{
166+
"inputs": [
167+
{
168+
"internalType": "address",
169+
"name": "addr",
170+
"type": "address"
171+
}
172+
],
173+
"name": "getBalance",
174+
"outputs": [
175+
{
176+
"internalType": "uint256",
177+
"name": "",
178+
"type": "uint256"
179+
}
180+
],
181+
"stateMutability": "view",
182+
"type": "function"
183+
},
184+
{
185+
"inputs": [],
186+
"name": "getDeployer",
187+
"outputs": [
188+
{
189+
"internalType": "address",
190+
"name": "",
191+
"type": "address"
192+
}
193+
],
194+
"stateMutability": "view",
195+
"type": "function"
196+
},
165197
{
166198
"inputs": [],
167199
"name": "random",

tests/go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ require (
77
github.com/goccy/go-json v0.10.4
88
github.com/onflow/cadence v1.7.0
99
github.com/onflow/crypto v0.25.3
10-
github.com/onflow/flow-emulator v1.7.2-0.20250916183715-baa3aeb95f6a
10+
github.com/onflow/flow-emulator v1.7.2
1111
github.com/onflow/flow-evm-gateway v0.0.0-20240201154855-4d4d3d3f19c7
1212
github.com/onflow/flow-go v0.43.0
13-
github.com/onflow/flow-go-sdk v1.8.1
13+
github.com/onflow/flow-go-sdk v1.8.2
1414
github.com/rs/zerolog v1.34.0
1515
github.com/stretchr/testify v1.11.1
1616
golang.org/x/sync v0.16.0
@@ -247,7 +247,7 @@ require (
247247
google.golang.org/genproto/googleapis/api v0.0.0-20250707201910-8d1bb00bc6a7 // indirect
248248
google.golang.org/genproto/googleapis/rpc v0.0.0-20250804133106-a7a43d27e69b // indirect
249249
google.golang.org/grpc v1.75.1 // indirect
250-
google.golang.org/protobuf v1.36.8 // indirect
250+
google.golang.org/protobuf v1.36.9 // indirect
251251
gopkg.in/ini.v1 v1.67.0 // indirect
252252
gopkg.in/yaml.v2 v2.4.0 // indirect
253253
gopkg.in/yaml.v3 v3.0.1 // indirect

0 commit comments

Comments
 (0)