Skip to content

Commit

Permalink
Add yaml test
Browse files Browse the repository at this point in the history
  • Loading branch information
Bez625 committed Nov 4, 2024
1 parent 43ddb3e commit ec86cf0
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions spec/electra/singleattestation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
package electra_test

import (
"bytes"
"encoding/json"
"github.com/attestantio/go-eth2-client/spec/electra"
"testing"

"github.com/goccy/go-yaml"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -123,3 +125,34 @@ func TestSingleAttestationJSON(t *testing.T) {
})
}
}

func TestSingleAttestationYAML(t *testing.T) {
tests := []struct {
name string
input []byte
root []byte
err string
}{
{
name: "Good",
input: []byte(`{committee_index: '1', attester_index: '200', data: {slot: 100, index: 1, beacon_block_root: '0x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f', source: {epoch: 1, root: '0x202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f'}, target: {epoch: 2, root: '0x404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f'}}, signature: '0x606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebf'}`),
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
var res electra.SingleAttestation
err := yaml.Unmarshal(test.input, &res)
if test.err != "" {
require.EqualError(t, err, test.err)
} else {
require.NoError(t, err)
rt, err := yaml.Marshal(&res)
require.NoError(t, err)
assert.Equal(t, string(rt), res.String())
rt = bytes.TrimSuffix(rt, []byte("\n"))
assert.Equal(t, string(test.input), string(rt))
}
})
}
}

0 comments on commit ec86cf0

Please sign in to comment.