aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2015-05-20 17:31:52 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2015-05-20 17:31:52 +0800
commit0300eef94d7d1e58bc5cf94094a3d492c70486e1 (patch)
treed2828b978ad2a0128459c9a09096aec95b18af1c /cmd
parent6b83a0a589d4615382de3d9f3ed2800064b4c1b9 (diff)
parente1d1417729b82f00bcb62dffa36358cb74ab790f (diff)
downloaddexon-0300eef94d7d1e58bc5cf94094a3d492c70486e1.tar
dexon-0300eef94d7d1e58bc5cf94094a3d492c70486e1.tar.gz
dexon-0300eef94d7d1e58bc5cf94094a3d492c70486e1.tar.bz2
dexon-0300eef94d7d1e58bc5cf94094a3d492c70486e1.tar.lz
dexon-0300eef94d7d1e58bc5cf94094a3d492c70486e1.tar.xz
dexon-0300eef94d7d1e58bc5cf94094a3d492c70486e1.tar.zst
dexon-0300eef94d7d1e58bc5cf94094a3d492c70486e1.zip
Merge pull request #1048 from ethersphere/cli-fixes
CLI, JSRE admin and Solc improvements
Diffstat (limited to 'cmd')
-rw-r--r--cmd/geth/admin.go25
-rw-r--r--cmd/geth/info_test.json2
-rw-r--r--cmd/geth/js.go3
-rw-r--r--cmd/geth/js_test.go44
-rw-r--r--cmd/geth/main.go12
-rw-r--r--cmd/utils/flags.go1
6 files changed, 62 insertions, 25 deletions
diff --git a/cmd/geth/admin.go b/cmd/geth/admin.go
index 53dd0e6ad..523b7c406 100644
--- a/cmd/geth/admin.go
+++ b/cmd/geth/admin.go
@@ -35,6 +35,7 @@ func (js *jsre) adminBindings() {
eth := ethO.Object()
eth.Set("pendingTransactions", js.pendingTransactions)
eth.Set("resend", js.resend)
+ eth.Set("sign", js.sign)
js.re.Set("admin", struct{}{})
t, _ := js.re.Get("admin")
@@ -177,6 +178,30 @@ func (js *jsre) resend(call otto.FunctionCall) otto.Value {
return otto.FalseValue()
}
+func (js *jsre) sign(call otto.FunctionCall) otto.Value {
+ if len(call.ArgumentList) != 2 {
+ fmt.Println("requires 2 arguments: eth.sign(signer, data)")
+ return otto.UndefinedValue()
+ }
+ signer, err := call.Argument(0).ToString()
+ if err != nil {
+ fmt.Println(err)
+ return otto.UndefinedValue()
+ }
+
+ data, err := call.Argument(1).ToString()
+ if err != nil {
+ fmt.Println(err)
+ return otto.UndefinedValue()
+ }
+ v, err := js.xeth.Sign(signer, data, false)
+ if err != nil {
+ fmt.Println(err)
+ return otto.UndefinedValue()
+ }
+ return js.re.ToVal(v)
+}
+
func (js *jsre) debugBlock(call otto.FunctionCall) otto.Value {
block, err := js.getBlock(call)
if err != nil {
diff --git a/cmd/geth/info_test.json b/cmd/geth/info_test.json
index 1e0c271ac..63f2163a9 100644
--- a/cmd/geth/info_test.json
+++ b/cmd/geth/info_test.json
@@ -1 +1 @@
-{"code":"605280600c6000396000f3006000357c010000000000000000000000000000000000000000000000000000000090048063c6888fa114602e57005b60376004356041565b8060005260206000f35b6000600782029050604d565b91905056","info":{"abiDefinition":[{"constant":false,"inputs":[{"name":"a","type":"uint256"}],"name":"multiply","outputs":[{"name":"d","type":"uint256"}],"type":"function"}],"compilerVersion":"0.9.17","developerDoc":{"methods":{}},"language":"Solidity","languageVersion":"0","source":"contract test {\n /// @notice Will multiply `a` by 7.\n function multiply(uint a) returns(uint d) {\n return a * 7;\n }\n}\n","userDoc":{"methods":{"multiply(uint256)":{"notice":"Will multiply `a` by 7."}}}}} \ No newline at end of file
+{"code":"0x605880600c6000396000f3006000357c010000000000000000000000000000000000000000000000000000000090048063c6888fa114602e57005b603d6004803590602001506047565b8060005260206000f35b60006007820290506053565b91905056","info":{"abiDefinition":[{"constant":false,"inputs":[{"name":"a","type":"uint256"}],"name":"multiply","outputs":[{"name":"d","type":"uint256"}],"type":"function"}],"compilerVersion":"0.9.23","developerDoc":{"methods":{}},"language":"Solidity","languageVersion":"0","source":"contract test {\n /// @notice Will multiply `a` by 7.\n function multiply(uint a) returns(uint d) {\n return a * 7;\n }\n}\n","userDoc":{"methods":{"multiply(uint256)":{"notice":"Will multiply `a` by 7."}}}}} \ No newline at end of file
diff --git a/cmd/geth/js.go b/cmd/geth/js.go
index 4ddb3bd9c..f99051a1e 100644
--- a/cmd/geth/js.go
+++ b/cmd/geth/js.go
@@ -71,7 +71,7 @@ type jsre struct {
prompter
}
-func newJSRE(ethereum *eth.Ethereum, libPath, solcPath, corsDomain string, interactive bool, f xeth.Frontend) *jsre {
+func newJSRE(ethereum *eth.Ethereum, libPath, corsDomain string, interactive bool, f xeth.Frontend) *jsre {
js := &jsre{ethereum: ethereum, ps1: "> "}
// set default cors domain used by startRpc from CLI flag
js.corsDomain = corsDomain
@@ -81,7 +81,6 @@ func newJSRE(ethereum *eth.Ethereum, libPath, solcPath, corsDomain string, inter
js.xeth = xeth.New(ethereum, f)
js.wait = js.xeth.UpdateState()
// update state in separare forever blocks
- js.xeth.SetSolc(solcPath)
js.re = re.New(libPath)
js.apiBindings(f)
js.adminBindings()
diff --git a/cmd/geth/js_test.go b/cmd/geth/js_test.go
index 6368efbfc..41e1034e9 100644
--- a/cmd/geth/js_test.go
+++ b/cmd/geth/js_test.go
@@ -24,7 +24,7 @@ import (
const (
testSolcPath = ""
- solcVersion = "0.9.17"
+ solcVersion = "0.9.23"
testKey = "e6fab74a43941f82d89cb7faa408e227cdad3153c4720e540e855c19b15e6674"
testAddress = "0x8605cdbbdb6d264aa742e77020dcbc58fcdce182"
@@ -34,6 +34,7 @@ const (
)
var (
+ versionRE = regexp.MustCompile(strconv.Quote(`"compilerVersion":"` + solcVersion + `"`))
testGenesis = `{"` + testAddress[2:] + `": {"balance": "` + testBalance + `"}}`
)
@@ -75,6 +76,7 @@ func testJEthRE(t *testing.T) (string, *testjethre, *eth.Ethereum) {
AccountManager: am,
MaxPeers: 0,
Name: "test",
+ SolcPath: testSolcPath,
})
if err != nil {
t.Fatal("%v", err)
@@ -101,7 +103,7 @@ func testJEthRE(t *testing.T) (string, *testjethre, *eth.Ethereum) {
t.Errorf("Error creating DocServer: %v", err)
}
tf := &testjethre{ds: ds, stateDb: ethereum.ChainManager().State().Copy()}
- repl := newJSRE(ethereum, assetPath, testSolcPath, "", false, tf)
+ repl := newJSRE(ethereum, assetPath, "", false, tf)
tf.jsre = repl
return tmp, tf, ethereum
}
@@ -228,11 +230,11 @@ func TestSignature(t *testing.T) {
defer ethereum.Stop()
defer os.RemoveAll(tmp)
- val, err := repl.re.Run(`eth.sign({from: "` + testAddress + `", data: "` + testHash + `"})`)
+ val, err := repl.re.Run(`eth.sign("` + testAddress + `", "` + testHash + `")`)
// This is a very preliminary test, lacking actual signature verification
if err != nil {
- t.Errorf("Error runnig js: %v", err)
+ t.Errorf("Error running js: %v", err)
return
}
output := val.String()
@@ -246,7 +248,6 @@ func TestSignature(t *testing.T) {
}
func TestContract(t *testing.T) {
- t.Skip()
tmp, repl, ethereum := testJEthRE(t)
if err := ethereum.Start(); err != nil {
@@ -259,7 +260,9 @@ func TestContract(t *testing.T) {
var txc uint64
coinbase := common.HexToAddress(testAddress)
resolver.New(repl.xeth).CreateContracts(coinbase)
+ // time.Sleep(1000 * time.Millisecond)
+ // checkEvalJSON(t, repl, `eth.getBlock("pending", true).transactions.length`, `2`)
source := `contract test {\n` +
" /// @notice Will multiply `a` by 7." + `\n` +
` function multiply(uint a) returns(uint d) {\n` +
@@ -279,10 +282,9 @@ func TestContract(t *testing.T) {
// if solc is found with right version, test it, otherwise read from file
sol, err := compiler.New("")
if err != nil {
- t.Logf("solc not found: skipping compiler test")
+ t.Logf("solc not found: mocking contract compilation step")
} else if sol.Version() != solcVersion {
- err = fmt.Errorf("solc wrong version found (%v, expect %v): skipping compiler test", sol.Version(), solcVersion)
- t.Log(err)
+ t.Logf("WARNING: solc different version found (%v, test written for %v, may need to update)", sol.Version(), solcVersion)
}
if err != nil {
@@ -295,10 +297,10 @@ func TestContract(t *testing.T) {
t.Errorf("%v", err)
}
} else {
- checkEvalJSON(t, repl, `contract = eth.compile.solidity(source)`, string(contractInfo))
+ checkEvalJSON(t, repl, `contract = eth.compile.solidity(source).test`, string(contractInfo))
}
- checkEvalJSON(t, repl, `contract.code`, `"605280600c6000396000f3006000357c010000000000000000000000000000000000000000000000000000000090048063c6888fa114602e57005b60376004356041565b8060005260206000f35b6000600782029050604d565b91905056"`)
+ checkEvalJSON(t, repl, `contract.code`, `"0x605880600c6000396000f3006000357c010000000000000000000000000000000000000000000000000000000090048063c6888fa114602e57005b603d6004803590602001506047565b8060005260206000f35b60006007820290506053565b91905056"`)
checkEvalJSON(
t, repl,
@@ -308,15 +310,16 @@ func TestContract(t *testing.T) {
callSetup := `abiDef = JSON.parse('[{"constant":false,"inputs":[{"name":"a","type":"uint256"}],"name":"multiply","outputs":[{"name":"d","type":"uint256"}],"type":"function"}]');
Multiply7 = eth.contract(abiDef);
-multiply7 = new Multiply7(contractaddress);
+multiply7 = Multiply7.at(contractaddress);
`
-
+ // time.Sleep(1500 * time.Millisecond)
_, err = repl.re.Run(callSetup)
if err != nil {
- t.Errorf("unexpected error registering, got %v", err)
+ t.Errorf("unexpected error setting up contract, got %v", err)
}
- // updatespec
+ // checkEvalJSON(t, repl, `eth.getBlock("pending", true).transactions.length`, `3`)
+
// why is this sometimes failing?
// checkEvalJSON(t, repl, `multiply7.multiply.call(6)`, `42`)
expNotice := ""
@@ -324,20 +327,23 @@ multiply7 = new Multiply7(contractaddress);
t.Errorf("incorrect confirmation message: expected %v, got %v", expNotice, repl.lastConfirm)
}
- // why 0?
- checkEvalJSON(t, repl, `eth.getBlock("pending", true).transactions.length`, `0`)
-
txc, repl.xeth = repl.xeth.ApplyTestTxs(repl.stateDb, coinbase, txc)
checkEvalJSON(t, repl, `admin.contractInfo.start()`, `true`)
checkEvalJSON(t, repl, `multiply7.multiply.sendTransaction(6, { from: primary, gas: "1000000", gasPrice: "100000" })`, `undefined`)
- expNotice = `About to submit transaction (no NatSpec info found for contract: content hash not found for '0x4a6c99e127191d2ee302e42182c338344b39a37a47cdbb17ab0f26b6802eb4d1'): {"params":[{"to":"0x5dcaace5982778b409c524873b319667eba5d074","data": "0xc6888fa10000000000000000000000000000000000000000000000000000000000000006"}]}`
+ expNotice = `About to submit transaction (no NatSpec info found for contract: content hash not found for '0x87e2802265838c7f14bb69eecd2112911af6767907a702eeaa445239fb20711b'): {"params":[{"to":"0x5dcaace5982778b409c524873b319667eba5d074","data": "0xc6888fa10000000000000000000000000000000000000000000000000000000000000006"}]}`
if repl.lastConfirm != expNotice {
t.Errorf("incorrect confirmation message: expected %v, got %v", expNotice, repl.lastConfirm)
}
+ var contenthash = `"0x86d2b7cf1e72e9a7a3f8d96601f0151742a2f780f1526414304fbe413dc7f9bd"`
+ if sol != nil {
+ modContractInfo := versionRE.ReplaceAll(contractInfo, []byte(`"compilerVersion":"`+sol.Version()+`"`))
+ _ = modContractInfo
+ // contenthash = crypto.Sha3(modContractInfo)
+ }
checkEvalJSON(t, repl, `filename = "/tmp/info.json"`, `"/tmp/info.json"`)
- checkEvalJSON(t, repl, `contenthash = admin.contractInfo.register(primary, contractaddress, contract, filename)`, `"0x0d067e2dd99a4d8f0c0279738b17130dd415a89f24a23f0e7cf68c546ae3089d"`)
+ checkEvalJSON(t, repl, `contenthash = admin.contractInfo.register(primary, contractaddress, contract, filename)`, contenthash)
checkEvalJSON(t, repl, `admin.contractInfo.registerUrl(primary, contenthash, "file://"+filename)`, `true`)
if err != nil {
t.Errorf("unexpected error registering, got %v", err)
diff --git a/cmd/geth/main.go b/cmd/geth/main.go
index 2afc92f10..ba253bbeb 100644
--- a/cmd/geth/main.go
+++ b/cmd/geth/main.go
@@ -99,7 +99,15 @@ The output of this command is supposed to be machine-readable.
Usage: "import ethereum presale wallet",
},
},
- },
+ Description: `
+
+ get wallet import /path/to/my/presale.wallet
+
+will prompt for your password and imports your ether presale account.
+It can be used non-interactively with the --password option taking a
+passwordfile as argument containing the wallet password in plaintext.
+
+`},
{
Action: accountList,
Name: "account",
@@ -326,7 +334,6 @@ func console(ctx *cli.Context) {
repl := newJSRE(
ethereum,
ctx.String(utils.JSpathFlag.Name),
- ctx.String(utils.SolcPathFlag.Name),
ctx.GlobalString(utils.RPCCORSDomainFlag.Name),
true,
nil,
@@ -348,7 +355,6 @@ func execJSFiles(ctx *cli.Context) {
repl := newJSRE(
ethereum,
ctx.String(utils.JSpathFlag.Name),
- ctx.String(utils.SolcPathFlag.Name),
ctx.GlobalString(utils.RPCCORSDomainFlag.Name),
false,
nil,
diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go
index f646e4fcc..2766e7517 100644
--- a/cmd/utils/flags.go
+++ b/cmd/utils/flags.go
@@ -313,6 +313,7 @@ func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config {
Dial: true,
BootNodes: ctx.GlobalString(BootnodesFlag.Name),
GasPrice: common.String2Big(ctx.GlobalString(GasPriceFlag.Name)),
+ SolcPath: ctx.GlobalString(SolcPathFlag.Name),
}
}