-
Notifications
You must be signed in to change notification settings - Fork 545
/
Copy pathhistorical_block_hash_test.go
46 lines (38 loc) · 1.13 KB
/
historical_block_hash_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package arbtest
import (
"bytes"
"context"
"encoding/binary"
"math/big"
"testing"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/params"
)
func TestHistoricalBlockHash(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
builder := NewNodeBuilder(ctx).DefaultConfig(t, true)
cleanup := builder.Build(t)
defer cleanup()
for {
builder.L2.TransferBalance(t, "Faucet", "Faucet", common.Big1, builder.L2Info)
number, err := builder.L2.Client.BlockNumber(ctx)
Require(t, err)
if number > 300 {
break
}
}
block, err := builder.L2.Client.BlockByNumber(ctx, nil)
Require(t, err)
for i := uint64(0); i < block.Number().Uint64(); i++ {
var key common.Hash
binary.BigEndian.PutUint64(key[24:], i)
expectedBlock, err := builder.L2.Client.BlockByNumber(ctx, new(big.Int).SetUint64(i))
Require(t, err)
blockHash := sendContractCall(t, ctx, params.HistoryStorageAddress, builder.L2.Client, key.Bytes())
if !bytes.Equal(blockHash, expectedBlock.Hash().Bytes()) {
t.Fatalf("Expected block hash %s, got %s", expectedBlock.Hash(), blockHash)
}
}
}