Skip to content

Commit

Permalink
Merge branch 'release/v1.0.x' into state-changes-cmd
Browse files Browse the repository at this point in the history
Signed-off-by: yihuang <huang@crypto.com>
  • Loading branch information
yihuang authored Jan 31, 2023
2 parents feb2939 + 4e4b015 commit e54a893
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 84 deletions.
82 changes: 32 additions & 50 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,84 +1,66 @@
run:
tests: false
# timeout for analysis, e.g. 30s, 5m, default is 1m
# timeout: 5m
tests: true
timeout: 10m
sort-results: true
allow-parallel-runners: true
exclude-dir: testutil/testdata_pulsar
concurrency: 4

linters:
disable-all: true
enable:
# - bodyclose
- deadcode
- depguard
- dogsled
- dupl
- errcheck
- exportloopref
- goconst
- gocritic
- gofmt
- goimports
- revive
- gofumpt
- gosec
- gosimple
- govet
- ineffassign
# - lll TODO: enable
- misspell
- nakedret
- prealloc
- exportloopref
- nolintlint
- staticcheck
# - structcheck
- revive
- stylecheck
- typecheck
- unconvert
# - unparam
- unused
- varcheck
- nolintlint
- asciicheck
# - exhaustive
- exportloopref
- gofumpt
- gomodguard
# - nestif
# - nlreturn
# - noctx
# - rowserrcheck
# - whitespace
# - wsl
disable:
- typecheck

issues:
exclude-rules:
- path: _test\.go
- text: "Use of weak random number generator"
linters:
- gosec
- linters:
- lll
source: "https://"
max-same-issues: 50
- text: "ST1003:"
linters:
- stylecheck
# FIXME: Disabled until golangci-lint updates stylecheck with this fix:
# https://github.com/dominikh/go-tools/issues/389
- text: "ST1016:"
linters:
- stylecheck
- path: "migrations"
text: "SA1019:"
linters:
- staticcheck
- text: "leading space"
linters:
- nolintlint

max-issues-per-linter: 10000
max-same-issues: 10000

