From 6f770f50d247e3792da9661f234c5ce77b5db990 Mon Sep 17 00:00:00 2001 From: Peter Kieltyka Date: Thu, 19 Dec 2024 11:19:10 -0500 Subject: [PATCH] more tests --- ethcoder/typed_data_test.go | 50 +++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/ethcoder/typed_data_test.go b/ethcoder/typed_data_test.go index 9320b88..8ed67d9 100644 --- a/ethcoder/typed_data_test.go +++ b/ethcoder/typed_data_test.go @@ -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) { @@ -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) { @@ -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) { @@ -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) {