Skip to content

Commit

Permalink
chore(orm): add missing error checks (#15141)
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-rushakoff committed Feb 23, 2023
1 parent 79b74ff commit 2b126af
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions orm/model/ormdb/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ func runSimpleBankTests(t *testing.T, k Keeper, ctx context.Context) {
// send coins
acct2 := "sally"
err = k.Send(ctx, acct1, acct2, denom, 30)
assert.NilError(t, err)
bal, err = k.Balance(ctx, acct1, denom)
assert.NilError(t, err)
assert.Equal(t, uint64(70), bal)
Expand All @@ -287,6 +288,7 @@ func runSimpleBankTests(t *testing.T, k Keeper, ctx context.Context) {

// burn coins
err = k.Burn(ctx, acct2, denom, 3)
assert.NilError(t, err)
bal, err = k.Balance(ctx, acct2, denom)
assert.NilError(t, err)
assert.Equal(t, uint64(27), bal)
Expand Down
3 changes: 3 additions & 0 deletions orm/model/ormtable/table_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ func (t tableImpl) doSave(ctx context.Context, writer *batchIndexCommitmentWrite

// store object
bz, err := proto.MarshalOptions{Deterministic: true}.Marshal(message)
if err != nil {
return err
}
err = writer.CommitmentStore().Set(pk, bz)
if err != nil {
return err
Expand Down
11 changes: 11 additions & 0 deletions orm/model/ormtable/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func TestPaginationLimitCountTotal(t *testing.T) {
table, err := ormtable.Build(ormtable.Options{
MessageType: (&testpb.ExampleTable{}).ProtoReflect().Type(),
})
assert.NilError(t, err)
backend := testkv.NewSplitMemBackend()
ctx := ormtable.WrapContextDefault(backend)
store, err := testpb.NewExampleTableTable(table)
Expand Down Expand Up @@ -104,6 +105,7 @@ func TestTimestampIndex(t *testing.T) {
table, err := ormtable.Build(ormtable.Options{
MessageType: (&testpb.ExampleTimestamp{}).ProtoReflect().Type(),
})
assert.NilError(t, err)
backend := testkv.NewDebugBackend(testkv.NewSplitMemBackend(), &testkv.EntryCodecDebugger{
EntryCodec: table,
Print: func(s string) {
Expand Down Expand Up @@ -157,6 +159,7 @@ func TestTimestampIndex(t *testing.T) {
assert.NilError(t, err)

res, err := store.Get(ctx, id)
assert.NilError(t, err)
assert.Assert(t, res.Ts == nil)

it, err = store.List(ctx, testpb.ExampleTimestampTsIndexKey{})
Expand Down Expand Up @@ -200,6 +203,7 @@ func checkEncodeDecodeEntries(t *testing.T, table ormtable.Table, store kv.Reado
entry, err := table.DecodeEntry(key, value)
assert.NilError(t, err)
k, v, err := table.EncodeEntry(entry)
assert.NilError(t, err)
assert.Assert(t, bytes.Equal(key, k), "%x %x %s", key, k, entry)
assert.Assert(t, bytes.Equal(value, v), "%x %x %s", value, v, entry)
it.Next()
Expand All @@ -209,6 +213,7 @@ func checkEncodeDecodeEntries(t *testing.T, table ormtable.Table, store kv.Reado
func runTestScenario(t *testing.T, table ormtable.Table, backend ormtable.Backend) {
ctx := ormtable.WrapContextDefault(backend)
store, err := testpb.NewExampleTableTable(table)
assert.NilError(t, err)

// let's create 10 data items we'll use later and give them indexes
data := []*testpb.ExampleTable{
Expand Down Expand Up @@ -240,13 +245,15 @@ func runTestScenario(t *testing.T, table ormtable.Table, backend ormtable.Backen

// insert one record
err = store.Insert(ctx, data[0])
assert.NilError(t, err)
// trivial prefix query has one record
it, err := store.List(ctx, testpb.ExampleTablePrimaryKey{})
assert.NilError(t, err)
assertIteratorItems(it, 0)

// insert one record
err = store.Insert(ctx, data[1])
assert.NilError(t, err)
// trivial prefix query has two records
it, err = store.List(ctx, testpb.ExampleTablePrimaryKey{})
assert.NilError(t, err)
Expand Down Expand Up @@ -296,19 +303,22 @@ func runTestScenario(t *testing.T, table ormtable.Table, backend ormtable.Backen
testpb.ExampleTableStrU32IndexKey{}.WithStr("abd"),
ormlist.Reverse(),
)
assert.NilError(t, err)
assertIteratorItems(it, 9, 3, 1, 8, 7, 2, 0)

// another prefix query forwards

it, err = store.List(ctx,
testpb.ExampleTableStrU32IndexKey{}.WithStrU32("abe", 7),
)
assert.NilError(t, err)
assertIteratorItems(it, 5, 6)
// and backwards
it, err = store.List(ctx,
testpb.ExampleTableStrU32IndexKey{}.WithStrU32("abc", 4),
ormlist.Reverse(),
)
assert.NilError(t, err)
assertIteratorItems(it, 2, 0)

// try filtering
Expand Down Expand Up @@ -838,6 +848,7 @@ func TestInsertReturningFieldName(t *testing.T) {
table, err := ormtable.Build(ormtable.Options{
MessageType: (&testpb.ExampleAutoIncFieldName{}).ProtoReflect().Type(),
})
assert.NilError(t, err)
backend := testkv.NewSplitMemBackend()
ctx := ormtable.WrapContextDefault(backend)
store, err := testpb.NewExampleAutoIncFieldNameTable(table)
Expand Down

0 comments on commit 2b126af

Please sign in to comment.