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 1 commit
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
1 change: 1 addition & 0 deletions legacy/v1.0.0/minipool/minipool.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//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: 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
5 changes: 3 additions & 2 deletions tests/rewards/node_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//nolint:all
package rewards

import (
Expand Down Expand Up @@ -119,9 +120,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
1 change: 1 addition & 0 deletions tests/rewards/trusted_node_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//nolint:all
package rewards

import (
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
}
2 changes: 1 addition & 1 deletion tests/testutils/minipool/minipool.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ 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
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 @@ -68,7 +68,7 @@ func Deposit(t *testing.T, rp *rocketpool.RocketPool, nodeAccount *accounts.Acco
if err != nil {
return common.Address{}, nil, fmt.Errorf("Error executing deposit: %w", err)
}
txReceipt, err := utils.WaitForTransaction(rp.Client, hash)
txReceipt, err := utils.WaitForTransaction(rp.Client, hash.Hash())
if err != nil {
return common.Address{}, nil, fmt.Errorf("Error waiting for deposit transaction: %w", err)
}
Expand Down
56 changes: 45 additions & 11 deletions tests/utils/stage4_bootstrap.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package utils

import (
"log"
"time"

"github.com/rocket-pool/rocketpool-go/rocketpool"
Expand All @@ -14,17 +15,50 @@ func Stage4Bootstrap(rp *rocketpool.RocketPool, ownerAccount *accounts.Account)

opts := ownerAccount.GetTransactor()

protocol.BootstrapDepositEnabled(rp, true, opts)
protocol.BootstrapAssignDepositsEnabled(rp, true, opts)
protocol.BootstrapMaximumDepositPoolSize(rp, eth.EthToWei(1000), opts)
protocol.BootstrapNodeRegistrationEnabled(rp, true, opts)
protocol.BootstrapNodeDepositEnabled(rp, true, opts)
protocol.BootstrapMinipoolSubmitWithdrawableEnabled(rp, true, opts)
protocol.BootstrapMinimumNodeFee(rp, 0.05, opts)
protocol.BootstrapTargetNodeFee(rp, 0.1, opts)
protocol.BootstrapMaximumNodeFee(rp, 0.2, opts)
protocol.BootstrapNodeFeeDemandRange(rp, eth.EthToWei(1000), opts)
protocol.BootstrapInflationStartTime(rp,
_, err := protocol.BootstrapDepositEnabled(rp, true, opts)
if err != nil {
log.Fatal(err)
}
_, err = protocol.BootstrapAssignDepositsEnabled(rp, true, opts)
if err != nil {
log.Fatal(err)
}
_, err = protocol.BootstrapMaximumDepositPoolSize(rp, eth.EthToWei(1000), opts)
if err != nil {
log.Fatal(err)
}
_, err = protocol.BootstrapNodeRegistrationEnabled(rp, true, opts)
if err != nil {
log.Fatal(err)
}
_, err = protocol.BootstrapNodeDepositEnabled(rp, true, opts)
if err != nil {
log.Fatal(err)
}
_, err = protocol.BootstrapMinipoolSubmitWithdrawableEnabled(rp, true, opts)
if err != nil {
log.Fatal(err)
}
_, err = protocol.BootstrapMinimumNodeFee(rp, 0.05, opts)
if err != nil {
log.Fatal(err)
}
_, err = protocol.BootstrapTargetNodeFee(rp, 0.1, opts)
if err != nil {
log.Fatal(err)
}
_, err = protocol.BootstrapMaximumNodeFee(rp, 0.2, opts)
if err != nil {
log.Fatal(err)
}
_, err = protocol.BootstrapNodeFeeDemandRange(rp, eth.EthToWei(1000), opts)
if err != nil {
log.Fatal(err)
}
_, err = protocol.BootstrapInflationStartTime(rp,
uint64(time.Now().Unix()+(60*60*24*14)), opts)
if err != nil {
log.Fatal(err)
}

}