chore: linting (#15813)

This commit is contained in:
Marko
2023-04-12 12:36:42 +00:00
committed by GitHub
parent 00e1f85eca
commit 37032fb948
35 changed files with 150 additions and 138 deletions
+5 -5
View File
@@ -30,7 +30,7 @@ type fileDescriptorDBOptions struct {
type fileDescriptorDB struct {
id uint32
prefix []byte
tablesById map[uint32]ormtable.Table
tablesByID map[uint32]ormtable.Table
tablesByName map[protoreflect.FullName]ormtable.Table
fileDescriptor protoreflect.FileDescriptor
}
@@ -41,7 +41,7 @@ func newFileDescriptorDB(fileDescriptor protoreflect.FileDescriptor, options fil
schema := &fileDescriptorDB{
id: options.ID,
prefix: prefix,
tablesById: map[uint32]ormtable.Table{},
tablesByID: map[uint32]ormtable.Table{},
tablesByName: map[protoreflect.FullName]ormtable.Table{},
fileDescriptor: fileDescriptor,
}
@@ -76,10 +76,10 @@ func newFileDescriptorDB(fileDescriptor protoreflect.FileDescriptor, options fil
}
id := table.ID()
if _, ok := schema.tablesById[id]; ok {
if _, ok := schema.tablesByID[id]; ok {
return nil, ormerrors.InvalidTableId.Wrapf("duplicate ID %d for %s", id, tableName)
}
schema.tablesById[id] = table
schema.tablesByID[id] = table
if _, ok := schema.tablesByName[tableName]; ok {
return nil, ormerrors.InvalidTableDefinition.Wrapf("duplicate table %s", tableName)
@@ -106,7 +106,7 @@ func (f fileDescriptorDB) DecodeEntry(k, v []byte) (ormkv.Entry, error) {
return nil, ormerrors.UnexpectedDecodePrefix.Wrapf("uint32 varint id out of range %d", id)
}
table, ok := f.tablesById[uint32(id)]
table, ok := f.tablesByID[uint32(id)]
if !ok {
return nil, ormerrors.UnexpectedDecodePrefix.Wrapf("can't find table with id %d", id)
}
+4 -4
View File
@@ -47,7 +47,7 @@ type ModuleDB interface {
type moduleDB struct {
prefix []byte
filesById map[uint32]*fileDescriptorDB
filesByID map[uint32]*fileDescriptorDB
tablesByName map[protoreflect.FullName]ormtable.Table
}
@@ -83,7 +83,7 @@ func NewModuleDB(schema *ormv1alpha1.ModuleSchemaDescriptor, options ModuleDBOpt
prefix := schema.Prefix
db := &moduleDB{
prefix: prefix,
filesById: map[uint32]*fileDescriptorDB{},
filesByID: map[uint32]*fileDescriptorDB{},
tablesByName: map[protoreflect.FullName]ormtable.Table{},
}
@@ -162,7 +162,7 @@ func NewModuleDB(schema *ormv1alpha1.ModuleSchemaDescriptor, options ModuleDBOpt
return nil, err
}
db.filesById[id] = fdSchema
db.filesByID[id] = fdSchema
for name, table := range fdSchema.tablesByName {
if _, ok := db.tablesByName[name]; ok {
return nil, ormerrors.UnexpectedError.Wrapf("duplicate table %s", name)
@@ -191,7 +191,7 @@ func (m moduleDB) DecodeEntry(k, v []byte) (ormkv.Entry, error) {
return nil, ormerrors.UnexpectedDecodePrefix.Wrapf("uint32 varint id out of range %d", id)
}
fileSchema, ok := m.filesById[uint32(id)]
fileSchema, ok := m.filesByID[uint32(id)]
if !ok {
return nil, ormerrors.UnexpectedDecodePrefix.Wrapf("can't find FileDescriptor schema with id %d", id)
}
+9 -9
View File
@@ -89,7 +89,7 @@ func (k keeper) Mint(ctx context.Context, acct, denom string, amount uint64) err
if supply == nil {
supply = &testpb.Supply{Denom: denom, Amount: amount}
} else {
supply.Amount = supply.Amount + amount
supply.Amount += amount
}
err = k.store.SupplyTable().Save(ctx, supply)
@@ -111,7 +111,7 @@ func (k keeper) Burn(ctx context.Context, acct, denom string, amount uint64) err
return fmt.Errorf("insufficient supply")
}
supply.Amount = supply.Amount - amount
supply.Amount -= amount
if supply.Amount == 0 {
err = supplyStore.Delete(ctx, supply)
@@ -183,9 +183,9 @@ func (k keeper) safeSubBalance(ctx context.Context, acct, denom string, amount u
if balance.Amount == 0 {
return balanceStore.Delete(ctx, balance)
} else {
return balanceStore.Save(ctx, balance)
}
return balanceStore.Save(ctx, balance)
}
func TestModuleDB(t *testing.T) {
@@ -227,13 +227,13 @@ func TestModuleDB(t *testing.T) {
// check JSON
target := genesis.RawJSONTarget{}
assert.NilError(t, db.GenesisHandler().DefaultGenesis(target.Target()))
rawJson, err := target.JSON()
rawJSON, err := target.JSON()
assert.NilError(t, err)
golden.Assert(t, string(rawJson), "default_json.golden")
golden.Assert(t, string(rawJSON), "default_json.golden")
target = genesis.RawJSONTarget{}
assert.NilError(t, db.GenesisHandler().ExportGenesis(ctx, target.Target()))
rawJson, err = target.JSON()
rawJSON, err = target.JSON()
assert.NilError(t, err)
goodJSON := `{
@@ -255,14 +255,14 @@ func TestModuleDB(t *testing.T) {
backend2 := ormtest.NewMemoryBackend()
ctx2 := ormtable.WrapContextDefault(backend2)
source, err = genesis.SourceFromRawJSON(rawJson)
source, err = genesis.SourceFromRawJSON(rawJSON)
assert.NilError(t, err)
assert.NilError(t, db.GenesisHandler().ValidateGenesis(source))
assert.NilError(t, db.GenesisHandler().InitGenesis(ctx2, source))
testkv.AssertBackendsEqual(t, backend, backend2)
}
func runSimpleBankTests(t *testing.T, k Keeper, ctx context.Context) {
func runSimpleBankTests(t *testing.T, k Keeper, ctx context.Context) { // nolint:revive // test function
// mint coins
denom := "foo"
acct1 := "bob"