Skip to content

Commit d33276f

Browse files
committed
test: add suit test
1 parent a62ec06 commit d33276f

File tree

10 files changed

+8246
-8090
lines changed

10 files changed

+8246
-8090
lines changed

cmd/devp2p/internal/ethtest/chain.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ type Chain struct {
5151
state map[common.Address]state.DumpAccount // state of head block
5252
senders map[common.Address]*senderInfo
5353
config *params.ChainConfig
54+
55+
txInfo txInfo
56+
}
57+
58+
type txInfo struct {
59+
LargeReceiptBlock uint64 `json:"tx-largereceipt"`
5460
}
5561

5662
// NewChain takes the given chain.rlp file, and decodes and returns
@@ -74,12 +80,20 @@ func NewChain(dir string) (*Chain, error) {
7480
if err != nil {
7581
return nil, err
7682
}
83+
84+
var txInfo txInfo
85+
err = common.LoadJSON(filepath.Join(dir, "txinfo.json"), &txInfo)
86+
if err != nil {
87+
return nil, err
88+
}
89+
7790
return &Chain{
7891
genesis: gen,
7992
blocks: blocks,
8093
state: state,
8194
senders: accounts,
8295
config: gen.Config,
96+
txInfo: txInfo,
8397
}, nil
8498
}
8599

