Changes added console.

This commit is contained in:
AnilChinchawale 2019-01-09 08:33:22 +05:30
parent bc15c48163
commit b15708af5b
3 changed files with 31 additions and 3 deletions

View file

@ -575,4 +575,4 @@ func (ethash *Ethash) APIs(chain consensus.ChainReader) []rpc.API {
// dataset.
func SeedHash(block uint64) []byte {
return seedHash(block)
}
}

View file

@ -273,7 +273,7 @@ func (c *Console) AutoCompleteInput(line string, pos int) (string, []string, str
// console's available modules.
func (c *Console) Welcome() {
// Print some generic XDC metadata
fmt.Fprintf(c.printer, "Welcome to the XinFin JavaScript console!\n\n")
fmt.Fprintf(c.printer, "Welcome to the XDC JavaScript console!\n\n")
c.jsre.Run(`
console.log("instance: " + web3.version.node);
console.log("coinbase: " + eth.coinbase);

View file

@ -19,6 +19,7 @@ package console
import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"os"
"strings"
@ -154,6 +155,33 @@ func (env *tester) Close(t *testing.T) {
os.RemoveAll(env.workspace)
}
// Tests that the node lists the correct welcome message, notably that it contains
// the instance name, coinbase account, block number, data directory and supported
// console modules.
func TestWelcome(t *testing.T) {
tester := newTester(t, nil)
defer tester.Close(t)
tester.console.Welcome()
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)
}
if want := fmt.Sprintf("instance: %s", testInstance); !strings.Contains(output, want) {
t.Fatalf("console output missing instance: have\n%s\nwant also %s", output, want)
}
if want := fmt.Sprintf("coinbase: %s", testAddress); !strings.Contains(output, want) {
t.Fatalf("console output missing coinbase: have\n%s\nwant also %s", output, want)
}
if want := "at block: 0"; !strings.Contains(output, want) {
t.Fatalf("console output missing sync status: have\n%s\nwant also %s", output, want)
}
if want := fmt.Sprintf("datadir: %s", tester.workspace); !strings.Contains(output, want) {
t.Fatalf("console output missing coinbase: have\n%s\nwant also %s", output, want)
}
}
// Tests that JavaScript statement evaluation works as intended.
func TestEvaluate(t *testing.T) {
tester := newTester(t, nil)
@ -308,4 +336,4 @@ func TestIndenting(t *testing.T) {
t.Errorf("test %d: invalid indenting: have %d, want %d", i, counted, tt.expectedIndentCount)
}
}
}
}