github.com/status-im/status-go@v1.1.0/services/typeddata/sign_test.go (about)

     1  package typeddata
     2  
     3  import (
     4  	"encoding/json"
     5  	"math/big"
     6  	"testing"
     7  
     8  	"github.com/stretchr/testify/require"
     9  )
    10  
    11  func TestChainIDValidation(t *testing.T) {
    12  	chain := big.NewInt(10)
    13  	type testCase struct {
    14  		description string
    15  		domain      map[string]json.RawMessage
    16  	}
    17  	for _, tc := range []testCase{
    18  		{
    19  			"ChainIDMismatch",
    20  			map[string]json.RawMessage{ChainIDKey: json.RawMessage("1")},
    21  		},
    22  		{
    23  			"ChainIDNotAnInt",
    24  			map[string]json.RawMessage{ChainIDKey: json.RawMessage(`"aa"`)},
    25  		},
    26  		{
    27  			"NoChainIDKey",
    28  			nil,
    29  		},
    30  	} {
    31  		t.Run(tc.description, func(t *testing.T) {
    32  			typed := TypedData{Domain: tc.domain}
    33  			_, err := Sign(typed, nil, chain)
    34  			require.Error(t, err)
    35  		})
    36  	}
    37  }