@agoric/cosmos 0.34.2-dev-b0b230a.0 → 0.34.2-dev-d6bb564.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/app/app.go CHANGED
@@ -102,11 +102,13 @@ import (
102
102
  tmjson "github.com/tendermint/tendermint/libs/json"
103
103
  "github.com/tendermint/tendermint/libs/log"
104
104
  tmos "github.com/tendermint/tendermint/libs/os"
105
+ tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
105
106
  dbm "github.com/tendermint/tm-db"
106
107
 
107
108
  gaiaappparams "github.com/Agoric/agoric-sdk/golang/cosmos/app/params"
108
109
 
109
110
  appante "github.com/Agoric/agoric-sdk/golang/cosmos/ante"
111
+ agorictypes "github.com/Agoric/agoric-sdk/golang/cosmos/types"
110
112
  "github.com/Agoric/agoric-sdk/golang/cosmos/vm"
111
113
  "github.com/Agoric/agoric-sdk/golang/cosmos/x/lien"
112
114
  "github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset"
@@ -472,10 +474,19 @@ func NewAgoricApp(
472
474
  return sendToController(true, string(bz))
473
475
  },
474
476
  )
477
+
478
+ getSwingStoreExportDataShadowCopyReader := func(height int64) agorictypes.KVEntryReader {
479
+ ctx := app.NewUncachedContext(false, tmproto.Header{Height: height})
480
+ exportDataEntries := app.SwingSetKeeper.ExportSwingStore(ctx)
481
+ if len(exportDataEntries) == 0 {
482
+ return nil
483
+ }
484
+ return agorictypes.NewVstorageDataEntriesReader(exportDataEntries)
485
+ }
475
486
  app.SwingSetSnapshotter = *swingsetkeeper.NewExtensionSnapshotter(
476
487
  bApp,
477
488
  &app.SwingStoreExportsHandler,
478
- app.SwingSetKeeper.ExportSwingStore,
489
+ getSwingStoreExportDataShadowCopyReader,
479
490
  )
480
491
 
