chore: gofumpt (#11839)
* fumpt using main not master... * be more descriptive * fumpt * fix nits Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
co-authored by
Julien Robert
parent
bc2d553f77
commit
55054282d2
@@ -13,7 +13,6 @@ import (
|
||||
|
||||
// Codec defines an interface for decoding and encoding values in ORM index keys.
|
||||
type Codec interface {
|
||||
|
||||
// Decode decodes a value in a key.
|
||||
Decode(r Reader) (protoreflect.Value, error)
|
||||
|
||||
|
||||
@@ -14,8 +14,10 @@ type Int32Codec struct{}
|
||||
|
||||
var int32Codec = Int32Codec{}
|
||||
|
||||
const int32Max = 2147483647
|
||||
const int32Offset = int32Max + 1
|
||||
const (
|
||||
int32Max = 2147483647
|
||||
int32Offset = int32Max + 1
|
||||
)
|
||||
|
||||
func (i Int32Codec) Decode(r Reader) (protoreflect.Value, error) {
|
||||
var x uint32
|
||||
|
||||
@@ -6,7 +6,6 @@ import "google.golang.org/protobuf/reflect/protoreflect"
|
||||
// kv-store backing an ORM instance. EntryCodec's enable full logical decoding
|
||||
// of ORM data.
|
||||
type EntryCodec interface {
|
||||
|
||||
// DecodeEntry decodes a kv-pair into an Entry.
|
||||
DecodeEntry(k, v []byte) (Entry, error)
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ type Entry interface {
|
||||
|
||||
// PrimaryKeyEntry represents a logically decoded primary-key entry.
|
||||
type PrimaryKeyEntry struct {
|
||||
|
||||
// TableName is the table this entry represents.
|
||||
TableName protoreflect.FullName
|
||||
|
||||
@@ -71,7 +70,6 @@ func (p *PrimaryKeyEntry) doNotImplement() {}
|
||||
|
||||
// IndexKeyEntry represents a logically decoded index entry.
|
||||
type IndexKeyEntry struct {
|
||||
|
||||
// TableName is the table this entry represents.
|
||||
TableName protoreflect.FullName
|
||||
|
||||
@@ -111,14 +109,12 @@ func (i *IndexKeyEntry) String() string {
|
||||
if i.IsUnique {
|
||||
return fmt.Sprintf("UNIQ %s", i.string())
|
||||
} else {
|
||||
|
||||
return fmt.Sprintf("IDX %s", i.string())
|
||||
}
|
||||
}
|
||||
|
||||
// SeqEntry represents a sequence for tables with auto-incrementing primary keys.
|
||||
type SeqEntry struct {
|
||||
|
||||
// TableName is the table this entry represents.
|
||||
TableName protoreflect.FullName
|
||||
|
||||
|
||||
@@ -62,7 +62,6 @@ func NewIndexKeyCodec(prefix []byte, messageType protoreflect.MessageType, index
|
||||
}
|
||||
|
||||
func (cdc IndexKeyCodec) DecodeIndexKey(k, _ []byte) (indexFields, primaryKey []protoreflect.Value, err error) {
|
||||
|
||||
values, err := cdc.DecodeKey(bytes.NewReader(k))
|
||||
// got prefix key
|
||||
if err == io.EOF {
|
||||
|
||||
@@ -51,7 +51,6 @@ func (p PrimaryKeyCodec) DecodeIndexKey(k, _ []byte) (indexFields, primaryKey []
|
||||
primaryKey = indexFields
|
||||
}
|
||||
return indexFields, primaryKey, nil
|
||||
|
||||
}
|
||||
|
||||
func (p PrimaryKeyCodec) DecodeEntry(k, v []byte) (Entry, error) {
|
||||
|
||||
@@ -153,7 +153,6 @@ func (f fileGen) genStoreConstructor(stores []*protogen.Message) {
|
||||
}
|
||||
f.P("}, nil")
|
||||
f.P("}")
|
||||
|
||||
}
|
||||
|
||||
func (f fileGen) fieldsToCamelCase(fields string) string {
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
)
|
||||
|
||||
func (t tableGen) genIndexKeys() {
|
||||
|
||||
// interface that all keys must adhere to
|
||||
t.P("type ", t.indexKeyInterfaceName(), " interface {")
|
||||
t.P("id() uint32")
|
||||
@@ -112,7 +111,6 @@ func (t tableGen) genIndex(fields string, id uint32, isPrimaryKey bool) {
|
||||
for i := 1; i < len(fieldsSlc)+1; i++ {
|
||||
t.genWithMethods(idxKeyName, fieldsSlc[:i])
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (t tableGen) genIndexInterfaceMethods(id uint32, indexStructName string) {
|
||||
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
|
||||
// Debugger is an interface that handles debug info from the debug store wrapper.
|
||||
type Debugger interface {
|
||||
|
||||
// Log logs a single log message.
|
||||
Log(string)
|
||||
|
||||
|
||||
@@ -51,7 +51,6 @@ type moduleDB struct {
|
||||
|
||||
// ModuleDBOptions are options for constructing a ModuleDB.
|
||||
type ModuleDBOptions struct {
|
||||
|
||||
// TypeResolver is an optional type resolver to be used when unmarshaling
|
||||
// protobuf messages. If it is nil, protoregistry.GlobalTypes will be used.
|
||||
TypeResolver ormtable.TypeResolver
|
||||
|
||||
@@ -355,13 +355,14 @@ func TestGetBackendResolver(t *testing.T) {
|
||||
})
|
||||
assert.ErrorContains(t, err, "unsupported")
|
||||
|
||||
_, err = ormdb.NewModuleDB(&ormv1alpha1.ModuleSchemaDescriptor{SchemaFile: []*ormv1alpha1.ModuleSchemaDescriptor_FileEntry{
|
||||
{
|
||||
Id: 1,
|
||||
ProtoFileName: testpb.File_testpb_bank_proto.Path(),
|
||||
StorageType: ormv1alpha1.StorageType_STORAGE_TYPE_MEMORY,
|
||||
_, err = ormdb.NewModuleDB(&ormv1alpha1.ModuleSchemaDescriptor{
|
||||
SchemaFile: []*ormv1alpha1.ModuleSchemaDescriptor_FileEntry{
|
||||
{
|
||||
Id: 1,
|
||||
ProtoFileName: testpb.File_testpb_bank_proto.Path(),
|
||||
StorageType: ormv1alpha1.StorageType_STORAGE_TYPE_MEMORY,
|
||||
},
|
||||
},
|
||||
},
|
||||
}, ormdb.ModuleDBOptions{
|
||||
GetBackendResolver: getResolver,
|
||||
})
|
||||
|
||||
@@ -50,7 +50,6 @@ type Backend interface {
|
||||
// If the index store is not defined, the commitment store will be
|
||||
// used for all operations.
|
||||
type ReadBackendOptions struct {
|
||||
|
||||
// CommitmentStoreReader is a reader for the commitment store.
|
||||
CommitmentStoreReader kv.ReadonlyStore
|
||||
|
||||
@@ -135,7 +134,6 @@ func (c backend) IndexStore() kv.Store {
|
||||
// If the index store is not defined, the commitment store will be
|
||||
// used for all operations.
|
||||
type BackendOptions struct {
|
||||
|
||||
// CommitmentStore is the commitment store.
|
||||
CommitmentStore kv.Store
|
||||
|
||||
|
||||
@@ -75,7 +75,6 @@ func flushBuf(store kv.Store, writes []*batchWriterEntry) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -219,7 +219,7 @@ func getBalance(store kv.Store, address, denom string) (*testpb.Balance, error)
|
||||
return nil, fmt.Errorf("not found")
|
||||
}
|
||||
|
||||
var balance = testpb.Balance{}
|
||||
balance := testpb.Balance{}
|
||||
err = proto.Unmarshal(bz, &balance)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
// ValidateHooks defines an interface for a table hooks which can intercept
|
||||
// insert, update and delete operations and possibly return an error.
|
||||
type ValidateHooks interface {
|
||||
|
||||
// ValidateInsert is called before the message is inserted.
|
||||
// If error is not nil the insertion will fail.
|
||||
ValidateInsert(context.Context, proto.Message) error
|
||||
@@ -30,7 +29,6 @@ type ValidateHooks interface {
|
||||
// may be called but the enclosing transaction may still fail. The context
|
||||
// is provided in each method to help coordinate this.
|
||||
type WriteHooks interface {
|
||||
|
||||
// OnInsert is called after an message is inserted into the store.
|
||||
OnInsert(context.Context, proto.Message)
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ import (
|
||||
// are stateless, with all state existing only in the store passed
|
||||
// to index methods.
|
||||
type Index interface {
|
||||
|
||||
// List does iteration over the index with the provided prefix key and options.
|
||||
// Prefix key values must correspond in type to the index's fields and the
|
||||
// number of values provided cannot exceed the number of fields in the index,
|
||||
|
||||
@@ -61,8 +61,10 @@ func (i indexKeyIndex) ListRange(ctx context.Context, from, to []interface{}, op
|
||||
return rangeIterator(backend.IndexStoreReader(), backend, i, i.KeyCodec, from, to, options)
|
||||
}
|
||||
|
||||
var _ indexer = &indexKeyIndex{}
|
||||
var _ Index = &indexKeyIndex{}
|
||||
var (
|
||||
_ indexer = &indexKeyIndex{}
|
||||
_ Index = &indexKeyIndex{}
|
||||
)
|
||||
|
||||
func (i indexKeyIndex) doNotImplement() {}
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ import (
|
||||
// Instead you should do reads and writes separately, or use a helper
|
||||
// function like DeleteBy which does this efficiently.
|
||||
type Iterator interface {
|
||||
|
||||
// Next advances the iterator and returns true if a valid entry is found.
|
||||
// Next must be called before starting iteration.
|
||||
Next() bool
|
||||
|
||||
@@ -76,7 +76,6 @@ func (it *paginationIterator) Next() bool {
|
||||
// so the index == total entries.
|
||||
it.pageRes.Total = uint64(it.i)
|
||||
}
|
||||
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -3,11 +3,12 @@ package ormtable_test
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/orm/model/ormtable"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"google.golang.org/protobuf/encoding/protojson"
|
||||
"testing"
|
||||
|
||||
"github.com/regen-network/gocuke"
|
||||
"gotest.tools/v3/assert"
|
||||
|
||||
@@ -414,8 +414,10 @@ func (t tableImpl) Get(ctx context.Context, message proto.Message) (found bool,
|
||||
return t.primaryKeyIndex.get(backend, message, keyValues)
|
||||
}
|
||||
|
||||
var _ Table = &tableImpl{}
|
||||
var _ Schema = &tableImpl{}
|
||||
var (
|
||||
_ Table = &tableImpl{}
|
||||
_ Schema = &tableImpl{}
|
||||
)
|
||||
|
||||
type saveMode int
|
||||
|
||||
|
||||
@@ -98,7 +98,6 @@ func TestPaginationLimitCountTotal(t *testing.T) {
|
||||
pr := it.PageResponse()
|
||||
assert.Check(t, pr != nil)
|
||||
assert.Equal(t, uint64(3), pr.Total)
|
||||
|
||||
}
|
||||
|
||||
func TestImportedMessageIterator(t *testing.T) {
|
||||
@@ -187,7 +186,7 @@ func runTestScenario(t *testing.T, table ormtable.Table, backend ormtable.Backen
|
||||
assert.Assert(t, it.Next())
|
||||
msg, err := it.GetMessage()
|
||||
assert.NilError(t, err)
|
||||
//t.Logf("data[%d] %v == %v", i, data[i], msg)
|
||||
// t.Logf("data[%d] %v == %v", i, data[i], msg)
|
||||
assert.DeepEqual(t, data[i], msg, protocmp.Transform())
|
||||
}
|
||||
// make sure the iterator is done
|
||||
@@ -498,7 +497,6 @@ func runTestScenario(t *testing.T, table ormtable.Table, backend ormtable.Backen
|
||||
it, err = store.List(ctx, testpb.ExampleTablePrimaryKey{})
|
||||
assert.NilError(t, err)
|
||||
assertIteratorItems(it, 2, 6, 10)
|
||||
|
||||
}
|
||||
|
||||
func TestRandomTableData(t *testing.T) {
|
||||
@@ -604,7 +602,6 @@ func testIndex(t *testing.T, model *IndexModel) {
|
||||
assert.DeepEqual(t, model.data[i], data2[i], protocmp.Transform())
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func reverseData(data []proto.Message) []proto.Message {
|
||||
|
||||
@@ -190,8 +190,10 @@ func (u uniqueKeyIndex) Fields() string {
|
||||
return u.fields.String()
|
||||
}
|
||||
|
||||
var _ indexer = &uniqueKeyIndex{}
|
||||
var _ UniqueIndex = &uniqueKeyIndex{}
|
||||
var (
|
||||
_ indexer = &uniqueKeyIndex{}
|
||||
_ UniqueIndex = &uniqueKeyIndex{}
|
||||
)
|
||||
|
||||
// isNonTrivialUniqueKey checks if unique key fields are non-trivial, meaning that they
|
||||
// don't contain the full primary key. If they contain the full primary key, then
|
||||
|
||||
Reference in New Issue
Block a user