2019-07-08 20:34:06 +00:00
|
|
|
// Copyright 2018 Vulcanize
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package test_data
|
|
|
|
|
|
|
|
import (
|
2019-09-30 17:34:43 +00:00
|
|
|
"math/big"
|
|
|
|
"math/rand"
|
|
|
|
|
2019-07-08 20:34:06 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
"github.com/ethereum/go-ethereum/core/state"
|
|
|
|
"github.com/ethereum/go-ethereum/core/types"
|
|
|
|
"github.com/ethereum/go-ethereum/crypto"
|
|
|
|
"github.com/ethereum/go-ethereum/rlp"
|
|
|
|
"github.com/ethereum/go-ethereum/statediff"
|
2019-09-30 17:34:43 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/libraries/shared/storage/utils"
|
2019-07-08 20:34:06 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2019-09-03 17:32:02 +00:00
|
|
|
BlockNumber = big.NewInt(rand.Int63())
|
2019-09-30 17:34:43 +00:00
|
|
|
BlockNumber2 = big.NewInt(0).Add(BlockNumber, big.NewInt(1))
|
2019-09-03 17:32:02 +00:00
|
|
|
BlockHash = "0xfa40fbe2d98d98b3363a778d52f2bcd29d6790b9b3f3cab2b167fd12d3550f73"
|
2019-09-30 17:34:43 +00:00
|
|
|
BlockHash2 = "0xaa40fbe2d98d98b3363a778d52f2bcd29d6790b9b3f3cab2b167fd12d3550f72"
|
2019-09-03 17:32:02 +00:00
|
|
|
CodeHash = common.Hex2Bytes("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470")
|
|
|
|
NewNonceValue = rand.Uint64()
|
|
|
|
NewBalanceValue = rand.Int63()
|
|
|
|
ContractRoot = common.HexToHash("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
|
|
|
|
StoragePath = common.HexToHash("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470").Bytes()
|
|
|
|
StorageKey = common.HexToHash("0000000000000000000000000000000000000000000000000000000000000001").Bytes()
|
|
|
|
SmallStorageValue = common.Hex2Bytes("03")
|
2019-08-30 19:17:26 +00:00
|
|
|
SmallStorageValueRlp, _ = rlp.EncodeToBytes(SmallStorageValue)
|
2020-05-19 20:09:30 +00:00
|
|
|
storageWithSmallValue = []statediff.StorageNode{{
|
2020-03-11 18:41:59 +00:00
|
|
|
LeafKey: StorageKey,
|
|
|
|
NodeValue: SmallStorageValueRlp,
|
|
|
|
NodeType: statediff.Leaf,
|
|
|
|
Path: StoragePath,
|
2019-07-08 20:34:06 +00:00
|
|
|
}}
|
2019-09-30 17:34:43 +00:00
|
|
|
LargeStorageValue = common.Hex2Bytes("00191b53778c567b14b50ba0000")
|
|
|
|
LargeStorageValueRlp, _ = rlp.EncodeToBytes(LargeStorageValue)
|
2020-05-19 20:09:30 +00:00
|
|
|
storageWithLargeValue = []statediff.StorageNode{{
|
2020-03-11 18:41:59 +00:00
|
|
|
LeafKey: StorageKey,
|
|
|
|
NodeValue: LargeStorageValueRlp,
|
|
|
|
Path: StoragePath,
|
|
|
|
NodeType: statediff.Leaf,
|
2019-08-30 19:17:26 +00:00
|
|
|
}}
|
2020-05-19 20:09:30 +00:00
|
|
|
StorageWithBadValue = statediff.StorageNode{
|
2020-03-11 18:41:59 +00:00
|
|
|
LeafKey: StorageKey,
|
|
|
|
NodeValue: []byte{0, 1, 2},
|
|
|
|
NodeType: statediff.Leaf,
|
|
|
|
Path: StoragePath,
|
2019-09-03 17:32:02 +00:00
|
|
|
// this storage value will fail to be decoded as an RLP with the following error message:
|
|
|
|
// "input contains more than one value"
|
|
|
|
}
|
2019-07-08 20:34:06 +00:00
|
|
|
contractAddress = common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476592")
|
|
|
|
ContractLeafKey = crypto.Keccak256Hash(contractAddress[:])
|
|
|
|
anotherContractAddress = common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476593")
|
|
|
|
AnotherContractLeafKey = crypto.Keccak256Hash(anotherContractAddress[:])
|
|
|
|
|
2019-07-08 22:52:06 +00:00
|
|
|
testAccount = state.Account{
|
2019-07-08 20:34:06 +00:00
|
|
|
Nonce: NewNonceValue,
|
|
|
|
Balance: big.NewInt(NewBalanceValue),
|
|
|
|
Root: ContractRoot,
|
|
|
|
CodeHash: CodeHash,
|
|
|
|
}
|
|
|
|
valueBytes, _ = rlp.EncodeToBytes(testAccount)
|
2020-05-19 20:09:30 +00:00
|
|
|
CreatedAccountDiffs = []statediff.StateNode{
|
2019-07-08 20:34:06 +00:00
|
|
|
{
|
2020-05-19 20:09:30 +00:00
|
|
|
LeafKey: ContractLeafKey.Bytes(),
|
|
|
|
NodeValue: valueBytes,
|
|
|
|
StorageNodes: storageWithSmallValue,
|
2019-07-08 20:34:06 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-05-19 20:09:30 +00:00
|
|
|
UpdatedAccountDiffs = []statediff.StateNode{{
|
|
|
|
LeafKey: AnotherContractLeafKey.Bytes(),
|
|
|
|
NodeValue: valueBytes,
|
|
|
|
StorageNodes: storageWithLargeValue,
|
2019-07-08 20:34:06 +00:00
|
|
|
}}
|
2020-05-19 20:09:30 +00:00
|
|
|
UpdatedAccountDiffs2 = []statediff.StateNode{{
|
|
|
|
LeafKey: AnotherContractLeafKey.Bytes(),
|
|
|
|
NodeValue: valueBytes,
|
|
|
|
StorageNodes: storageWithSmallValue,
|
2019-09-30 17:34:43 +00:00
|
|
|
}}
|
2019-07-08 20:34:06 +00:00
|
|
|
|
2020-05-19 20:09:30 +00:00
|
|
|
DeletedAccountDiffs = []statediff.StateNode{{
|
|
|
|
LeafKey: AnotherContractLeafKey.Bytes(),
|
|
|
|
NodeValue: valueBytes,
|
|
|
|
StorageNodes: storageWithSmallValue,
|
2019-07-08 20:34:06 +00:00
|
|
|
}}
|
|
|
|
|
2020-05-19 20:09:30 +00:00
|
|
|
MockStateDiff = statediff.StateObject{
|
|
|
|
BlockNumber: BlockNumber,
|
|
|
|
BlockHash: common.HexToHash(BlockHash),
|
|
|
|
Nodes: append(append(CreatedAccountDiffs, UpdatedAccountDiffs...), DeletedAccountDiffs...),
|
2019-07-08 20:34:06 +00:00
|
|
|
}
|
2020-05-19 20:09:30 +00:00
|
|
|
MockStateDiff2 = statediff.StateObject{
|
|
|
|
BlockNumber: BlockNumber2,
|
|
|
|
BlockHash: common.HexToHash(BlockHash2),
|
|
|
|
Nodes: UpdatedAccountDiffs2,
|
2019-09-30 17:34:43 +00:00
|
|
|
}
|
|
|
|
MockStateDiffBytes, _ = rlp.EncodeToBytes(MockStateDiff)
|
|
|
|
MockStateDiff2Bytes, _ = rlp.EncodeToBytes(MockStateDiff2)
|
2019-07-08 20:34:06 +00:00
|
|
|
|
|
|
|
mockTransaction1 = types.NewTransaction(0, common.HexToAddress("0x0"), big.NewInt(1000), 50, big.NewInt(100), nil)
|
|
|
|
mockTransaction2 = types.NewTransaction(1, common.HexToAddress("0x1"), big.NewInt(2000), 100, big.NewInt(200), nil)
|
|
|
|
MockTransactions = types.Transactions{mockTransaction1, mockTransaction2}
|
|
|
|
|
|
|
|
mockReceipt1 = types.NewReceipt(common.HexToHash("0x0").Bytes(), false, 50)
|
|
|
|
mockReceipt2 = types.NewReceipt(common.HexToHash("0x1").Bytes(), false, 100)
|
|
|
|
MockReceipts = types.Receipts{mockReceipt1, mockReceipt2}
|
|
|
|
|
|
|
|
MockHeader = types.Header{
|
|
|
|
Time: 0,
|
|
|
|
Number: BlockNumber,
|
|
|
|
Root: common.HexToHash("0x0"),
|
|
|
|
TxHash: common.HexToHash("0x0"),
|
|
|
|
ReceiptHash: common.HexToHash("0x0"),
|
|
|
|
}
|
2019-09-30 17:34:43 +00:00
|
|
|
MockHeader2 = types.Header{
|
|
|
|
Time: 0,
|
|
|
|
Number: BlockNumber2,
|
|
|
|
Root: common.HexToHash("0x1"),
|
|
|
|
TxHash: common.HexToHash("0x1"),
|
|
|
|
ReceiptHash: common.HexToHash("0x1"),
|
|
|
|
}
|
|
|
|
MockBlock = types.NewBlock(&MockHeader, MockTransactions, nil, MockReceipts)
|
|
|
|
MockBlock2 = types.NewBlock(&MockHeader2, MockTransactions, nil, MockReceipts)
|
|
|
|
MockBlockRlp, _ = rlp.EncodeToBytes(MockBlock)
|
|
|
|
MockBlockRlp2, _ = rlp.EncodeToBytes(MockBlock2)
|
2019-07-08 20:34:06 +00:00
|
|
|
|
|
|
|
MockStatediffPayload = statediff.Payload{
|
2020-05-19 20:09:30 +00:00
|
|
|
BlockRlp: MockBlockRlp,
|
|
|
|
StateObjectRlp: MockStateDiffBytes,
|
2019-07-08 20:34:06 +00:00
|
|
|
}
|
2019-09-30 17:34:43 +00:00
|
|
|
MockStatediffPayload2 = statediff.Payload{
|
2020-05-19 20:09:30 +00:00
|
|
|
BlockRlp: MockBlockRlp2,
|
|
|
|
StateObjectRlp: MockStateDiff2Bytes,
|
2019-07-08 20:34:06 +00:00
|
|
|
}
|
|
|
|
|
2019-10-31 16:04:53 +00:00
|
|
|
CreatedExpectedStorageDiff = utils.StorageDiffInput{
|
2019-09-30 17:34:43 +00:00
|
|
|
HashedAddress: common.BytesToHash(ContractLeafKey[:]),
|
2019-11-01 05:29:57 +00:00
|
|
|
BlockHash: common.HexToHash(BlockHash),
|
2019-09-30 17:34:43 +00:00
|
|
|
BlockHeight: int(BlockNumber.Int64()),
|
|
|
|
StorageKey: common.BytesToHash(StorageKey),
|
|
|
|
StorageValue: common.BytesToHash(SmallStorageValue),
|
|
|
|
}
|
2019-10-31 16:04:53 +00:00
|
|
|
UpdatedExpectedStorageDiff = utils.StorageDiffInput{
|
2019-09-30 17:34:43 +00:00
|
|
|
HashedAddress: common.BytesToHash(AnotherContractLeafKey[:]),
|
2019-11-01 05:29:57 +00:00
|
|
|
BlockHash: common.HexToHash(BlockHash),
|
2019-09-30 17:34:43 +00:00
|
|
|
BlockHeight: int(BlockNumber.Int64()),
|
|
|
|
StorageKey: common.BytesToHash(StorageKey),
|
|
|
|
StorageValue: common.BytesToHash(LargeStorageValue),
|
|
|
|
}
|
2019-10-31 16:04:53 +00:00
|
|
|
UpdatedExpectedStorageDiff2 = utils.StorageDiffInput{
|
2019-09-30 17:34:43 +00:00
|
|
|
HashedAddress: common.BytesToHash(AnotherContractLeafKey[:]),
|
2019-11-01 05:29:57 +00:00
|
|
|
BlockHash: common.HexToHash(BlockHash2),
|
2019-09-30 17:34:43 +00:00
|
|
|
BlockHeight: int(BlockNumber2.Int64()),
|
|
|
|
StorageKey: common.BytesToHash(StorageKey),
|
|
|
|
StorageValue: common.BytesToHash(SmallStorageValue),
|
|
|
|
}
|
2019-10-31 16:04:53 +00:00
|
|
|
DeletedExpectedStorageDiff = utils.StorageDiffInput{
|
2019-09-30 17:34:43 +00:00
|
|
|
HashedAddress: common.BytesToHash(AnotherContractLeafKey[:]),
|
2019-11-01 05:29:57 +00:00
|
|
|
BlockHash: common.HexToHash(BlockHash),
|
2019-09-30 17:34:43 +00:00
|
|
|
BlockHeight: int(BlockNumber.Int64()),
|
|
|
|
StorageKey: common.BytesToHash(StorageKey),
|
|
|
|
StorageValue: common.BytesToHash(SmallStorageValue),
|
2019-07-08 20:34:06 +00:00
|
|
|
}
|
|
|
|
)
|