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

Add pre-commit #12

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
repos:
- repo: https://github.com/golangci/golangci-lint
rev: v1.50.1
hooks:
- id: golangci-lint
2 changes: 2 additions & 0 deletions legacy/v1.0.0/minipool/minipool.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Package minipool is legacy so no linting is applied.
//nolint:all
package minipool

import (
Expand Down
2 changes: 1 addition & 1 deletion minipool/minipool-contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ func (mp *Minipool) GetPrestakeEvent(intervalSize *big.Int, opts *bind.CallOpts)

// Decode the event
prestakeEvent := new(minipoolPrestakeEvent)
mp.Contract.Contract.UnpackLog(prestakeEvent, "MinipoolPrestaked", log)
err = mp.Contract.Contract.UnpackLog(prestakeEvent, "MinipoolPrestaked", log)
if err != nil {
return PrestakeData{}, fmt.Errorf("Error unpacking prestake data: %w", err)
}
Expand Down
32 changes: 16 additions & 16 deletions minipool/minipool.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,23 +362,23 @@ func GetMinipoolCountPerStatus(rp *rocketpool.RocketPool, opts *bind.CallOpts) (
if err := rocketMinipoolManager.Call(opts, newMinipoolCounts, "getMinipoolCountPerStatus", offset, limit); err != nil {
return MinipoolCountsPerStatus{}, fmt.Errorf("Could not get minipool counts: %w", err)
}
if newMinipoolCounts != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linter flagged that this is always true

if newMinipoolCounts.Initialized != nil {
minipoolCounts.Initialized.Add(minipoolCounts.Initialized, newMinipoolCounts.Initialized)
}
if newMinipoolCounts.Prelaunch != nil {
minipoolCounts.Prelaunch.Add(minipoolCounts.Prelaunch, newMinipoolCounts.Prelaunch)
}
if newMinipoolCounts.Staking != nil {
minipoolCounts.Staking.Add(minipoolCounts.Staking, newMinipoolCounts.Staking)
}
if newMinipoolCounts.Dissolved != nil {
minipoolCounts.Dissolved.Add(minipoolCounts.Dissolved, newMinipoolCounts.Dissolved)
}
if newMinipoolCounts.Withdrawable != nil {
minipoolCounts.Withdrawable.Add(minipoolCounts.Withdrawable, newMinipoolCounts.Withdrawable)
}

if newMinipoolCounts.Initialized != nil {
minipoolCounts.Initialized.Add(minipoolCounts.Initialized, newMinipoolCounts.Initialized)
}
if newMinipoolCounts.Prelaunch != nil {
minipoolCounts.Prelaunch.Add(minipoolCounts.Prelaunch, newMinipoolCounts.Prelaunch)
}
if newMinipoolCounts.Staking != nil {
minipoolCounts.Staking.Add(minipoolCounts.Staking, newMinipoolCounts.Staking)
}
if newMinipoolCounts.Dissolved != nil {
minipoolCounts.Dissolved.Add(minipoolCounts.Dissolved, newMinipoolCounts.Dissolved)
}
if newMinipoolCounts.Withdrawable != nil {
minipoolCounts.Withdrawable.Add(minipoolCounts.Withdrawable, newMinipoolCounts.Withdrawable)
}

}
return minipoolCounts, nil
}
Expand Down
44 changes: 22 additions & 22 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,28 @@ type NodeDetails struct {
}

// Node details
type nodeDetails_Native struct {
exists bool
registrationTime *big.Int
timezoneLocation string
feeDistributorInitialised bool
feeDistributorAddress common.Address
rewardNetwork *big.Int
rplStake *big.Int
effectiveRPLStake *big.Int
minimumRPLStake *big.Int
maximumRPLStake *big.Int
minipoolLimit *big.Int
minipoolCount *big.Int
balanceETH *big.Int
balanceRETH *big.Int
balanceRPL *big.Int
balanceOldRPL *big.Int
withdrawalAddress common.Address
pendingWithdrawalAddress common.Address
smoothingPoolRegistrationState bool
smoothingPoolRegistrationChanged *big.Int
}
//type nodeDetails_Native struct {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unused, but looks like active development so commented it out.

// exists bool
// registrationTime *big.Int
// timezoneLocation string
// feeDistributorInitialised bool
// feeDistributorAddress common.Address
// rewardNetwork *big.Int
// rplStake *big.Int
// effectiveRPLStake *big.Int
// minimumRPLStake *big.Int
// maximumRPLStake *big.Int
// minipoolLimit *big.Int
// minipoolCount *big.Int
// balanceETH *big.Int
// balanceRETH *big.Int
// balanceRPL *big.Int
// balanceOldRPL *big.Int
// withdrawalAddress common.Address
// pendingWithdrawalAddress common.Address
// smoothingPoolRegistrationState bool
// smoothingPoolRegistrationChanged *big.Int
//}

