Skip to content

Commit

Permalink
Enable Formatting and linting (#180)
Browse files Browse the repository at this point in the history
Co-authored-by: Tyler Ruppert <{ID}+{username}@users.noreply.github.com>
  • Loading branch information
MechanicalTyler and Tyler Ruppert authored Jun 8, 2023
1 parent 5ab11da commit 4777164
Show file tree
Hide file tree
Showing 32 changed files with 174 additions and 270 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,17 @@ jobs:
go-version: '1.20'
- name: Run tests
run: go test -v ./...
- name: Go lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.51.2
args: --verbose
# Optional: if set to true then the all caching functionality will be complete disabled,
# takes precedence over all other caching options.
# skip-cache: true

# Optional: if set to true then the action don't cache or restore ~/go/pkg.
skip-pkg-cache: true

# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
skip-build-cache: true
16 changes: 15 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,28 @@ linters:
disable-all: true
enable:
- errcheck
- gci
- gofmt
- gofumpt
- goimports
- govet
- misspell
- unused
- gosec
fast: false

issues:
# Restricts maximum count of issues to display with the same text, and show all instead.
max-same-issues: 0
max-issues-per-linter: 0
exclude-rules:
# disabling some linters for test files
# disabling some linters for test files
- path: _test\.go
linters:
- errcheck
- gosec
# disabling some linters rules
exclude:
# gosec
- G101 # Potential hardcoded credentials
- G114 # Use of net/http serve function that has no support for setting timeouts
27 changes: 0 additions & 27 deletions chain/client_test.go

This file was deleted.

9 changes: 1 addition & 8 deletions chain/evm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"time"

"github.com/VolumeFi/whoops"
"github.com/cosmos/gogoproto/proto"
"github.com/ethereum/go-ethereum"
etherum "github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts"
Expand All @@ -27,7 +28,6 @@ import (
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/event"
"github.com/cosmos/gogoproto/proto"
compassABI "github.com/palomachain/pigeon/chain/evm/abi/compass"
"github.com/palomachain/pigeon/config"
"github.com/palomachain/pigeon/errors"
Expand All @@ -36,10 +36,6 @@ import (
log "github.com/sirupsen/logrus"
)

const (
smartContractFilename = "compass-evm"
)

type StoredContract struct {
ABI abi.ABI
Source []byte
Expand Down Expand Up @@ -161,7 +157,6 @@ type CompassBinding interface {

func (c *Client) init() error {
return whoops.Try(func() {

if !ethcommon.IsHexAddress(c.config.SigningKey) {
whoops.Assert(errors.Unrecoverable(ErrInvalidAddress.Format(c.config.SigningKey)))
}
Expand Down Expand Up @@ -362,7 +357,6 @@ func (c *Client) sign(ctx context.Context, bytes []byte) ([]byte, error) {
// splitting the possible set in two, recursively.
func (c *Client) FilterLogs(ctx context.Context, fq etherum.FilterQuery, currBlockHeight *big.Int, fn func(logs []ethtypes.Log) bool) (bool, error) {
found, err := filterLogs(ctx, c.conn, fq, currBlockHeight, true, fn)

if err != nil {
log.WithError(err).Error("error filtering logs")
}
Expand All @@ -385,7 +379,6 @@ type ethClientToFilterLogs interface {
}

func shouldDoBinarySearchFromError(err error) bool {

switch {
case strings.Contains(err.Error(), "query returned more than 10000 results"):
return true
Expand Down
1 change: 0 additions & 1 deletion chain/evm/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ func TestFilterLogs(t *testing.T) {
}

func TestFindingTheBlockNearestToTime(t *testing.T) {

type ethHeader struct {
height uint64
time uint64
Expand Down
6 changes: 0 additions & 6 deletions chain/evm/compass.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ const (
maxPower uint64 = 1 << 32
powerThreshold uint64 = 2_863_311_530
SignedMessagePrefix = "\x19Ethereum Signed Message:\n32"

valsetUpdatedABISignature = "ValsetUpdated(bytes32,uint256)"
)

//go:generate mockery --name=evmClienter --inpackage --testonly
Expand Down Expand Up @@ -206,7 +204,6 @@ func (t compass) submitLogicCall(
new(big.Int).SetInt64(int64(origMessage.ID)),
new(big.Int).SetInt64(msg.GetDeadline()),
})

if err != nil {
isSmartContractError := whoops.Must(t.tryProvidingEvidenceIfSmartContractErr(ctx, queueTypeName, origMessage.ID, err))
if isSmartContractError {
Expand Down Expand Up @@ -274,7 +271,6 @@ func (t compass) uploadSmartContract(
msg.GetBytecode(),
constructorInput,
)

if err != nil {
logger.
WithField("error", err.Error()).
Expand Down Expand Up @@ -310,7 +306,6 @@ func (t compass) tryProvidingEvidenceIfSmartContractErr(ctx context.Context, que
err := t.paloma.AddMessageEvidence(ctx, queueTypeName, msgID, &types.SmartContractExecutionErrorProof{
ErrorMessage: jsonRpcErr.Error(),
})

if err != nil {
return false, err
}
Expand All @@ -334,7 +329,6 @@ func (t compass) findLastValsetMessageID(ctx context.Context) (uint64, error) {

func (t compass) isArbitraryCallAlreadyExecuted(ctx context.Context, messageID uint64) (bool, error) {
blockNumber, err := t.evm.FindCurrentBlockNumber(ctx)

if err != nil {
return false, err
}
Expand Down
22 changes: 3 additions & 19 deletions chain/evm/compass_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,6 @@ func powerFromPercentage(p float64) uint64 {
return uint64(float64(maxPower) * p)
}

func valsetUpdatedEvent(blockNumber uint64, checkpoint string, valsetID int64) etherumtypes.Log {
compassABI := StoredContracts()["compass-evm"].ABI
// checkpoint bytes32
// valset_id uint256
var cp32 [32]byte
copy(cp32[:], []byte(checkpoint))
data, err := compassABI.Events["ValsetUpdated"].Inputs.Pack(cp32, big.NewInt(valsetID))
if err != nil {
panic(err)
}
return etherumtypes.Log{
BlockNumber: blockNumber,
Data: data,
}
}

func TestIsArbitraryCallAlreadyExecuted(t *testing.T) {
tests := []struct {
name string
Expand Down Expand Up @@ -608,7 +592,8 @@ func TestMessageProcessing(t *testing.T) {
return evm, paloma
},
expErr: nil,
}, {
},
{
name: "upload_smart_contract/when smart contract returns an error and sending it to paloma fails, it returns it back",
msgs: []chain.MessageWithSignatures{
{
Expand Down Expand Up @@ -710,7 +695,6 @@ func TestProcessingvalidatorBalancesRequest(t *testing.T) {
}

func TestProvidingEvidenceForAMessage(t *testing.T) {

addValidSignature := func(pk *ecdsa.PrivateKey) chain.ValidatorSignature {
return signMessage(ethCompatibleBytesToSign, pk)
}
Expand Down Expand Up @@ -799,8 +783,8 @@ func TestProvidingEvidenceForAMessage(t *testing.T) {
})
}
}
func TestIfTheConsensusHasBeenReached(t *testing.T) {

func TestIfTheConsensusHasBeenReached(t *testing.T) {
addValidSignature := func(pk *ecdsa.PrivateKey) chain.ValidatorSignature {
return signMessage(ethCompatibleBytesToSign, pk)
}
Expand Down
14 changes: 0 additions & 14 deletions chain/evm/deploy_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
log "github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -153,16 +152,3 @@ func deployContract(
})
return
}

func rawDeploy(opts *bind.TransactOpts, abi abi.ABI, bytecode []byte, backend bind.ContractBackend, packedConstructorInput []byte) (common.Address, *ethtypes.Transaction, error) {
// Otherwise try to deploy the contract
c := bind.NewBoundContract(common.Address{}, abi, backend, backend, backend)

tx, err := c.RawTransact(opts, append(bytecode, packedConstructorInput...))
logger := log.WithField("constructor-input", packedConstructorInput)
logger.Info("raw deploy")
if err != nil {
return common.Address{}, nil, err
}
return crypto.CreateAddress(opts.From, tx.Nonce()), tx, nil
}
1 change: 0 additions & 1 deletion chain/evm/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ func (f *Factory) Build(
blockHeightHash common.Hash,
minOnChainBalance *big.Int,
) (chain.Processor, error) {

var smartContractABI *abi.ABI
if len(smartContractABIJson) > 0 {
aabi, err := abi.JSON(strings.NewReader(smartContractABIJson))
Expand Down
1 change: 0 additions & 1 deletion chain/evm/health_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,4 @@ var _ = Describe("health check", func() {
})
})
})

})
5 changes: 1 addition & 4 deletions chain/evm/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@ type Processor struct {
chainType string
chainReferenceID string

turnstoneEVMContract common.Address
turnstoneEVMContract common.Address //nolint:unused

blockHeight int64
blockHeightHash common.Hash
minOnChainBalance *big.Int
}

var _ chain.Processor = Processor{}

func (p Processor) SupportedQueues() []string {
return slice.Map(
[]string{
Expand Down Expand Up @@ -78,7 +76,6 @@ func (p Processor) SignMessages(ctx context.Context, queueTypeName string, messa
}, nil
},
)

}

func (p Processor) ProcessMessages(ctx context.Context, queueTypeName string, msgs []chain.MessageWithSignatures) error {
Expand Down
7 changes: 3 additions & 4 deletions chain/paloma/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ import (
"time"

"github.com/VolumeFi/whoops"
coretypes "github.com/cometbft/cometbft/rpc/core/types"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/cosmos/gogoproto/grpc"
"github.com/cosmos/gogoproto/proto"
"github.com/strangelove-ventures/lens/client/query"

coretypes "github.com/cometbft/cometbft/rpc/core/types"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/palomachain/pigeon/chain"
"github.com/palomachain/pigeon/config"
consensus "github.com/palomachain/pigeon/types/paloma/x/consensus/types"
Expand All @@ -23,6 +21,7 @@ import (
valset "github.com/palomachain/pigeon/types/paloma/x/valset/types"
"github.com/palomachain/pigeon/util/slice"
log "github.com/sirupsen/logrus"
"github.com/strangelove-ventures/lens/client/query"
)

type ResultStatus = coretypes.ResultStatus
Expand Down
24 changes: 6 additions & 18 deletions chain/paloma/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import (
"net"
"testing"

"github.com/VolumeFi/whoops"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/gogoproto/proto"
"github.com/palomachain/pigeon/chain"
clientmocks "github.com/palomachain/pigeon/chain/paloma/mocks"
Expand All @@ -20,27 +22,11 @@ import (
lens "github.com/strangelove-ventures/lens/client"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

"google.golang.org/grpc/test/bufconn"

"github.com/VolumeFi/whoops"
"github.com/cosmos/cosmos-sdk/types/module"
"google.golang.org/grpc"
"google.golang.org/grpc/test/bufconn"
)

var (
errTestErr = errors.New("sample error")
simpleMessageTestData1 = &testdata.SimpleMessage{
Sender: "bob",
Hello: "mars",
World: "!",
}
simpleMessageTestData2 = &testdata.SimpleMessage{
Sender: "alice",
Hello: "jupiter",
World: "!",
}
)
var errTestErr = errors.New("sample error")

func consensusQueryServerDialer(t *testing.T, msgsrv *consensusmocks.QueryServer) func(context.Context, string) (net.Conn, error) {
listener := bufconn.Listen(1024 * 1024)
Expand Down Expand Up @@ -305,6 +291,7 @@ func TestGetMessagesInQueue(t *testing.T) {
})
}
}

func TestQueryValidatorInfo(t *testing.T) {
fakeErr := errors.New("something")
fakeExternalInfo := []*valset.ExternalChainInfo{
Expand Down Expand Up @@ -443,6 +430,7 @@ type mockMsgSender func(context.Context, sdk.Msg, string) (*sdk.TxResponse, erro
func (m mockMsgSender) SendMsg(ctx context.Context, msg sdk.Msg, memo string) (*sdk.TxResponse, error) {
return m(ctx, msg, memo)
}

func TestBroadcastingMessageSignatures(t *testing.T) {
ctx := context.Background()
for _, tt := range []struct {
Expand Down
3 changes: 1 addition & 2 deletions chain/paloma/collision/zero_collision.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Zero collision strategy ensures that all pigeons are using the same way of determinig if they can execute a message or not.
// Zero collision strategy ensures that all pigeons are using the same way of determining if they can execute a message or not.
// That way we can distribute the jobs without having to write data to paloma so that paloma could do it, as it could be slow.
// Of course, paloma does not care about the strategy pigeons are using. Somebody could rewrite pigeon to do send all the messages,
// but then they would be "fighting" with paloma and they (and other pigeons) would spend gas unceccecary.
Expand Down Expand Up @@ -143,7 +143,6 @@ func pickWinner(seed []byte, dump []byte, vals []sdk.ValAddress) sdk.ValAddress
}
return possibleWinners[0]
}

}

// rounds down the block height to the nearest 10
Expand Down
Loading

0 comments on commit 4777164

Please sign in to comment.