Skip to content

Commit 7c2d6a5

Browse files
internal/ethapi: fix simulate tests related to gas, base fee (#95)
* internal/ethapi: fix simulate tests related to gas, base fee * ethapi: fix simulate validation tests * ethapi: pass nonce to message --------- Co-authored-by: chiphamskymavis <[email protected]>
1 parent dd68b61 commit 7c2d6a5

File tree

3 files changed

+49
-19
lines changed

3 files changed

+49
-19
lines changed

internal/ethapi/api_test.go

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,10 @@ func TestSimulateV1(t *testing.T) {
10291029
}
10301030
sha256Address = common.BytesToAddress([]byte{0x02})
10311031
)
1032+
1033+
// Enable Venoki hardfork to enable basefee
1034+
genesis.Config.VenokiBlock = big.NewInt(0)
1035+
10321036
api := NewPublicBlockChainAPI(newTestBackend(t, genBlocks, genesis, ethash.NewFaker(), func(i int, b *core.BlockGen) {
10331037
b.SetCoinbase(common.HexToAddress(coinbase))
10341038
// Transfer from account[0] to account[1]
@@ -1091,6 +1095,7 @@ func TestSimulateV1(t *testing.T) {
10911095
validation *bool
10921096
expectErr error
10931097
want []blockRes
1098+
skip bool
10941099
}{
10951100
// State build-up over calls:
10961101
// First value transfer OK after state
@@ -1570,12 +1575,12 @@ func TestSimulateV1(t *testing.T) {
15701575
want: []blockRes{{
15711576
Number: "0xb",
15721577
GasLimit: "0x47e7c4",
1573-
GasUsed: "0x77dc",
1578+
GasUsed: "0xd984",
15741579
Miner: coinbase,
15751580
BaseFeePerGas: "0x0",
15761581
Calls: []callRes{{
15771582
ReturnValue: "0x",
1578-
GasUsed: "0x77dc",
1583+
GasUsed: "0xd984",
15791584
Logs: []log{{
15801585
Address: transferAddress,
15811586
Topics: []common.Hash{
@@ -1618,26 +1623,26 @@ func TestSimulateV1(t *testing.T) {
16181623
// if gt(balance(cac), 0) {
16191624
// revert(0, 0)
16201625
// }
1621-
// if gt(extcodesize(cac), 0) {
1626+
// if eq(extcodesize(cac), 0) { // After EIP-6780, code not be deleted
16221627
// revert(0, 0)
16231628
// }
16241629
// if eq(balance(dad), 0) {
16251630
// revert(0, 0)
16261631
// }
16271632
// }
16281633
// }
1629-
Input: hex2Bytes("610cac610dad600082311115601357600080fd5b6000823b1115602157600080fd5b6000813103602e57600080fd5b5050"),
1634+
Input: hex2Bytes("610cac610dad905f8131116025575f903b146021575f903114601d57005b5f80fd5b5f80fd5b5f80fd"),
16301635
}},
16311636
}, {
16321637
Calls: []TransactionArgs{{
16331638
From: &accounts[0].addr,
1634-
Input: hex2Bytes("610cac610dad600082311115601357600080fd5b6000823b1115602157600080fd5b6000813103602e57600080fd5b5050"),
1639+
Input: hex2Bytes("610cac610dad905f8131116025575f903b146021575f903114601d57005b5f80fd5b5f80fd5b5f80fd"),
16351640
}},
16361641
}},
16371642
want: []blockRes{{
16381643
Number: "0xb",
16391644
GasLimit: "0x47e7c4",
1640-
GasUsed: "0x1b83f",
1645+
GasUsed: "0x1b7ee",
16411646
Miner: coinbase,
16421647
BaseFeePerGas: "0x0",
16431648
Calls: []callRes{{
@@ -1647,19 +1652,19 @@ func TestSimulateV1(t *testing.T) {
16471652
Status: "0x1",
16481653
}, {
16491654
ReturnValue: "0x",
1650-
GasUsed: "0xe6d9",
1655+
GasUsed: "0xe688",
16511656
Logs: []log{},
16521657
Status: "0x1",
16531658
}},
16541659
}, {
16551660
Number: "0xc",
16561661
GasLimit: "0x47e7c4",
1657-
GasUsed: "0xe6d9",
1662+
GasUsed: "0xe688",
16581663
Miner: coinbase,
16591664
BaseFeePerGas: "0x0",
16601665
Calls: []callRes{{
16611666
ReturnValue: "0x",
1662-
GasUsed: "0xe6d9",
1667+
GasUsed: "0xe688",
16631668
Logs: []log{},
16641669
Status: "0x1",
16651670
}},
@@ -1671,9 +1676,10 @@ func TestSimulateV1(t *testing.T) {
16711676
tag: latest,
16721677
blocks: []simBlock{{
16731678
Calls: []TransactionArgs{{
1674-
From: &accounts[2].addr,
1675-
To: &cac,
1676-
Nonce: newUint64(2),
1679+
From: &accounts[2].addr,
1680+
To: &cac,
1681+
Nonce: newUint64(2),
1682+
MaxFeePerGas: newInt(1000000000),
16771683
}},
16781684
}},
16791685
validation: &validation,
@@ -1684,10 +1690,11 @@ func TestSimulateV1(t *testing.T) {
16841690
{
16851691
name: "validation-checks-from-contract",
16861692
tag: latest,
1693+
skip: true, // This require eip-7702 enabled to pass
16871694
blocks: []simBlock{{
16881695
StateOverrides: &StateOverride{
16891696
randomAccounts[2].addr: OverrideAccount{
1690-
Balance: newRPCBalance(big.NewInt(2098640803896784)),
1697+
Balance: newRPCBalance(big.NewInt(4712388000000000)),
16911698
Code: hex2Bytes("00"),
16921699
Nonce: newUint64(1),
16931700
},
@@ -1696,7 +1703,7 @@ func TestSimulateV1(t *testing.T) {
16961703
From: &randomAccounts[2].addr,
16971704
To: &cac,
16981705
Nonce: newUint64(1),
1699-
MaxFeePerGas: newInt(233138868),
1706+
MaxFeePerGas: newInt(1000000000),
17001707
MaxPriorityFeePerGas: newInt(1),
17011708
}},
17021709
}},
@@ -1706,7 +1713,7 @@ func TestSimulateV1(t *testing.T) {
17061713
GasLimit: "0x47e7c4",
17071714
GasUsed: "0xd166",
17081715
Miner: coinbase,
1709-
BaseFeePerGas: "0xde56ab3",
1716+
BaseFeePerGas: "0x3b9aca00",
17101717
Calls: []callRes{{
17111718
ReturnValue: "0x",
17121719
GasUsed: "0xd166",
@@ -2071,7 +2078,7 @@ func TestSimulateV1(t *testing.T) {
20712078
Calls: []TransactionArgs{{
20722079
From: &accounts[0].addr,
20732080
To: &randomAccounts[2].addr,
2074-
MaxFeePerGas: newInt(233138868),
2081+
MaxFeePerGas: newInt(1000000000),
20752082
MaxPriorityFeePerGas: newInt(1),
20762083
}},
20772084
}},
@@ -2081,9 +2088,9 @@ func TestSimulateV1(t *testing.T) {
20812088
GasLimit: "0x47e7c4",
20822089
GasUsed: "0x5227",
20832090
Miner: coinbase,
2084-
BaseFeePerGas: "0xde56ab3",
2091+
BaseFeePerGas: "0x3b9aca00",
20852092
Calls: []callRes{{
2086-
ReturnValue: "0x000000000000000000000000000000000000000000000000000000000de56ab4000000000000000000000000000000000000000000000000000000000de56ab3",
2093+
ReturnValue: "0x000000000000000000000000000000000000000000000000000000003b9aca00000000000000000000000000000000000000000000000000000000003b9aca00",
20872094
GasUsed: "0x5227",
20882095
Logs: []log{},
20892096
Status: "0x1",
@@ -2093,6 +2100,10 @@ func TestSimulateV1(t *testing.T) {
20932100
}
20942101

20952102
for _, tc := range testSuite {
2103+
if tc.skip {
2104+
continue
2105+
}
2106+
20962107
t.Run(tc.name, func(t *testing.T) {
20972108
opts := simOpts{BlockStateCalls: tc.blocks}
20982109
if tc.includeTransfers != nil && *tc.includeTransfers {

internal/ethapi/simulate.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ func (sim *simulator) processBlock(ctx context.Context, block *simBlock, header,
304304
sim.state.SetTxContext(txHash, i)
305305
// EoA check is always skipped, even in validation mode.
306306
msg, err := call.ToMessage(sim.base.GasLimit, header.BaseFee)
307+
msg.SkipAccountChecks = !sim.validate
307308
if err != nil {
308309
return nil, nil, nil, err
309310
}

internal/ethapi/transaction_args.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,25 @@ func (args *TransactionArgs) ToMessage(globalGasCap uint64, baseFee *big.Int) (*
294294
if args.BlobHashes != nil && args.BlobFeeCap == nil {
295295
args.BlobFeeCap = new(hexutil.Big)
296296
}
297-
msg := core.NewMessage(addr, args.To, 0, value, gas, gasPrice, gasFeeCap, gasTipCap, data, accessList, true, (*big.Int)(args.BlobFeeCap), args.BlobHashes)
297+
var nonce uint64
298+
if args.Nonce != nil {
299+
nonce = uint64(*args.Nonce)
300+
}
301+
msg := core.NewMessage(
302+
addr,
303+
args.To,
304+
nonce,
305+
value,
306+
gas,
307+
gasPrice,
308+
gasFeeCap,
309+
gasTipCap,
310+
data,
311+
accessList,
312+
true,
313+
(*big.Int)(args.BlobFeeCap),
314+
args.BlobHashes,
315+
)
298316
return msg, nil
299317
}
300318

0 commit comments

Comments
 (0)