linters-settings:
dogsled:
max-blank-identifiers: 3
golint:
min-confidence: 0
maligned:
# print struct with more effective memory layout or not, false by default
suggest-new: true
misspell:
locale: US
nolintlint:
allow-unused: false
allow-leading-space: true
require-explanation: false
require-specific: false
gofumpt:
lang-version: "1.18"
gomodguard:
blocked:
versions: # List of blocked module version constraints
- https://github.com/etcd-io/etcd: # Blocked module with version constraint
version: ">= 3.4.10 || ~3.3.23" # Version constraint, see https://github.com/Masterminds/semver#basic-comparisons
reason: "CVE-2020-15114; CVE-2020-15136; CVE-2020-15115" # Reason why the version constraint exists. (Optional)
- https://github.com/dgrijalva/jwt-go: # Blocked module with version constraint
version: ">= 4.0.0-preview1" # Version constraint, see https://github.com/Masterminds/semver#basic-comparisons
reason: "CVE-2020-26160" # Reason why the version constraint exists. (Optional)
4 changes: 2 additions & 2 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import sources.nixpkgs {
go-ethereum = pkgs.callPackage ./go-ethereum.nix {
inherit (pkgs.darwin) libobjc;
inherit (pkgs.darwin.apple_sdk.frameworks) IOKit;
buildGoModule = pkgs.buildGo117Module;
buildGoModule = pkgs.buildGo118Module;
};
flake-compat = import sources.flake-compat;
chain-maind = pkgs.callPackage sources.chain-main { rocksdb = null; };
Expand Down Expand Up @@ -55,7 +55,7 @@ import sources.nixpkgs {
rocksdb = final.callPackage ./rocksdb.nix { enableJemalloc = true; };
})
(_: pkgs: {
cosmovisor = pkgs.buildGo117Module rec {
cosmovisor = pkgs.buildGo118Module rec {
name = "cosmovisor";
src = sources.cosmos-sdk + "/cosmovisor";
subPackages = [ "./cmd/cosmovisor" ];
Expand Down
8 changes: 4 additions & 4 deletions nix/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@
"branch": "master",
"description": "Convert applications using Go modules to Nix expressions",
"homepage": null,
"owner": "yihuang",
"owner": "nix-community",
"repo": "gomod2nix",
"rev": "598c5ab1a677eee3c799e09d23bab8cecb9b1e2f",
"sha256": "0vfb1fjrx8vfzqgrk39ilwxlb591kyz4c0dazai5cl6hbxjb0i2w",
"rev": "89cd0675b96775aa3ee86e7c0cf5bc238dd27976",
"sha256": "1x7w9ibp9nxzsaqg9lm6sav0438rwdh76r9pi40hikzn4nl9w4p0",
"type": "tarball",
"url": "https://github.com/yihuang/gomod2nix/archive/598c5ab1a677eee3c799e09d23bab8cecb9b1e2f.tar.gz",
"url": "https://github.com/nix-community/gomod2nix/archive/89cd0675b96775aa3ee86e7c0cf5bc238dd27976.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"gravity-bridge": {
Expand Down
8 changes: 4 additions & 4 deletions x/cronos/keeper/evm_hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package keeper_test

import (
"fmt"
handlers "github.com/crypto-org-chain/cronos/x/cronos/keeper/evmhandlers"
"math/big"

handlers "github.com/crypto-org-chain/cronos/x/cronos/keeper/evmhandlers"

gravitytypes "github.com/peggyjv/gravity-bridge/module/v2/x/gravity/types"

"github.com/crypto-org-chain/cronos/app"
Expand All @@ -23,7 +24,6 @@ func (suite *KeeperTestSuite) TestEvmHooks() {
contract := common.BigToAddress(big.NewInt(1))
recipient := common.BigToAddress(big.NewInt(3))
sender := common.BigToAddress(big.NewInt(4))
denom := "testdenom"

testCases := []struct {
msg string
Expand Down Expand Up @@ -142,7 +142,7 @@ func (suite *KeeperTestSuite) TestEvmHooks() {
"success send to chain",
func() {
suite.SetupTest()
denom := "gravity0x0000000000000000000000000000000000000000"
denom := denomGravity

suite.app.CronosKeeper.SetExternalContractForDenom(suite.ctx, denom, contract)
coin := sdk.NewCoin(denom, sdk.NewInt(100))
Expand Down Expand Up @@ -177,7 +177,7 @@ func (suite *KeeperTestSuite) TestEvmHooks() {
balance = suite.app.BankKeeper.GetBalance(suite.ctx, sdk.AccAddress(contract.Bytes()), denom)
suite.Require().Equal(sdk.NewCoin(denom, sdk.NewInt(0)), balance)
// query unbatched SendToEthereum message exist
rsp, err := suite.app.GravityKeeper.UnbatchedSendToEthereums(sdk.WrapSDKContext(suite.ctx), &gravitytypes.UnbatchedSendToEthereumsRequest{
rsp, _ := suite.app.GravityKeeper.UnbatchedSendToEthereums(sdk.WrapSDKContext(suite.ctx), &gravitytypes.UnbatchedSendToEthereumsRequest{
SenderAddress: sdk.AccAddress(sender.Bytes()).String(),
})
suite.Require().Equal(1, len(rsp.SendToEthereums))
Expand Down
3 changes: 2 additions & 1 deletion x/cronos/keeper/evm_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package keeper_test

import (
"github.com/crypto-org-chain/cronos/x/cronos/types"
"math/big"

"github.com/crypto-org-chain/cronos/x/cronos/types"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
"github.com/evmos/ethermint/crypto/ethsecp256k1"
Expand Down
29 changes: 14 additions & 15 deletions x/cronos/keeper/evmhandlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
func (suite *KeeperTestSuite) TestSendToAccountHandler() {
contract := common.BigToAddress(big.NewInt(1))
recipient := common.BigToAddress(big.NewInt(3))
denom := "testdenom"
var data []byte

testCases := []struct {
Expand Down Expand Up @@ -99,8 +98,8 @@ func (suite *KeeperTestSuite) TestSendToChainHandler() {
contract := common.BigToAddress(big.NewInt(1))
sender := common.BigToAddress(big.NewInt(2))
recipient := common.BigToAddress(big.NewInt(3))
invalidDenom := "testdenom"
validDenom := "gravity0x0000000000000000000000000000000000000000"
invalidDenom := denom
validDenom := denomGravity
var data []byte

testCases := []struct {
Expand All @@ -120,7 +119,7 @@ func (suite *KeeperTestSuite) TestSendToChainHandler() {
balance := suite.app.BankKeeper.GetBalance(suite.ctx, sdk.AccAddress(contract.Bytes()), invalidDenom)
suite.Require().Equal(coin, balance)

input, err := evmhandlers.SendToChainEvent.Inputs.Pack(
input, _ := evmhandlers.SendToChainEvent.Inputs.Pack(
sender,
recipient,
coin.Amount.BigInt(),
Expand All @@ -143,7 +142,7 @@ func (suite *KeeperTestSuite) TestSendToChainHandler() {
balance := suite.app.BankKeeper.GetBalance(suite.ctx, sdk.AccAddress(contract.Bytes()), validDenom)
suite.Require().Equal(coin, balance)

input, err := evmhandlers.SendToChainEvent.Inputs.Pack(
input, _ := evmhandlers.SendToChainEvent.Inputs.Pack(
sender,
recipient,
coin.Amount.BigInt(),
Expand All @@ -165,7 +164,7 @@ func (suite *KeeperTestSuite) TestSendToChainHandler() {
balance := suite.app.BankKeeper.GetBalance(suite.ctx, sdk.AccAddress(contract.Bytes()), invalidDenom)
suite.Require().Equal(coin, balance)

input, err := evmhandlers.SendToChainEvent.Inputs.Pack(
input, _ := evmhandlers.SendToChainEvent.Inputs.Pack(
sender,
recipient,
coin.Amount.BigInt(),
Expand All @@ -188,7 +187,7 @@ func (suite *KeeperTestSuite) TestSendToChainHandler() {
balance := suite.app.BankKeeper.GetBalance(suite.ctx, sdk.AccAddress(contract.Bytes()), validDenom)
suite.Require().Equal(coin, balance)

input, err := evmhandlers.SendToChainEvent.Inputs.Pack(
input, _ := evmhandlers.SendToChainEvent.Inputs.Pack(
sender,
recipient,
coin.Amount.BigInt(),
Expand Down Expand Up @@ -233,7 +232,7 @@ func (suite *KeeperTestSuite) TestSendToChainHandler() {
func (suite *KeeperTestSuite) TestSendToIbcHandler() {
contract := common.BigToAddress(big.NewInt(1))
sender := common.BigToAddress(big.NewInt(2))
invalidDenom := "testdenom"
invalidDenom := denom
validDenom := CorrectIbcDenom
var data []byte

Expand All @@ -253,7 +252,7 @@ func (suite *KeeperTestSuite) TestSendToIbcHandler() {
balance := suite.app.BankKeeper.GetBalance(suite.ctx, sdk.AccAddress(contract.Bytes()), invalidDenom)
suite.Require().Equal(coin, balance)

input, err := evmhandlers.SendToIbcEvent.Inputs.Pack(
input, _ := evmhandlers.SendToIbcEvent.Inputs.Pack(
sender,
"recipient",
coin.Amount.BigInt(),
Expand All @@ -274,7 +273,7 @@ func (suite *KeeperTestSuite) TestSendToIbcHandler() {
balance := suite.app.BankKeeper.GetBalance(suite.ctx, sdk.AccAddress(contract.Bytes()), invalidDenom)
suite.Require().Equal(coin, balance)

input, err := evmhandlers.SendToIbcEvent.Inputs.Pack(
input, _ := evmhandlers.SendToIbcEvent.Inputs.Pack(
sender,
"recipient",
coin.Amount.BigInt(),
Expand All @@ -295,7 +294,7 @@ func (suite *KeeperTestSuite) TestSendToIbcHandler() {
balance := suite.app.BankKeeper.GetBalance(suite.ctx, sdk.AccAddress(contract.Bytes()), validDenom)
suite.Require().Equal(coin, balance)

input, err := evmhandlers.SendToIbcEvent.Inputs.Pack(
input, _ := evmhandlers.SendToIbcEvent.Inputs.Pack(
sender,
"recipient",
coin.Amount.BigInt(),
Expand Down Expand Up @@ -373,7 +372,7 @@ func (suite *KeeperTestSuite) TestSendCroToIbcHandler() {

// Mint coin for the module
suite.MintCoinsToModule(types.ModuleName, sdk.NewCoins(sdk.NewCoin(types.IbcCroDenomDefaultValue, sdk.NewInt(123))))
input, err := evmhandlers.SendToIbcEvent.Inputs.Pack(
input, _ := evmhandlers.SendToIbcEvent.Inputs.Pack(
sender,
"recipient",
coin.Amount.BigInt(),
Expand Down Expand Up @@ -431,7 +430,7 @@ func (suite *KeeperTestSuite) TestCancelSendToChainHandler() {
contract := common.BigToAddress(big.NewInt(1))
sender := common.BigToAddress(big.NewInt(2))
random := common.BigToAddress(big.NewInt(3))
validDenom := "gravity0x0000000000000000000000000000000000000000"
validDenom := denomGravity
var data []byte

testCases := []struct {
Expand All @@ -451,7 +450,7 @@ func (suite *KeeperTestSuite) TestCancelSendToChainHandler() {
balance := suite.app.BankKeeper.GetBalance(suite.ctx, sdk.AccAddress(sender.Bytes()), validDenom)
suite.Require().Equal(coin, balance)

input, err := evmhandlers.CancelSendToChainEvent.Inputs.Pack(
input, _ := evmhandlers.CancelSendToChainEvent.Inputs.Pack(
sender,
big.NewInt(1),
)
Expand Down Expand Up @@ -488,7 +487,7 @@ func (suite *KeeperTestSuite) TestCancelSendToChainHandler() {
suite.Require().Equal(sdk.NewCoin(validDenom, sdk.NewInt(0)), balance)

// Then cancel the SendToChain transaction
input, err := evmhandlers.CancelSendToChainEvent.Inputs.Pack(
input, _ := evmhandlers.CancelSendToChainEvent.Inputs.Pack(
sender,
big.NewInt(int64(resp.Id)),
)
Expand Down
17 changes: 12 additions & 5 deletions x/cronos/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ import (
"github.com/crypto-org-chain/cronos/app"
)

const (
denom = "testdenom"
denomGravity = "gravity0x0000000000000000000000000000000000000000"
)

func TestKeeperTestSuite(t *testing.T) {
suite.Run(t, new(KeeperTestSuite))
}
Expand Down Expand Up @@ -91,6 +96,7 @@ func (suite *KeeperTestSuite) DoSetupTest(t *testing.T) {

valAddr := sdk.ValAddress(suite.address.Bytes())
validator, err := stakingtypes.NewValidator(valAddr, priv.PubKey(), stakingtypes.Description{})
require.NoError(t, err)
err = suite.app.StakingKeeper.SetValidatorByConsAddr(suite.ctx, validator)
require.NoError(t, err)
err = suite.app.StakingKeeper.SetValidatorByConsAddr(suite.ctx, validator)
Expand All @@ -117,7 +123,8 @@ func (suite *KeeperTestSuite) MintCoins(address sdk.AccAddress, coins sdk.Coins)
}

func (suite *KeeperTestSuite) RegisterSourceToken(
contractAddress, symbol string, decimal uint32) error {
contractAddress, symbol string, decimal uint32,
) error {
denom := "cronos" + contractAddress
msg := types.MsgUpdateTokenMapping{
Denom: denom,
Expand All @@ -129,8 +136,8 @@ func (suite *KeeperTestSuite) RegisterSourceToken(
}

func (suite *KeeperTestSuite) TestDenomContractMap() {
denom1 := "testdenom1"
denom2 := "testdenom2"
denom1 := denom + "1"
denom2 := denom + "2"

autoContract := common.BigToAddress(big.NewInt(1))
externalContract := common.BigToAddress(big.NewInt(2))
Expand All @@ -144,12 +151,12 @@ func (suite *KeeperTestSuite) TestDenomContractMap() {
func() {
keeper := suite.app.CronosKeeper

contract, found := keeper.GetContractByDenom(suite.ctx, denom1)
_, found := keeper.GetContractByDenom(suite.ctx, denom1)
suite.Require().False(found)

keeper.SetAutoContractForDenom(suite.ctx, denom1, autoContract)

contract, found = keeper.GetContractByDenom(suite.ctx, denom1)
contract, found := keeper.GetContractByDenom(suite.ctx, denom1)
suite.Require().True(found)
suite.Require().Equal(autoContract, contract)

Expand Down
4 changes: 2 additions & 2 deletions x/cronos/keeper/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ func (suite *KeeperTestSuite) TestGetSourceChannelID() {
)
suite.app.CronosKeeper = cronosKeeper

channelId, err := suite.app.CronosKeeper.GetSourceChannelID(suite.ctx, tc.ibcDenom)
channelID, err := suite.app.CronosKeeper.GetSourceChannelID(suite.ctx, tc.ibcDenom)
if tc.expectedError != nil {
suite.Require().EqualError(err, tc.expectedError.Error())
} else {
suite.Require().NoError(err)
tc.postCheck(channelId)
tc.postCheck(channelID)
}
})
}
Expand Down
Loading

0 comments on commit e54a893

Please sign in to comment.