481
492
  app.VibcKeeper = vibc.NewKeeper(
package/git-revision.txt CHANGED
@@ -1 +1 @@
1
- b0b230a
1
+ d6bb564
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agoric/cosmos",
3
- "version": "0.34.2-dev-b0b230a.0+b0b230a",
3
+ "version": "0.34.2-dev-d6bb564.0+d6bb564",
4
4
  "description": "Connect JS to the Cosmos blockchain SDK",
5
5
  "parsers": {
6
6
  "js": "mjs"
@@ -35,5 +35,5 @@
35
35
  "publishConfig": {
36
36
  "access": "public"
37
37
  },
38
- "gitHead": "b0b230ad6b5e729e63f27a3549bc1f9e51bbb8b8"
38
+ "gitHead": "d6bb5643dc6d4973217c86597cf00f9c2ab71e73"
39
39
  }
@@ -0,0 +1,114 @@
1
+ package types
2
+
3
+ import (
4
+ "encoding/json"
5
+ "fmt"
6
+ )
7
+
8
+ var _ json.Marshaler = &KVEntry{}
9
+ var _ json.Unmarshaler = &KVEntry{}
10
+
11
+ // KVEntry represents a string key / string value pair, where the value may be
12
+ // missing, which is different from an empty value.
13
+ // The semantics of a missing value are purpose-dependent rather than specified
14
+ // here, but frequently correspond with deletion/incompleteness/etc.
15
+ // A KVEntry with an empty key is considered invalid.
16
+ type KVEntry struct {
17
+ key string
18
+ value *string
19
+ }
20
+
21
+ // NewKVEntry creates a KVEntry with the provided key and value
22
+ func NewKVEntry(key string, value string) KVEntry {
23
+ return KVEntry{key, &value}
24
+ }
25
+
26
+ // NewKVEntryWithNoValue creates a KVEntry with the provided key and no value
27
+ func NewKVEntryWithNoValue(key string) KVEntry {
28
+ return KVEntry{key, nil}
29
+ }
30
+
31
+ // UnmarshalJSON updates a KVEntry from JSON text corresponding with a
32
+ // [key: string, value?: string | null] shape, or returns an error indicating
33
+ // invalid input.
34
+ // The key must be a non-empty string, and the value (if present) must be a
35
+ // string or null.
36
+ //
37
+ // Implements json.Unmarshaler
38
+ // Note: unlike other methods, this accepts a pointer to satisfy
39
+ // the Unmarshaler semantics.
40
+ func (entry *KVEntry) UnmarshalJSON(input []byte) (err error) {
41
+ var generic []*string
42
+ err = json.Unmarshal(input, &generic)
43
+ if err != nil {
44
+ return err
45
+ }
46
+
47
+ length := len(generic)
48
+
49
+ if generic == nil {
50
+ return fmt.Errorf("KVEntry cannot be null")
51
+ }
52
+ if length != 1 && length != 2 {
53
+ return fmt.Errorf("KVEntry must be an array of length 1 or 2 (not %d)", length)
54
+ }
55
+
56
+ key := generic[0]
57
+ if key == nil || *key == "" {
58
+ return fmt.Errorf("KVEntry key must be a non-empty string: %v", key)
59
+ }
60
+
61
+ var value *string
62
+ if length == 2 {
63
+ value = generic[1]
64
+ }
65
+
66
+ entry.key = *key
67
+ entry.value = value
68
+
69
+ return nil
70
+ }
71
+
72
+ // MarshalJSON encodes the KVEntry into a JSON array of [key: string, value?: string],
73
+ // with the value missing (array length of 1) if the entry has no value.
74
+ //
75
+ // Implements json.Marshaler
76
+ func (entry KVEntry) MarshalJSON() ([]byte, error) {
77
+ if !entry.IsValidKey() {
78
+ return nil, fmt.Errorf("cannot marshal invalid KVEntry")
79
+ }
80
+ if entry.value != nil {
81
+ return json.Marshal([2]string{entry.key, *entry.value})
82
+ } else {
83
+ return json.Marshal([1]string{entry.key})
84
+ }
85
+ }
86
+
87
+ // IsValidKey returns whether the KVEntry has a non-empty key.
88
+ func (entry KVEntry) IsValidKey() bool {
89
+ return entry.key != ""
90
+ }
91
+
92
+ // Key returns the string key.
93
+ func (entry KVEntry) Key() string {
94
+ return entry.key
95
+ }
96
+
97
+ // HasValue returns whether the KVEntry has a value or not.
98
+ func (entry KVEntry) HasValue() bool {
99
+ return entry.value != nil
100
+ }
101
+
102
+ // Value returns a pointer to the string value or nil if the entry has no value.
103
+ func (entry KVEntry) Value() *string {
104
+ return entry.value
105
+ }
106
+
107
+ // StringValue returns the string value, or the empty string if the entry has no value.
108
+ // Note that the result therefore does not differentiate an empty string value from no value.
109
+ func (entry KVEntry) StringValue() string {
110
+ if entry.value != nil {
111
+ return *entry.value
112
+ }
113
+ return ""
114
+ }
@@ -0,0 +1,220 @@
1
+ package types
2
+
3
+ import (
4
+ "encoding/json"
5
+ "fmt"
6
+ "io"
7
+
8
+ vstoragetypes "github.com/Agoric/agoric-sdk/golang/cosmos/x/vstorage/types"
9
+ sdk "github.com/cosmos/cosmos-sdk/types"
10
+ )
11
+
12
+ // These helpers facilitate handling KVEntry streams, in particular for the
13
+ // swing-store "export data" use case. The goal is to avoid passing around
14
+ // large slices of key/value pairs.
15
+ //
16
+ // Handling of these streams is primarily accomplished through a KVEntryReader
17
+ // interface, with multiple implementations for different backing sources, as
18
+ // well as a helper function to consume a reader and write the entries into a
19
+ // byte Writer as line terminated json encoded KVEntry.
20
+
21
+ // We attempt to pass sdk.Iterator around as much as possible to abstract a
22
+ // stream of Key/Value pairs without requiring the whole slice to be held in
23
+ // memory if possible. Cosmos SDK defines iterators as yielding Key/Value
24
+ // pairs, both as byte slices.
25
+ //
26
+ // More precisely, we define here the following:
27
+ // - A KVEntryReader interface allowing to Read the KVEntry one by one from an
28
+ // underlying source.
29
+ // - Multiple implementations of the KVEntryReader interface:
30
+ // - NewKVIteratorReader constructs a reader which consumes an sdk.Iterator.
31
+ // Keys and values are converted from byte slices to strings, and nil values
32
+ // are preserved as KVEntry instances with no value.
33
+ // - A generic reader which uses a slice of key/value data, and a conversion
34
+ // function from that data type to a KVEntry. The reader does bounds
35
+ // checking and keeps track of the current position. The following data
36
+ // types are available:
37
+ // - NewVstorageDataEntriesReader constructs a reader from a slice of
38
+ // vstorage DataEntry values.
39
+ // - NewJsonRawMessageKVEntriesReader constructs a reader from a slice of
40
+ // [key: string, value?: string | null] JSON array values.
41
+ // - NewJsonlKVEntryDecoderReader constructs a reader from an io.ReadCloser
42
+ // (like a file) containing JSON Lines in which each item is a
43
+ // [key: string, value?: string | null] array.
44
+ // - EncodeKVEntryReaderToJsonl consumes a KVEntryReader and writes its entries
45
+ // into an io.Writer as a sequence of single-line JSON texts. The encoding of
46
+ // each line is [key, value] if the KVEntry has a value, and [key] otherwise.
47
+ // This format terminates each line, but is still compatible with JSON Lines
48
+ // (which is line feed *separated*) for Go and JS decoders.
49
+
50
+ // KVEntryReader is an abstraction for iteratively reading KVEntry data.
51
+ type KVEntryReader interface {
52
+ // Read returns the next KVEntry, or an error.
53
+ // An `io.EOF` error indicates that the previous Read() returned the final KVEntry.
54
+ Read() (KVEntry, error)
55
+ // Close frees the underlying resource (such as a slice or file descriptor).
56
+ Close() error
57
+ }
58
+
59
+ var _ KVEntryReader = &kvIteratorReader{}
60
+
61
+ // kvIteratorReader is a KVEntryReader backed by an sdk.Iterator
62
+ type kvIteratorReader struct {
63
+ iter sdk.Iterator
64
+ }
65
+
66
+ // NewKVIteratorReader returns a KVEntryReader backed by an sdk.Iterator.
67
+ func NewKVIteratorReader(iter sdk.Iterator) KVEntryReader {
68
+ return &kvIteratorReader{
69
+ iter: iter,
70
+ }
71
+ }
72
+
73
+ // Read yields the next KVEntry from the source iterator
74
+ // Implements KVEntryReader
75
+ func (ir kvIteratorReader) Read() (next KVEntry, err error) {
76
+ if !ir.iter.Valid() {
77
+ // There is unfortunately no way to differentiate completion from iteration
78
+ // errors with the implementation of Iterators by cosmos-sdk since the
79
+ // iter.Error() returns an error in both cases
80
+ return KVEntry{}, io.EOF
81
+ }
82
+
83
+ key := ir.iter.Key()
84
+ if len(key) == 0 {
85
+ return KVEntry{}, fmt.Errorf("nil or empty key yielded by iterator")
86
+ }
87
+
88
+ value := ir.iter.Value()
89
+ ir.iter.Next()
90
+ if value == nil {
91
+ return NewKVEntryWithNoValue(string(key)), nil
92
+ } else {
93
+ return NewKVEntry(string(key), string(value)), nil
94
+ }
95
+ }
96
+
97
+ func (ir kvIteratorReader) Close() error {
98
+ return ir.iter.Close()
99
+ }
100
+
101
+ var _ KVEntryReader = &kvEntriesReader[any]{}
102
+
103
+ // kvEntriesReader is the KVEntryReader using an underlying slice of generic
104
+ // kv entries. It reads from the slice sequentially using a type specific
105
+ // toKVEntry func, performing bounds checks, and tracking the position.
106
+ type kvEntriesReader[T any] struct {
107
+ entries []T
108
+ toKVEntry func(T) (KVEntry, error)
109
+ nextIndex int
110
+ }
111
+
112
+ // Read yields the next KVEntry from the source
113
+ // Implements KVEntryReader
114
+ func (reader *kvEntriesReader[T]) Read() (next KVEntry, err error) {
115
+ if reader.entries == nil {
116
+ return KVEntry{}, fmt.Errorf("reader closed")
117
+ }
118
+
119
+ length := len(reader.entries)
120
+
121
+ if reader.nextIndex < length {
122
+ entry, err := reader.toKVEntry(reader.entries[reader.nextIndex])
123
+ reader.nextIndex += 1
124
+ if err != nil {
125
+ return KVEntry{}, err
126
+ }
127
+ if !entry.IsValidKey() {
128
+ return KVEntry{}, fmt.Errorf("source yielded a KVEntry with an invalid key")
129
+ }
130
+ return entry, err
131
+ } else if reader.nextIndex == length {
132
+ reader.nextIndex += 1
133
+ return KVEntry{}, io.EOF
134
+ } else {
135
+ return KVEntry{}, fmt.Errorf("index %d is out of source bounds (length %d)", reader.nextIndex, length)
136
+ }
137
+ }
138
+
139
+ // Close releases the source slice
140
+ // Implements KVEntryReader
141
+ func (reader *kvEntriesReader[any]) Close() error {
142
+ reader.entries = nil
143
+ return nil
144
+ }
145
+
146
+ // NewVstorageDataEntriesReader creates a KVEntryReader backed by a
147
+ // vstorage DataEntry slice
148
+ func NewVstorageDataEntriesReader(vstorageDataEntries []*vstoragetypes.DataEntry) KVEntryReader {
149
+ return &kvEntriesReader[*vstoragetypes.DataEntry]{
150
+ entries: vstorageDataEntries,
151
+ toKVEntry: func(sourceEntry *vstoragetypes.DataEntry) (KVEntry, error) {
152
+ return NewKVEntry(sourceEntry.Path, sourceEntry.Value), nil
153
+ },
154
+ }
155
+ }
156
+
157
+ // NewJsonRawMessageKVEntriesReader creates a KVEntryReader backed by
158
+ // a json.RawMessage slice
159
+ func NewJsonRawMessageKVEntriesReader(jsonEntries []json.RawMessage) KVEntryReader {
160
+ return &kvEntriesReader[json.RawMessage]{
161
+ entries: jsonEntries,
162
+ toKVEntry: func(sourceEntry json.RawMessage) (entry KVEntry, err error) {
163
+ err = json.Unmarshal(sourceEntry, &entry)
164
+ return entry, err
165
+ },
166
+ }
167
+ }
168
+
169
+ var _ KVEntryReader = &jsonlKVEntryDecoderReader{}
170
+
171
+ // jsonlKVEntryDecoderReader is the KVEntryReader decoding
172
+ // jsonl-like encoded key/value pairs.
173
+ type jsonlKVEntryDecoderReader struct {
174
+ closer io.Closer
175
+ decoder *json.Decoder
176
+ }
177
+
178
+ // Read yields the next decoded KVEntry
179
+ // Implements KVEntryReader
180
+ func (reader jsonlKVEntryDecoderReader) Read() (next KVEntry, err error) {
181
+ err = reader.decoder.Decode(&next)
182
+ return next, err
183
+ }
184
+
185
+ // Close release the underlying resource backing the decoder
186
+ // Implements KVEntryReader
187
+ func (reader jsonlKVEntryDecoderReader) Close() error {
188
+ return reader.closer.Close()
189
+ }
190
+
191
+ // NewJsonlKVEntryDecoderReader creates a KVEntryReader over a byte
192
+ // stream reader that decodes each line as a json encoded KVEntry. The entries
193
+ // are yielded in order they're present in the stream.
194
+ func NewJsonlKVEntryDecoderReader(byteReader io.ReadCloser) KVEntryReader {
195
+ return &jsonlKVEntryDecoderReader{
196
+ closer: byteReader,
197
+ decoder: json.NewDecoder(byteReader),
198
+ }
199
+ }
200
+
201
+ // EncodeKVEntryReaderToJsonl consumes a KVEntryReader and JSON encodes each
202
+ // KVEntry, terminating by new lines.
203
+ // It will not Close the Reader when done
204
+ func EncodeKVEntryReaderToJsonl(reader KVEntryReader, bytesWriter io.Writer) (err error) {
205
+ encoder := json.NewEncoder(bytesWriter)
206
+ encoder.SetEscapeHTML(false)
207
+ for {
208
+ entry, err := reader.Read()
209
+ if err == io.EOF {
210
+ return nil
211
+ } else if err != nil {
212
+ return err
213
+ }
214
+
215
+ err = encoder.Encode(entry)
216
+ if err != nil {
217
+ return err
218
+ }
219
+ }
220
+ }
@@ -0,0 +1,237 @@
1
+ package types
2
+
3
+ import (
4
+ "bytes"
5
+ "errors"
6
+ "io"
7
+ "strings"
8
+ "testing"
9
+
10
+ sdk "github.com/cosmos/cosmos-sdk/types"
11
+ )
12
+
13
+ func toKVEntryIdentity(entry KVEntry) (KVEntry, error) {
14
+ return entry, nil
15
+ }
16
+
17
+ func toKVEntryError(err error) (KVEntry, error) {
18
+ return KVEntry{}, err
19
+ }
20
+
21
+ func checkSameKVEntry(t *testing.T, got KVEntry, expected KVEntry) {
22
+ if got.key != expected.key {
23
+ t.Errorf("got key %s, expected key %s", got.key, expected.key)
24
+ }
25
+ if got.value == nil && expected.value != nil {
26
+ t.Errorf("got nil value, expected string %s", *expected.value)
27
+ } else if got.value != nil && expected.value == nil {
28
+ t.Errorf("got string value %s, expected nil", *got.value)
29
+ } else if got.value != nil && expected.value != nil {
30
+ if *got.value != *expected.value {
31
+ t.Errorf("got string value %s, expected %s", *got.value, *expected.value)
32
+ }
33
+ }
34
+ }
35
+
36
+ func TestKVEntriesReaderNormal(t *testing.T) {
37
+ source := []KVEntry{NewKVEntry("foo", "bar"), NewKVEntryWithNoValue("baz")}
38
+ reader := kvEntriesReader[KVEntry]{entries: source, toKVEntry: toKVEntryIdentity}
39
+
40
+ got1, err := reader.Read()
41
+ if err != nil {
42
+ t.Errorf("unexpected error: %v", err)
43
+ }
44
+ checkSameKVEntry(t, got1, source[0])
45
+
46
+ got2, err := reader.Read()
47
+ if err != nil {
48
+ t.Errorf("unexpected error: %v", err)
49
+ }
50
+ checkSameKVEntry(t, got2, source[1])
51
+
52
+ _, err = reader.Read()
53
+ if err != io.EOF {
54
+ t.Errorf("expected error io.EOF, got %v", err)
55
+ }
56
+
57
+ _, err = reader.Read()
58
+ if err == nil || !strings.Contains(err.Error(), "bounds") {
59
+ t.Errorf("expected out of bounds error, got %v", err)
60
+ }
61
+
62
+ err = reader.Close()
63
+ if err != nil {
64
+ t.Errorf("unexpected error: %v", err)
65
+ }
66
+
67
+ _, err = reader.Read()
68
+ if err == nil || !strings.Contains(err.Error(), "reader closed") {
69
+ t.Errorf("expected reader closed error, got %v", err)
70
+ }
71
+ }
72
+
73
+ func TestKVEntriesReaderErrors(t *testing.T) {
74
+ source := []error{errors.New("foo"), errors.New("bar")}
75
+ reader := kvEntriesReader[error]{entries: source, toKVEntry: toKVEntryError}
76
+
77
+ _, err := reader.Read()
78
+ if err != source[0] {
79
+ t.Errorf("got error %v, expected error %v", err, source[0])
80
+ }
81
+
82
+ // Nothing in the reader prevents reading after previous errors
83
+ _, err = reader.Read()
84
+ if err != source[1] {
85
+ t.Errorf("got error %v, expected error %v", err, source[1])
86
+ }
87
+
88
+ _, err = reader.Read()
89
+ if err != io.EOF {
90
+ t.Errorf("expected error io.EOF, got %v", err)
91
+ }
92
+ }
93
+
94
+ type kvEntryReaderIterator struct {
95
+ reader KVEntryReader
96
+ current KVEntry
97
+ err error
98
+ }
99
+
100
+ // newKVEntryReaderIterator creates an iterator over a KVEntryReader.
101
+ // KVEntry keys and values are reported as []byte from the reader in order.
102
+ func newKVEntryReaderIterator(reader KVEntryReader) sdk.Iterator {
103
+ iter := &kvEntryReaderIterator{
104
+ reader: reader,
105
+ }
106
+ iter.Next()
107
+ return iter
108
+ }
109
+
110
+ // Domain implements sdk.Iterator
111
+ func (iter *kvEntryReaderIterator) Domain() (start []byte, end []byte) {
112
+ return nil, nil
113
+ }
114
+
115
+ // Valid returns whether the current iterator is valid. Once invalid, the
116
+ // Iterator remains invalid forever.
117
+ func (iter *kvEntryReaderIterator) Valid() bool {
118
+ if iter.err == io.EOF {
119
+ return false
120
+ } else if iter.err != nil {
121
+ panic(iter.err)
122
+ }
123
+ return true
124
+ }
125
+
126
+ // checkValid implements the validity invariants of sdk.Iterator methods.
127
+ func (iter *kvEntryReaderIterator) checkValid() {
128
+ if !iter.Valid() {
129
+ panic("invalid iterator")
130
+ }
131
+ }
132
+
133
+ // Next moves the iterator to the next entry from the reader.
134
+ // If Valid() returns false, this method will panic.
135
+ func (iter *kvEntryReaderIterator) Next() {
136
+ iter.checkValid()
137
+
138
+ iter.current, iter.err = iter.reader.Read()
139
+ }
140
+
141
+ // Key returns the key at the current position. Panics if the iterator is invalid.
142
+ // CONTRACT: key readonly []byte
143
+ func (iter *kvEntryReaderIterator) Key() (key []byte) {
144
+ iter.checkValid()
145
+
146
+ return []byte(iter.current.Key())
147
+ }
148
+
149
+ // Value returns the value at the current position. Panics if the iterator is invalid.
150
+ // CONTRACT: value readonly []byte
151
+ func (iter *kvEntryReaderIterator) Value() (value []byte) {
152
+ iter.checkValid()
153
+
154
+ if !iter.current.HasValue() {
155
+ return nil
156
+ } else {
157
+ return []byte(iter.current.StringValue())
158
+ }
159
+ }
160
+
161
+ // Error returns the last error encountered by the iterator, if any.
162
+ func (iter *kvEntryReaderIterator) Error() error {
163
+ err := iter.err
164
+ if err == io.EOF {
165
+ return nil
166
+ }
167
+
168
+ return err
169
+ }
170
+
171
+ // Close closes the iterator, releasing any allocated resources.
172
+ func (iter *kvEntryReaderIterator) Close() error {
173
+ return iter.reader.Close()
174
+ }
175
+
176
+ func TestKVIteratorReader(t *testing.T) {
177
+ source := []KVEntry{NewKVEntry("foo", "bar"), NewKVEntryWithNoValue("baz")}
178
+ iterator := newKVEntryReaderIterator(&kvEntriesReader[KVEntry]{entries: source, toKVEntry: toKVEntryIdentity})
179
+ reader := NewKVIteratorReader(iterator)
180
+
181
+ got1, err := reader.Read()
182
+ if err != nil {
183
+ t.Errorf("unexpected error: %v", err)
184
+ }
185
+ checkSameKVEntry(t, got1, source[0])
186
+
187
+ got2, err := reader.Read()
188
+ if err != nil {
189
+ t.Errorf("unexpected error: %v", err)
190
+ }
191
+ checkSameKVEntry(t, got2, source[1])
192
+
193
+ _, err = reader.Read()
194
+ if err != io.EOF {
195
+ t.Errorf("expected error io.EOF, got %v", err)
196
+ }
197
+
198
+ err = reader.Close()
199
+ if err != nil {
200
+ t.Errorf("unexpected error: %v", err)
201
+ }
202
+ }
203
+
204
+ func TestJsonlEncodeAndReadBack(t *testing.T) {
205
+ source := []KVEntry{NewKVEntry("foo", "bar"), NewKVEntryWithNoValue("baz")}
206
+ sourceReader := &kvEntriesReader[KVEntry]{entries: source, toKVEntry: toKVEntryIdentity}
207
+
208
+ var encodedKVEntries bytes.Buffer
209
+ err := EncodeKVEntryReaderToJsonl(sourceReader, &encodedKVEntries)
210
+ if err != nil {
211
+ t.Errorf("unexpected encode error %v", err)
212
+ }
213
+
214
+ jsonlReader := NewJsonlKVEntryDecoderReader(io.NopCloser(&encodedKVEntries))
215
+
216
+ got1, err := jsonlReader.Read()
217
+ if err != nil {
218
+ t.Errorf("unexpected error: %v", err)
219
+ }
220
+ checkSameKVEntry(t, got1, source[0])
221
+
222
+ got2, err := jsonlReader.Read()
223
+ if err != nil {
224
+ t.Errorf("unexpected error: %v", err)
225
+ }
226
+ checkSameKVEntry(t, got2, source[1])
227
+
228
+ _, err = jsonlReader.Read()
229
+ if err != io.EOF {
230
+ t.Errorf("expected error io.EOF, got %v", err)
231
+ }
232
+
233
+ err = jsonlReader.Close()
234
+ if err != nil {
235
+ t.Errorf("unexpected error: %v", err)
236
+ }
237
+ }