Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lint: enable stylecheck #1960

Merged
merged 4 commits into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ linters:
# - sqlclosecheck <- needs go 1.18 support
# - staticcheck <- later
# - structcheck <- later
# - stylecheck <- enable later, atriggers on underscores in variable names and on poolId
- stylecheck # replacement of golint, subset of staticcheck binary.
# - tagliatelle <- disabled for defying cosmos idiom
- tenv
- testpackage
Expand Down Expand Up @@ -102,5 +102,8 @@ issues:
# across its files, once stableswap is fully complete.
- unused
- deadcode
- linters:
- stylecheck
text: "ST1003:" # requires identifiers with "id" to be "ID".
max-issues-per-linter: 10000
max-same-issues: 10000
52 changes: 26 additions & 26 deletions app/apptesting/gamm.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ var DefaultAcctFunds sdk.Coins = sdk.NewCoins(
)

// Returns a Univ2 pool with the initial liquidity being the provided balances
func (suite *KeeperTestHelper) PrepareUni2PoolWithAssets(asset1, asset2 sdk.Coin) uint64 {
return suite.PrepareBalancerPoolWithPoolAsset(
func (s *KeeperTestHelper) PrepareUni2PoolWithAssets(asset1, asset2 sdk.Coin) uint64 {
return s.PrepareBalancerPoolWithPoolAsset(
[]balancer.PoolAsset{
{
Weight: sdk.NewInt(1),
Expand All @@ -30,30 +30,30 @@ func (suite *KeeperTestHelper) PrepareUni2PoolWithAssets(asset1, asset2 sdk.Coin
)
}

func (suite *KeeperTestHelper) PrepareBalancerPool() uint64 {
poolId := suite.PrepareBalancerPoolWithPoolParams(balancer.PoolParams{
func (s *KeeperTestHelper) PrepareBalancerPool() uint64 {
poolId := s.PrepareBalancerPoolWithPoolParams(balancer.PoolParams{
SwapFee: sdk.NewDec(0),
ExitFee: sdk.NewDec(0),
})

spotPrice, err := suite.App.GAMMKeeper.CalculateSpotPrice(suite.Ctx, poolId, "foo", "bar")
suite.NoError(err)
suite.Equal(sdk.NewDec(2).String(), spotPrice.String())
spotPrice, err = suite.App.GAMMKeeper.CalculateSpotPrice(suite.Ctx, poolId, "bar", "baz")
suite.NoError(err)
suite.Equal(sdk.NewDecWithPrec(15, 1).String(), spotPrice.String())
spotPrice, err = suite.App.GAMMKeeper.CalculateSpotPrice(suite.Ctx, poolId, "baz", "foo")
suite.NoError(err)
s := sdk.NewDec(1).Quo(sdk.NewDec(3))
sp := s.MulInt(gammtypes.SigFigs).RoundInt().ToDec().QuoInt(gammtypes.SigFigs)
suite.Equal(sp.String(), spotPrice.String())
spotPrice, err := s.App.GAMMKeeper.CalculateSpotPrice(s.Ctx, poolId, "foo", "bar")
s.NoError(err)
s.Equal(sdk.NewDec(2).String(), spotPrice.String())
spotPrice, err = s.App.GAMMKeeper.CalculateSpotPrice(s.Ctx, poolId, "bar", "baz")
s.NoError(err)
s.Equal(sdk.NewDecWithPrec(15, 1).String(), spotPrice.String())
spotPrice, err = s.App.GAMMKeeper.CalculateSpotPrice(s.Ctx, poolId, "baz", "foo")
s.NoError(err)
oneThird := sdk.NewDec(1).Quo(sdk.NewDec(3))
sp := oneThird.MulInt(gammtypes.SigFigs).RoundInt().ToDec().QuoInt(gammtypes.SigFigs)
s.Equal(sp.String(), spotPrice.String())

return poolId
}

func (suite *KeeperTestHelper) PrepareBalancerPoolWithPoolParams(poolParams balancer.PoolParams) uint64 {
func (s *KeeperTestHelper) PrepareBalancerPoolWithPoolParams(poolParams balancer.PoolParams) uint64 {
// Mint some assets to the account.
suite.FundAcc(suite.TestAccs[0], DefaultAcctFunds)
s.FundAcc(s.TestAccs[0], DefaultAcctFunds)

poolAssets := []balancer.PoolAsset{
{
Expand All @@ -69,27 +69,27 @@ func (suite *KeeperTestHelper) PrepareBalancerPoolWithPoolParams(poolParams bala
Token: sdk.NewCoin("baz", sdk.NewInt(5000000)),
},
}
msg := balancer.NewMsgCreateBalancerPool(suite.TestAccs[0], poolParams, poolAssets, "")
poolId, err := suite.App.GAMMKeeper.CreatePool(suite.Ctx, msg)
suite.NoError(err)
msg := balancer.NewMsgCreateBalancerPool(s.TestAccs[0], poolParams, poolAssets, "")
poolId, err := s.App.GAMMKeeper.CreatePool(s.Ctx, msg)
s.NoError(err)
return poolId
}

func (suite *KeeperTestHelper) PrepareBalancerPoolWithPoolAsset(assets []balancer.PoolAsset) uint64 {
suite.Require().Len(assets, 2)
func (s *KeeperTestHelper) PrepareBalancerPoolWithPoolAsset(assets []balancer.PoolAsset) uint64 {
s.Require().Len(assets, 2)

// Add coins for pool creation fee + coins needed to mint balances
fundCoins := sdk.Coins{sdk.NewCoin("uosmo", sdk.NewInt(10000000000))}
for _, a := range assets {
fundCoins = fundCoins.Add(a.Token)
}
suite.FundAcc(suite.TestAccs[0], fundCoins)
s.FundAcc(s.TestAccs[0], fundCoins)

msg := balancer.NewMsgCreateBalancerPool(suite.TestAccs[0], balancer.PoolParams{
msg := balancer.NewMsgCreateBalancerPool(s.TestAccs[0], balancer.PoolParams{
SwapFee: sdk.ZeroDec(),
ExitFee: sdk.ZeroDec(),
}, assets, "")
poolId, err := suite.App.GAMMKeeper.CreatePool(suite.Ctx, msg)
suite.NoError(err)
poolId, err := s.App.GAMMKeeper.CreatePool(s.Ctx, msg)
s.NoError(err)
return poolId
}
11 changes: 5 additions & 6 deletions app/apptesting/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/libs/log"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmtypes "github.com/tendermint/tendermint/proto/tendermint/types"
dbm "github.com/tendermint/tm-db"

Expand All @@ -42,7 +41,7 @@ type KeeperTestHelper struct {

func (s *KeeperTestHelper) Setup() {
s.App = app.Setup(false)
s.Ctx = s.App.BaseApp.NewContext(false, tmproto.Header{Height: 1, ChainID: "osmosis-1", Time: time.Now().UTC()})
s.Ctx = s.App.BaseApp.NewContext(false, tmtypes.Header{Height: 1, ChainID: "osmosis-1", Time: time.Now().UTC()})
s.QueryHelper = &baseapp.QueryServiceTestHelper{
GRPCQueryRouter: s.App.GRPCQueryRouter(),
Ctx: s.Ctx,
Expand Down Expand Up @@ -138,7 +137,7 @@ func (s *KeeperTestHelper) BeginNewBlockWithProposer(executeNextEpoch bool, prop
newBlockTime = endEpochTime.Add(time.Second)
}

header := tmproto.Header{Height: s.Ctx.BlockHeight() + 1, Time: newBlockTime}
header := tmtypes.Header{Height: s.Ctx.BlockHeight() + 1, Time: newBlockTime}
newCtx := s.Ctx.WithBlockTime(newBlockTime).WithBlockHeight(s.Ctx.BlockHeight() + 1)
s.Ctx = newCtx
lastCommitInfo := abci.LastCommitInfo{
Expand Down Expand Up @@ -200,16 +199,16 @@ func (s *KeeperTestHelper) SetupGammPoolsWithBondDenomMultiplier(multipliers []s
defaultFutureGovernor = ""

// pool assets
defaultFooAsset balancer.PoolAsset = balancer.PoolAsset{
defaultFooAsset = balancer.PoolAsset{
Weight: sdk.NewInt(100),
Token: sdk.NewCoin(bondDenom, uosmoAmount),
}
defaultBarAsset balancer.PoolAsset = balancer.PoolAsset{
defaultBarAsset = balancer.PoolAsset{
Weight: sdk.NewInt(100),
Token: sdk.NewCoin(token, sdk.NewInt(10000)),
}

poolAssets []balancer.PoolAsset = []balancer.PoolAsset{defaultFooAsset, defaultBarAsset}
poolAssets = []balancer.PoolAsset{defaultFooAsset, defaultBarAsset}
)

poolParams := balancer.PoolParams{
Expand Down
4 changes: 2 additions & 2 deletions store/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ func (node *Node) setAcc(idx int, acc sdk.Int) *Node {
return node
}

func (cs *Node) insert(idx int, c *Child) *Node {
arr := append(cs.Children[:idx], append([]*Child{c}, cs.Children[idx:]...)...)
func (node *Node) insert(idx int, c *Child) *Node {
arr := append(node.Children[:idx], append([]*Child{c}, node.Children[idx:]...)...)
return NewNode(arr...)
}

Expand Down
36 changes: 18 additions & 18 deletions x/gamm/pool-models/balancer/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,48 +16,48 @@ type balancerPoolPretty struct {
PoolAssets []PoolAsset `json:"pool_assets" yaml:"pool_assets"`
}

func (pa Pool) String() string {
out, err := pa.MarshalJSON()
func (p Pool) String() string {
out, err := p.MarshalJSON()
if err != nil {
panic(err)
}
return string(out)
}

// MarshalJSON returns the JSON representation of a Pool.
func (pa Pool) MarshalJSON() ([]byte, error) {
accAddr, err := sdk.AccAddressFromBech32(pa.Address)
func (p Pool) MarshalJSON() ([]byte, error) {
accAddr, err := sdk.AccAddressFromBech32(p.Address)
if err != nil {
return nil, err
}

decTotalWeight := sdk.NewDecFromInt(pa.TotalWeight)
decTotalWeight := sdk.NewDecFromInt(p.TotalWeight)

return json.Marshal(balancerPoolPretty{
Address: accAddr,
Id: pa.Id,
PoolParams: pa.PoolParams,
FuturePoolGovernor: pa.FuturePoolGovernor,
Id: p.Id,
PoolParams: p.PoolParams,
FuturePoolGovernor: p.FuturePoolGovernor,
TotalWeight: decTotalWeight,
TotalShares: pa.TotalShares,
PoolAssets: pa.PoolAssets,
TotalShares: p.TotalShares,
PoolAssets: p.PoolAssets,
})
}

// UnmarshalJSON unmarshals raw JSON bytes into a Pool.
func (pa *Pool) UnmarshalJSON(bz []byte) error {
func (p *Pool) UnmarshalJSON(bz []byte) error {
var alias balancerPoolPretty
if err := json.Unmarshal(bz, &alias); err != nil {
return err
}

pa.Address = alias.Address.String()
pa.Id = alias.Id
pa.PoolParams = alias.PoolParams
pa.FuturePoolGovernor = alias.FuturePoolGovernor
pa.TotalWeight = alias.TotalWeight.RoundInt()
pa.TotalShares = alias.TotalShares
pa.PoolAssets = alias.PoolAssets
p.Address = alias.Address.String()
p.Id = alias.Id
p.PoolParams = alias.PoolParams
p.FuturePoolGovernor = alias.FuturePoolGovernor
p.TotalWeight = alias.TotalWeight.RoundInt()
p.TotalShares = alias.TotalShares
p.PoolAssets = alias.PoolAssets

return nil
}
Loading