cmd/devp2p/internal/ethtest/snap.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -86,29 +86,29 @@ func (s *Suite) TestSnapGetAccountRange(t *utesting.T) {
8686
root: root,
8787
startingHash: zero,
8888
limitHash: ffHash,
89-
expAccounts: 67,
89+
expAccounts: 68,
9090
expFirst: firstKey,
91-
expLast: common.HexToHash("0x622e662246601dd04f996289ce8b85e86db7bb15bb17f86487ec9d543ddb6f9a"),
91+
expLast: common.HexToHash("0x59312f89c13e9e24c1cb8b103aa39a9b2800348d97a92c2c9e2a78fa02b70025"),
9292
desc: "In this test, we request the entire state range, but limit the response to 4000 bytes.",
9393
},
9494
{
9595
nBytes: 3000,
9696
root: root,
9797
startingHash: zero,
9898
limitHash: ffHash,
99-
expAccounts: 49,
99+
expAccounts: 50,
100100
expFirst: firstKey,
101-
expLast: common.HexToHash("0x445cb5c1278fdce2f9cbdb681bdd76c52f8e50e41dbd9e220242a69ba99ac099"),
101+
expLast: common.HexToHash("0x4615e5f5df5b25349a00ad313c6cd0436b6c08ee5826e33a018661997f85ebaa"),
102102
desc: "In this test, we request the entire state range, but limit the response to 3000 bytes.",
103103
},
104104
{
105105
nBytes: 2000,
106106
root: root,
107107
startingHash: zero,
108108
limitHash: ffHash,
109-
expAccounts: 34,
109+
expAccounts: 35,
110110
expFirst: firstKey,
111-
expLast: common.HexToHash("0x2ef46ebd2073cecde499c2e8df028ad79a26d57bfaa812c4c6f7eb4c9617b913"),
111+
expLast: common.HexToHash("0x2de4bdbddcfbb9c3e195dae6b45f9c38daff897e926764bf34887fb0db5c3284"),
112112
desc: "In this test, we request the entire state range, but limit the response to 2000 bytes.",
113113
},
114114
{
@@ -177,9 +177,9 @@ The server should return the first available account.`,
177177
root: root,
178178
startingHash: firstKey,
179179
limitHash: ffHash,
180-
expAccounts: 67,
180+
expAccounts: 68,
181181
expFirst: firstKey,
182-
expLast: common.HexToHash("0x622e662246601dd04f996289ce8b85e86db7bb15bb17f86487ec9d543ddb6f9a"),
182+
expLast: common.HexToHash("0x59312f89c13e9e24c1cb8b103aa39a9b2800348d97a92c2c9e2a78fa02b70025"),
183183
desc: `In this test, startingHash is exactly the first available account key.
184184
The server should return the first available account of the state as the first item.`,
185185
},
@@ -188,9 +188,9 @@ The server should return the first available account of the state as the first i
188188
root: root,
189189
startingHash: hashAdd(firstKey, 1),
190190
limitHash: ffHash,
191-
expAccounts: 67,
191+
expAccounts: 68,
192192
expFirst: secondKey,
193-
expLast: common.HexToHash("0x66192e4c757fba1cdc776e6737008f42d50370d3cd801db3624274283bf7cd63"),
193+
expLast: common.HexToHash("0x59a7c8818f1c16b298a054020dc7c3f403a970d1d1db33f9478b1c36e3a2e509"),
194194
desc: `In this test, startingHash is after the first available key.
195195
The server should return the second account of the state as the first item.`,
196196
},
@@ -226,9 +226,9 @@ server to return no data because genesis is older than 127 blocks.`,
226226
root: s.chain.RootAt(int(s.chain.Head().Number().Uint64()) - 127),
227227
startingHash: zero,
228228
limitHash: ffHash,
229-
expAccounts: 66,
229+
expAccounts: 68,
230230
expFirst: firstKey,
231-
expLast: common.HexToHash("0x729953a43ed6c913df957172680a17e5735143ad767bda8f58ac84ec62fbec5e"),
231+
expLast: common.HexToHash("0x683b6c03cc32afe5db8cb96050f711fdaff8f8ff44c7587a9a848f921d02815e"),
232232
desc: `This test requests data at a state root that is 127 blocks old.
233233
We expect the server to have this state available.`,
234234
},
@@ -657,8 +657,8 @@ The server should reject the request.`,
657657
// It's a bit unfortunate these are hard-coded, but the result depends on
658658
// a lot of aspects of the state trie and can't be guessed in a simple
659659
// way. So you'll have to update this when the test chain is changed.
660-
common.HexToHash("0x5bdc0d6057b35642a16d27223ea5454e5a17a400e28f7328971a5f2a87773b76"),
661-
common.HexToHash("0x0a76c9812ca90ffed8ee4d191e683f93386b6e50cfe3679c0760d27510aa7fc5"),
660+
common.HexToHash("0x4bdecec09691ad38113eebee2df94fadefdff5841c0f182bae1be3c8a6d60bf3"),
661+
common.HexToHash("0x4178696465d4514ff5924ef8c28ce64d41a669634b63184c2c093e252d6b4bc4"),
662662
empty, empty, empty, empty, empty, empty, empty, empty, empty, empty, empty, empty,
663663
empty, empty, empty, empty, empty, empty, empty, empty, empty, empty, empty, empty,
664664
empty, empty, empty, empty, empty, empty, empty, empty, empty, empty, empty, empty,
@@ -678,8 +678,8 @@ The server should reject the request.`,
678678
// be updated when the test chain is changed.
679679
expHashes: []common.Hash{
680680
empty,
681-
common.HexToHash("0x0a76c9812ca90ffed8ee4d191e683f93386b6e50cfe3679c0760d27510aa7fc5"),
682-
common.HexToHash("0x5bdc0d6057b35642a16d27223ea5454e5a17a400e28f7328971a5f2a87773b76"),
681+
common.HexToHash("0x4178696465d4514ff5924ef8c28ce64d41a669634b63184c2c093e252d6b4bc4"),
682+
common.HexToHash("0x4bdecec09691ad38113eebee2df94fadefdff5841c0f182bae1be3c8a6d60bf3"),
683683
},
684684
},
685685

cmd/devp2p/internal/ethtest/suite.go

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"github.com/ethereum/go-ethereum/internal/utesting"
3535
"github.com/ethereum/go-ethereum/p2p"
3636
"github.com/ethereum/go-ethereum/p2p/enode"
37+
"github.com/ethereum/go-ethereum/trie"
3738
"github.com/holiman/uint256"
3839
)
3940

