Added tests for 0x45

This commit is contained in:
Paul Berg 2018-10-03 00:16:27 +01:00 committed by Martin Holst Swende
parent 46746d55f8
commit a4c20eeacb
No known key found for this signature in database
GPG key ID: 683B438C05A5DDF0
2 changed files with 41 additions and 8 deletions

View file

@ -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) {

View file

@ -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)