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
5d216675
Commit
5d216675
authored
Nov 23, 2019
by
Guillaume Ballet
Committed by
Felix Lange
Nov 23, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests, signer: remove staticcheck warnings (#20364)
parent
fdff182f
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
60 additions
and
68 deletions
+60
-68
api.go
signer/core/api.go
+4
-1
api_test.go
signer/core/api_test.go
+2
-2
cliui.go
signer/core/cliui.go
+0
-28
stdioui.go
signer/core/stdioui.go
+0
-2
types.go
signer/core/types.go
+1
-1
uiapi.go
signer/core/uiapi.go
+1
-1
bindata.go
signer/rules/deps/bindata.go
+15
-6
rules.go
signer/rules/rules.go
+1
-1
storage.go
signer/storage/storage.go
+2
-3
block_test_util.go
tests/block_test_util.go
+19
-19
init_test.go
tests/init_test.go
+11
-0
transaction_test_util.go
tests/transaction_test_util.go
+4
-4
No files found.
signer/core/api.go
View file @
5d216675
...
...
@@ -269,7 +269,7 @@ type (
}
)
var
ErrRequestDenied
=
errors
.
New
(
"
R
equest denied"
)
var
ErrRequestDenied
=
errors
.
New
(
"
r
equest denied"
)
// NewSignerAPI creates a new API that can be used for Account management.
// ksLocation specifies the directory where to store the password protected private
...
...
@@ -552,6 +552,9 @@ func (api *SignerAPI) SignTransaction(ctx context.Context, args SendTxArgs, meth
}
rlpdata
,
err
:=
rlp
.
EncodeToBytes
(
signedTx
)
if
err
!=
nil
{
return
nil
,
err
}
response
:=
ethapi
.
SignTransactionResult
{
Raw
:
rlpdata
,
Tx
:
signedTx
}
// Finally, send the signed tx to the UI
...
...
signer/core/api_test.go
View file @
5d216675
...
...
@@ -71,7 +71,7 @@ func (ui *headlessUi) ApproveTx(request *core.SignTxRequest) (core.SignTxRespons
}
func
(
ui
*
headlessUi
)
ApproveSignData
(
request
*
core
.
SignDataRequest
)
(
core
.
SignDataResponse
,
error
)
{
approved
:=
"Y"
==
<-
ui
.
approveCh
approved
:=
(
<-
ui
.
approveCh
==
"Y"
)
return
core
.
SignDataResponse
{
approved
},
nil
}
...
...
@@ -91,7 +91,7 @@ func (ui *headlessUi) ApproveListing(request *core.ListRequest) (core.ListRespon
}
func
(
ui
*
headlessUi
)
ApproveNewAccount
(
request
*
core
.
NewAccountRequest
)
(
core
.
NewAccountResponse
,
error
)
{
if
"Y"
==
<-
ui
.
approveCh
{
if
<-
ui
.
approveCh
==
"Y"
{
return
core
.
NewAccountResponse
{
true
},
nil
}
return
core
.
NewAccountResponse
{
false
},
nil
...
...
signer/core/cliui.go
View file @
5d216675
...
...
@@ -58,34 +58,6 @@ func (ui *CommandlineUI) readString() string {
}
}
// readPassword reads a single line from stdin, trimming it from the trailing new
// line and returns it. The input will not be echoed.
func
(
ui
*
CommandlineUI
)
readPassword
()
string
{
fmt
.
Printf
(
"Enter password to approve:
\n
"
)
fmt
.
Printf
(
"> "
)
text
,
err
:=
terminal
.
ReadPassword
(
int
(
os
.
Stdin
.
Fd
()))
if
err
!=
nil
{
log
.
Crit
(
"Failed to read password"
,
"err"
,
err
)
}
fmt
.
Println
()
fmt
.
Println
(
"-----------------------"
)
return
string
(
text
)
}
// readPassword reads a single line from stdin, trimming it from the trailing new
// line and returns it. The input will not be echoed.
func
(
ui
*
CommandlineUI
)
readPasswordText
(
inputstring
string
)
string
{
fmt
.
Printf
(
"Enter %s:
\n
"
,
inputstring
)
fmt
.
Printf
(
"> "
)
text
,
err
:=
terminal
.
ReadPassword
(
int
(
os
.
Stdin
.
Fd
()))
if
err
!=
nil
{
log
.
Crit
(
"Failed to read password"
,
"err"
,
err
)
}
fmt
.
Println
(
"-----------------------"
)
return
string
(
text
)
}
func
(
ui
*
CommandlineUI
)
OnInputRequired
(
info
UserInputRequest
)
(
UserInputResponse
,
error
)
{
fmt
.
Printf
(
"## %s
\n\n
%s
\n
"
,
info
.
Title
,
info
.
Prompt
)
...
...
signer/core/stdioui.go
View file @
5d216675
...
...
@@ -18,7 +18,6 @@ package core
import
(
"context"
"sync"
"github.com/ethereum/go-ethereum/internal/ethapi"
"github.com/ethereum/go-ethereum/log"
...
...
@@ -27,7 +26,6 @@ import (
type
StdIOUI
struct
{
client
rpc
.
Client
mu
sync
.
Mutex
}
func
NewStdIOUI
()
*
StdIOUI
{
...
...
signer/core/types.go
View file @
5d216675
...
...
@@ -60,7 +60,7 @@ func (v *ValidationMessages) getWarnings() error {
}
}
if
len
(
messages
)
>
0
{
return
fmt
.
Errorf
(
"
V
alidation failed: %s"
,
strings
.
Join
(
messages
,
","
))
return
fmt
.
Errorf
(
"
v
alidation failed: %s"
,
strings
.
Join
(
messages
,
","
))
}
return
nil
}
...
...
signer/core/uiapi.go
View file @
5d216675
...
...
@@ -173,7 +173,7 @@ func (s *UIServerAPI) Export(ctx context.Context, addr common.Address) (json.Raw
return
nil
,
err
}
if
wallet
.
URL
()
.
Scheme
!=
keystore
.
KeyStoreScheme
{
return
nil
,
fmt
.
Errorf
(
"
A
ccount is not a keystore-account"
)
return
nil
,
fmt
.
Errorf
(
"
a
ccount is not a keystore-account"
)
}
return
ioutil
.
ReadFile
(
wallet
.
URL
()
.
Path
)
}
...
...
signer/rules/deps/bindata.go
View file @
5d216675
//
Code generated by go-bindata
.
//
Package deps Code generated by go-bindata. (@generated) DO NOT EDIT
.
// sources:
// bignumber.js
// DO NOT EDIT!
package
deps
import
(
...
...
@@ -20,7 +18,7 @@ import (
func
bindataRead
(
data
[]
byte
,
name
string
)
([]
byte
,
error
)
{
gz
,
err
:=
gzip
.
NewReader
(
bytes
.
NewBuffer
(
data
))
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"
R
ead %q: %v"
,
name
,
err
)
return
nil
,
fmt
.
Errorf
(
"
r
ead %q: %v"
,
name
,
err
)
}
var
buf
bytes
.
Buffer
...
...
@@ -28,7 +26,7 @@ func bindataRead(data []byte, name string) ([]byte, error) {
clErr
:=
gz
.
Close
()
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"
R
ead %q: %v"
,
name
,
err
)
return
nil
,
fmt
.
Errorf
(
"
r
ead %q: %v"
,
name
,
err
)
}
if
clErr
!=
nil
{
return
nil
,
err
...
...
@@ -49,21 +47,32 @@ type bindataFileInfo struct {
modTime
time
.
Time
}
// Name return file name
func
(
fi
bindataFileInfo
)
Name
()
string
{
return
fi
.
name
}
// Size return file size
func
(
fi
bindataFileInfo
)
Size
()
int64
{
return
fi
.
size
}
// Mode return file mode
func
(
fi
bindataFileInfo
)
Mode
()
os
.
FileMode
{
return
fi
.
mode
}
// ModTime return file modify time
func
(
fi
bindataFileInfo
)
ModTime
()
time
.
Time
{
return
fi
.
modTime
}
// IsDir return file whether a directory
func
(
fi
bindataFileInfo
)
IsDir
()
bool
{
return
f
alse
return
f
i
.
mode
&
os
.
ModeDir
!=
0
}
// Sys return file is sys mode
func
(
fi
bindataFileInfo
)
Sys
()
interface
{}
{
return
nil
}
...
...
signer/rules/rules.go
View file @
5d216675
...
...
@@ -152,7 +152,7 @@ func (r *rulesetUI) checkApproval(jsfunc string, jsarg []byte, err error) (bool,
log
.
Info
(
"Op rejected"
)
return
false
,
nil
}
return
false
,
fmt
.
Errorf
(
"
U
nknown response"
)
return
false
,
fmt
.
Errorf
(
"
u
nknown response"
)
}
func
(
r
*
rulesetUI
)
ApproveTx
(
request
*
core
.
SignTxRequest
)
(
core
.
SignTxResponse
,
error
)
{
...
...
signer/storage/storage.go
View file @
5d216675
...
...
@@ -41,8 +41,7 @@ type Storage interface {
// EphemeralStorage is an in-memory storage that does
// not persist values to disk. Mainly used for testing
type
EphemeralStorage
struct
{
data
map
[
string
]
string
namespace
string
data
map
[
string
]
string
}
// Put stores a value by key. 0-length keys results in noop.
...
...
@@ -83,5 +82,5 @@ type NoStorage struct{}
func
(
s
*
NoStorage
)
Put
(
key
,
value
string
)
{}
func
(
s
*
NoStorage
)
Del
(
key
string
)
{}
func
(
s
*
NoStorage
)
Get
(
key
string
)
(
string
,
error
)
{
return
""
,
errors
.
New
(
"
I
forgot"
)
return
""
,
errors
.
New
(
"
missing key, I probably
forgot"
)
}
tests/block_test_util.go
View file @
5d216675
...
...
@@ -179,7 +179,7 @@ func (t *BlockTest) insertBlocks(blockchain *core.BlockChain) ([]btBlock, error)
if
b
.
BlockHeader
==
nil
{
continue
// OK - block is supposed to be invalid, continue with next block
}
else
{
return
nil
,
fmt
.
Errorf
(
"
B
lock RLP decoding failed when expected to succeed: %v"
,
err
)
return
nil
,
fmt
.
Errorf
(
"
b
lock RLP decoding failed when expected to succeed: %v"
,
err
)
}
}
// RLP decoding worked, try to insert into chain:
...
...
@@ -189,16 +189,16 @@ func (t *BlockTest) insertBlocks(blockchain *core.BlockChain) ([]btBlock, error)
if
b
.
BlockHeader
==
nil
{
continue
// OK - block is supposed to be invalid, continue with next block
}
else
{
return
nil
,
fmt
.
Errorf
(
"
B
lock #%v insertion into chain failed: %v"
,
blocks
[
i
]
.
Number
(),
err
)
return
nil
,
fmt
.
Errorf
(
"
b
lock #%v insertion into chain failed: %v"
,
blocks
[
i
]
.
Number
(),
err
)
}
}
if
b
.
BlockHeader
==
nil
{
return
nil
,
fmt
.
Errorf
(
"
B
lock insertion should have failed"
)
return
nil
,
fmt
.
Errorf
(
"
b
lock insertion should have failed"
)
}
// validate RLP decoding by checking all values against test file JSON
if
err
=
validateHeader
(
b
.
BlockHeader
,
cb
.
Header
());
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"
D
eserialised block header validation failed: %v"
,
err
)
return
nil
,
fmt
.
Errorf
(
"
d
eserialised block header validation failed: %v"
,
err
)
}
validBlocks
=
append
(
validBlocks
,
b
)
}
...
...
@@ -207,49 +207,49 @@ func (t *BlockTest) insertBlocks(blockchain *core.BlockChain) ([]btBlock, error)
func
validateHeader
(
h
*
btHeader
,
h2
*
types
.
Header
)
error
{
if
h
.
Bloom
!=
h2
.
Bloom
{
return
fmt
.
Errorf
(
"
B
loom: want: %x have: %x"
,
h
.
Bloom
,
h2
.
Bloom
)
return
fmt
.
Errorf
(
"
b
loom: want: %x have: %x"
,
h
.
Bloom
,
h2
.
Bloom
)
}
if
h
.
Coinbase
!=
h2
.
Coinbase
{
return
fmt
.
Errorf
(
"
C
oinbase: want: %x have: %x"
,
h
.
Coinbase
,
h2
.
Coinbase
)
return
fmt
.
Errorf
(
"
c
oinbase: want: %x have: %x"
,
h
.
Coinbase
,
h2
.
Coinbase
)
}
if
h
.
MixHash
!=
h2
.
MixDigest
{
return
fmt
.
Errorf
(
"MixHash: want: %x have: %x"
,
h
.
MixHash
,
h2
.
MixDigest
)
}
if
h
.
Nonce
!=
h2
.
Nonce
{
return
fmt
.
Errorf
(
"
N
once: want: %x have: %x"
,
h
.
Nonce
,
h2
.
Nonce
)
return
fmt
.
Errorf
(
"
n
once: want: %x have: %x"
,
h
.
Nonce
,
h2
.
Nonce
)
}
if
h
.
Number
.
Cmp
(
h2
.
Number
)
!=
0
{
return
fmt
.
Errorf
(
"
N
umber: want: %v have: %v"
,
h
.
Number
,
h2
.
Number
)
return
fmt
.
Errorf
(
"
n
umber: want: %v have: %v"
,
h
.
Number
,
h2
.
Number
)
}
if
h
.
ParentHash
!=
h2
.
ParentHash
{
return
fmt
.
Errorf
(
"
P
arent hash: want: %x have: %x"
,
h
.
ParentHash
,
h2
.
ParentHash
)
return
fmt
.
Errorf
(
"
p
arent hash: want: %x have: %x"
,
h
.
ParentHash
,
h2
.
ParentHash
)
}
if
h
.
ReceiptTrie
!=
h2
.
ReceiptHash
{
return
fmt
.
Errorf
(
"
R
eceipt hash: want: %x have: %x"
,
h
.
ReceiptTrie
,
h2
.
ReceiptHash
)
return
fmt
.
Errorf
(
"
r
eceipt hash: want: %x have: %x"
,
h
.
ReceiptTrie
,
h2
.
ReceiptHash
)
}
if
h
.
TransactionsTrie
!=
h2
.
TxHash
{
return
fmt
.
Errorf
(
"
T
x hash: want: %x have: %x"
,
h
.
TransactionsTrie
,
h2
.
TxHash
)
return
fmt
.
Errorf
(
"
t
x hash: want: %x have: %x"
,
h
.
TransactionsTrie
,
h2
.
TxHash
)
}
if
h
.
StateRoot
!=
h2
.
Root
{
return
fmt
.
Errorf
(
"
S
tate hash: want: %x have: %x"
,
h
.
StateRoot
,
h2
.
Root
)
return
fmt
.
Errorf
(
"
s
tate hash: want: %x have: %x"
,
h
.
StateRoot
,
h2
.
Root
)
}
if
h
.
UncleHash
!=
h2
.
UncleHash
{
return
fmt
.
Errorf
(
"
U
ncle hash: want: %x have: %x"
,
h
.
UncleHash
,
h2
.
UncleHash
)
return
fmt
.
Errorf
(
"
u
ncle hash: want: %x have: %x"
,
h
.
UncleHash
,
h2
.
UncleHash
)
}
if
!
bytes
.
Equal
(
h
.
ExtraData
,
h2
.
Extra
)
{
return
fmt
.
Errorf
(
"
E
xtra data: want: %x have: %x"
,
h
.
ExtraData
,
h2
.
Extra
)
return
fmt
.
Errorf
(
"
e
xtra data: want: %x have: %x"
,
h
.
ExtraData
,
h2
.
Extra
)
}
if
h
.
Difficulty
.
Cmp
(
h2
.
Difficulty
)
!=
0
{
return
fmt
.
Errorf
(
"
D
ifficulty: want: %v have: %v"
,
h
.
Difficulty
,
h2
.
Difficulty
)
return
fmt
.
Errorf
(
"
d
ifficulty: want: %v have: %v"
,
h
.
Difficulty
,
h2
.
Difficulty
)
}
if
h
.
GasLimit
!=
h2
.
GasLimit
{
return
fmt
.
Errorf
(
"
G
asLimit: want: %d have: %d"
,
h
.
GasLimit
,
h2
.
GasLimit
)
return
fmt
.
Errorf
(
"
g
asLimit: want: %d have: %d"
,
h
.
GasLimit
,
h2
.
GasLimit
)
}
if
h
.
GasUsed
!=
h2
.
GasUsed
{
return
fmt
.
Errorf
(
"
G
asUsed: want: %d have: %d"
,
h
.
GasUsed
,
h2
.
GasUsed
)
return
fmt
.
Errorf
(
"
g
asUsed: want: %d have: %d"
,
h
.
GasUsed
,
h2
.
GasUsed
)
}
if
h
.
Timestamp
!=
h2
.
Time
{
return
fmt
.
Errorf
(
"
T
imestamp: want: %v have: %v"
,
h
.
Timestamp
,
h2
.
Time
)
return
fmt
.
Errorf
(
"
t
imestamp: want: %v have: %v"
,
h
.
Timestamp
,
h2
.
Time
)
}
return
nil
}
...
...
@@ -287,7 +287,7 @@ func (t *BlockTest) validateImportedHeaders(cm *core.BlockChain, validBlocks []b
// be part of the longest chain until last block is imported.
for
b
:=
cm
.
CurrentBlock
();
b
!=
nil
&&
b
.
NumberU64
()
!=
0
;
b
=
cm
.
GetBlockByHash
(
b
.
Header
()
.
ParentHash
)
{
if
err
:=
validateHeader
(
bmap
[
b
.
Hash
()]
.
BlockHeader
,
b
.
Header
());
err
!=
nil
{
return
fmt
.
Errorf
(
"
I
mported block header validation failed: %v"
,
err
)
return
fmt
.
Errorf
(
"
i
mported block header validation failed: %v"
,
err
)
}
}
return
nil
...
...
tests/init_test.go
View file @
5d216675
...
...
@@ -289,3 +289,14 @@ func runTestFunc(runTest interface{}, t *testing.T, name string, m reflect.Value
m
.
MapIndex
(
reflect
.
ValueOf
(
key
)),
})
}
func
TestMatcherWhitelist
(
t
*
testing
.
T
)
{
t
.
Parallel
()
tm
:=
new
(
testMatcher
)
tm
.
whitelist
(
"invalid*"
)
tm
.
walk
(
t
,
rlpTestDir
,
func
(
t
*
testing
.
T
,
name
string
,
test
*
RLPTest
)
{
if
name
[
:
len
(
"invalidRLPTest.json"
)]
!=
"invalidRLPTest.json"
{
t
.
Fatalf
(
"invalid test found: %s != invalidRLPTest.json"
,
name
)
}
})
}
tests/transaction_test_util.go
View file @
5d216675
...
...
@@ -86,25 +86,25 @@ func (tt *TransactionTest) Run(config *params.ChainConfig) error {
if
testcase
.
fork
.
Sender
==
(
common
.
UnprefixedAddress
{})
{
if
err
==
nil
{
return
fmt
.
Errorf
(
"
E
xpected error, got none (address %v)[%v]"
,
sender
.
String
(),
testcase
.
name
)
return
fmt
.
Errorf
(
"
e
xpected error, got none (address %v)[%v]"
,
sender
.
String
(),
testcase
.
name
)
}
continue
}
// Should resolve the right address
if
err
!=
nil
{
return
fmt
.
Errorf
(
"
G
ot error, expected none: %v"
,
err
)
return
fmt
.
Errorf
(
"
g
ot error, expected none: %v"
,
err
)
}
if
sender
==
nil
{
return
fmt
.
Errorf
(
"sender was nil, should be %x"
,
common
.
Address
(
testcase
.
fork
.
Sender
))
}
if
*
sender
!=
common
.
Address
(
testcase
.
fork
.
Sender
)
{
return
fmt
.
Errorf
(
"
S
ender mismatch: got %x, want %x"
,
sender
,
testcase
.
fork
.
Sender
)
return
fmt
.
Errorf
(
"
s
ender mismatch: got %x, want %x"
,
sender
,
testcase
.
fork
.
Sender
)
}
if
txhash
==
nil
{
return
fmt
.
Errorf
(
"txhash was nil, should be %x"
,
common
.
Hash
(
testcase
.
fork
.
Hash
))
}
if
*
txhash
!=
common
.
Hash
(
testcase
.
fork
.
Hash
)
{
return
fmt
.
Errorf
(
"
H
ash mismatch: got %x, want %x"
,
*
txhash
,
testcase
.
fork
.
Hash
)
return
fmt
.
Errorf
(
"
h
ash mismatch: got %x, want %x"
,
*
txhash
,
testcase
.
fork
.
Hash
)
}
}
return
nil
...
...
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