@@ -82,6 +83,7 @@ func (s *Suite) EthTests() []utesting.Test {
8283
// get history
8384
{Name: "GetBlockBodies", Fn: s.TestGetBlockBodies},
8485
{Name: "GetReceipts", Fn: s.TestGetReceipts},
86+
{Name: "GetLargeReceipts", Fn: s.TestGetLargeReceipts},
8587
// test transactions
8688
{Name: "LargeTxRequest", Fn: s.TestLargeTxRequest, Slow: true},
8789
{Name: "Transaction", Fn: s.TestTransaction},
@@ -455,6 +457,86 @@ func (s *Suite) TestGetReceipts(t *utesting.T) {
455457
}
456458
}
457459

460+
func (s *Suite) TestGetLargeReceipts(t *utesting.T) {
461+
t.Log(`This test sends GetReceipts requests to the node for large receipt (>10MiB) in the test chain.`)
462+
conn, err := s.dialAndPeer(nil)
463+
if err != nil {
464+
t.Fatalf("peering failed: %v", err)
465+
}
466+
defer conn.Close()
467+
468+
// Find block with large receipt.
469+
// Place the large receipt block hash in the middle of the query
470+
start := max(s.chain.txInfo.LargeReceiptBlock-2, 0)
471+
end := min(s.chain.txInfo.LargeReceiptBlock+2, uint64(len(s.chain.blocks)))
472+
473+
var blocks []common.Hash
474+
var receiptHashes []common.Hash
475+
476+
for i := start; i < end; i++ {
477+
block := s.chain.GetBlock(int(i))
478+
blocks = append(blocks, block.Hash())
479+
receiptHashes = append(receiptHashes, block.Header().ReceiptHash)
480+
}
481+
482+
// Query recursively until we collect every receipt
483+
var loopLimit = 6
484+
485+
incomplete := false
486+
lastBlock := 0
487+
receipts := make([]*eth.ReceiptList69, len(blocks))
488+
for i := range receipts {
489+
receipts[i] = &eth.ReceiptList69{}
490+
}
491+
492+
for incomplete || loopLimit > 0 {
493+
// Create get receipt request.
494+
req := &eth.GetReceiptsPacket70{
495+
RequestId: 66,
496+
GetReceiptsRequest: blocks[lastBlock:],
497+
FirstBlockReceiptIndex: uint64(receipts[lastBlock].Len()),
498+
}
499+
if err := conn.Write(ethProto, eth.GetReceiptsMsg, req); err != nil {
500+
t.Fatalf("could not write to connection: %v", err)
501+
}
502+
// Wait for response.
503+
resp := new(eth.ReceiptsPacket70)
504+
if err := conn.ReadMsg(ethProto, eth.ReceiptsMsg, &resp); err != nil {
505+
t.Fatalf("error reading block receipts msg: %v", err)
506+
}
507+
if got, want := resp.RequestId, req.RequestId; got != want {
508+
t.Fatalf("unexpected request id in respond", got, want)
509+
}
510+
511+
for i, rc := range resp.List {
512+
receipts[lastBlock+i].Append(rc)
513+
}
514+
lastBlock += len(resp.List) - 1
515+
516+
incomplete = resp.LastBlockIncomplete
517+
loopLimit -= 1
518+
}
519+
if incomplete {
520+
t.Fatal("loop terminated before the completion of request")
521+
}
522+
523+
if len(receipts) != len(receiptHashes) {
524+
t.Fatalf("wrong total response length: want %d, got %d", len(receiptHashes), len(receipts))
525+
}
526+
527+
hasher := trie.NewStackTrie(nil)
528+
hashes := make([]common.Hash, len(receipts))
529+
for i := range receipts {
530+
hashes[i] = types.DeriveSha(receipts[i], hasher)
531+
}
532+
533+
for i, hash := range hashes {
534+
if receiptHashes[i] != hash {
535+
t.Fatalf("wrong receipt root: want %x, got %x", receiptHashes[i], hash)
536+
}
537+
}
538+
}
539+
458540
// randBuf makes a random buffer size kilobytes large.
459541
func randBuf(size int) []byte {
460542
buf := make([]byte, size*1024)
5.95 KB
Binary file not shown.

cmd/devp2p/internal/ethtest/testdata/genesis.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"nonce": "0x0",
3838
"timestamp": "0x0",
3939
"extraData": "0x68697665636861696e",
40-
"gasLimit": "0x23f3e20",
40+
"gasLimit": "0x11e1a300",
4141
"difficulty": "0x20000",
4242
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
4343
"coinbase": "0x0000000000000000000000000000000000000000",
@@ -119,6 +119,10 @@
119119
"balance": "0x1",
120120
"nonce": "0x1"
121121
},
122+
"8dcd17433742f4c0ca53122ab541d0ba67fc27ff": {
123+
"code": "0x6202e6306000a0",
124+
"balance": "0x0"
125+
},
122126
"c7b99a164efd027a93f147376cc7da7c67c6bbe0": {
123127
"balance": "0xc097ce7bc90715b34b9f1000000000"
124128
},
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
{
2-
"parentHash": "0x65151b101682b54cd08ba226f640c14c86176865ff9bfc57e0147dadaeac34bb",
2+
"parentHash": "0x7e80093a491eba0e5b2c1895837902f64f514100221801318fe391e1e09c96a6",
33
"sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
44
"miner": "0x0000000000000000000000000000000000000000",
5-
"stateRoot": "0xce423ebc60fc7764a43f09f1fe3ae61eef25e3eb8d09b1108f7e7eb77dfff5e6",
6-
"transactionsRoot": "0x7ec1ae3989efa75d7bcc766e5e2443afa8a89a5fda42ebba90050e7e702980f7",
7-
"receiptsRoot": "0xfe160832b1ca85f38c6674cb0aae3a24693bc49be56e2ecdf3698b71a794de86",
5+
"stateRoot": "0x8fcfb02cfca007773bd55bc1c3e50a3c8612a59c87ce057e5957e8bf17c1728b",
6+
"transactionsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
7+
"receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
88
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
99
"difficulty": "0x0",
1010
"number": "0x258",
11-
"gasLimit": "0x23f3e20",
12-
"gasUsed": "0x19d36",
11+
"gasLimit": "0x11e1a300",
12+
"gasUsed": "0x0",
1313
"timestamp": "0x1770",
1414
"extraData": "0x",
1515
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
1616
"nonce": "0x0000000000000000",
1717
"baseFeePerGas": "0x7",
18-
"withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
18+
"withdrawalsRoot": "0x92abfda39de7df7d705c5a8f30386802ad59d31e782a06d5c5b0f9a260056cf0",
1919
"blobGasUsed": "0x0",
2020
"excessBlobGas": "0x0",
2121
"parentBeaconBlockRoot": "0xf5003fc8f92358e790a114bce93ce1d9c283c85e1787f8d7d56714d3489b49e6",
2222
"requestsHash": "0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
23-
"hash": "0xce8d86ba17a2ec303155f0e264c58a4b8f94ce3436274cf1924f91acdb7502d0"
23+
"hash": "0x44e3809c9a3cda717f00aea3a9da336d149612c8d5657fbc0028176ef8d94d2a"
2424
}

cmd/devp2p/internal/ethtest/testdata/headfcu.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
"method": "engine_forkchoiceUpdatedV3",
55
"params": [
66
{
7-
"headBlockHash": "0xce8d86ba17a2ec303155f0e264c58a4b8f94ce3436274cf1924f91acdb7502d0",
8-
"safeBlockHash": "0xce8d86ba17a2ec303155f0e264c58a4b8f94ce3436274cf1924f91acdb7502d0",
9-
"finalizedBlockHash": "0xce8d86ba17a2ec303155f0e264c58a4b8f94ce3436274cf1924f91acdb7502d0"
7+
"headBlockHash": "0x44e3809c9a3cda717f00aea3a9da336d149612c8d5657fbc0028176ef8d94d2a",
8+
"safeBlockHash": "0x44e3809c9a3cda717f00aea3a9da336d149612c8d5657fbc0028176ef8d94d2a",
9+
"finalizedBlockHash": "0x44e3809c9a3cda717f00aea3a9da336d149612c8d5657fbc0028176ef8d94d2a"
1010
},
1111
null
1212
]

0 commit comments

Comments
 (0)