Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit f315988

Browse files
Factor out a bad storage diff for testing
1 parent 6869330 commit f315988

File tree

3 files changed

+22
-30
lines changed

3 files changed

+22
-30
lines changed

libraries/shared/fetcher/geth_rpc_storage_fetcher_test.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,17 +146,8 @@ var _ = Describe("Geth RPC Storage Fetcher", func() {
146146
})
147147

148148
It("adds errors to error channel if formatting the diff as a StateDiff object fails", func(done Done) {
149-
badStorageDiffs := []statediff.StorageDiff{{
150-
Key: test_data.StorageKey,
151-
Value: []byte{1, 2, 3},
152-
// this storage value will fail to be decoded as an RLP with the following error message:
153-
// "input contains more than one value"
154-
Path: test_data.StoragePath,
155-
Proof: [][]byte{},
156-
}}
157-
158149
accountDiffs := test_data.CreatedAccountDiffs
159-
accountDiffs[0].Storage = badStorageDiffs
150+
accountDiffs[0].Storage = []statediff.StorageDiff{test_data.StorageWithBadValue}
160151

161152
stateDiff := statediff.StateDiff{
162153
BlockNumber: test_data.BlockNumber,

libraries/shared/storage/utils/diff_test.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ var _ = Describe("Storage row parsing", func() {
6767
Describe("FromGethStateDiff", func() {
6868
var (
6969
accountDiff = statediff.AccountDiff{Key: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0}}
70-
stateDiff = &statediff.StateDiff{
70+
stateDiff = &statediff.StateDiff{
7171
BlockNumber: big.NewInt(rand.Int63()),
7272
BlockHash: fakes.FakeHash,
7373
}
@@ -113,12 +113,7 @@ var _ = Describe("Storage row parsing", func() {
113113
})
114114

115115
It("returns an err if decoding the storage value Rlp fails", func() {
116-
storageDiff := statediff.StorageDiff{
117-
Key: []byte{0, 9, 8, 7, 6, 5, 4, 3, 2, 1},
118-
Value: test_data.StorageKey,
119-
}
120-
121-
_, err := utils.FromGethStateDiff(accountDiff, stateDiff, storageDiff)
116+
_, err := utils.FromGethStateDiff(accountDiff, stateDiff, test_data.StorageWithBadValue)
122117
Expect(err).To(HaveOccurred())
123118
Expect(err).To(MatchError("rlp: input contains more than one value"))
124119
})

libraries/shared/test_data/statediff.go

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,37 @@ import (
2727
)
2828

2929
var (
30-
BlockNumber = big.NewInt(rand.Int63())
31-
BlockHash = "0xfa40fbe2d98d98b3363a778d52f2bcd29d6790b9b3f3cab2b167fd12d3550f73"
32-
CodeHash = common.Hex2Bytes("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470")
33-
NewNonceValue = rand.Uint64()
34-
NewBalanceValue = rand.Int63()
35-
ContractRoot = common.HexToHash("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
36-
StoragePath = common.HexToHash("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470").Bytes()
37-
StorageKey = common.HexToHash("0000000000000000000000000000000000000000000000000000000000000001").Bytes()
38-
SmallStorageValue = common.Hex2Bytes("03")
30+
BlockNumber = big.NewInt(rand.Int63())
31+
BlockHash = "0xfa40fbe2d98d98b3363a778d52f2bcd29d6790b9b3f3cab2b167fd12d3550f73"
32+
CodeHash = common.Hex2Bytes("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470")
33+
NewNonceValue = rand.Uint64()
34+
NewBalanceValue = rand.Int63()
35+
ContractRoot = common.HexToHash("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
36+
StoragePath = common.HexToHash("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470").Bytes()
37+
StorageKey = common.HexToHash("0000000000000000000000000000000000000000000000000000000000000001").Bytes()
38+
SmallStorageValue = common.Hex2Bytes("03")
3939
SmallStorageValueRlp, _ = rlp.EncodeToBytes(SmallStorageValue)
40-
storageWithSmallValue = []statediff.StorageDiff{{
40+
storageWithSmallValue = []statediff.StorageDiff{{
4141
Key: StorageKey,
4242
Value: SmallStorageValueRlp,
4343
Path: StoragePath,
4444
Proof: [][]byte{},
4545
}}
46-
LargeStorageValue = common.Hex2Bytes("00191b53778c567b14b50ba0000")
46+
LargeStorageValue = common.Hex2Bytes("00191b53778c567b14b50ba0000")
4747
LargeStorageValueRlp, rlpErr = rlp.EncodeToBytes(LargeStorageValue)
48-
storageWithLargeValue = []statediff.StorageDiff{{
48+
storageWithLargeValue = []statediff.StorageDiff{{
4949
Key: StorageKey,
5050
Value: LargeStorageValueRlp,
5151
Path: StoragePath,
5252
Proof: [][]byte{},
5353
}}
54-
EmptyStorage = make([]statediff.StorageDiff, 0)
54+
EmptyStorage = make([]statediff.StorageDiff, 0)
55+
StorageWithBadValue = statediff.StorageDiff{
56+
Key: StorageKey,
57+
Value: []byte{0, 1, 2},
58+
// this storage value will fail to be decoded as an RLP with the following error message:
59+
// "input contains more than one value"
60+
}
5561
contractAddress = common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476592")
5662
ContractLeafKey = crypto.Keccak256Hash(contractAddress[:])
5763
anotherContractAddress = common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476593")

0 commit comments

Comments
 (0)