Skip to content

Commit

Permalink
Merge branch 'main' into facu/fix-uint-mut
Browse files Browse the repository at this point in the history
  • Loading branch information
facundomedica authored Oct 23, 2023
2 parents 4efd5e9 + 442c3c5 commit 2b4c78d
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 57 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ benchmark:
### Linting ###
###############################################################################

golangci_version=v1.54.2
golangci_version=v1.55.0

lint-install:
@echo "--> Installing golangci-lint $(golangci_version)"
Expand Down
30 changes: 18 additions & 12 deletions baseapp/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth/signing"
)

const (
failStr = "&failOnAnte=false"
fooStr = "foo"
counterStr = "counter="
)

func TestABCI_Info(t *testing.T) {
suite := NewBaseAppSuite(t)
ctx := suite.baseApp.NewContext(true)
Expand Down Expand Up @@ -242,7 +248,7 @@ func TestABCI_FinalizeBlock_WithBeginAndEndBlocker(t *testing.T) {
Type: "sometype",
Attributes: []abci.EventAttribute{
{
Key: "foo",
Key: fooStr,
Value: "bar",
},
},
Expand All @@ -258,7 +264,7 @@ func TestABCI_FinalizeBlock_WithBeginAndEndBlocker(t *testing.T) {
Type: "anothertype",
Attributes: []abci.EventAttribute{
{
Key: "foo",
Key: fooStr,
Value: "bar",
},
},
Expand All @@ -280,13 +286,13 @@ func TestABCI_FinalizeBlock_WithBeginAndEndBlocker(t *testing.T) {
require.Len(t, res.Events, 2)

require.Equal(t, "sometype", res.Events[0].Type)
require.Equal(t, "foo", res.Events[0].Attributes[0].Key)
require.Equal(t, fooStr, res.Events[0].Attributes[0].Key)
require.Equal(t, "bar", res.Events[0].Attributes[0].Value)
require.Equal(t, "mode", res.Events[0].Attributes[1].Key)
require.Equal(t, "BeginBlock", res.Events[0].Attributes[1].Value)

require.Equal(t, "anothertype", res.Events[1].Type)
require.Equal(t, "foo", res.Events[1].Attributes[0].Key)
require.Equal(t, fooStr, res.Events[1].Attributes[0].Key)
require.Equal(t, "bar", res.Events[1].Attributes[0].Value)
require.Equal(t, "mode", res.Events[1].Attributes[1].Key)
require.Equal(t, "EndBlock", res.Events[1].Attributes[1].Value)
Expand All @@ -303,13 +309,13 @@ func TestABCI_ExtendVote(t *testing.T) {
app := baseapp.NewBaseApp(name, log.NewTestLogger(t), db, nil)

app.SetExtendVoteHandler(func(ctx sdk.Context, req *abci.RequestExtendVote) (*abci.ResponseExtendVote, error) {
voteExt := "foo" + hex.EncodeToString(req.Hash) + strconv.FormatInt(req.Height, 10)
voteExt := fooStr + hex.EncodeToString(req.Hash) + strconv.FormatInt(req.Height, 10)
return &abci.ResponseExtendVote{VoteExtension: []byte(voteExt)}, nil
})

app.SetVerifyVoteExtensionHandler(func(ctx sdk.Context, req *abci.RequestVerifyVoteExtension) (*abci.ResponseVerifyVoteExtension, error) {
// do some kind of verification here
expectedVoteExt := "foo" + hex.EncodeToString(req.Hash) + strconv.FormatInt(req.Height, 10)
expectedVoteExt := fooStr + hex.EncodeToString(req.Hash) + strconv.FormatInt(req.Height, 10)
if !bytes.Equal(req.VoteExtension, []byte(expectedVoteExt)) {
return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, nil
}
Expand Down Expand Up @@ -387,7 +393,7 @@ func TestABCI_OnlyVerifyVoteExtension(t *testing.T) {

app.SetVerifyVoteExtensionHandler(func(ctx sdk.Context, req *abci.RequestVerifyVoteExtension) (*abci.ResponseVerifyVoteExtension, error) {
// do some kind of verification here
expectedVoteExt := "foo" + hex.EncodeToString(req.Hash) + strconv.FormatInt(req.Height, 10)
expectedVoteExt := fooStr + hex.EncodeToString(req.Hash) + strconv.FormatInt(req.Height, 10)
if !bytes.Equal(req.VoteExtension, []byte(expectedVoteExt)) {
return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, nil
}
Expand Down Expand Up @@ -450,7 +456,7 @@ func TestABCI_GRPCQuery(t *testing.T) {
})
require.NoError(t, err)

req := testdata.SayHelloRequest{Name: "foo"}
req := testdata.SayHelloRequest{Name: fooStr}
reqBz, err := req.Marshal()
require.NoError(t, err)

Expand Down Expand Up @@ -1482,7 +1488,7 @@ func TestABCI_Proposal_Read_State_PrepareProposal(t *testing.T) {

setInitChainerOpt := func(bapp *baseapp.BaseApp) {
bapp.SetInitChainer(func(ctx sdk.Context, req *abci.RequestInitChain) (*abci.ResponseInitChain, error) {
ctx.KVStore(capKey1).Set(someKey, []byte("foo"))
ctx.KVStore(capKey1).Set(someKey, []byte(fooStr))
return &abci.ResponseInitChain{}, nil
})
}
Expand All @@ -1491,7 +1497,7 @@ func TestABCI_Proposal_Read_State_PrepareProposal(t *testing.T) {
bapp.SetPrepareProposal(func(ctx sdk.Context, req *abci.RequestPrepareProposal) (*abci.ResponsePrepareProposal, error) {
value := ctx.KVStore(capKey1).Get(someKey)
// We should be able to access any state written in InitChain
require.Equal(t, "foo", string(value))
require.Equal(t, fooStr, string(value))
return &abci.ResponsePrepareProposal{Txs: req.Txs}, nil
})
}
Expand Down Expand Up @@ -1666,7 +1672,7 @@ func TestABCI_PrepareProposal_OverGasUnderBytes(t *testing.T) {
builder := suite.txConfig.NewTxBuilder()
err = builder.SetMsgs(msgs...)
require.NoError(t, err)
builder.SetMemo("counter=" + strconv.FormatInt(i, 10) + "&failOnAnte=false")
builder.SetMemo(counterStr + strconv.FormatInt(i, 10) + failStr)
builder.SetGasLimit(10)
setTxSignature(t, builder, uint64(i))

Expand Down Expand Up @@ -1706,7 +1712,7 @@ func TestABCI_PrepareProposal_MaxGas(t *testing.T) {
builder := suite.txConfig.NewTxBuilder()
err = builder.SetMsgs(msgs...)
require.NoError(t, err)
builder.SetMemo("counter=" + strconv.FormatInt(i, 10) + "&failOnAnte=false")
builder.SetMemo(counterStr + strconv.FormatInt(i, 10) + failStr)
builder.SetGasLimit(10)
setTxSignature(t, builder, uint64(i))

Expand Down
13 changes: 7 additions & 6 deletions go.work.example
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@ use (
./orm
./simapp
./tests
./tests/starship/tests
./store
./tools/cosmovisor
./tools/confix
./tools/hubl
./x/accounts
./x/group
./x/tx
./x/nft
./x/circuit
./x/feegrant
./x/evidence
./x/upgrade
./x/protocolpool
./x/feegrant
./x/group
./x/nft
./x/params
./x/protocolpool
./x/tx
./x/upgrade
)
1 change: 1 addition & 0 deletions math/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Ref: https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.j
### Bug Fixes

* [#18214](https://github.com/cosmos/cosmos-sdk/pull/18214) Ensure that modifying the argument to `NewUIntFromBigInt` doesn't mutate the returned value.
* [#18211](https://github.com/cosmos/cosmos-sdk/pull/18211) RelativePow now returns 1 when 0^0, before it was returning the scale factor.
* [#17725](https://github.com/cosmos/cosmos-sdk/pull/17725) Fix state break in ApproxRoot. This has been present since math/v1.0.1. It changed the rounding behavior at precision end in an intermediary division from banker's to truncation. The truncation occurs from binary right shift in the case of square roots. The change is now reverted back to banker's rounding universally for any root.

## [math/v1.1.2](https://github.com/cosmos/cosmos-sdk/releases/tag/math/v1.1.2) - 2023-08-21
Expand Down
2 changes: 1 addition & 1 deletion math/uint.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func checkNewUint(i *big.Int) (Uint, error) {
func RelativePow(x, n, b Uint) (z Uint) {
if x.IsZero() {
if n.IsZero() {
z = b // 0^0 = 1
z = OneUint() // 0^0 = 1
return z
}
z = ZeroUint() // otherwise 0^a = 0
Expand Down
2 changes: 1 addition & 1 deletion math/uint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func (s *uintTestSuite) TestRelativePow() {
want sdkmath.Uint
}{
{[]sdkmath.Uint{sdkmath.ZeroUint(), sdkmath.ZeroUint(), sdkmath.OneUint()}, sdkmath.OneUint()},
{[]sdkmath.Uint{sdkmath.ZeroUint(), sdkmath.ZeroUint(), sdkmath.NewUint(10)}, sdkmath.NewUint(10)},
{[]sdkmath.Uint{sdkmath.ZeroUint(), sdkmath.ZeroUint(), sdkmath.NewUint(10)}, sdkmath.NewUint(1)},
{[]sdkmath.Uint{sdkmath.ZeroUint(), sdkmath.OneUint(), sdkmath.NewUint(10)}, sdkmath.ZeroUint()},
{[]sdkmath.Uint{sdkmath.NewUint(10), sdkmath.NewUint(2), sdkmath.OneUint()}, sdkmath.NewUint(100)},
{[]sdkmath.Uint{sdkmath.NewUint(210), sdkmath.NewUint(2), sdkmath.NewUint(100)}, sdkmath.NewUint(441)},
Expand Down
8 changes: 5 additions & 3 deletions orm/internal/codegen/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"google.golang.org/protobuf/reflect/protoreflect"
)

const indexKey = "IndexKey"

func (t tableGen) genIndexKeys() {
// interface that all keys must adhere to
t.P("type ", t.indexKeyInterfaceName(), " interface {")
Expand Down Expand Up @@ -58,7 +60,7 @@ func (t tableGen) genIndexInterfaceGuard(idxKeyName string) {
}

func (t tableGen) indexKeyInterfaceName() string {
return t.msg.GoIdent.GoName + "IndexKey"
return t.msg.GoIdent.GoName + indexKey
}

func (t tableGen) genIndexKey(idxKeyName string) {
Expand All @@ -82,7 +84,7 @@ func (t tableGen) indexKeyName(names []protoreflect.Name) string {
cnames[i] = strcase.ToCamel(string(name))
}
joinedNames := strings.Join(cnames, "")
return t.msg.GoIdent.GoName + joinedNames + "IndexKey"
return t.msg.GoIdent.GoName + joinedNames + indexKey
}

func (t tableGen) indexStructName(fields []string) string {
Expand All @@ -91,7 +93,7 @@ func (t tableGen) indexStructName(fields []string) string {
names[i] = strcase.ToCamel(field)
}
joinedNames := strings.Join(names, "")
return t.msg.GoIdent.GoName + joinedNames + "IndexKey"
return t.msg.GoIdent.GoName + joinedNames + indexKey
}

func (t tableGen) genIndex(fields string, id uint32, isPrimaryKey bool) {
Expand Down
10 changes: 7 additions & 3 deletions tools/cosmovisor/cmd/cosmovisor/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import (
"cosmossdk.io/tools/cosmovisor"
)

const (
notset = " is not set"
)

type InitTestSuite struct {
suite.Suite
}
Expand Down Expand Up @@ -302,13 +306,13 @@ func (s *InitTestSuite) TestInitializeCosmovisorNegativeValidation() {
name: "no name",
env: cosmovisorInitEnv{Home: "/example", Name: ""},
args: []string{tmpExe},
inErr: []string{cosmovisor.EnvName + " is not set"},
inErr: []string{cosmovisor.EnvName + notset},
},
{
name: "no home",
env: cosmovisorInitEnv{Home: "", Name: "foo"},
args: []string{tmpExe},
inErr: []string{cosmovisor.EnvHome + " is not set"},
inErr: []string{cosmovisor.EnvHome + notset},
},
{
name: "home is relative",
Expand All @@ -320,7 +324,7 @@ func (s *InitTestSuite) TestInitializeCosmovisorNegativeValidation() {
name: "no name and no home",
env: cosmovisorInitEnv{Home: "", Name: ""},
args: []string{tmpExe},
inErr: []string{cosmovisor.EnvName + " is not set", cosmovisor.EnvHome + " is not set"},
inErr: []string{cosmovisor.EnvName + notset, cosmovisor.EnvHome + notset},
},
}

Expand Down
32 changes: 20 additions & 12 deletions types/address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ import (
"github.com/cosmos/cosmos-sdk/types/bech32/legacybech32" //nolint:staticcheck // we're using this to support the legacy way of dealing with bech32
)

const (
pubStr = "pub"
valoper = "valoper"
valoperpub = "valoperpub"
valcons = "valcons"
valconspub = "valconspub"
)

type addressTestSuite struct {
suite.Suite
}
Expand Down Expand Up @@ -138,18 +146,18 @@ func (s *addressTestSuite) TestAddrCache() {
// Set SDK bech32 prefixes to 'osmo'
prefix := "osmo"
conf := types.GetConfig()
conf.SetBech32PrefixForAccount(prefix, prefix+"pub")
conf.SetBech32PrefixForValidator(prefix+"valoper", prefix+"valoperpub")
conf.SetBech32PrefixForConsensusNode(prefix+"valcons", prefix+"valconspub")
conf.SetBech32PrefixForAccount(prefix, prefix+pubStr)
conf.SetBech32PrefixForValidator(prefix+valoper, prefix+valoperpub)
conf.SetBech32PrefixForConsensusNode(prefix+valcons, prefix+valconspub)

acc := types.AccAddress(pub.Address())
osmoAddrBech32 := acc.String()

// Set SDK bech32 to 'cosmos'
prefix = "cosmos"
conf.SetBech32PrefixForAccount(prefix, prefix+"pub")
conf.SetBech32PrefixForValidator(prefix+"valoper", prefix+"valoperpub")
conf.SetBech32PrefixForConsensusNode(prefix+"valcons", prefix+"valconspub")
conf.SetBech32PrefixForAccount(prefix, prefix+pubStr)
conf.SetBech32PrefixForValidator(prefix+valoper, prefix+valoperpub)
conf.SetBech32PrefixForConsensusNode(prefix+valcons, prefix+valconspub)

// We name this 'addrCosmos' to prove a point, but the bech32 address will still begin with 'osmo' due to the cache behavior.
addrCosmos := types.AccAddress(pub.Address())
Expand All @@ -175,18 +183,18 @@ func (s *addressTestSuite) TestAddrCacheDisabled() {
// Set SDK bech32 prefixes to 'osmo'
prefix := "osmo"
conf := types.GetConfig()
conf.SetBech32PrefixForAccount(prefix, prefix+"pub")
conf.SetBech32PrefixForValidator(prefix+"valoper", prefix+"valoperpub")
conf.SetBech32PrefixForConsensusNode(prefix+"valcons", prefix+"valconspub")
conf.SetBech32PrefixForAccount(prefix, prefix+pubStr)
conf.SetBech32PrefixForValidator(prefix+valoper, prefix+valoperpub)
conf.SetBech32PrefixForConsensusNode(prefix+valcons, prefix+valconspub)

acc := types.AccAddress(pub.Address())
osmoAddrBech32 := acc.String()

// Set SDK bech32 to 'cosmos'
prefix = "cosmos"
conf.SetBech32PrefixForAccount(prefix, prefix+"pub")
conf.SetBech32PrefixForValidator(prefix+"valoper", prefix+"valoperpub")
conf.SetBech32PrefixForConsensusNode(prefix+"valcons", prefix+"valconspub")
conf.SetBech32PrefixForAccount(prefix, prefix+pubStr)
conf.SetBech32PrefixForValidator(prefix+valoper, prefix+valoperpub)
conf.SetBech32PrefixForConsensusNode(prefix+valcons, prefix+valconspub)

addrCosmos := types.AccAddress(pub.Address())
cosmosAddrBech32 := addrCosmos.String()
Expand Down
17 changes: 11 additions & 6 deletions types/context_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ import (
"github.com/cosmos/cosmos-sdk/testutil"
)

const (
tcc = "_TestCacheContext"
transient = "transient_"
)

func BenchmarkContext_KVStore(b *testing.B) {
key := types.NewKVStoreKey(b.Name() + "_TestCacheContext")
key := types.NewKVStoreKey(b.Name() + tcc)

ctx := testutil.DefaultContext(key, types.NewTransientStoreKey("transient_"+b.Name()))
ctx := testutil.DefaultContext(key, types.NewTransientStoreKey(transient+b.Name()))

b.ResetTimer()
for i := 0; i < b.N; i++ {
Expand All @@ -20,9 +25,9 @@ func BenchmarkContext_KVStore(b *testing.B) {
}

func BenchmarkContext_TransientStore(b *testing.B) {
key := types.NewKVStoreKey(b.Name() + "_TestCacheContext")
key := types.NewKVStoreKey(b.Name() + tcc)

ctx := testutil.DefaultContext(key, types.NewTransientStoreKey("transient_"+b.Name()))
ctx := testutil.DefaultContext(key, types.NewTransientStoreKey(transient+b.Name()))

b.ResetTimer()
for i := 0; i < b.N; i++ {
Expand All @@ -31,9 +36,9 @@ func BenchmarkContext_TransientStore(b *testing.B) {
}

func BenchmarkContext_CacheContext(b *testing.B) {
key := types.NewKVStoreKey(b.Name() + "_TestCacheContext")
key := types.NewKVStoreKey(b.Name() + tcc)

ctx := testutil.DefaultContext(key, types.NewTransientStoreKey("transient_"+b.Name()))
ctx := testutil.DefaultContext(key, types.NewTransientStoreKey(transient+b.Name()))

b.ResetTimer()
for i := 0; i < b.N; i++ {
Expand Down
15 changes: 11 additions & 4 deletions x/gov/client/cli/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ import (
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

const (
strPlus = ` string\s+`
startStr = `(?m:^\s+--`
strDollar = `$)`
strHelp = "help output"
)

func TestParseSubmitLegacyProposal(t *testing.T) {
okJSON := testutil.WriteToNewTempFile(t, `
{
Expand Down Expand Up @@ -280,10 +287,10 @@ func TestAddGovPropFlagsToCmd(t *testing.T) {
expSummaryDesc := "The summary to include with the governance proposal"
// Regexp notes: (?m:...) = multi-line mode so ^ and $ match the beginning and end of each line.
// Each regexp assertion checks for a line containing only a specific flag and its description.
assert.Regexp(t, `(?m:^\s+--`+FlagDeposit+` string\s+`+expDepositDesc+`$)`, help, "help output")
assert.Regexp(t, `(?m:^\s+--`+FlagMetadata+` string\s+`+expMetadataDesc+`$)`, help, "help output")
assert.Regexp(t, `(?m:^\s+--`+FlagTitle+` string\s+`+expTitleDesc+`$)`, help, "help output")
assert.Regexp(t, `(?m:^\s+--`+FlagSummary+` string\s+`+expSummaryDesc+`$)`, help, "help output")
assert.Regexp(t, startStr+FlagDeposit+strPlus+expDepositDesc+strDollar, help, strHelp)
assert.Regexp(t, startStr+FlagMetadata+strPlus+expMetadataDesc+strDollar, help, strHelp)
assert.Regexp(t, startStr+FlagTitle+strPlus+expTitleDesc+strDollar, help, strHelp)
assert.Regexp(t, startStr+FlagSummary+strPlus+expSummaryDesc+strDollar, help, strHelp)
}

func TestReadGovPropFlags(t *testing.T) {
Expand Down
Loading

0 comments on commit 2b4c78d

Please sign in to comment.