Skip to content

Commit

Permalink
Merge branch 'main' into alex/sims2_s0
Browse files Browse the repository at this point in the history
* main:
  refactor(schema)!: move bech32 address prefixes to a higher level (#21026)
  chore(core): sync changelog (#21025)
  • Loading branch information
alpe committed Jul 23, 2024
2 parents 6582f00 + 2c236af commit 8018c01
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 46 deletions.
12 changes: 4 additions & 8 deletions core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,15 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [#18861](https://github.com/cosmos/cosmos-sdk/pull/18861) Moved `coin.ParseCoin` to `client/v2/internal`.
* [#18866](https://github.com/cosmos/cosmos-sdk/pull/18866) All items related to depinject have been moved to `cosmossdk.io/depinject` (`Provide`, `Invoke`, `Register`)
* [#19041](https://github.com/cosmos/cosmos-sdk/pull/19041) `HasEventListeners` was removed from appmodule due to the fact that it was not used anywhere in the SDK nor implemented

## [v0.12.0](https://github.com/cosmos/cosmos-sdk/releases/tag/core%2Fv0.12.0)

:::note
This release contains breaking changes and should not be used with 0.50.x or earlier versions of the Cosmos SDK.
:::

* [#17689](https://github.com/cosmos/cosmos-sdk/pull/17689) Move Comet service to return structs instead of interfaces.
* `BlockInfo` was renamed to `Info` and `BlockInfoService` was renamed to `CometInfoService`
* [#17693](https://github.com/cosmos/cosmos-sdk/pull/17693) Remove `appmodule.UpgradeModule` interface in favor of preblock

## [v0.11.0](https://github.com/cosmos/cosmos-sdk/releases/tag/core%2Fv0.11.0)
## [v0.11.1](https://github.com/cosmos/cosmos-sdk/releases/tag/core%2Fv0.11.1)

* [#21022](https://github.com/cosmos/cosmos-sdk/pull/21022) Upgrade depinject to v1.0.0.

## [v0.11.0](https://github.com/cosmos/cosmos-sdk/releases/tag/core%2Fv0.11.0)

* [#17468](https://github.com/cosmos/cosmos-sdk/pull/17468) Add `appmodule.HasPreBlocker` interface.

Expand Down
3 changes: 3 additions & 0 deletions core/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ require (
google.golang.org/genproto/googleapis/rpc v0.0.0-20240709173604-40e1e62336c5 // indirect
google.golang.org/protobuf v1.34.2 // indirect
)

// Version tagged too early and incompatible with v0.50 (latest at the time of tagging)
retract v0.12.0
11 changes: 0 additions & 11 deletions schema/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ type Field struct {
// Nullable indicates whether null values are accepted for the field. Key fields CANNOT be nullable.
Nullable bool

// AddressPrefix is the address prefix of the field's kind, currently only used for Bech32AddressKind.
// TODO: in a future update, stricter criteria and validation for address prefixes should be added.
AddressPrefix string

// EnumDefinition is the definition of the enum type and is only valid when Kind is EnumKind.
// The same enum types can be reused in the same module schema, but they always must contain
// the same values for the same enum name. This possibly introduces some duplication of
Expand All @@ -36,13 +32,6 @@ func (c Field) Validate() error {
return fmt.Errorf("invalid field kind for %q: %v", c.Name, err) //nolint:errorlint // false positive due to using go1.12
}

// address prefix only valid with Bech32AddressKind
if c.Kind == Bech32AddressKind && c.AddressPrefix == "" {
return fmt.Errorf("missing address prefix for field %q", c.Name)
} else if c.Kind != Bech32AddressKind && c.AddressPrefix != "" {
return fmt.Errorf("address prefix is only valid for field %q with type Bech32AddressKind", c.Name)
}

// enum definition only valid with EnumKind
if c.Kind == EnumKind {
if err := c.EnumDefinition.Validate(); err != nil {
Expand Down
17 changes: 0 additions & 17 deletions schema/field_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,6 @@ func TestField_Validate(t *testing.T) {
},
errContains: "invalid field kind",
},
{
name: "missing address prefix",
field: Field{
Name: "field1",
Kind: Bech32AddressKind,
},
errContains: "missing address prefix",
},
{
name: "address prefix with non-Bech32AddressKind",
field: Field{
Name: "field1",
Kind: StringKind,
AddressPrefix: "prefix",
},
errContains: "address prefix is only valid for field \"field1\" with type Bech32AddressKind",
},
{
name: "invalid enum definition",
field: Field{
Expand Down
14 changes: 7 additions & 7 deletions schema/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ const (
// Float64Kind is a float64 type and values of this type must be of the go type float64.
Float64Kind

// Bech32AddressKind is a bech32 address type and values of this type must be of the go type []byte.
// Fields of this type are expected to set the AddressPrefix field in the field definition to the
// bech32 address prefix so that indexers can properly convert them to strings.
Bech32AddressKind
// AddressKind represents an account address and must be of type []byte. Addresses usually have a
// human-readable rendering, such as bech32, and tooling should provide a way for apps to define a
// string encoder for friendly user-facing display.
AddressKind

// EnumKind is an enum type and values of this type must be of the go type string.
// Fields of this type are expected to set the EnumDefinition field in the field definition to the enum
Expand Down Expand Up @@ -150,7 +150,7 @@ func (t Kind) String() string {
return "float32"
case Float64Kind:
return "float64"
case Bech32AddressKind:
case AddressKind:
return "bech32address"
case EnumKind:
return "enum"
Expand Down Expand Up @@ -254,7 +254,7 @@ func (t Kind) ValidateValueType(value interface{}) error {
if !ok {
return fmt.Errorf("expected float64, got %T", value)
}
case Bech32AddressKind:
case AddressKind:
_, ok := value.([]byte)
if !ok {
return fmt.Errorf("expected []byte, got %T", value)
Expand Down Expand Up @@ -321,7 +321,7 @@ var (
)

// KindForGoValue finds the simplest kind that can represent the given go value. It will not, however,
// return kinds such as IntegerStringKind, DecimalStringKind, Bech32AddressKind, or EnumKind which all can be
// return kinds such as IntegerStringKind, DecimalStringKind, AddressKind, or EnumKind which all can be
// represented as strings.
func KindForGoValue(value interface{}) Kind {
switch value.(type) {
Expand Down
6 changes: 3 additions & 3 deletions schema/kind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ func TestKind_ValidateValueType(t *testing.T) {
{kind: DecimalStringKind, value: "1", valid: true},
{kind: DecimalStringKind, value: "1.1e4", valid: true},
{kind: DecimalStringKind, value: int32(1), valid: false},
{kind: Bech32AddressKind, value: []byte("hello"), valid: true},
{kind: Bech32AddressKind, value: 1, valid: false},
{kind: AddressKind, value: []byte("hello"), valid: true},
{kind: AddressKind, value: 1, valid: false},
{kind: BoolKind, value: true, valid: true},
{kind: BoolKind, value: false, valid: true},
{kind: BoolKind, value: 1, valid: false},
Expand Down Expand Up @@ -213,7 +213,7 @@ func TestKind_String(t *testing.T) {
{Float64Kind, "float64"},
{JSONKind, "json"},
{EnumKind, "enum"},
{Bech32AddressKind, "bech32address"},
{AddressKind, "bech32address"},
{InvalidKind, "invalid(0)"},
}
for i, tt := range tests {
Expand Down

0 comments on commit 8018c01

Please sign in to comment.