cleanup chain maker
This commit is contained in:
parent
c4529a1139
commit
859e18aea4
@ -267,13 +267,13 @@ var (
|
||||
)
|
||||
|
||||
func TestBuilder(t *testing.T) {
|
||||
BlockHashes, blockMap, chain := testhelpers.MakeChain(3, testhelpers.Genesis)
|
||||
blocks, chain := testhelpers.MakeChain(3, testhelpers.Genesis)
|
||||
contractLeafKey = testhelpers.AddressToLeafKey(testhelpers.ContractAddr)
|
||||
defer chain.Stop()
|
||||
block0 = blockMap[BlockHashes[3]]
|
||||
block1 = blockMap[BlockHashes[2]]
|
||||
block2 = blockMap[BlockHashes[1]]
|
||||
block3 = blockMap[BlockHashes[0]]
|
||||
block0 = testhelpers.Genesis
|
||||
block1 = blocks[0]
|
||||
block2 = blocks[1]
|
||||
block3 = blocks[2]
|
||||
params := statediff.Params{}
|
||||
builder = statediff.NewBuilder(chain.StateCache())
|
||||
|
||||
@ -492,13 +492,13 @@ func TestBuilder(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBuilderWithIntermediateNodes(t *testing.T) {
|
||||
BlockHashes, blockMap, chain := testhelpers.MakeChain(3, testhelpers.Genesis)
|
||||
blocks, chain := testhelpers.MakeChain(3, testhelpers.Genesis)
|
||||
contractLeafKey = testhelpers.AddressToLeafKey(testhelpers.ContractAddr)
|
||||
defer chain.Stop()
|
||||
block0 = blockMap[BlockHashes[3]]
|
||||
block1 = blockMap[BlockHashes[2]]
|
||||
block2 = blockMap[BlockHashes[1]]
|
||||
block3 = blockMap[BlockHashes[0]]
|
||||
block0 = testhelpers.Genesis
|
||||
block1 = blocks[0]
|
||||
block2 = blocks[1]
|
||||
block3 = blocks[2]
|
||||
params := statediff.Params{
|
||||
IntermediateStateNodes: true,
|
||||
IntermediateStorageNodes: true,
|
||||
@ -743,13 +743,13 @@ func TestBuilderWithIntermediateNodes(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBuilderWithWatchedAddressList(t *testing.T) {
|
||||
BlockHashes, blockMap, chain := testhelpers.MakeChain(3, testhelpers.Genesis)
|
||||
blocks, chain := testhelpers.MakeChain(3, testhelpers.Genesis)
|
||||
contractLeafKey = testhelpers.AddressToLeafKey(testhelpers.ContractAddr)
|
||||
defer chain.Stop()
|
||||
block0 = blockMap[BlockHashes[3]]
|
||||
block1 = blockMap[BlockHashes[2]]
|
||||
block2 = blockMap[BlockHashes[1]]
|
||||
block3 = blockMap[BlockHashes[0]]
|
||||
block0 = testhelpers.Genesis
|
||||
block1 = blocks[0]
|
||||
block2 = blocks[1]
|
||||
block3 = blocks[2]
|
||||
params := statediff.Params{
|
||||
WatchedAddresses: []common.Address{testhelpers.Account1Addr, testhelpers.ContractAddr},
|
||||
}
|
||||
@ -912,13 +912,13 @@ func TestBuilderWithWatchedAddressList(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBuilderWithWatchedAddressAndStorageKeyList(t *testing.T) {
|
||||
BlockHashes, blockMap, chain := testhelpers.MakeChain(3, testhelpers.Genesis)
|
||||
blocks, chain := testhelpers.MakeChain(3, testhelpers.Genesis)
|
||||
contractLeafKey = testhelpers.AddressToLeafKey(testhelpers.ContractAddr)
|
||||
defer chain.Stop()
|
||||
block0 = blockMap[BlockHashes[3]]
|
||||
block1 = blockMap[BlockHashes[2]]
|
||||
block2 = blockMap[BlockHashes[1]]
|
||||
block3 = blockMap[BlockHashes[0]]
|
||||
block0 = testhelpers.Genesis
|
||||
block1 = blocks[0]
|
||||
block2 = blocks[1]
|
||||
block3 = blocks[2]
|
||||
params := statediff.Params{
|
||||
WatchedAddresses: []common.Address{testhelpers.Account1Addr, testhelpers.ContractAddr},
|
||||
WatchedStorageSlots: []common.Hash{originalStorageKey},
|
||||
|
@ -29,22 +29,11 @@ import (
|
||||
)
|
||||
|
||||
// MakeChain creates a chain of n blocks starting at and including parent.
|
||||
// the returned hash chain is ordered head->parent. In addition, every 3rd block
|
||||
// contains a transaction and every 5th an uncle to allow testing correct block
|
||||
// reassembly.
|
||||
func MakeChain(n int, parent *types.Block) ([]common.Hash, map[common.Hash]*types.Block, *core.BlockChain) {
|
||||
// the returned hash chain is ordered head->parent.
|
||||
func MakeChain(n int, parent *types.Block) ([]*types.Block, *core.BlockChain) {
|
||||
blocks, _ := core.GenerateChain(params.TestChainConfig, parent, ethash.NewFaker(), Testdb, n, testChainGen)
|
||||
chain, _ := core.NewBlockChain(Testdb, nil, params.TestChainConfig, ethash.NewFaker(), vm.Config{}, nil)
|
||||
|
||||
hashes := make([]common.Hash, n+1)
|
||||
hashes[len(hashes)-1] = parent.Hash()
|
||||
blockm := make(map[common.Hash]*types.Block, n+1)
|
||||
blockm[parent.Hash()] = parent
|
||||
for i, b := range blocks {
|
||||
hashes[len(hashes)-i-2] = b.Hash()
|
||||
blockm[b.Hash()] = b
|
||||
}
|
||||
return hashes, blockm, chain
|
||||
return blocks, chain
|
||||
}
|
||||
|
||||
func testChainGen(i int, block *core.BlockGen) {
|
||||
|
@ -81,12 +81,10 @@ func TestAPI(t *testing.T) {
|
||||
}
|
||||
|
||||
func testSubscriptionAPI(t *testing.T) {
|
||||
_, blockMap, chain := testhelpers.MakeChain(3, testhelpers.Genesis)
|
||||
blocks, chain := testhelpers.MakeChain(1, testhelpers.Genesis)
|
||||
defer chain.Stop()
|
||||
block0Hash := common.HexToHash("0xd1721cfd0b29c36fd7a68f25c128e86413fb666a6e1d68e89b875bd299262661")
|
||||
block1Hash := common.HexToHash("0xbbe88de60ba33a3f18c0caa37d827bfb70252e19e40a07cd34041696c35ecb1a")
|
||||
block0 = blockMap[block0Hash]
|
||||
block1 = blockMap[block1Hash]
|
||||
block0 = testhelpers.Genesis
|
||||
block1 = blocks[0]
|
||||
expectedBlockRlp, _ := rlp.EncodeToBytes(block1)
|
||||
mockReceipt := &types.Receipt{
|
||||
BlockNumber: block1.Number(),
|
||||
@ -125,8 +123,8 @@ func testSubscriptionAPI(t *testing.T) {
|
||||
parentBlockChain := make(chan *types.Block)
|
||||
serviceQuitChan := make(chan bool)
|
||||
mockBlockChain := &BlockChain{}
|
||||
mockBlockChain.SetReceiptsForHash(block1Hash, types.Receipts{mockReceipt})
|
||||
mockBlockChain.SetTdByHash(block1Hash, mockTotalDifficulty)
|
||||
mockBlockChain.SetReceiptsForHash(block1.Hash(), types.Receipts{mockReceipt})
|
||||
mockBlockChain.SetTdByHash(block1.Hash(), mockTotalDifficulty)
|
||||
mockService := MockStateDiffService{
|
||||
Mutex: sync.Mutex{},
|
||||
Builder: statediff.NewBuilder(chain.StateCache()),
|
||||
@ -167,12 +165,10 @@ func testSubscriptionAPI(t *testing.T) {
|
||||
}
|
||||
|
||||
func testHTTPAPI(t *testing.T) {
|
||||
_, blockMap, chain := testhelpers.MakeChain(3, testhelpers.Genesis)
|
||||
blocks, chain := testhelpers.MakeChain(1, testhelpers.Genesis)
|
||||
defer chain.Stop()
|
||||
block0Hash := common.HexToHash("0xd1721cfd0b29c36fd7a68f25c128e86413fb666a6e1d68e89b875bd299262661")
|
||||
block1Hash := common.HexToHash("0xbbe88de60ba33a3f18c0caa37d827bfb70252e19e40a07cd34041696c35ecb1a")
|
||||
block0 = blockMap[block0Hash]
|
||||
block1 = blockMap[block1Hash]
|
||||
block0 = testhelpers.Genesis
|
||||
block1 = blocks[0]
|
||||
expectedBlockRlp, _ := rlp.EncodeToBytes(block1)
|
||||
mockReceipt := &types.Receipt{
|
||||
BlockNumber: block1.Number(),
|
||||
@ -208,10 +204,13 @@ func testHTTPAPI(t *testing.T) {
|
||||
}
|
||||
expectedStateDiffBytes, _ := rlp.EncodeToBytes(expectedStateDiff)
|
||||
mockBlockChain := &BlockChain{}
|
||||
mockBlockChain.SetBlocksForHashes(blockMap)
|
||||
mockBlockChain.SetBlocksForHashes(map[common.Hash]*types.Block{
|
||||
block0.Hash(): block0,
|
||||
block1.Hash(): block1,
|
||||
})
|
||||
mockBlockChain.SetBlockForNumber(block1, block1.Number().Uint64())
|
||||
mockBlockChain.SetReceiptsForHash(block1Hash, types.Receipts{mockReceipt})
|
||||
mockBlockChain.SetTdByHash(block1Hash, big.NewInt(1337))
|
||||
mockBlockChain.SetReceiptsForHash(block1.Hash(), types.Receipts{mockReceipt})
|
||||
mockBlockChain.SetTdByHash(block1.Hash(), big.NewInt(1337))
|
||||
mockService := MockStateDiffService{
|
||||
Mutex: sync.Mutex{},
|
||||
Builder: statediff.NewBuilder(chain.StateCache()),
|
||||
|
Loading…
Reference in New Issue
Block a user