// Count of nodes belonging to a timezone
type TimezoneCount struct {
Expand Down
19 changes: 0 additions & 19 deletions rocketpool/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,25 +157,6 @@ func (c *Contract) estimateGasLimit(opts *bind.TransactOpts, input []byte) (uint

}

// Wait for a transaction to be mined and get a tx receipt
func (c *Contract) getTransactionReceipt(tx *types.Transaction) (*types.Receipt, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused method. Since no recent development on this, deleted.


// Wait for transaction to be mined
txReceipt, err := bind.WaitMined(context.Background(), c.Client, tx)
if err != nil {
return nil, err
}

// Check transaction status
if txReceipt.Status == 0 {
return txReceipt, errors.New("Transaction failed with status 0")
}

// Return
return txReceipt, nil

}

// Get contract events from a transaction
// eventPrototype must be an event struct type
// Returns a slice of untyped values; assert returned events to event struct type
Expand Down
4 changes: 2 additions & 2 deletions storage/address-queue-storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func GetAddressQueueLength(rp *rocketpool.RocketPool, opts *bind.CallOpts, key [
}
length := new(*big.Int)
if err := addressQueueStorage.Call(opts, length, "getIndexOf", key); err != nil {
return 0, fmt.Errorf("Could not get address queue length for key: %w", key, err)
return 0, fmt.Errorf("Could not get address queue length for key %x: %w", key, err)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chose %x lower-case hexadecimal repr for [32]bytes object

}
return (*length).Uint64(), nil
}
Expand All @@ -33,7 +33,7 @@ func GetAddressQueueItem(rp *rocketpool.RocketPool, opts *bind.CallOpts, key [32
}
address := new(common.Address)
if err := addressQueueStorage.Call(opts, address, "getItem", key, index); err != nil {
return common.Address{}, fmt.Errorf("Could not get address item at index %d: %w", index, key, err)
return common.Address{}, fmt.Errorf("Could not get address item at index %d for key %x: %w", index, key, err)
}
return *address, nil
}
Expand Down
4 changes: 2 additions & 2 deletions tests/dao/trustednode/dao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,12 @@ func TestUpgradeContract(t *testing.T) {
}

// Get & check updated contract details
if contractAddress, err := rp.GetAddress(contractName); err != nil {
if contractAddress, err := rp.GetAddress(contractName, nil); err != nil {
t.Error(err)
} else if !bytes.Equal(contractAddress.Bytes(), contractNewAddress.Bytes()) {
t.Errorf("Incorrect updated contract address %s", contractAddress.Hex())
}
if contractAbi, err := rp.GetABI(contractName); err != nil {
if contractAbi, err := rp.GetABI(contractName, nil); err != nil {
t.Error(err)
} else if _, ok := contractAbi.Methods["foo"]; !ok {
t.Errorf("Incorrect updated contract ABI")
Expand Down
4 changes: 2 additions & 2 deletions tests/dao/trustednode/proposals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,12 +298,12 @@ func TestProposeUpgradeContract(t *testing.T) {
}

// Get & check updated contract details
if contractAddress, err := rp.GetAddress(proposalContractName); err != nil {
if contractAddress, err := rp.GetAddress(proposalContractName, nil); err != nil {
t.Error(err)
} else if !bytes.Equal(contractAddress.Bytes(), proposalContractAddress.Bytes()) {
t.Errorf("Incorrect updated contract address %s", contractAddress.Hex())
}
if contractAbi, err := rp.GetABI(proposalContractName); err != nil {
if contractAbi, err := rp.GetABI(proposalContractName, nil); err != nil {
t.Error(err)
} else if _, ok := contractAbi.Methods["foo"]; !ok {
t.Errorf("Incorrect updated contract ABI")
Expand Down
4 changes: 3 additions & 1 deletion tests/minipool/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,9 @@ func TestClose(t *testing.T) {
if err != nil {
t.Errorf("Error sending ETH to minipool: %s", err.Error())
}
utils.WaitForTransaction(rp.Client, hash)
if _, err := utils.WaitForTransaction(rp.Client, hash); err != nil {
t.Fatal(err)
}

// Close minipool
if _, err := mp.Close(nodeAccount.GetTransactor()); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions tests/node/staking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestStakeRPL(t *testing.T) {
}

// Approve RPL transfer for staking
rocketNodeStakingAddress, err := rp.GetAddress("rocketNodeStaking")
rocketNodeStakingAddress, err := rp.GetAddress("rocketNodeStaking", nil)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -142,7 +142,7 @@ func TestStakeRPL(t *testing.T) {
if err != nil {
t.Fatal(err)
}
mp, err := minipool.NewMinipool(rp, minipoolAddress)
mp, err := minipool.NewMinipool(rp, minipoolAddress, nil)
if err != nil {
t.Fatal(err)
}
Expand Down
7 changes: 5 additions & 2 deletions tests/rewards/node_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Package rewards has some outdated function references, so no linting is applied for now.
//
//nolint:all
package rewards

import (
Expand Down Expand Up @@ -119,9 +122,9 @@ func TestNodeRewards(t *testing.T) {
}

// Get & check initial RPL rewards amount
if pendingRewards, err := rewards.GetPendingRewards(rp, nil); err != nil {
if pendingRewards, err := rewards.GetPendingRPLRewards(rp, nil); err != nil {
t.Error(err)
} else if pendingRewards != 0 {
} else if pendingRewards != big.NewInt(0) {
t.Errorf("Incorrect initial pending rewards amount %f", pendingRewards)
}

Expand Down
3 changes: 3 additions & 0 deletions tests/rewards/trusted_node_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Package rewards has some outdated function references, so no linting is applied for now.
//
//nolint:all
package rewards

import (
Expand Down
28 changes: 14 additions & 14 deletions tests/rocketpool/rocketpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import (
func TestGetAddress(t *testing.T) {

// Get contract address
address1, err := rp.GetAddress("rocketDepositPool")
address1, err := rp.GetAddress("rocketDepositPool", nil)
if err != nil {
t.Fatalf("Could not get contract address: %s", err)
} else if bytes.Equal(address1.Bytes(), common.Address{}.Bytes()) {
t.Error("Contract address was not found")
}

// Get cached contract address
address2, err := rp.GetAddress("rocketDepositPool")
address2, err := rp.GetAddress("rocketDepositPool", nil)
if err != nil {
t.Fatalf("Could not get cached contract address: %s", err)
} else if !bytes.Equal(address2.Bytes(), address1.Bytes()) {
Expand All @@ -31,7 +31,7 @@ func TestGetAddress(t *testing.T) {
func TestGetAddresses(t *testing.T) {

// Get contract addresses
addresses1, err := rp.GetAddresses("rocketNodeManager", "rocketNodeDeposit")
addresses1, err := rp.GetAddresses(nil, "rocketNodeManager", "rocketNodeDeposit")
if err != nil {
t.Fatalf("Could not get contract addresses: %s", err)
} else {
Expand All @@ -43,7 +43,7 @@ func TestGetAddresses(t *testing.T) {
}

// Get cached contract addresses
addresses2, err := rp.GetAddresses("rocketNodeManager", "rocketNodeDeposit")
addresses2, err := rp.GetAddresses(nil, "rocketNodeManager", "rocketNodeDeposit")
if err != nil {
t.Fatalf("Could not get cached contract addresses: %s", err)
} else {
Expand All @@ -59,13 +59,13 @@ func TestGetAddresses(t *testing.T) {
func TestGetABI(t *testing.T) {

// Get ABI
abi1, err := rp.GetABI("rocketDepositPool")
abi1, err := rp.GetABI("rocketDepositPool", nil)
if err != nil {
t.Fatalf("Could not get contract ABI: %s", err)
}

// Get cached ABI
abi2, err := rp.GetABI("rocketDepositPool")
abi2, err := rp.GetABI("rocketDepositPool", nil)
if err != nil {
t.Fatalf("Could not get cached contract ABI: %s", err)
} else {
Expand All @@ -87,13 +87,13 @@ func TestGetABI(t *testing.T) {
func TestGetABIs(t *testing.T) {

// Get ABIs
abis1, err := rp.GetABIs("rocketNodeManager", "rocketNodeDeposit")
abis1, err := rp.GetABIs(nil, "rocketNodeManager", "rocketNodeDeposit")
if err != nil {
t.Fatalf("Could not get contract ABIs: %s", err)
}

// Get cached ABIs
abis2, err := rp.GetABIs("rocketNodeManager", "rocketNodeDeposit")
abis2, err := rp.GetABIs(nil, "rocketNodeManager", "rocketNodeDeposit")
if err != nil {
t.Fatalf("Could not get cached contract ABIs: %s", err)
} else {
Expand All @@ -117,12 +117,12 @@ func TestGetABIs(t *testing.T) {
func TestGetContract(t *testing.T) {

// Get contract
if _, err := rp.GetContract("rocketDepositPool"); err != nil {
if _, err := rp.GetContract("rocketDepositPool", nil); err != nil {
t.Fatalf("Could not get contract: %s", err)
}

// Get cached contract
if _, err := rp.GetContract("rocketDepositPool"); err != nil {
if _, err := rp.GetContract("rocketDepositPool", nil); err != nil {
t.Fatalf("Could not get cached contract: %s", err)
}

Expand All @@ -131,12 +131,12 @@ func TestGetContract(t *testing.T) {
func TestGetContracts(t *testing.T) {

// Get contracts
if _, err := rp.GetContracts("rocketNodeManager", "rocketNodeDeposit"); err != nil {
if _, err := rp.GetContracts(nil, "rocketNodeManager", "rocketNodeDeposit"); err != nil {
t.Fatalf("Could not get contracts: %s", err)
}

// Get cached contracts
if _, err := rp.GetContracts("rocketNodeManager", "rocketNodeDeposit"); err != nil {
if _, err := rp.GetContracts(nil, "rocketNodeManager", "rocketNodeDeposit"); err != nil {
t.Fatalf("Could not get cached contracts: %s", err)
}

Expand All @@ -145,12 +145,12 @@ func TestGetContracts(t *testing.T) {
func TestMakeContract(t *testing.T) {

// Make contract
if _, err := rp.MakeContract("rocketMinipool", common.HexToAddress("0x1111111111111111111111111111111111111111")); err != nil {
if _, err := rp.MakeContract("rocketMinipool", common.HexToAddress("0x1111111111111111111111111111111111111111"), nil); err != nil {
t.Fatalf("Could not make contract: %s", err)
}

// Make contract with cached ABI
if _, err := rp.MakeContract("rocketMinipool", common.HexToAddress("0x2222222222222222222222222222222222222222")); err != nil {
if _, err := rp.MakeContract("rocketMinipool", common.HexToAddress("0x2222222222222222222222222222222222222222"), nil); err != nil {
t.Fatalf("Could not make contract with cached ABI: %s", err)
}

Expand Down
3 changes: 2 additions & 1 deletion tests/testutils/accounts/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ func GetAccount(index uint8) (*Account, error) {

// Get a transactor for an account
func (a *Account) GetTransactor() *bind.TransactOpts {
opts := bind.NewKeyedTransactor(a.PrivateKey)
// TODO: Update to `NewKeyedTransactorWithChainID`
opts := bind.NewKeyedTransactor(a.PrivateKey) //nolint:all
Comment on lines +46 to +47
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deprecated method. Can pick up in future PR.

opts.Context = context.Background()
return opts
}
6 changes: 3 additions & 3 deletions tests/testutils/minipool/minipool.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func CreateMinipool(t *testing.T, rp *rocketpool.RocketPool, ownerAccount, nodeA
}

// Get minipool manager contract
rocketMinipoolManager, err := rp.GetContract("rocketMinipoolManager")
rocketMinipoolManager, err := rp.GetContract("rocketMinipoolManager", nil)
if err != nil {
return nil, err
}
Expand All @@ -59,11 +59,11 @@ func CreateMinipool(t *testing.T, rp *rocketpool.RocketPool, ownerAccount, nodeA

// Sanity check to verify the created minipool is at the expected address
if expectedMinipoolAddress != minipoolAddress {
return nil, errors.New(fmt.Sprintf("Expected minipool address %s but got %s", expectedMinipoolAddress.Hex(), minipoolAddress.Hex()))
return nil, fmt.Errorf("Expected minipool address %s but got %s", expectedMinipoolAddress.Hex(), minipoolAddress.Hex())
}

// Return minipool instance
return minipool.NewMinipool(rp, minipoolAddress)
return minipool.NewMinipool(rp, minipoolAddress, nil)

}

Expand Down
2 changes: 1 addition & 1 deletion tests/testutils/node/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func Deposit(t *testing.T, rp *rocketpool.RocketPool, nodeAccount *accounts.Acco
if err != nil {
return common.Address{}, nil, fmt.Errorf("Error getting validator pubkey: %w", err)
}
expectedMinipoolAddress, err := utils.GenerateAddress(rp, nodeAccount.Address, depositType, salt, nil)
expectedMinipoolAddress, err := utils.GenerateAddress(rp, nodeAccount.Address, depositType, salt, nil, nil)
if err != nil {
return common.Address{}, nil, fmt.Errorf("Error generating minipool address: %w", err)
}
Expand Down
Loading