Skip to content
This repository has been archived by the owner on Oct 4, 2019. It is now read-only.

Commit

Permalink
Merge pull request #423 from ethereumproject/feat/log-display
Browse files Browse the repository at this point in the history
improve logging, separate display/debug logs
  • Loading branch information
whilei authored Jan 1, 2018
2 parents f77d9d9 + 8acd46a commit 844bb48
Show file tree
Hide file tree
Showing 56 changed files with 2,589 additions and 690 deletions.
6 changes: 6 additions & 0 deletions accounts/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package accounts
import (
"fmt"
"github.com/davecgh/go-spew/spew"
"github.com/ethereumproject/go-ethereum/logger/glog"
"io/ioutil"
"math/rand"
"os"
Expand All @@ -29,6 +30,11 @@ import (
"time"
)

func init() {
glog.SetD(0)
glog.SetV(0)
}

var testSigData = make([]byte, 32)

func tmpManager(t *testing.T) (string, *Manager) {
Expand Down
2 changes: 1 addition & 1 deletion accounts/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (w *watcher) loop() {

err := notify.Watch(w.ac.getKeydir(), w.ev, notify.All)
if err != nil {
glog.V(logger.Detail).Infof("can't watch %s: %v", w.ac.getKeydir(), err)
glog.V(logger.Warn).Errorf("can't watch %s: %v", w.ac.getKeydir(), err)
return
}
defer notify.Stop(w.ev)
Expand Down
4 changes: 3 additions & 1 deletion cmd/geth/accountcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func accountIndex(ctx *cli.Context) error {
if len(errs) > 0 {
for _, e := range errs {
if e != nil {
glog.V(logger.Error).Infof("init cache db err: %v", e)
glog.V(logger.Error).Errorf("init cache db err: %v", e)
}
}
}
Expand Down Expand Up @@ -236,10 +236,12 @@ func unlockAccount(ctx *cli.Context, accman *accounts.Manager, address string, i
err = accman.Unlock(account, password)
if err == nil {
glog.V(logger.Info).Infof("Unlocked account %x", account.Address)
glog.D(logger.Error).Infof("Unlocked account %x", account.Address)
return account, password
}
if err, ok := err.(*accounts.AmbiguousAddrError); ok {
glog.V(logger.Info).Infof("Unlocked account %x", account.Address)
glog.D(logger.Error).Infof("Unlocked account %x", account.Address)
return ambiguousAddrRecovery(accman, err, password), password
}
if err != accounts.ErrDecrypt {
Expand Down
2 changes: 1 addition & 1 deletion cmd/geth/chainconfig.bats
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ teardown() {
run $GETH_CMD --data-dir $DATA_DIR --chain kitty --bootnodes=enode://e809c4a2fec7daed400e5e28564e23693b23b2cc5a019b612505631bbe7b9ccf709c1796d2a3d29ef2b045f210caf51e3c4f5b6d3587d43ad5d6397526fa6179@174.112.32.157:30303 console
echo "$output"
[ "$status" -eq 0 ]
[[ "$output" == *"WARNING"* ]]
[[ "$output" == *"Overwriting external bootnodes"* ]]
}

# Test fails to load invalid chain configuration from testdata/ JSON file.
Expand Down
66 changes: 39 additions & 27 deletions cmd/geth/cli.bats
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ teardown() {
echo "$output"

[ "$status" -eq 0 ]
[[ "$output" == *"Starting"* ]]
[[ "$output" == *"Blockchain DB Version: "* ]]
[[ "$output" == *"Starting Server"* ]]
[[ "$output" == *"Blockchain"* ]]
[[ "$output" == *"Local head"* ]]
[[ "$output" == *"Starting server"* ]]
}

@test "displays help with invalid flag and valid command" {
Expand Down Expand Up @@ -75,7 +75,7 @@ teardown() {
@test "custom testnet subdir --testnet --chain=morden2 | exit !=0" {
run $GETH_CMD --data-dir $DATA_DIR --testnet --chain=morden2 --maxpeers 0 --nodiscover --nat none --ipcdisable --exec 'exit' console
echo "$output"
[ "$status" -ne 0 ]
[ "$status" -ne 0 ]
[[ "$output" == *"invalid flag "* ]]
}

Expand Down Expand Up @@ -109,57 +109,67 @@ teardown() {
# # ipc-path/ipcpath
run $GETH_CMD --data-dir $DATA_DIR --ipc-path abc.ipc console
[ "$status" -eq 0 ]
[[ "$output" == *"IPC endpoint opened: $DATA_DIR/mainnet/abc.ipc"* ]]
echo "$output"
[[ "$output" == *"IPC endpoint opened"* ]]
[[ "$output" == *"$DATA_DIR/mainnet/abc.ipc"* ]]

run $GETH_CMD --data-dir $DATA_DIR --ipcpath $DATA_DIR/mainnet/abc.ipc console
[ "$status" -eq 0 ]
[[ "$output" == *"IPC endpoint opened: $DATA_DIR/mainnet/abc.ipc"* ]]
echo "$output"
[[ "$output" == *"IPC endpoint opened"* ]]
[[ "$output" == *"$DATA_DIR/mainnet/abc.ipc"* ]]

run $GETH_CMD --data-dir $DATA_DIR --ipc-path $DATA_DIR/mainnet/abc console
[ "$status" -eq 0 ]
[[ "$output" == *"IPC endpoint opened: $DATA_DIR/mainnet/abc"* ]]
echo "$output"
[[ "$output" == *"IPC endpoint opened"* ]]
[[ "$output" == *"$DATA_DIR/mainnet/abc"* ]]

run $GETH_CMD --data-dir $DATA_DIR --ipcpath $DATA_DIR/mainnet/abc console
[ "$status" -eq 0 ]
[[ "$output" == *"IPC endpoint opened: $DATA_DIR/mainnet/abc"* ]]

echo "$output"
[[ "$output" == *"IPC endpoint opened"* ]]
[[ "$output" == *"$DATA_DIR/mainnet/abc"* ]]

}

# ... assuming that if two work, the rest will work.
@test "aliasing hyphenated flags: --no-discover==--nodiscover, --ipc-disable==--ipcdisable | exit 0" {
old_command_names=(nodiscover ipcdisable)
old_command_names=(nodiscover ipcdisable)
new_command_names=(no-discover ipc-disable)

for var in "${old_command_names[@]}"
do
# hardcode --datadir/--data-dir
run $GETH_CMD --datadir $DATA_DIR --$var --exec 'exit' console
[ "$status" -eq 0 ]
[[ "$output" == *"Starting"* ]]
[[ "$output" == *"Blockchain DB Version: "* ]]
[[ "$output" == *"Starting Server"* ]]
[[ "$output" == *"Blockchain"* ]]
[[ "$output" == *"Local head"* ]]
[[ "$output" == *"Starting server"* ]]
done

for var in "${new_command_names[@]}"
do
run $GETH_CMD --data-dir $DATA_DIR --$var --exec 'exit' console
[ "$status" -eq 0 ]
[[ "$output" == *"Starting"* ]]
[[ "$output" == *"Blockchain DB Version: "* ]]
[[ "$output" == *"Starting Server"* ]]
[[ "$output" == *"Blockchain"* ]]
[[ "$output" == *"Local head"* ]]
[[ "$output" == *"Starting server"* ]]
done
}

@test "--cache 16 | exit 0" {
run $GETH_CMD --data-dir $DATA_DIR --cache 17 console
[ "$status" -eq 0 ]
[[ "$output" == *"Allotted 17MB cache"* ]]
[[ "$output" == *"Allotted"* ]]
[[ "$output" == *"17MB"* ]]
[[ "$output" == *"cache"* ]]
}

# Test `dump` command.
# All tests copy testdata/testdatadir to $DATA_DIR to ensure we're consistently testing against a not-only-init'ed chaindb.
@test "dump [noargs] | exit >0" {
cp -a $BATS_TEST_DIRNAME/../../cmd/geth/testdata/testdatadir/. $DATA_DIR/
cp -a $BATS_TEST_DIRNAME/../../cmd/geth/testdata/testdatadir/. $DATA_DIR/
run $GETH_CMD --data-dir $DATA_DIR dump
echo "$output"
[ "$status" -gt 0 ]
Expand All @@ -174,8 +184,8 @@ teardown() {
[[ "$output" == *"balance"* ]]
[[ "$output" == *"accounts"* ]]
[[ "$output" == *"d7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544"* ]] # block state root
[[ "$output" == *"ffec0913c635baca2f5e57a37aa9fb7b6c9b6e26"* ]] # random hex address existing in genesis
[[ "$output" == *"253319000000000000000"* ]] # random address balance existing in genesis
[[ "$output" == *"ffec0913c635baca2f5e57a37aa9fb7b6c9b6e26"* ]] # random hex address existing in genesis
[[ "$output" == *"253319000000000000000"* ]] # random address balance existing in genesis
}
@test "dump 0 fff7ac99c8e4feb60c9750054bdc14ce1857f181 | exit 0" {
cp -a $BATS_TEST_DIRNAME/../../cmd/geth/testdata/testdatadir/. $DATA_DIR/
Expand All @@ -198,7 +208,7 @@ teardown() {
[[ "$output" == *"balance"* ]]
[[ "$output" == *"accounts"* ]]
[[ "$output" == *"d7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544"* ]] # block 0 state root

[[ "$output" == *"fff7ac99c8e4feb60c9750054bdc14ce1857f181"* ]] # hex address
[[ "$output" == *"1000000000000000000000"* ]] # address balance

Expand All @@ -214,10 +224,10 @@ teardown() {
[[ "$output" == *"root"* ]] # block state root
[[ "$output" == *"balance"* ]]
[[ "$output" == *"accounts"* ]]

[[ "$output" == *"d7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544"* ]] # block 0 state root
[[ "$output" == *"d67e4d450343046425ae4271474353857ab860dbc0a1dde64b41b5cd3a532bf3"* ]] # block 1 state root

[[ "$output" == *"fff7ac99c8e4feb60c9750054bdc14ce1857f181"* ]] # hex address
[[ "$output" == *"1000000000000000000000"* ]] # address balance

Expand All @@ -232,9 +242,9 @@ teardown() {
[[ "$output" == *"root"* ]] # block state root
[[ "$output" == *"balance"* ]]
[[ "$output" == *"accounts"* ]]

[[ "$output" == *"d7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544"* ]] # block 0 state root

[[ "$output" == *"fff7ac99c8e4feb60c9750054bdc14ce1857f181"* ]] # hex address
[[ "$output" == *"1000000000000000000000"* ]] # address balance

Expand Down Expand Up @@ -277,6 +287,7 @@ teardown() {
# When I tried using heredoc and other more elegant solutions than line-by-line checking.

# Chain Configuration Genesis
echo "$output"
[[ "$output" == *"mainnet"* ]]
[[ "$output" == *"Ethereum Classic Mainnet"* ]]
[[ "$output" == *"Genesis"* ]]
Expand All @@ -293,6 +304,7 @@ teardown() {
[ "$status" -eq 0 ]

# Chain database Genesis
echo "$output"
[[ "$output" == *"Genesis"* ]]
[[ "$output" == *"0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3"* ]]
[[ "$output" == *"0x0000000000000000000000000000000000000000000000000000000000000000"* ]]
Expand Down Expand Up @@ -337,4 +349,4 @@ teardown() {
[[ "$output" == *"3141592"* ]]
[[ "$output" == *"0"* ]]
[[ "$output" == *"[]"* ]]
}
}
2 changes: 1 addition & 1 deletion cmd/geth/cmd.bats
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ teardown() {
run $GETH_CMD --data-dir $DATA_DIR reset <<< $'y'
[ "$status" -eq 0 ]
! [ -d $DATA_DIR/mainnet/chaindata ]
}
}
Loading

0 comments on commit 844bb48

Please sign in to comment.