github.com/koko1123/flow-go-1@v0.29.6/utils/unittest/equals.go (about) 1 package unittest 2 3 import ( 4 "encoding/json" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 "github.com/stretchr/testify/require" 9 10 "github.com/koko1123/flow-go-1/model/flow" 11 "github.com/koko1123/flow-go-1/state/protocol" 12 "github.com/koko1123/flow-go-1/state/protocol/inmem" 13 ) 14 15 func toHex(ids []flow.Identifier) []string { 16 hex := make([]string, 0, len(ids)) 17 for _, id := range ids { 18 hex = append(hex, id.String()) 19 } 20 return hex 21 } 22 23 func IDEqual(t *testing.T, id1, id2 flow.Identifier) { 24 require.Equal(t, id1.String(), id2.String()) 25 } 26 27 func IDsEqual(t *testing.T, id1, id2 []flow.Identifier) { 28 require.Equal(t, toHex(id1), toHex(id2)) 29 } 30 31 func AssertSnapshotsEqual(t *testing.T, snap1, snap2 protocol.Snapshot) { 32 inmem1, err := inmem.FromSnapshot(snap1) 33 require.NoError(t, err) 34 inmem2, err := inmem.FromSnapshot(snap2) 35 require.NoError(t, err) 36 37 encoded1, err := json.Marshal(inmem1.Encodable()) 38 require.NoError(t, err) 39 encoded2, err := json.Marshal(inmem2.Encodable()) 40 require.NoError(t, err) 41 42 assert.Equal(t, encoded1, encoded2) 43 }