aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTaylor Gerring <taylor.gerring@gmail.com>2015-03-19 08:30:09 +0800
committerTaylor Gerring <taylor.gerring@gmail.com>2015-03-19 08:30:09 +0800
commit8b20c3cc976a149c64ef0ac2cabbe49e93ba739d (patch)
tree07ef5356ae58e637d676bc28b3e8659f11bdcbcf
parentda427e8843e96bcee5f4eaedde966b0b8cf09520 (diff)
downloaddexon-8b20c3cc976a149c64ef0ac2cabbe49e93ba739d.tar
dexon-8b20c3cc976a149c64ef0ac2cabbe49e93ba739d.tar.gz
dexon-8b20c3cc976a149c64ef0ac2cabbe49e93ba739d.tar.bz2
dexon-8b20c3cc976a149c64ef0ac2cabbe49e93ba739d.tar.lz
dexon-8b20c3cc976a149c64ef0ac2cabbe49e93ba739d.tar.xz
dexon-8b20c3cc976a149c64ef0ac2cabbe49e93ba739d.tar.zst
dexon-8b20c3cc976a149c64ef0ac2cabbe49e93ba739d.zip
Validate NewTx From field is not blank
-rw-r--r--rpc/api.go5
-rw-r--r--rpc/args.go7
-rw-r--r--rpc/args_test.go28
3 files changed, 40 insertions, 0 deletions
diff --git a/rpc/api.go b/rpc/api.go
index 6154a0b28..5d4e235d9 100644
--- a/rpc/api.go
+++ b/rpc/api.go
@@ -257,6 +257,11 @@ func (p *EthereumApi) Transact(args *NewTxArgs, reply *interface{}) (err error)
p.register[ags.From] = append(p.register[args.From], args)
}
*/
+
+ if err := args.requirements(); err != nil {
+ return err
+ }
+
// TODO: align default values to have the same type, e.g. not depend on
// common.Value conversions later on
if args.Gas.Cmp(big.NewInt(0)) == 0 {
diff --git a/rpc/args.go b/rpc/args.go
index 992ea1eed..ab1c40585 100644
--- a/rpc/args.go
+++ b/rpc/args.go
@@ -145,6 +145,13 @@ func (args *NewTxArgs) UnmarshalJSON(b []byte) (err error) {
return nil
}
+func (args *NewTxArgs) requirements() error {
+ if len(args.From) == 0 {
+ return NewValidationError("From", "Is required")
+ }
+ return nil
+}
+
type GetStorageArgs struct {
Address string
BlockNumber int64
diff --git a/rpc/args_test.go b/rpc/args_test.go
index 872c535fa..0d8dc4085 100644
--- a/rpc/args_test.go
+++ b/rpc/args_test.go
@@ -219,6 +219,34 @@ func TestNewTxArgsEmpty(t *testing.T) {
}
}
+func TestNewTxArgsReqs(t *testing.T) {
+ args := new(NewTxArgs)
+ args.From = "0xb60e8dd61c5d32be8058bb8eb970870f07233155"
+
+ err := args.requirements()
+ switch err.(type) {
+ case nil:
+ break
+ default:
+ t.Errorf("Get %T", err)
+ }
+}
+
+func TestNewTxArgsReqsFromBlank(t *testing.T) {
+ args := new(NewTxArgs)
+ args.From = ""
+
+ err := args.requirements()
+ switch err.(type) {
+ case nil:
+ t.Error("Expected error but didn't get one")
+ case *ValidationError:
+ break
+ default:
+ t.Error("Wrong type of error")
+ }
+}
+
func TestGetStorageArgs(t *testing.T) {
input := `["0x407d73d8a49eeb85d32cf465507dd71d507100c1", "latest"]`
expected := new(GetStorageArgs)