Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
aecf3f95
Unverified
Commit
aecf3f95
authored
Jul 11, 2023
by
Delweng
Committed by
GitHub
Jul 11, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
internal/blocktest: add package for shared test code (#27270)
parent
e1fd3d67
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
66 additions
and
83 deletions
+66
-83
accessors_indexes_test.go
core/rawdb/accessors_indexes_test.go
+2
-26
block_test.go
core/types/block_test.go
+2
-28
test_hash.go
internal/blocktest/test_hash.go
+59
-0
api_test.go
internal/ethapi/api_test.go
+3
-29
No files found.
core/rawdb/accessors_indexes_test.go
View file @
aecf3f95
...
...
@@ -18,42 +18,18 @@ package rawdb
import
(
"bytes"
"hash"
"math/big"
"testing"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/internal/blocktest"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
"golang.org/x/crypto/sha3"
)
// testHasher is the helper tool for transaction/receipt list hashing.
// The original hasher is trie, in order to get rid of import cycle,
// use the testing hasher instead.
type
testHasher
struct
{
hasher
hash
.
Hash
}
func
newHasher
()
*
testHasher
{
return
&
testHasher
{
hasher
:
sha3
.
NewLegacyKeccak256
()}
}
func
(
h
*
testHasher
)
Reset
()
{
h
.
hasher
.
Reset
()
}
func
(
h
*
testHasher
)
Update
(
key
,
val
[]
byte
)
error
{
h
.
hasher
.
Write
(
key
)
h
.
hasher
.
Write
(
val
)
return
nil
}
func
(
h
*
testHasher
)
Hash
()
common
.
Hash
{
return
common
.
BytesToHash
(
h
.
hasher
.
Sum
(
nil
))
}
var
newHasher
=
blocktest
.
NewHasher
// Tests that positional lookup metadata can be stored and retrieved.
func
TestLookupStorage
(
t
*
testing
.
T
)
{
...
...
core/types/block_test.go
View file @
aecf3f95
...
...
@@ -18,7 +18,6 @@ package types
import
(
"bytes"
"hash"
"math/big"
"reflect"
"testing"
...
...
@@ -26,9 +25,9 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/internal/blocktest"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
"golang.org/x/crypto/sha3"
)
// from bcValidBlockTest.json, "SimpleTx"
...
...
@@ -217,31 +216,6 @@ func BenchmarkEncodeBlock(b *testing.B) {
}
}
// testHasher is the helper tool for transaction/receipt list hashing.
// The original hasher is trie, in order to get rid of import cycle,
// use the testing hasher instead.
type
testHasher
struct
{
hasher
hash
.
Hash
}
func
newHasher
()
*
testHasher
{
return
&
testHasher
{
hasher
:
sha3
.
NewLegacyKeccak256
()}
}
func
(
h
*
testHasher
)
Reset
()
{
h
.
hasher
.
Reset
()
}
func
(
h
*
testHasher
)
Update
(
key
,
val
[]
byte
)
error
{
h
.
hasher
.
Write
(
key
)
h
.
hasher
.
Write
(
val
)
return
nil
}
func
(
h
*
testHasher
)
Hash
()
common
.
Hash
{
return
common
.
BytesToHash
(
h
.
hasher
.
Sum
(
nil
))
}
func
makeBenchBlock
()
*
Block
{
var
(
key
,
_
=
crypto
.
GenerateKey
()
...
...
@@ -280,7 +254,7 @@ func makeBenchBlock() *Block {
Extra
:
[]
byte
(
"benchmark uncle"
),
}
}
return
NewBlock
(
header
,
txs
,
uncles
,
receipts
,
n
ewHasher
())
return
NewBlock
(
header
,
txs
,
uncles
,
receipts
,
blocktest
.
N
ewHasher
())
}
func
TestRlpDecodeParentHash
(
t
*
testing
.
T
)
{
...
...
internal/blocktest/test_hash.go
0 → 100644
View file @
aecf3f95
// Copyright 2023 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/>.
// Package utesting provides a standalone replacement for package testing.
//
// This package exists because package testing cannot easily be embedded into a
// standalone go program. It provides an API that mirrors the standard library
// testing API.
package
blocktest
import
(
"hash"
"github.com/ethereum/go-ethereum/common"
"golang.org/x/crypto/sha3"
)
// testHasher is the helper tool for transaction/receipt list hashing.
// The original hasher is trie, in order to get rid of import cycle,
// use the testing hasher instead.
type
testHasher
struct
{
hasher
hash
.
Hash
}
// NewHasher returns a new testHasher instance.
func
NewHasher
()
*
testHasher
{
return
&
testHasher
{
hasher
:
sha3
.
NewLegacyKeccak256
()}
}
// Reset resets the hash state.
func
(
h
*
testHasher
)
Reset
()
{
h
.
hasher
.
Reset
()
}
// Update updates the hash state with the given key and value.
func
(
h
*
testHasher
)
Update
(
key
,
val
[]
byte
)
error
{
h
.
hasher
.
Write
(
key
)
h
.
hasher
.
Write
(
val
)
return
nil
}
// Hash returns the hash value.
func
(
h
*
testHasher
)
Hash
()
common
.
Hash
{
return
common
.
BytesToHash
(
h
.
hasher
.
Sum
(
nil
))
}
internal/ethapi/api_test.go
View file @
aecf3f95
...
...
@@ -21,7 +21,6 @@ import (
"crypto/ecdsa"
"encoding/json"
"errors"
"hash"
"math/big"
"reflect"
"testing"
...
...
@@ -42,10 +41,10 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/internal/blocktest"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rpc"
"github.com/stretchr/testify/require"
"golang.org/x/crypto/sha3"
"golang.org/x/exp/slices"
)
...
...
@@ -668,31 +667,6 @@ func hex2Bytes(str string) *hexutil.Bytes {
return
&
rpcBytes
}
// testHasher is the helper tool for transaction/receipt list hashing.
// The original hasher is trie, in order to get rid of import cycle,
// use the testing hasher instead.
type
testHasher
struct
{
hasher
hash
.
Hash
}
func
newHasher
()
*
testHasher
{
return
&
testHasher
{
hasher
:
sha3
.
NewLegacyKeccak256
()}
}
func
(
h
*
testHasher
)
Reset
()
{
h
.
hasher
.
Reset
()
}
func
(
h
*
testHasher
)
Update
(
key
,
val
[]
byte
)
error
{
h
.
hasher
.
Write
(
key
)
h
.
hasher
.
Write
(
val
)
return
nil
}
func
(
h
*
testHasher
)
Hash
()
common
.
Hash
{
return
common
.
BytesToHash
(
h
.
hasher
.
Sum
(
nil
))
}
func
TestRPCMarshalBlock
(
t
*
testing
.
T
)
{
t
.
Parallel
()
var
(
...
...
@@ -723,7 +697,7 @@ func TestRPCMarshalBlock(t *testing.T) {
}
txs
=
append
(
txs
,
tx
)
}
block
:=
types
.
NewBlock
(
&
types
.
Header
{
Number
:
big
.
NewInt
(
100
)},
txs
,
nil
,
nil
,
n
ewHasher
())
block
:=
types
.
NewBlock
(
&
types
.
Header
{
Number
:
big
.
NewInt
(
100
)},
txs
,
nil
,
nil
,
blocktest
.
N
ewHasher
())
var
testSuite
=
[]
struct
{
inclTx
bool
...
...
@@ -795,7 +769,7 @@ func TestRPCGetBlockOrHeader(t *testing.T) {
Address
:
common
.
Address
{
0x12
,
0x34
},
Amount
:
10
,
}
pending
=
types
.
NewBlockWithWithdrawals
(
&
types
.
Header
{
Number
:
big
.
NewInt
(
11
),
Time
:
42
},
[]
*
types
.
Transaction
{
tx
},
nil
,
nil
,
[]
*
types
.
Withdrawal
{
withdrawal
},
n
ewHasher
())
pending
=
types
.
NewBlockWithWithdrawals
(
&
types
.
Header
{
Number
:
big
.
NewInt
(
11
),
Time
:
42
},
[]
*
types
.
Transaction
{
tx
},
nil
,
nil
,
[]
*
types
.
Withdrawal
{
withdrawal
},
blocktest
.
N
ewHasher
())
)
backend
:=
newTestBackend
(
t
,
genBlocks
,
genesis
,
func
(
i
int
,
b
*
core
.
BlockGen
)
{
// Transfer from account[0] to account[1]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment