2016-11-08 19:01:56 -06:00
|
|
|
// Copyright 2016 The go-ethereum Authors
|
|
|
|
// This file is part of the go-ethereum library.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2016-10-13 22:51:29 -05:00
|
|
|
package les
|
|
|
|
|
2023-07-17 13:48:11 -05:00
|
|
|
// Note: these tests are disabled now because they cannot work with the old sync
|
|
|
|
// mechanism removed but will be useful again once the PoS ultralight mode is implemented
|
|
|
|
|
|
|
|
/*
|
2016-10-13 22:51:29 -05:00
|
|
|
import (
|
2017-03-22 12:20:33 -05:00
|
|
|
"context"
|
2016-10-13 22:51:29 -05:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2018-05-07 06:35:06 -05:00
|
|
|
"github.com/ethereum/go-ethereum/core/rawdb"
|
core/state, light, les: make signature of ContractCode hash-independent (#27209)
* core/state, light, les: make signature of ContractCode hash-independent
* push current state for feedback
* les: fix unit test
* core, les, light: fix les unittests
* core/state, trie, les, light: fix state iterator
* core, les: address comments
* les: fix lint
---------
Co-authored-by: Gary Rong <garyrong0905@gmail.com>
2023-06-28 04:11:02 -05:00
|
|
|
"github.com/ethereum/go-ethereum/core/types"
|
2016-10-13 22:51:29 -05:00
|
|
|
"github.com/ethereum/go-ethereum/crypto"
|
|
|
|
"github.com/ethereum/go-ethereum/ethdb"
|
|
|
|
"github.com/ethereum/go-ethereum/light"
|
|
|
|
)
|
|
|
|
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 02:34:02 -05:00
|
|
|
var testBankSecureTrieKey = secAddr(bankAddr)
|
2016-10-13 22:51:29 -05:00
|
|
|
|
|
|
|
func secAddr(addr common.Address) []byte {
|
|
|
|
return crypto.Keccak256(addr[:])
|
|
|
|
}
|
|
|
|
|
|
|
|
type accessTestFn func(db ethdb.Database, bhash common.Hash, number uint64) light.OdrRequest
|
|
|
|
|
2017-10-24 08:19:09 -05:00
|
|
|
func TestBlockAccessLes2(t *testing.T) { testAccess(t, 2, tfBlockAccess) }
|
2019-08-21 04:29:34 -05:00
|
|
|
func TestBlockAccessLes3(t *testing.T) { testAccess(t, 3, tfBlockAccess) }
|
2021-02-12 13:48:18 -06:00
|
|
|
func TestBlockAccessLes4(t *testing.T) { testAccess(t, 4, tfBlockAccess) }
|
2017-10-24 08:19:09 -05:00
|
|
|
|
2016-10-13 22:51:29 -05:00
|
|
|
func tfBlockAccess(db ethdb.Database, bhash common.Hash, number uint64) light.OdrRequest {
|
|
|
|
return &light.BlockRequest{Hash: bhash, Number: number}
|
|
|
|
}
|
|
|
|
|
2017-10-24 08:19:09 -05:00
|
|
|
func TestReceiptsAccessLes2(t *testing.T) { testAccess(t, 2, tfReceiptsAccess) }
|
2019-08-21 04:29:34 -05:00
|
|
|
func TestReceiptsAccessLes3(t *testing.T) { testAccess(t, 3, tfReceiptsAccess) }
|
2021-02-12 13:48:18 -06:00
|
|
|
func TestReceiptsAccessLes4(t *testing.T) { testAccess(t, 4, tfReceiptsAccess) }
|
2017-10-24 08:19:09 -05:00
|
|
|
|
2016-10-13 22:51:29 -05:00
|
|
|
func tfReceiptsAccess(db ethdb.Database, bhash common.Hash, number uint64) light.OdrRequest {
|
|
|
|
return &light.ReceiptsRequest{Hash: bhash, Number: number}
|
|
|
|
}
|
|
|
|
|
2017-10-24 08:19:09 -05:00
|
|
|
func TestTrieEntryAccessLes2(t *testing.T) { testAccess(t, 2, tfTrieEntryAccess) }
|
2019-08-21 04:29:34 -05:00
|
|
|
func TestTrieEntryAccessLes3(t *testing.T) { testAccess(t, 3, tfTrieEntryAccess) }
|
2021-02-12 13:48:18 -06:00
|
|
|
func TestTrieEntryAccessLes4(t *testing.T) { testAccess(t, 4, tfTrieEntryAccess) }
|
2017-10-24 08:19:09 -05:00
|
|
|
|
2016-10-13 22:51:29 -05:00
|
|
|
func tfTrieEntryAccess(db ethdb.Database, bhash common.Hash, number uint64) light.OdrRequest {
|
2018-05-07 06:35:06 -05:00
|
|
|
if number := rawdb.ReadHeaderNumber(db, bhash); number != nil {
|
|
|
|
return &light.TrieRequest{Id: light.StateTrieID(rawdb.ReadHeader(db, bhash, *number)), Key: testBankSecureTrieKey}
|
|
|
|
}
|
|
|
|
return nil
|
2016-10-13 22:51:29 -05:00
|
|
|
}
|
|
|
|
|
2017-10-24 08:19:09 -05:00
|
|
|
func TestCodeAccessLes2(t *testing.T) { testAccess(t, 2, tfCodeAccess) }
|
2019-08-21 04:29:34 -05:00
|
|
|
func TestCodeAccessLes3(t *testing.T) { testAccess(t, 3, tfCodeAccess) }
|
2021-02-12 13:48:18 -06:00
|
|
|
func TestCodeAccessLes4(t *testing.T) { testAccess(t, 4, tfCodeAccess) }
|
2017-10-24 08:19:09 -05:00
|
|
|
|
2018-05-07 06:35:06 -05:00
|
|
|
func tfCodeAccess(db ethdb.Database, bhash common.Hash, num uint64) light.OdrRequest {
|
|
|
|
number := rawdb.ReadHeaderNumber(db, bhash)
|
|
|
|
if number != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
header := rawdb.ReadHeader(db, bhash, *number)
|
2016-11-08 18:20:49 -06:00
|
|
|
if header.Number.Uint64() < testContractDeployed {
|
2016-10-13 22:51:29 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
sti := light.StateTrieID(header)
|
core/state, light, les: make signature of ContractCode hash-independent (#27209)
* core/state, light, les: make signature of ContractCode hash-independent
* push current state for feedback
* les: fix unit test
* core, les, light: fix les unittests
* core/state, trie, les, light: fix state iterator
* core, les: address comments
* les: fix lint
---------
Co-authored-by: Gary Rong <garyrong0905@gmail.com>
2023-06-28 04:11:02 -05:00
|
|
|
ci := light.StorageTrieID(sti, testContractAddr, types.EmptyRootHash)
|
2016-10-13 22:51:29 -05:00
|
|
|
return &light.CodeRequest{Id: ci, Hash: crypto.Keccak256Hash(testContractCodeDeployed)}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccess(t *testing.T, protocol int, fn accessTestFn) {
|
|
|
|
// Assemble the test environment
|
2021-02-25 07:24:04 -06:00
|
|
|
netconfig := testnetConfig{
|
|
|
|
blocks: 4,
|
|
|
|
protocol: protocol,
|
|
|
|
indexFn: nil,
|
|
|
|
connect: true,
|
|
|
|
nopruning: true,
|
|
|
|
}
|
|
|
|
server, client, tearDown := newClientServerEnv(t, netconfig)
|
2018-08-28 02:08:16 -05:00
|
|
|
defer tearDown()
|
2016-10-13 22:51:29 -05:00
|
|
|
|
2019-11-02 07:02:35 -05:00
|
|
|
// Ensure the client has synced all necessary data.
|
|
|
|
clientHead := client.handler.backend.blockchain.CurrentHeader()
|
|
|
|
if clientHead.Number.Uint64() != 4 {
|
|
|
|
t.Fatalf("Failed to sync the chain with server, head: %v", clientHead.Number.Uint64())
|
|
|
|
}
|
|
|
|
|
2016-10-13 22:51:29 -05:00
|
|
|
test := func(expFail uint64) {
|
2019-08-21 04:29:34 -05:00
|
|
|
for i := uint64(0); i <= server.handler.blockchain.CurrentHeader().Number.Uint64(); i++ {
|
2018-08-28 02:08:16 -05:00
|
|
|
bhash := rawdb.ReadCanonicalHash(server.db, i)
|
|
|
|
if req := fn(client.db, bhash, i); req != nil {
|
2017-03-22 12:20:33 -05:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 200*time.Millisecond)
|
cmd, core, eth, les, light: track deleted nodes (#25757)
* cmd, core, eth, les, light: track deleted nodes
* trie: add docs
* trie: address comments
* cmd, core, eth, les, light, trie: trie id
* trie: add tests
* trie, core: updates
* trie: fix imports
* trie: add utility print-method for nodeset
* trie: import err
* trie: fix go vet warnings
Co-authored-by: Martin Holst Swende <martin@swende.se>
2022-09-27 03:01:02 -05:00
|
|
|
|
2019-08-21 04:29:34 -05:00
|
|
|
err := client.handler.backend.odr.Retrieve(ctx, req)
|
|
|
|
cancel()
|
|
|
|
|
2016-10-13 22:51:29 -05:00
|
|
|
got := err == nil
|
|
|
|
exp := i < expFail
|
|
|
|
if exp && !got {
|
|
|
|
t.Errorf("object retrieval failed")
|
|
|
|
}
|
|
|
|
if !exp && got {
|
|
|
|
t.Errorf("unexpected object retrieval success")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
test(5)
|
|
|
|
}
|
2023-07-17 13:48:11 -05:00
|
|
|
*/
|