Skip to content

Commit

Permalink
MarshalJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
pkieltyka committed Dec 19, 2024
1 parent 27dbc71 commit 21b2f58
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions ethcoder/typed_data_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ethcoder_test

import (
"encoding/json"
"math/big"
"testing"

Expand Down Expand Up @@ -472,6 +473,20 @@ func TestTypedDataFromJSONPart5(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 TestTypedDataFromJSONPart6(t *testing.T) {
Expand Down Expand Up @@ -651,4 +666,18 @@ func TestTypedDataFromJSONPart6(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)
}

0 comments on commit 21b2f58

Please sign in to comment.