Skip to content

Commit

Permalink
Add Unmarshal() to felt package (#2246)
Browse files Browse the repository at this point in the history
  • Loading branch information
IronGauntlets authored Nov 1, 2024
1 parent 2e69acc commit 3088325
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions core/felt/felt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
11 changes: 11 additions & 0 deletions core/felt/felt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

0 comments on commit 3088325

Please sign in to comment.