Skip to content

Commit 5365d3d

Browse files
committed
Update prev-randao tests
1 parent 39f5606 commit 5365d3d

File tree

3 files changed

+110
-77
lines changed

3 files changed

+110
-77
lines changed

simulators/ethereum/engine/suites/cancun/tests.go

+6
Original file line numberDiff line numberDiff line change
@@ -1865,4 +1865,10 @@ func init() {
18651865
TransactionCount: 1, // Only one blob tx gets through due to blob gas limit
18661866
},
18671867
)
1868+
// Prev Randao Tests (New Transaction Type)
1869+
Tests = append(Tests,
1870+
suite_engine.PrevRandaoTransactionTest{
1871+
BaseSpec: onlyBlobTxsSpec,
1872+
},
1873+
)
18681874
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package suite_engine
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/ethereum/go-ethereum/common"
8+
"github.com/ethereum/hive/simulators/ethereum/engine/clmock"
9+
"github.com/ethereum/hive/simulators/ethereum/engine/config"
10+
"github.com/ethereum/hive/simulators/ethereum/engine/globals"
11+
"github.com/ethereum/hive/simulators/ethereum/engine/helper"
12+
"github.com/ethereum/hive/simulators/ethereum/engine/test"
13+
typ "github.com/ethereum/hive/simulators/ethereum/engine/types"
14+
)
15+
16+
type PrevRandaoTransactionTest struct {
17+
test.BaseSpec
18+
BlockCount int
19+
}
20+
21+
func (s PrevRandaoTransactionTest) WithMainFork(fork config.Fork) test.Spec {
22+
specCopy := s
23+
specCopy.MainFork = fork
24+
return specCopy
25+
}
26+
27+
func (t PrevRandaoTransactionTest) GetName() string {
28+
return fmt.Sprintf("PrevRandao Opcode Transactions Test (%s)", t.TestTransactionType)
29+
}
30+
31+
func (tc PrevRandaoTransactionTest) Execute(t *test.Env) {
32+
t.CLMock.WaitForTTD()
33+
34+
// Create a single block to not having to build on top of genesis
35+
t.CLMock.ProduceSingleBlock(clmock.BlockProcessCallbacks{})
36+
37+
startBlockNumber := t.CLMock.LatestHeader.Number.Uint64() + 1
38+
39+
// Send transactions in PoS, the value of the storage in these blocks must match the prevRandao value
40+
var (
41+
blockCount = 10
42+
currentTxIndex = 0
43+
txs = make([]typ.Transaction, 0)
44+
)
45+
if tc.BlockCount > 0 {
46+
blockCount = tc.BlockCount
47+
}
48+
t.CLMock.ProduceBlocks(blockCount, clmock.BlockProcessCallbacks{
49+
OnPayloadProducerSelected: func() {
50+
tx, err := t.SendNextTransaction(
51+
t.TestContext,
52+
t.Engine,
53+
&helper.BaseTransactionCreator{
54+
Recipient: &globals.PrevRandaoContractAddr,
55+
Amount: big0,
56+
Payload: nil,
57+
TxType: t.TestTransactionType,
58+
GasLimit: 75000,
59+
ForkConfig: t.ForkConfig,
60+
},
61+
)
62+
if err != nil {
63+
t.Fatalf("FAIL (%s): Error trying to send transaction: %v", t.TestName, err)
64+
}
65+
txs = append(txs, tx)
66+
currentTxIndex++
67+
},
68+
OnForkchoiceBroadcast: func() {
69+
// Check the transaction tracing, which is client specific
70+
expectedPrevRandao := t.CLMock.PrevRandaoHistory[t.CLMock.LatestHeader.Number.Uint64()+1]
71+
ctx, cancel := context.WithTimeout(t.TestContext, globals.RPCTimeout)
72+
defer cancel()
73+
if err := helper.DebugPrevRandaoTransaction(ctx, t.Client.RPC(), t.Client.Type, txs[currentTxIndex-1],
74+
&expectedPrevRandao); err != nil {
75+
t.Fatalf("FAIL (%s): Error during transaction tracing: %v", t.TestName, err)
76+
}
77+
},
78+
})
79+
80+
for i := uint64(startBlockNumber); i <= t.CLMock.LatestExecutedPayload.Number; i++ {
81+
checkPrevRandaoValue(t, t.CLMock.PrevRandaoHistory[i], i)
82+
}
83+
}
84+
85+
func checkPrevRandaoValue(t *test.Env, expectedPrevRandao common.Hash, blockNumber uint64) {
86+
storageKey := common.Hash{}
87+
storageKey[31] = byte(blockNumber)
88+
r := t.TestEngine.TestStorageAt(globals.PrevRandaoContractAddr, storageKey, nil)
89+
r.ExpectStorageEqual(expectedPrevRandao)
90+
}

