Skip to content

Commit

Permalink
faddat/re merge main (#1274)
Browse files Browse the repository at this point in the history
undefined
  • Loading branch information
faddat committed Mar 20, 2023
1 parent f66036a commit 49ed6f0
Show file tree
Hide file tree
Showing 32 changed files with 151 additions and 162 deletions.
9 changes: 4 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,10 @@ issues:
max-same-issues: 10000

linters-settings:
dogsled:
max-blank-identifiers: 3
maligned:
# print struct with more effective memory layout or not, false by default
suggest-new: true
revive:
# When set to false, ignores files with "GENERATED" header, similar to golint
ignore-generated-header: true

nolintlint:
allow-unused: false
allow-leading-space: true
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func buildTxFromMsg(builder func(info *AppInfo) ([]sdk.Msg, error)) func(b *test
}
}

func buildMemDB(b *testing.B) dbm.DB {
func buildMemDB(_ *testing.B) dbm.DB {
return dbm.NewMemDB()
}

Expand Down
2 changes: 1 addition & 1 deletion x/wasm/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ type (
BankEncoder = keeper.BankEncoder
CustomEncoder = keeper.CustomEncoder
StakingEncoder = keeper.StakingEncoder
WasmEncoder = keeper.WasmEncoder //nolint:revive
WasmEncoder = keeper.WasmEncoder
MessageEncoders = keeper.MessageEncoders
Keeper = keeper.Keeper
QueryHandler = keeper.QueryHandler
Expand Down
1 change: 1 addition & 0 deletions x/wasm/client/cli/new_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func UpdateContractAdminCmd() *cobra.Command {
}

msg := parseUpdateContractAdminArgs(args, clientCtx)

if err := msg.ValidateBasic(); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestInitGenesis(t *testing.T) {
require.NoError(t, err)
assertStoreCodeResponse(t, res.Data, 1)

_, _, bob := keyPubAddr()
bob := keyPubAddr()
initMsg := initMsg{
Verifier: fred,
Beneficiary: bob,
Expand Down
18 changes: 9 additions & 9 deletions x/wasm/ibctesting/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ func (chain *TestChain) CreateTMClientHeader(chainID string, blockHeight int64,
AppHash: chain.CurrentHeader.AppHash,
LastResultsHash: tmhash.Sum([]byte("last_results_hash")),
EvidenceHash: tmhash.Sum([]byte("evidence_hash")),
ProposerAddress: tmValSet.Proposer.Address, //nolint:staticcheck
ProposerAddress: tmValSet.Proposer.Address, //nolint:staticcheck // SA5011: possible nil pointer dereference
}

hhash := tmHeader.Hash()
Expand Down Expand Up @@ -550,11 +550,11 @@ func (chain *TestChain) CreatePortCapability(scopedKeeper capabilitykeeper.Scope
_, ok := chain.App.ScopedIBCKeeper.GetCapability(chain.GetContext(), host.PortPath(portID))
if !ok {
// create capability using the IBC capability keeper
cap, err := chain.App.ScopedIBCKeeper.NewCapability(chain.GetContext(), host.PortPath(portID))
portCap, err := chain.App.ScopedIBCKeeper.NewCapability(chain.GetContext(), host.PortPath(portID))
require.NoError(chain.t, err)

// claim capability using the scopedKeeper
err = scopedKeeper.ClaimCapability(chain.GetContext(), cap, host.PortPath(portID))
err = scopedKeeper.ClaimCapability(chain.GetContext(), portCap, host.PortPath(portID))
require.NoError(chain.t, err)
}

Expand All @@ -564,10 +564,10 @@ func (chain *TestChain) CreatePortCapability(scopedKeeper capabilitykeeper.Scope
// GetPortCapability returns the port capability for the given portID. The capability must
// exist, otherwise testing will fail.
func (chain *TestChain) GetPortCapability(portID string) *capabilitytypes.Capability {
cap, ok := chain.App.ScopedIBCKeeper.GetCapability(chain.GetContext(), host.PortPath(portID))
portCap, ok := chain.App.ScopedIBCKeeper.GetCapability(chain.GetContext(), host.PortPath(portID))
require.True(chain.t, ok)

return cap
return portCap
}

// CreateChannelCapability binds and claims a capability for the given portID and channelID
Expand All @@ -578,9 +578,9 @@ func (chain *TestChain) CreateChannelCapability(scopedKeeper capabilitykeeper.Sc
// check if the portId is already binded, if not bind it
_, ok := chain.App.ScopedIBCKeeper.GetCapability(chain.GetContext(), capName)
if !ok {
cap, err := chain.App.ScopedIBCKeeper.NewCapability(chain.GetContext(), capName)
portCap, err := chain.App.ScopedIBCKeeper.NewCapability(chain.GetContext(), capName)
require.NoError(chain.t, err)
err = scopedKeeper.ClaimCapability(chain.GetContext(), cap, capName)
err = scopedKeeper.ClaimCapability(chain.GetContext(), portCap, capName)
require.NoError(chain.t, err)
}

Expand All @@ -590,10 +590,10 @@ func (chain *TestChain) CreateChannelCapability(scopedKeeper capabilitykeeper.Sc
// GetChannelCapability returns the channel capability for the given portID and channelID.
// The capability must exist, otherwise testing will fail.
func (chain *TestChain) GetChannelCapability(portID, channelID string) *capabilitytypes.Capability {
cap, ok := chain.App.ScopedIBCKeeper.GetCapability(chain.GetContext(), host.ChannelCapabilityPath(portID, channelID))
chanCap, ok := chain.App.ScopedIBCKeeper.GetCapability(chain.GetContext(), host.ChannelCapabilityPath(portID, channelID))
require.True(chain.t, ok)

return cap
return chanCap
}

// GetTimeoutHeight is a convenience function which returns a IBC packet timeout height
Expand Down
12 changes: 4 additions & 8 deletions x/wasm/ibctesting/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,9 @@ func (coord *Coordinator) ConnOpenInitOnBothChains(path *Path) error {
return err
}

if err := path.EndpointB.UpdateClient(); err != nil {
return err
}
err := path.EndpointB.UpdateClient()

return nil
return err
}

// ChanOpenInitOnBothChains initializes a channel on the source chain and counterparty chain
Expand All @@ -242,11 +240,9 @@ func (coord *Coordinator) ChanOpenInitOnBothChains(path *Path) error {
return err
}

if err := path.EndpointB.UpdateClient(); err != nil {
return err
}
err := path.EndpointB.UpdateClient()

return nil
return err
}

// RelayAndAckPendingPackets sends pending packages from path.EndpointA to the counterparty chain and acks
Expand Down
14 changes: 5 additions & 9 deletions x/wasm/ibctesting/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (path *Path) SetChannelOrdered() {
// RelayPacket attempts to relay the packet first on EndpointA and then on EndpointB
// if EndpointA does not contain a packet commitment for that packet. An error is returned
// if a relay step fails or the packet commitment does not exist on either endpoint.
func (path *Path) RelayPacket(packet channeltypes.Packet, ack []byte) error {
func (path *Path) RelayPacket(packet channeltypes.Packet, _ []byte) error {
pc := path.EndpointA.Chain.App.IBCKeeper.ChannelKeeper.GetPacketCommitment(path.EndpointA.Chain.GetContext(), packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence())
if bytes.Equal(pc, channeltypes.CommitPacket(path.EndpointA.Chain.App.AppCodec(), packet)) {

Expand All @@ -59,11 +59,9 @@ func (path *Path) RelayPacket(packet channeltypes.Packet, ack []byte) error {
return err
}

if err := path.EndpointA.AcknowledgePacket(packet, ack); err != nil {
return err
}
err = path.EndpointA.AcknowledgePacket(packet, ack)

return nil
return err
}

pc = path.EndpointB.Chain.App.IBCKeeper.ChannelKeeper.GetPacketCommitment(path.EndpointB.Chain.GetContext(), packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence())
Expand All @@ -84,10 +82,8 @@ func (path *Path) RelayPacket(packet channeltypes.Packet, ack []byte) error {
return err
}

if err := path.EndpointB.AcknowledgePacket(packet, ack); err != nil {
return err
}
return nil
err = path.EndpointB.AcknowledgePacket(packet, ack)
return err
}

return fmt.Errorf("packet commitment does not exist on either endpoint for provided packet")
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/keeper/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func TestCountTxDecorator(t *testing.T) {
func TestLimitSimulationGasDecorator(t *testing.T) {
var (
hundred sdk.Gas = 100
zero sdk.Gas = 0 //nolint:revive // leave the zero for clarity
zero sdk.Gas = 0
)
specs := map[string]struct {
customLimit *sdk.Gas
Expand Down
6 changes: 3 additions & 3 deletions x/wasm/keeper/handler_plugin_encoders.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func EncodeBankMsg(sender sdk.AccAddress, msg *wasmvmtypes.BankMsg) ([]sdk.Msg,
return []sdk.Msg{&sdkMsg}, nil
}

func NoCustomMsg(sender sdk.AccAddress, msg json.RawMessage) ([]sdk.Msg, error) {
func NoCustomMsg(_ sdk.AccAddress, _ json.RawMessage) ([]sdk.Msg, error) {
return nil, errorsmod.Wrap(types.ErrUnknownMsg, "custom variant not supported")
}

Expand Down Expand Up @@ -194,12 +194,12 @@ func EncodeStakingMsg(sender sdk.AccAddress, msg *wasmvmtypes.StakingMsg) ([]sdk

func EncodeStargateMsg(unpacker codectypes.AnyUnpacker) StargateEncoder {
return func(sender sdk.AccAddress, msg *wasmvmtypes.StargateMsg) ([]sdk.Msg, error) {
any := codectypes.Any{
codecAny := codectypes.Any{
TypeUrl: msg.TypeURL,
Value: msg.Value,
}
var sdkMsg sdk.Msg
if err := unpacker.UnpackAny(&any, &sdkMsg); err != nil {
if err := unpacker.UnpackAny(&codecAny, &sdkMsg); err != nil {
return nil, errorsmod.Wrap(types.ErrInvalidMsg, fmt.Sprintf("Cannot unpack proto message with type URL: %s", msg.TypeURL))
}
if err := codectypes.UnpackInterfaces(sdkMsg, unpacker); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions x/wasm/keeper/ibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
// returns a string name of the port or error if we cannot bind it.
// this will fail if call twice.
func (k Keeper) bindIbcPort(ctx sdk.Context, portID string) error {
cap := k.portKeeper.BindPort(ctx, portID)
return k.ClaimCapability(ctx, cap, host.PortPath(portID))
portCap := k.portKeeper.BindPort(ctx, portID)
return k.ClaimCapability(ctx, portCap, host.PortPath(portID))
}

// ensureIbcPort is like registerIbcPort, but it checks if we already hold the port
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,7 @@ func moduleLogger(ctx sdk.Context) log.Logger {
}

// Querier creates a new grpc querier instance
func Querier(k *Keeper) *grpcQuerier { //nolint:revive
func Querier(k *Keeper) *GrpcQuerier {
return NewGrpcQuerier(k.cdc, k.storeKey, k, k.queryGasLimit)
}

Expand Down
22 changes: 11 additions & 11 deletions x/wasm/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,6 @@ func TestInstantiateWithAccounts(t *testing.T) {

senderAddr := DeterministicAccountAddress(t, 1)
keepers.Faucet.Fund(parentCtx, senderAddr, sdk.NewInt64Coin("denom", 100000000))
const myLabel = "testing"
mySalt := []byte(`my salt`)
contractAddr := BuildContractAddressPredictable(example.Checksum, senderAddr, mySalt, []byte{})

Expand Down Expand Up @@ -674,7 +673,7 @@ func TestInstantiateWithAccounts(t *testing.T) {
}
}()
// when
gotAddr, _, gotErr := keepers.ContractKeeper.Instantiate2(ctx, 1, senderAddr, nil, initMsg, myLabel, spec.deposit, mySalt, false)
gotAddr, _, gotErr := keepers.ContractKeeper.Instantiate2(ctx, 1, senderAddr, nil, initMsg, myTestLabel, spec.deposit, mySalt, false)
if spec.expErr != nil {
assert.ErrorIs(t, gotErr, spec.expErr)
return
Expand Down Expand Up @@ -1000,7 +999,7 @@ func TestExecuteWithPanic(t *testing.T) {
contractID, _, err := keeper.Create(ctx, creator, hackatomWasm, nil)
require.NoError(t, err)

_, _, bob := keyPubAddr()
_, bob := keyPubAddr()
initMsg := HackatomExampleInitMsg{
Verifier: fred,
Beneficiary: bob,
Expand Down Expand Up @@ -1032,7 +1031,7 @@ func TestExecuteWithCpuLoop(t *testing.T) {
contractID, _, err := keeper.Create(ctx, creator, hackatomWasm, nil)
require.NoError(t, err)

_, _, bob := keyPubAddr()
_, bob := keyPubAddr()
initMsg := HackatomExampleInitMsg{
Verifier: fred,
Beneficiary: bob,
Expand Down Expand Up @@ -1063,6 +1062,7 @@ func TestExecuteWithCpuLoop(t *testing.T) {

func TestExecuteWithStorageLoop(t *testing.T) {
ctx, keepers := CreateTestInput(t, false, AvailableCapabilities)

keeper := keepers.ContractKeeper

deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000))
Expand All @@ -1074,7 +1074,7 @@ func TestExecuteWithStorageLoop(t *testing.T) {
contractID, _, err := keeper.Create(ctx, creator, hackatomWasm, nil)
require.NoError(t, err)

_, _, bob := keyPubAddr()
_, bob := keyPubAddr()
initMsg := HackatomExampleInitMsg{
Verifier: fred,
Beneficiary: bob,
Expand Down Expand Up @@ -1354,7 +1354,7 @@ func TestMigrateWithDispatchedMessage(t *testing.T) {
require.NoError(t, err)
require.NotEqual(t, originalContractID, burnerContractID)

_, _, myPayoutAddr := keyPubAddr()
_, myPayoutAddr := keyPubAddr()
initMsg := HackatomExampleInitMsg{
Verifier: fred,
Beneficiary: fred,
Expand Down Expand Up @@ -1518,8 +1518,8 @@ func TestSudo(t *testing.T) {
contractID, _, err := keeper.Create(ctx, creator, hackatomWasm, nil)
require.NoError(t, err)

_, _, bob := keyPubAddr()
_, _, fred := keyPubAddr()
_, bob := keyPubAddr()
_, fred := keyPubAddr()
initMsg := HackatomExampleInitMsg{
Verifier: fred,
Beneficiary: bob,
Expand All @@ -1531,7 +1531,7 @@ func TestSudo(t *testing.T) {
require.Equal(t, "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr", addr.String())

// the community is broke
_, _, community := keyPubAddr()
_, community := keyPubAddr()
comAcct := accKeeper.GetAccount(ctx, community)
require.Nil(t, comAcct)

Expand Down Expand Up @@ -1604,7 +1604,7 @@ func TestUpdateContractAdmin(t *testing.T) {
originalContractID, _, err := keeper.Create(parentCtx, creator, hackatomWasm, nil)
require.NoError(t, err)

_, _, anyAddr := keyPubAddr()
_, anyAddr := keyPubAddr()
initMsg := HackatomExampleInitMsg{
Verifier: fred,
Beneficiary: anyAddr,
Expand Down Expand Up @@ -1674,7 +1674,7 @@ func TestClearContractAdmin(t *testing.T) {
originalContractID, _, err := keeper.Create(parentCtx, creator, hackatomWasm, nil)
require.NoError(t, err)

_, _, anyAddr := keyPubAddr()
_, anyAddr := keyPubAddr()
initMsg := HackatomExampleInitMsg{
Verifier: fred,
Beneficiary: anyAddr,
Expand Down
6 changes: 2 additions & 4 deletions x/wasm/keeper/proposal_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,8 @@ func handleClearAdminProposal(ctx sdk.Context, k types.ContractOpsKeeper, p type
if err != nil {
return errorsmod.Wrap(err, "contract")
}
if err := k.ClearContractAdmin(ctx, contractAddr, nil); err != nil {
return err
}
return nil
err = k.ClearContractAdmin(ctx, contractAddr, nil)
return err
}

func handlePinCodesProposal(ctx sdk.Context, k types.ContractOpsKeeper, p types.PinCodesProposal) error {
Expand Down
3 changes: 2 additions & 1 deletion x/wasm/keeper/proposal_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ func TestExecuteProposal(t *testing.T) {
msgServer := govkeeper.NewMsgServerImpl(keepers.GovKeeper)
_, err = submitLegacyProposal(t, ctx, badSrc, exampleContract.BeneficiaryAddr.String(), govAuthority, msgServer)
require.Error(t, err)

// balance should not change
bal = bankKeeper.GetBalance(ctx, contractAddr, "denom")
require.Equal(t, bal.Amount, sdk.NewInt(100))
Expand Down Expand Up @@ -517,7 +518,7 @@ func TestSudoProposal(t *testing.T) {

exampleContract := InstantiateHackatomExampleContract(t, ctx, keepers)
contractAddr := exampleContract.Contract
_, _, anyAddr := keyPubAddr()
_, anyAddr := keyPubAddr()

// check balance
bal := bankKeeper.GetBalance(ctx, contractAddr, "denom")
Expand Down
Loading

0 comments on commit 49ed6f0

Please sign in to comment.