|
17 | 17 | package core
|
18 | 18 |
|
19 | 19 | import (
|
| 20 | + "encoding/binary" |
20 | 21 | "errors"
|
21 | 22 | "fmt"
|
22 | 23 | "io/ioutil"
|
@@ -4312,3 +4313,89 @@ func TestSidecarsPruning(t *testing.T) {
|
4312 | 4313 | }
|
4313 | 4314 | }
|
4314 | 4315 | }
|
| 4316 | + |
| 4317 | +func TestBlockChain_2000StorageUpdate(t *testing.T) { |
| 4318 | + var ( |
| 4319 | + numTxs = 2000 |
| 4320 | + signer = types.HomesteadSigner{} |
| 4321 | + testBankKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") |
| 4322 | + testBankAddress = crypto.PubkeyToAddress(testBankKey.PublicKey) |
| 4323 | + bankFunds = big.NewInt(100000000000000000) |
| 4324 | + contractAddress = common.HexToAddress("0x1234") |
| 4325 | + gspec = Genesis{ |
| 4326 | + Config: params.TestChainConfig, |
| 4327 | + Alloc: GenesisAlloc{ |
| 4328 | + testBankAddress: {Balance: bankFunds}, |
| 4329 | + contractAddress: { |
| 4330 | + Nonce: 1, |
| 4331 | + Balance: common.Big0, |
| 4332 | + // Store 1 into slot passed by calldata |
| 4333 | + Code: []byte{ |
| 4334 | + byte(vm.PUSH0), |
| 4335 | + byte(vm.CALLDATALOAD), |
| 4336 | + byte(vm.PUSH1), |
| 4337 | + byte(0x1), |
| 4338 | + byte(vm.SWAP1), |
| 4339 | + byte(vm.SSTORE), |
| 4340 | + byte(vm.STOP), |
| 4341 | + }, |
| 4342 | + Storage: make(map[common.Hash]common.Hash), |
| 4343 | + }, |
| 4344 | + }, |
| 4345 | + GasLimit: 100e6, // 100 M |
| 4346 | + } |
| 4347 | + ) |
| 4348 | + |
| 4349 | + for i := 0; i < 1000; i++ { |
| 4350 | + gspec.Alloc[contractAddress].Storage[common.BigToHash(big.NewInt(int64(i)))] = common.BigToHash(big.NewInt(0x100)) |
| 4351 | + } |
| 4352 | + |
| 4353 | + // Generate the original common chain segment and the two competing forks |
| 4354 | + engine := ethash.NewFaker() |
| 4355 | + db := rawdb.NewMemoryDatabase() |
| 4356 | + genesis := gspec.MustCommit(db) |
| 4357 | + |
| 4358 | + blockGenerator := func(i int, block *BlockGen) { |
| 4359 | + block.SetCoinbase(common.Address{1}) |
| 4360 | + for txi := 0; txi < numTxs; txi++ { |
| 4361 | + var calldata [32]byte |
| 4362 | + binary.BigEndian.PutUint64(calldata[:], uint64(txi)) |
| 4363 | + tx, err := types.SignTx( |
| 4364 | + types.NewTransaction(uint64(txi), contractAddress, common.Big0, 100_000, |
| 4365 | + block.header.BaseFee, calldata[:]), |
| 4366 | + signer, |
| 4367 | + testBankKey) |
| 4368 | + if err != nil { |
| 4369 | + t.Error(err) |
| 4370 | + } |
| 4371 | + block.AddTx(tx) |
| 4372 | + } |
| 4373 | + } |
| 4374 | + |
| 4375 | + shared, _ := GenerateChain(params.TestChainConfig, genesis, engine, db, 1, blockGenerator, true) |
| 4376 | + err := os.Mkdir("./pebble", 0775) |
| 4377 | + if err != nil { |
| 4378 | + t.Fatal(err) |
| 4379 | + } |
| 4380 | + defer os.RemoveAll("./pebble") |
| 4381 | + // Import the shared chain and the original canonical one |
| 4382 | + diskdb, err := rawdb.NewPebbleDBDatabase("./pebble", 1024, 500000, "", false, false) |
| 4383 | + if err != nil { |
| 4384 | + t.Fatal(err) |
| 4385 | + } |
| 4386 | + defer diskdb.Close() |
| 4387 | + gspec.MustCommit(diskdb) |
| 4388 | + |
| 4389 | + chain, err := NewBlockChain(diskdb, nil, params.TestChainConfig, engine, vm.Config{}, nil, nil) |
| 4390 | + if err != nil { |
| 4391 | + t.Fatalf("failed to create tester chain: %v", err) |
| 4392 | + } |
| 4393 | + if _, err := chain.InsertChain(shared, nil); err != nil { |
| 4394 | + t.Fatalf("failed to insert shared chain: %v", err) |
| 4395 | + } |
| 4396 | + |
| 4397 | + blockHash := chain.CurrentBlock().Hash() |
| 4398 | + if blockHash != (common.HexToHash("0x684f656efba5a77f0e8b4c768a2b3479b28250fd7b81dbb9a888abf6180b01bd")) { |
| 4399 | + t.Fatalf("Block hash mismatches, exp %s got %s", common.Hash{}, blockHash) |
| 4400 | + } |
| 4401 | +} |
0 commit comments