From 308832591a4303131e70b0c7baf3ebc1f81d7c56 Mon Sep 17 00:00:00 2001 From: Aneeque Date: Fri, 1 Nov 2024 12:26:19 +0000 Subject: [PATCH] Add Unmarshal() to felt package (#2246) --- core/felt/felt.go | 5 +++++ core/felt/felt_test.go | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/core/felt/felt.go b/core/felt/felt.go index 84fa3c2f3f..284e7a064b 100644 --- a/core/felt/felt.go +++ b/core/felt/felt.go @@ -144,6 +144,11 @@ func (z *Felt) Marshal() []byte { return z.val.Marshal() } +// Unmarshal forwards the call to underlying field element implementation +func (z *Felt) Unmarshal(e []byte) { + z.val.Unmarshal(e) +} + // Bytes forwards the call to underlying field element implementation func (z *Felt) Bytes() [32]byte { return z.val.Bytes() diff --git a/core/felt/felt_test.go b/core/felt/felt_test.go index 6a7c40afc9..e497dc6a1e 100644 --- a/core/felt/felt_test.go +++ b/core/felt/felt_test.go @@ -65,3 +65,14 @@ func TestShortString(t *testing.T) { assert.Equal(t, "0x1234...6789", f.ShortString()) }) } + +func TestFeltMarshalAndUnmarshal(t *testing.T) { + f := new(felt.Felt).SetBytes([]byte("somebytes")) + + fBytes := f.Marshal() + + f2 := new(felt.Felt) + f2.Unmarshal(fBytes) + + assert.True(t, f2.Equal(f)) +}