simulators/ethereum/engine/suites/engine/tests.go

+14-77
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,6 @@ var Tests = []test.Spec{
9595
SlotsToSafe: big.NewInt(1),
9696
SlotsToFinalized: big.NewInt(2),
9797
},
98-
99-
// PrevRandao opcode tests
100-
&test.BaseSpec{
101-
Name: "PrevRandao Opcode Transactions",
102-
Run: prevRandaoOpcodeTx,
103-
TestTransactionType: helper.LegacyTxOnly,
104-
},
105-
&test.BaseSpec{
106-
Name: "PrevRandao Opcode Transactions (EIP-1559 Transactions)",
107-
Run: prevRandaoOpcodeTx,
108-
TestTransactionType: helper.DynamicFeeTxOnly,
109-
},
11098
}
11199

112100
// Test to verify Block information available after a reorg using forkchoiceUpdated
@@ -789,72 +777,7 @@ func buildPayloadWithInvalidChainIDTx(t *test.Env) {
789777

790778
}
791779

792-
// TODO: Do a PENDING block suggestedFeeRecipient
793-
794-
func checkPrevRandaoValue(t *test.Env, expectedPrevRandao common.Hash, blockNumber uint64) {
795-
storageKey := common.Hash{}
796-
storageKey[31] = byte(blockNumber)
797-
r := t.TestEngine.TestStorageAt(globals.PrevRandaoContractAddr, storageKey, nil)
798-
r.ExpectStorageEqual(expectedPrevRandao)
799-
800-
}
801-
802-
// PrevRandao Opcode tests
803-
func prevRandaoOpcodeTx(t *test.Env) {
804-
t.CLMock.WaitForTTD()
805-
806-
// Send transactions in PoS, the value of the storage in these blocks must match the prevRandao value
807-
var (
808-
txCount = 10
809-
currentTxIndex = 0
810-
txs = make([]typ.Transaction, 0)
811-
)
812-
t.CLMock.ProduceBlocks(txCount, clmock.BlockProcessCallbacks{
813-
OnPayloadProducerSelected: func() {
814-
tx, err := t.SendNextTransaction(
815-
t.TestContext,
816-
t.Engine,
817-
&helper.BaseTransactionCreator{
818-
Recipient: &globals.PrevRandaoContractAddr,
819-
Amount: big0,
820-
Payload: nil,
821-
TxType: t.TestTransactionType,
822-
GasLimit: 75000,
823-
ForkConfig: t.ForkConfig,
824-
},
825-
)
826-
if err != nil {
827-
t.Fatalf("FAIL (%s): Error trying to send transaction: %v", t.TestName, err)
828-
}
829-
txs = append(txs, tx)
830-
currentTxIndex++
831-
},
832-
OnForkchoiceBroadcast: func() {
833-
// Check the transaction tracing, which is client specific
834-
expectedPrevRandao := t.CLMock.PrevRandaoHistory[t.CLMock.LatestHeader.Number.Uint64()+1]
835-
ctx, cancel := context.WithTimeout(t.TestContext, globals.RPCTimeout)
836-
defer cancel()
837-
if err := helper.DebugPrevRandaoTransaction(ctx, t.Client.RPC(), t.Client.Type, txs[currentTxIndex-1],
838-
&expectedPrevRandao); err != nil {
839-
t.Fatalf("FAIL (%s): Error during transaction tracing: %v", t.TestName, err)
840-
}
841-
},
842-
})
843-
844-
ctx, cancel := context.WithTimeout(t.TestContext, globals.RPCTimeout)
845-
defer cancel()
846-
lastBlockNumber, err := t.Eth.BlockNumber(ctx)
847-
if err != nil {
848-
t.Fatalf("FAIL (%s): Unable to get latest block number: %v", t.TestName, err)
849-
}
850-
for i := uint64(1); i <= lastBlockNumber; i++ {
851-
checkPrevRandaoValue(t, t.CLMock.PrevRandaoHistory[i], i)
852-
}
853-
854-
}
855-
856780
// Engine API errors
857-
858781
func pUint64(v uint64) *uint64 {
859782
return &v
860783
}
@@ -1150,6 +1073,20 @@ func init() {
11501073
},
11511074
)
11521075

1076+
// PrevRandao opcode tests
1077+
Tests = append(Tests,
1078+
PrevRandaoTransactionTest{
1079+
BaseSpec: test.BaseSpec{
1080+
TestTransactionType: helper.LegacyTxOnly,
1081+
},
1082+
},
1083+
PrevRandaoTransactionTest{
1084+
BaseSpec: test.BaseSpec{
1085+
TestTransactionType: helper.DynamicFeeTxOnly,
1086+
},
1087+
},
1088+
)
1089+
11531090
// Fork ID Tests
11541091
Tests = append(Tests,
11551092
ForkIDSpec{

0 commit comments

Comments
 (0)