fixes after rebase

This commit is contained in:
Ian Norden 2019-11-04 12:44:10 -06:00
parent 1500b8e248
commit 807770903e
4 changed files with 40 additions and 103 deletions

View File

@ -41,10 +41,6 @@ var (
burnAddress = common.HexToAddress("0x0") burnAddress = common.HexToAddress("0x0")
burnLeafKey = testhelpers.AddressToLeafKey(burnAddress) burnLeafKey = testhelpers.AddressToLeafKey(burnAddress)
block0Hash = common.HexToHash("0xd1721cfd0b29c36fd7a68f25c128e86413fb666a6e1d68e89b875bd299262661")
block1Hash = common.HexToHash("0xbbe88de60ba33a3f18c0caa37d827bfb70252e19e40a07cd34041696c35ecb1a")
block2Hash = common.HexToHash("0x34ad0fd9bb2911986b75d518c822641079dea823bc6952343ebf05da1062b6f5")
block3Hash = common.HexToHash("0x9872058136c560a6ebed0c0522b8d3016fc21f4fb0fb6585ddd8fd4c54f9909a")
balanceChange10000 = int64(10000) balanceChange10000 = int64(10000)
balanceChange1000 = int64(1000) balanceChange1000 = int64(1000)
block1BankBalance = int64(99990000) block1BankBalance = int64(99990000)
@ -140,13 +136,13 @@ type arguments struct {
} }
func TestBuilder(t *testing.T) { func TestBuilder(t *testing.T) {
_, blockMap, chain := testhelpers.MakeChain(3, testhelpers.Genesis) blockHashes, blockMap, chain := testhelpers.MakeChain(3, testhelpers.Genesis)
contractLeafKey = testhelpers.AddressToLeafKey(testhelpers.ContractAddr) contractLeafKey = testhelpers.AddressToLeafKey(testhelpers.ContractAddr)
defer chain.Stop() defer chain.Stop()
block0 = blockMap[block0Hash] block0 = blockMap[blockHashes[3]]
block1 = blockMap[block1Hash] block1 = blockMap[blockHashes[2]]
block2 = blockMap[block2Hash] block2 = blockMap[blockHashes[1]]
block3 = blockMap[block3Hash] block3 = blockMap[blockHashes[0]]
config := statediff.Config{ config := statediff.Config{
PathsAndProofs: true, PathsAndProofs: true,
IntermediateNodes: false, IntermediateNodes: false,
@ -164,16 +160,17 @@ func TestBuilder(t *testing.T) {
oldStateRoot: block0.Root(), oldStateRoot: block0.Root(),
newStateRoot: block0.Root(), newStateRoot: block0.Root(),
blockNumber: block0.Number(), blockNumber: block0.Number(),
blockHash: block0Hash, blockHash: block0.Hash(),
}, },
&statediff.StateDiff{ &statediff.StateDiff{
BlockNumber: block0.Number(), BlockNumber: block0.Number(),
BlockHash: block0Hash, BlockHash: block0.Hash(),
CreatedAccounts: emptyAccountDiffEventualMap, CreatedAccounts: emptyAccountDiffEventualMap,
DeletedAccounts: emptyAccountDiffEventualMap, DeletedAccounts: emptyAccountDiffEventualMap,
UpdatedAccounts: emptyAccountDiffIncrementalMap, UpdatedAccounts: emptyAccountDiffIncrementalMap,
}, },
}, },
{ {
"testBlock1", "testBlock1",
//10000 transferred from testBankAddress to account1Addr //10000 transferred from testBankAddress to account1Addr
@ -181,7 +178,7 @@ func TestBuilder(t *testing.T) {
oldStateRoot: block0.Root(), oldStateRoot: block0.Root(),
newStateRoot: block1.Root(), newStateRoot: block1.Root(),
blockNumber: block1.Number(), blockNumber: block1.Number(),
blockHash: block1Hash, blockHash: block1.Hash(),
}, },
&statediff.StateDiff{ &statediff.StateDiff{
BlockNumber: block1.Number(), BlockNumber: block1.Number(),
@ -228,7 +225,7 @@ func TestBuilder(t *testing.T) {
oldStateRoot: block1.Root(), oldStateRoot: block1.Root(),
newStateRoot: block2.Root(), newStateRoot: block2.Root(),
blockNumber: block2.Number(), blockNumber: block2.Number(),
blockHash: block2Hash, blockHash: block2.Hash(),
}, },
&statediff.StateDiff{ &statediff.StateDiff{
BlockNumber: block2.Number(), BlockNumber: block2.Number(),
@ -374,13 +371,13 @@ func TestBuilder(t *testing.T) {
} }
func TestBuilderWithWatchedAddressList(t *testing.T) { func TestBuilderWithWatchedAddressList(t *testing.T) {
_, blockMap, chain := testhelpers.MakeChain(3, testhelpers.Genesis) blockHashes, blockMap, chain := testhelpers.MakeChain(3, testhelpers.Genesis)
contractLeafKey = testhelpers.AddressToLeafKey(testhelpers.ContractAddr) contractLeafKey = testhelpers.AddressToLeafKey(testhelpers.ContractAddr)
defer chain.Stop() defer chain.Stop()
block0 = blockMap[block0Hash] block0 = blockMap[blockHashes[3]]
block1 = blockMap[block1Hash] block1 = blockMap[blockHashes[2]]
block2 = blockMap[block2Hash] block2 = blockMap[blockHashes[1]]
block3 = blockMap[block3Hash] block3 = blockMap[blockHashes[0]]
config := statediff.Config{ config := statediff.Config{
PathsAndProofs: true, PathsAndProofs: true,
IntermediateNodes: false, IntermediateNodes: false,
@ -399,11 +396,11 @@ func TestBuilderWithWatchedAddressList(t *testing.T) {
oldStateRoot: block0.Root(), oldStateRoot: block0.Root(),
newStateRoot: block0.Root(), newStateRoot: block0.Root(),
blockNumber: block0.Number(), blockNumber: block0.Number(),
blockHash: block0Hash, blockHash: block0.Hash(),
}, },
&statediff.StateDiff{ &statediff.StateDiff{
BlockNumber: block0.Number(), BlockNumber: block0.Number(),
BlockHash: block0Hash, BlockHash: block0.Hash(),
CreatedAccounts: emptyAccountDiffEventualMap, CreatedAccounts: emptyAccountDiffEventualMap,
DeletedAccounts: emptyAccountDiffEventualMap, DeletedAccounts: emptyAccountDiffEventualMap,
UpdatedAccounts: emptyAccountDiffIncrementalMap, UpdatedAccounts: emptyAccountDiffIncrementalMap,
@ -416,7 +413,7 @@ func TestBuilderWithWatchedAddressList(t *testing.T) {
oldStateRoot: block0.Root(), oldStateRoot: block0.Root(),
newStateRoot: block1.Root(), newStateRoot: block1.Root(),
blockNumber: block1.Number(), blockNumber: block1.Number(),
blockHash: block1Hash, blockHash: block1.Hash(),
}, },
&statediff.StateDiff{ &statediff.StateDiff{
BlockNumber: block1.Number(), BlockNumber: block1.Number(),
@ -444,7 +441,7 @@ func TestBuilderWithWatchedAddressList(t *testing.T) {
oldStateRoot: block1.Root(), oldStateRoot: block1.Root(),
newStateRoot: block2.Root(), newStateRoot: block2.Root(),
blockNumber: block2.Number(), blockNumber: block2.Number(),
blockHash: block2Hash, blockHash: block2.Hash(),
}, },
&statediff.StateDiff{ &statediff.StateDiff{
BlockNumber: block2.Number(), BlockNumber: block2.Number(),

View File

@ -34,10 +34,6 @@ import (
// reassembly. // reassembly.
func MakeChain(n int, parent *types.Block) ([]common.Hash, map[common.Hash]*types.Block, *core.BlockChain) { func MakeChain(n int, parent *types.Block) ([]common.Hash, map[common.Hash]*types.Block, *core.BlockChain) {
blocks, _ := core.GenerateChain(params.TestChainConfig, parent, ethash.NewFaker(), Testdb, n, testChainGen) blocks, _ := core.GenerateChain(params.TestChainConfig, parent, ethash.NewFaker(), Testdb, n, testChainGen)
headers := make([]*types.Header, len(blocks))
for i, block := range blocks {
headers[i] = block.Header()
}
chain, _ := core.NewBlockChain(Testdb, nil, params.TestChainConfig, ethash.NewFaker(), vm.Config{}, nil) chain, _ := core.NewBlockChain(Testdb, nil, params.TestChainConfig, ethash.NewFaker(), vm.Config{}, nil)
hashes := make([]common.Hash, n+1) hashes := make([]common.Hash, n+1)

View File

@ -23,10 +23,7 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/statediff"
) )
// AddressToLeafKey hashes an returns an address // AddressToLeafKey hashes an returns an address
@ -39,64 +36,11 @@ var (
BlockNumber = big.NewInt(rand.Int63()) BlockNumber = big.NewInt(rand.Int63())
BlockHash = "0xfa40fbe2d98d98b3363a778d52f2bcd29d6790b9b3f3cab2b167fd12d3550f73" BlockHash = "0xfa40fbe2d98d98b3363a778d52f2bcd29d6790b9b3f3cab2b167fd12d3550f73"
CodeHash = common.Hex2Bytes("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470") CodeHash = common.Hex2Bytes("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470")
NewNonceValue = rand.Uint64()
NewBalanceValue = rand.Int63()
ContractRoot = common.HexToHash("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
StoragePath = common.HexToHash("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470").Bytes() StoragePath = common.HexToHash("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470").Bytes()
StorageKey = common.HexToHash("0000000000000000000000000000000000000000000000000000000000000001").Bytes() StorageKey = common.HexToHash("0000000000000000000000000000000000000000000000000000000000000001").Bytes()
StorageValue = common.Hex2Bytes("0x03") StorageValue = common.Hex2Bytes("0x03")
storage = []statediff.StorageDiff{{
Key: StorageKey,
Value: StorageValue,
Path: StoragePath,
Proof: [][]byte{},
}}
emptyStorage = make([]statediff.StorageDiff, 0)
address = common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476592")
ContractLeafKey = AddressToLeafKey(address)
anotherAddress = common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476593")
AnotherContractLeafKey = AddressToLeafKey(anotherAddress)
testAccount = state.Account{
Nonce: NewNonceValue,
Balance: big.NewInt(NewBalanceValue),
Root: ContractRoot,
CodeHash: CodeHash,
}
valueBytes, _ = rlp.EncodeToBytes(testAccount)
CreatedAccountDiffs = []statediff.AccountDiff{
{
Key: ContractLeafKey.Bytes(),
Value: valueBytes,
Storage: storage,
},
{
Key: AnotherContractLeafKey.Bytes(),
Value: valueBytes,
Storage: emptyStorage,
},
}
UpdatedAccountDiffs = []statediff.AccountDiff{{
Key: ContractLeafKey.Bytes(),
Value: valueBytes,
Storage: storage,
}}
DeletedAccountDiffs = []statediff.AccountDiff{{
Key: ContractLeafKey.Bytes(),
Value: valueBytes,
Storage: storage,
}}
TestStateDiff = statediff.StateDiff{
BlockNumber: BlockNumber,
BlockHash: common.HexToHash(BlockHash),
CreatedAccounts: CreatedAccountDiffs,
DeletedAccounts: DeletedAccountDiffs,
UpdatedAccounts: UpdatedAccountDiffs,
}
Testdb = rawdb.NewMemoryDatabase() Testdb = rawdb.NewMemoryDatabase()
TestBankKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") TestBankKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
TestBankAddress = crypto.PubkeyToAddress(TestBankKey.PublicKey) //0x71562b71999873DB5b286dF957af199Ec94617F7 TestBankAddress = crypto.PubkeyToAddress(TestBankKey.PublicKey) //0x71562b71999873DB5b286dF957af199Ec94617F7
BankLeafKey = AddressToLeafKey(TestBankAddress) BankLeafKey = AddressToLeafKey(TestBankAddress)