From a4c20eeacbf9c66959c6a0b6be5f6778c0c0b2d6 Mon Sep 17 00:00:00 2001 From: Paul Berg Date: Wed, 3 Oct 2018 00:16:27 +0100 Subject: [PATCH] Added tests for 0x45 --- signer/core/api.go | 8 ++++---- signer/core/api_test.go | 41 +++++++++++++++++++++++++++++++++++++---- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/signer/core/api.go b/signer/core/api.go index a5c5900a10..68fe9b7837 100644 --- a/signer/core/api.go +++ b/signer/core/api.go @@ -111,8 +111,8 @@ type Metadata struct { } type SigFormat struct { - Mime string - ByteVersion byte + Mime string + ByteVersion byte } var ( @@ -663,14 +663,14 @@ func SignCliqueHeader(header *types.Header) (hexutil.Bytes, error) { return hash.Bytes(), nil } -// DataWithValidatorHash signs the given message which can be further recovered +// SignDataWithValidator signs the given message which can be further recovered // with the given validator. func SignDataWithValidator(data []byte) ([]byte, string) { msg := "TODO" return crypto.Keccak256([]byte(msg)), msg } -// DataStructuredHash signs the given message according to EIP712. +// SignDataStructured signs the given message according to EIP712. // // https://github.com/ethereum/EIPs/issues/712 func SignDataStructured(data []byte) ([]byte, string) { diff --git a/signer/core/api_test.go b/signer/core/api_test.go index abe67c9f4d..bf49dfaa94 100644 --- a/signer/core/api_test.go +++ b/signer/core/api_test.go @@ -245,7 +245,21 @@ func TestNewAcc(t *testing.T) { } } -func TestSignData(t *testing.T) { +func signApplicationValidator(t *testing.T) { + // TODO +} + +func signApplicationClique(t *testing.T) { + // https://etherscan.io/block/1 + //header := &types.Header{ + // "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3", + // "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + // "0x05a56e2d52c817161883f50c441c3228cfe54d9f", + //} + // TODO +} + +func signDataPlain(t *testing.T) { api, control := setup(t) //Create two accounts createAccount(control, api, t) @@ -259,7 +273,7 @@ func TestSignData(t *testing.T) { control <- "Y" control <- "wrongpassword" - h, err := api.SignData(context.Background(), "text/plain", a, []byte("EHLO world")) + h, err := api.SignData(context.Background(), DataPlain.Mime, a, []byte("EHLO world")) if h != nil { t.Errorf("Expected nil-data, got %x", h) } @@ -267,7 +281,7 @@ func TestSignData(t *testing.T) { t.Errorf("Expected ErrLocked! %v", err) } control <- "No way" - h, err = api.SignData(context.Background(), "text/plain", a, []byte("EHLO world")) + h, err = api.SignData(context.Background(), DataPlain.Mime, a, []byte("EHLO world")) if h != nil { t.Errorf("Expected nil-data, got %x", h) } @@ -276,7 +290,7 @@ func TestSignData(t *testing.T) { } control <- "Y" control <- "a_long_password" - h, err = api.SignData(context.Background(), "text/plain", a, []byte("EHLO world")) + h, err = api.SignData(context.Background(), DataPlain.Mime, a, []byte("EHLO world")) if err != nil { t.Fatal(err) } @@ -284,6 +298,25 @@ func TestSignData(t *testing.T) { t.Errorf("Expected 65 byte signature (got %d bytes)", len(h)) } } + +func signDataStructured(t *testing.T) { + // TODO +} + +func TestSignData(t *testing.T) { + // application/validator or `0x00` + signApplicationValidator(t) + + // application/clique or `0x01` + signApplicationClique(t) + + // data/plain or `0x45` + signDataPlain(t) + + // data/structured `0x46` + signDataStructured(t) +} + func mkTestTx(from common.MixedcaseAddress) SendTxArgs { to := common.NewMixedcaseAddress(common.HexToAddress("0x1337")) gas := hexutil.Uint64(21000)