diff options
Diffstat (limited to 'console')
-rw-r--r-- | console/console.go | 15 | ||||
-rw-r--r-- | console/console_test.go | 22 | ||||
-rw-r--r-- | console/prompter.go | 8 |
3 files changed, 34 insertions, 11 deletions
diff --git a/console/console.go b/console/console.go index 3cd2ad34b..1ecbfd0b0 100644 --- a/console/console.go +++ b/console/console.go @@ -47,7 +47,7 @@ const HistoryFile = "history" // DefaultPrompt is the default prompt line prefix to use for user input querying. const DefaultPrompt = "> " -// Config is te collection of configurations to fine tune the behavior of the +// Config is the collection of configurations to fine tune the behavior of the // JavaScript console. type Config struct { DataDir string // Data directory to store the console history at @@ -192,6 +192,7 @@ func (c *Console) init(preload []string) error { if obj := admin.Object(); obj != nil { // make sure the admin api is enabled over the interface obj.Set("sleepBlocks", bridge.SleepBlocks) obj.Set("sleep", bridge.Sleep) + obj.Set("clearHistory", c.clearHistory) } // Preload any JavaScript files before starting the console for _, path := range preload { @@ -216,6 +217,16 @@ func (c *Console) init(preload []string) error { return nil } +func (c *Console) clearHistory() { + c.history = nil + c.prompter.ClearHistory() + if err := os.Remove(c.histPath); err != nil { + fmt.Fprintln(c.printer, "can't delete history file:", err) + } else { + fmt.Fprintln(c.printer, "history file deleted") + } +} + // consoleOutput is an override for the console.log and console.error methods to // stream the output into the configured output stream instead of stdout. func (c *Console) consoleOutput(call otto.FunctionCall) otto.Value { @@ -238,7 +249,7 @@ func (c *Console) AutoCompleteInput(line string, pos int) (string, []string, str // E.g. in case of nested lines eth.getBalance(eth.coinb<tab><tab> start := pos - 1 for ; start > 0; start-- { - // Skip all methods and namespaces (i.e. including te dot) + // Skip all methods and namespaces (i.e. including the dot) if line[start] == '.' || (line[start] >= 'a' && line[start] <= 'z') || (line[start] >= 'A' && line[start] <= 'Z') { continue } diff --git a/console/console_test.go b/console/console_test.go index 8ac499bd1..7b1629c03 100644 --- a/console/console_test.go +++ b/console/console_test.go @@ -27,6 +27,7 @@ import ( "time" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/consensus/ethash" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/internal/jsre" @@ -67,6 +68,7 @@ func (p *hookedPrompter) PromptConfirm(prompt string) (bool, error) { } func (p *hookedPrompter) SetHistory(history []string) {} func (p *hookedPrompter) AppendHistory(command string) {} +func (p *hookedPrompter) ClearHistory() {} func (p *hookedPrompter) SetWordCompleter(completer WordCompleter) {} // tester is a console test environment for the console tests to operate on. @@ -94,9 +96,11 @@ func newTester(t *testing.T, confOverride func(*eth.Config)) *tester { t.Fatalf("failed to create node: %v", err) } ethConf := ð.Config{ - Genesis: core.DevGenesisBlock(), + Genesis: core.DeveloperGenesisBlock(15, common.Address{}), Etherbase: common.HexToAddress(testAddress), - PowTest: true, + Ethash: ethash.Config{ + PowMode: ethash.ModeTest, + }, } if confOverride != nil { confOverride(ethConf) @@ -160,7 +164,7 @@ func TestWelcome(t *testing.T) { tester.console.Welcome() - output := string(tester.output.Bytes()) + output := tester.output.String() if want := "Welcome"; !strings.Contains(output, want) { t.Fatalf("console output missing welcome message: have\n%s\nwant also %s", output, want) } @@ -184,7 +188,7 @@ func TestEvaluate(t *testing.T) { defer tester.Close(t) tester.console.Evaluate("2 + 2") - if output := string(tester.output.Bytes()); !strings.Contains(output, "4") { + if output := tester.output.String(); !strings.Contains(output, "4") { t.Fatalf("statement evaluation failed: have %s, want %s", output, "4") } } @@ -214,7 +218,7 @@ func TestInteractive(t *testing.T) { case <-time.After(time.Second): t.Fatalf("secondary prompt timeout") } - if output := string(tester.output.Bytes()); !strings.Contains(output, "4") { + if output := tester.output.String(); !strings.Contains(output, "4") { t.Fatalf("statement evaluation failed: have %s, want %s", output, "4") } } @@ -226,7 +230,7 @@ func TestPreload(t *testing.T) { defer tester.Close(t) tester.console.Evaluate("preloaded") - if output := string(tester.output.Bytes()); !strings.Contains(output, "some-preloaded-string") { + if output := tester.output.String(); !strings.Contains(output, "some-preloaded-string") { t.Fatalf("preloaded variable missing: have %s, want %s", output, "some-preloaded-string") } } @@ -239,7 +243,7 @@ func TestExecute(t *testing.T) { tester.console.Execute("exec.js") tester.console.Evaluate("execed") - if output := string(tester.output.Bytes()); !strings.Contains(output, "some-executed-string") { + if output := tester.output.String(); !strings.Contains(output, "some-executed-string") { t.Fatalf("execed variable missing: have %s, want %s", output, "some-executed-string") } } @@ -271,7 +275,7 @@ func TestPrettyPrint(t *testing.T) { string: ` + two + ` } ` - if output := string(tester.output.Bytes()); output != want { + if output := tester.output.String(); output != want { t.Fatalf("pretty print mismatch: have %s, want %s", output, want) } } @@ -283,7 +287,7 @@ func TestPrettyError(t *testing.T) { tester.console.Evaluate("throw 'hello'") want := jsre.ErrorColor("hello") + "\n" - if output := string(tester.output.Bytes()); output != want { + if output := tester.output.String(); output != want { t.Fatalf("pretty error mismatch: have %s, want %s", output, want) } } diff --git a/console/prompter.go b/console/prompter.go index 6acbfb0e2..ea03694d4 100644 --- a/console/prompter.go +++ b/console/prompter.go @@ -51,6 +51,9 @@ type UserPrompter interface { // if and only if the prompt to append was a valid command. AppendHistory(command string) + // ClearHistory clears the entire history + ClearHistory() + // SetWordCompleter sets the completion function that the prompter will call to // fetch completion candidates when the user presses tab. SetWordCompleter(completer WordCompleter) @@ -158,6 +161,11 @@ func (p *terminalPrompter) AppendHistory(command string) { p.State.AppendHistory(command) } +// ClearHistory clears the entire history +func (p *terminalPrompter) ClearHistory() { + p.State.ClearHistory() +} + // SetWordCompleter sets the completion function that the prompter will call to // fetch completion candidates when the user presses tab. func (p *terminalPrompter) SetWordCompleter(completer WordCompleter) { |