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
34c94d5f
Commit
34c94d5f
authored
Apr 27, 2015
by
Gustav Simonsson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add loading of block test privkey if present
parent
2a61611c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
9 deletions
+35
-9
blocktest.go
cmd/geth/blocktest.go
+1
-1
crypto.go
crypto/crypto.go
+13
-0
block_test.go
tests/block_test.go
+1
-1
block_test_util.go
tests/block_test_util.go
+20
-7
No files found.
cmd/geth/blocktest.go
View file @
34c94d5f
...
@@ -104,7 +104,7 @@ func runOneBlockTest(ctx *cli.Context, test *tests.BlockTest) (*eth.Ethereum, er
...
@@ -104,7 +104,7 @@ func runOneBlockTest(ctx *cli.Context, test *tests.BlockTest) (*eth.Ethereum, er
ethereum
.
ResetWithGenesisBlock
(
test
.
Genesis
)
ethereum
.
ResetWithGenesisBlock
(
test
.
Genesis
)
// import pre accounts
// import pre accounts
statedb
,
err
:=
test
.
InsertPreState
(
ethereum
.
StateDb
()
)
statedb
,
err
:=
test
.
InsertPreState
(
ethereum
)
if
err
!=
nil
{
if
err
!=
nil
{
return
ethereum
,
fmt
.
Errorf
(
"InsertPreState: %v"
,
err
)
return
ethereum
,
fmt
.
Errorf
(
"InsertPreState: %v"
,
err
)
}
}
...
...
crypto/crypto.go
View file @
34c94d5f
...
@@ -179,6 +179,19 @@ func Decrypt(prv *ecdsa.PrivateKey, ct []byte) ([]byte, error) {
...
@@ -179,6 +179,19 @@ func Decrypt(prv *ecdsa.PrivateKey, ct []byte) ([]byte, error) {
return
key
.
Decrypt
(
rand
.
Reader
,
ct
,
nil
,
nil
)
return
key
.
Decrypt
(
rand
.
Reader
,
ct
,
nil
,
nil
)
}
}
// Used only by block tests.
func
ImportBlockTestKey
(
privKeyBytes
[]
byte
)
error
{
ks
:=
NewKeyStorePassphrase
(
common
.
DefaultDataDir
()
+
"/keys"
)
ecKey
:=
ToECDSA
(
privKeyBytes
)
key
:=
&
Key
{
Id
:
uuid
.
NewRandom
(),
Address
:
PubkeyToAddress
(
ecKey
.
PublicKey
),
PrivateKey
:
ecKey
,
}
err
:=
ks
.
StoreKey
(
key
,
""
)
return
err
}
// creates a Key and stores that in the given KeyStore by decrypting a presale key JSON
// creates a Key and stores that in the given KeyStore by decrypting a presale key JSON
func
ImportPreSaleKey
(
keyStore
KeyStore2
,
keyJSON
[]
byte
,
password
string
)
(
*
Key
,
error
)
{
func
ImportPreSaleKey
(
keyStore
KeyStore2
,
keyJSON
[]
byte
,
password
string
)
(
*
Key
,
error
)
{
key
,
err
:=
decryptPreSaleKey
(
keyJSON
,
password
)
key
,
err
:=
decryptPreSaleKey
(
keyJSON
,
password
)
...
...
tests/block_test.go
View file @
34c94d5f
...
@@ -87,7 +87,7 @@ func runBlockTest(name string, test *BlockTest, t *testing.T) {
...
@@ -87,7 +87,7 @@ func runBlockTest(name string, test *BlockTest, t *testing.T) {
ethereum
.
ResetWithGenesisBlock
(
test
.
Genesis
)
ethereum
.
ResetWithGenesisBlock
(
test
.
Genesis
)
// import pre accounts
// import pre accounts
statedb
,
err
:=
test
.
InsertPreState
(
ethereum
.
StateDb
()
)
statedb
,
err
:=
test
.
InsertPreState
(
ethereum
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"InsertPreState: %v"
,
err
)
t
.
Fatalf
(
"InsertPreState: %v"
,
err
)
}
}
...
...
tests/block_test_util.go
View file @
34c94d5f
...
@@ -10,11 +10,14 @@ import (
...
@@ -10,11 +10,14 @@ import (
"runtime"
"runtime"
"strconv"
"strconv"
"strings"
"strings"
"time"
"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/state"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rlp"
)
)
...
@@ -41,10 +44,11 @@ type btBlock struct {
...
@@ -41,10 +44,11 @@ type btBlock struct {
}
}
type
btAccount
struct
{
type
btAccount
struct
{
Balance
string
Balance
string
Code
string
Code
string
Nonce
string
Nonce
string
Storage
map
[
string
]
string
Storage
map
[
string
]
string
PrivateKey
string
}
}
type
btHeader
struct
{
type
btHeader
struct
{
...
@@ -97,15 +101,24 @@ func LoadBlockTests(file string) (map[string]*BlockTest, error) {
...
@@ -97,15 +101,24 @@ func LoadBlockTests(file string) (map[string]*BlockTest, error) {
// InsertPreState populates the given database with the genesis
// InsertPreState populates the given database with the genesis
// accounts defined by the test.
// accounts defined by the test.
func
(
t
*
BlockTest
)
InsertPreState
(
db
common
.
Database
)
(
*
state
.
StateDB
,
error
)
{
func
(
t
*
BlockTest
)
InsertPreState
(
ethereum
*
eth
.
Ethereum
)
(
*
state
.
StateDB
,
error
)
{
db
:=
ethereum
.
StateDb
()
statedb
:=
state
.
New
(
common
.
Hash
{},
db
)
statedb
:=
state
.
New
(
common
.
Hash
{},
db
)
for
addrString
,
acct
:=
range
t
.
preAccounts
{
for
addrString
,
acct
:=
range
t
.
preAccounts
{
// XXX: is is worth it checking for errors here?
addr
,
_
:=
hex
.
DecodeString
(
addrString
)
//addr, _ := hex.DecodeString(addrString)
code
,
_
:=
hex
.
DecodeString
(
strings
.
TrimPrefix
(
acct
.
Code
,
"0x"
))
code
,
_
:=
hex
.
DecodeString
(
strings
.
TrimPrefix
(
acct
.
Code
,
"0x"
))
balance
,
_
:=
new
(
big
.
Int
)
.
SetString
(
acct
.
Balance
,
0
)
balance
,
_
:=
new
(
big
.
Int
)
.
SetString
(
acct
.
Balance
,
0
)
nonce
,
_
:=
strconv
.
ParseUint
(
acct
.
Nonce
,
16
,
64
)
nonce
,
_
:=
strconv
.
ParseUint
(
acct
.
Nonce
,
16
,
64
)
if
acct
.
PrivateKey
!=
""
{
privkey
,
err
:=
hex
.
DecodeString
(
strings
.
TrimPrefix
(
acct
.
PrivateKey
,
"0x"
))
err
=
crypto
.
ImportBlockTestKey
(
privkey
)
err
=
ethereum
.
AccountManager
()
.
TimedUnlock
(
addr
,
""
,
999999
*
time
.
Second
)
if
err
!=
nil
{
return
nil
,
err
}
}
obj
:=
statedb
.
CreateAccount
(
common
.
HexToAddress
(
addrString
))
obj
:=
statedb
.
CreateAccount
(
common
.
HexToAddress
(
addrString
))
obj
.
SetCode
(
code
)
obj
.
SetCode
(
code
)
obj
.
SetBalance
(
balance
)
obj
.
SetBalance
(
balance
)
...
...
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