Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pkieltyka committed Dec 19, 2024
1 parent 6078e48 commit 6f770f5
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions ethcoder/typed_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,17 @@ func TestTypedDataFromJSON(t *testing.T) {
valid, err := ethwallet.ValidateEthereumSignature(wallet.Address().Hex(), typedDataEncodedOut, ethSigedTypedDataHex)
require.NoError(t, err)
require.True(t, valid)

// test MarshalJSON by encoding, then comparing digests
jsonOut, err := json.Marshal(typedData)
require.NoError(t, err)

typedData2, err := ethcoder.TypedDataFromJSON(string(jsonOut))
require.NoError(t, err)

digest2, err := typedData2.EncodeDigest()
require.NoError(t, err)
require.Equal(t, digest, digest2)
}

func TestTypedDataFromJSONPart2(t *testing.T) {
Expand Down Expand Up @@ -294,6 +305,17 @@ func TestTypedDataFromJSONPart2(t *testing.T) {
valid, err := ethwallet.ValidateEthereumSignature(wallet.Address().Hex(), typedDataEncodedOut, ethSigedTypedDataHex)
require.NoError(t, err)
require.True(t, valid)

// test MarshalJSON by encoding, then comparing digests
jsonOut, err := json.Marshal(typedData)
require.NoError(t, err)

typedData2, err := ethcoder.TypedDataFromJSON(string(jsonOut))
require.NoError(t, err)

digest2, err := typedData2.EncodeDigest()
require.NoError(t, err)
require.Equal(t, digest, digest2)
}

func TestTypedDataFromJSONPart3(t *testing.T) {
Expand Down Expand Up @@ -357,6 +379,20 @@ func TestTypedDataFromJSONPart3(t *testing.T) {
valid, err := ethwallet.ValidateEthereumSignature(wallet.Address().Hex(), typedDataEncodedOut, ethSigedTypedDataHex)
require.NoError(t, err)
require.True(t, valid)

// test MarshalJSON by encoding, then comparing digests
jsonOut, err := json.Marshal(typedData)
require.NoError(t, err)

typedData2, err := ethcoder.TypedDataFromJSON(string(jsonOut))
require.NoError(t, err)

digest, err := typedData.EncodeDigest()
require.NoError(t, err)

digest2, err := typedData2.EncodeDigest()
require.NoError(t, err)
require.Equal(t, digest, digest2)
}

func TestTypedDataFromJSONPart4(t *testing.T) {
Expand Down Expand Up @@ -416,6 +452,20 @@ func TestTypedDataFromJSONPart4(t *testing.T) {
valid, err := ethwallet.ValidateEthereumSignature(wallet.Address().Hex(), typedDataEncodedOut, ethSigedTypedDataHex)
require.NoError(t, err)
require.True(t, valid)

// test MarshalJSON by encoding, then comparing digests
jsonOut, err := json.Marshal(typedData)
require.NoError(t, err)

typedData2, err := ethcoder.TypedDataFromJSON(string(jsonOut))
require.NoError(t, err)

digest, err := typedData.EncodeDigest()
require.NoError(t, err)

digest2, err := typedData2.EncodeDigest()
require.NoError(t, err)
require.Equal(t, digest, digest2)
}

func TestTypedDataFromJSONPart5(t *testing.T) {
Expand Down

0 comments on commit 6f770f5

Please sign in to comment.