diff --git a/codec/dagjson/roundtripBytes_test.go b/codec/dagjson/roundtripBytes_test.go index cd0f28ffa381b9ef012f3478cefc921cd58c7709..df4e9f636b01b2bc7a5e3f3cc2bd1374bd95120d 100644 --- a/codec/dagjson/roundtripBytes_test.go +++ b/codec/dagjson/roundtripBytes_test.go @@ -40,3 +40,35 @@ func TestRoundtripBytes(t *testing.T) { Wish(t, nb.Build(), ShouldEqual, byteNode) }) } + +var encapsulatedNode = fluent.MustBuildMap(basicnode.Prototype__Map{}, 1, func(na fluent.MapAssembler) { + na.AssembleEntry("/").CreateMap(1, func(sa fluent.MapAssembler) { + sa.AssembleEntry("bytes").AssignBytes([]byte("deadbeef")) + }) +}) +var encapsulatedSerial = `{ + "/": { + "bytes": { + "/": { + "bytes": "ZGVhZGJlZWY=" + } + } + } +} +` + +func TestEncapsulatedBytes(t *testing.T) { + t.Run("encoding", func(t *testing.T) { + var buf bytes.Buffer + err := Encode(encapsulatedNode, &buf) + Require(t, err, ShouldEqual, nil) + Wish(t, buf.String(), ShouldEqual, encapsulatedSerial) + }) + t.Run("decoding", func(t *testing.T) { + buf := strings.NewReader(encapsulatedSerial) + nb := basicnode.Prototype__Map{}.NewBuilder() + err := Decode(nb, buf) + Require(t, err, ShouldEqual, nil) + Wish(t, nb.Build(), ShouldEqual, encapsulatedNode) + }) +}