Skip to content

Commit

Permalink
Fix time-based tests and speed up block-based delays
Browse files Browse the repository at this point in the history
  • Loading branch information
kanewallmann committed May 17, 2021
1 parent c873863 commit a8a504f
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 92 deletions.
17 changes: 0 additions & 17 deletions settings/protocol/inflation.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,6 @@ func BootstrapInflationIntervalRate(rp *rocketpool.RocketPool, value float64, op
}


// RPL inflation interval time
func GetInflationIntervalTime(rp *rocketpool.RocketPool, opts *bind.CallOpts) (uint64, error) {
inflationSettingsContract, err := getInflationSettingsContract(rp)
if err != nil {
return 0, err
}
value := new(*big.Int)
if err := inflationSettingsContract.Call(opts, value, "getInflationIntervalTime"); err != nil {
return 0, fmt.Errorf("Could not get inflation interval: %w", err)
}
return (*value).Uint64(), nil
}
func BootstrapInflationIntervalTime(rp *rocketpool.RocketPool, value uint64, opts *bind.TransactOpts) (common.Hash, error) {
return protocoldao.BootstrapUint(rp, InflationSettingsContractName, "rpl.inflation.interval.time", big.NewInt(int64(value)), opts)
}


// RPL inflation start time
func GetInflationStartTime(rp *rocketpool.RocketPool, opts *bind.CallOpts) (uint64, error) {
inflationSettingsContract, err := getInflationSettingsContract(rp)
Expand Down
1 change: 1 addition & 0 deletions tests/dao/proposals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func TestProposalDetails(t *testing.T) {

// Set proposal cooldown
if _, err := trustednodesettings.BootstrapProposalCooldown(rp, 0, ownerAccount.GetTransactor()); err != nil { t.Fatal(err) }
if _, err := trustednodesettings.BootstrapProposalVoteDelayBlocks(rp, 5, ownerAccount.GetTransactor()); err != nil { t.Fatal(err) }

// Register nodes
if _, err := node.RegisterNode(rp, "Australia/Brisbane", nodeAccount.GetTransactor()); err != nil { t.Fatal(err) }
Expand Down
4 changes: 4 additions & 0 deletions tests/dao/trustednode/proposals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func TestProposeInviteMember(t *testing.T) {

// Set proposal cooldown
if _, err := trustednodesettings.BootstrapProposalCooldown(rp, 0, ownerAccount.GetTransactor()); err != nil { t.Fatal(err) }
if _, err := trustednodesettings.BootstrapProposalVoteDelayBlocks(rp, 5, ownerAccount.GetTransactor()); err != nil { t.Fatal(err) }

// Register nodes
if _, err := node.RegisterNode(rp, "Australia/Brisbane", nodeAccount.GetTransactor()); err != nil { t.Fatal(err) }
Expand Down Expand Up @@ -87,6 +88,7 @@ func TestProposeMemberLeave(t *testing.T) {

// Set proposal cooldown
if _, err := trustednodesettings.BootstrapProposalCooldown(rp, 0, ownerAccount.GetTransactor()); err != nil { t.Fatal(err) }
if _, err := trustednodesettings.BootstrapProposalVoteDelayBlocks(rp, 5, ownerAccount.GetTransactor()); err != nil { t.Fatal(err) }

// Register nodes
if err := nodeutils.RegisterTrustedNode(rp, ownerAccount, trustedNodeAccount1); err != nil { t.Fatal(err) }
Expand Down Expand Up @@ -149,6 +151,7 @@ func TestProposeKickMember(t *testing.T) {

// Set proposal cooldown
if _, err := trustednodesettings.BootstrapProposalCooldown(rp, 0, ownerAccount.GetTransactor()); err != nil { t.Fatal(err) }
if _, err := trustednodesettings.BootstrapProposalVoteDelayBlocks(rp, 5, ownerAccount.GetTransactor()); err != nil { t.Fatal(err) }

// Register nodes
if err := nodeutils.RegisterTrustedNode(rp, ownerAccount, trustedNodeAccount1); err != nil { t.Fatal(err) }
Expand Down Expand Up @@ -193,6 +196,7 @@ func TestProposeUpgradeContract(t *testing.T) {

// Set proposal cooldown
if _, err := trustednodesettings.BootstrapProposalCooldown(rp, 0, ownerAccount.GetTransactor()); err != nil { t.Fatal(err) }
if _, err := trustednodesettings.BootstrapProposalVoteDelayBlocks(rp, 5, ownerAccount.GetTransactor()); err != nil { t.Fatal(err) }

// Register node
if err := nodeutils.RegisterTrustedNode(rp, ownerAccount, trustedNodeAccount1); err != nil { t.Fatal(err) }
Expand Down
43 changes: 21 additions & 22 deletions tests/rewards/node_test.go
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
package rewards

import (
"context"
"math/big"
"testing"

"github.com/rocket-pool/rocketpool-go/node"
"github.com/rocket-pool/rocketpool-go/rewards"
"github.com/rocket-pool/rocketpool-go/settings/protocol"
"github.com/rocket-pool/rocketpool-go/tokens"
"github.com/rocket-pool/rocketpool-go/utils/eth"

"github.com/rocket-pool/rocketpool-go/tests/testutils/evm"
minipoolutils "github.com/rocket-pool/rocketpool-go/tests/testutils/minipool"
"context"
"github.com/rocket-pool/rocketpool-go/node"
"github.com/rocket-pool/rocketpool-go/rewards"
"github.com/rocket-pool/rocketpool-go/settings/protocol"
"github.com/rocket-pool/rocketpool-go/tests/testutils/evm"
minipoolutils "github.com/rocket-pool/rocketpool-go/tests/testutils/minipool"
"github.com/rocket-pool/rocketpool-go/tokens"
"github.com/rocket-pool/rocketpool-go/utils/eth"
"math/big"
"testing"
)


func TestNodeRewards(t *testing.T) {

var secondsPerBlock uint64 = 12

// State snapshotting
if err := evm.TakeSnapshot(); err != nil { t.Fatal(err) }
t.Cleanup(func() { if err := evm.RevertSnapshot(); err != nil { t.Fatal(err) } })

// Constants
oneDay := uint64(24 * 60 * 60)
rewardInterval := oneDay

// Register node
if _, err := node.RegisterNode(rp, "Australia/Brisbane", nodeAccount.GetTransactor()); err != nil { t.Fatal(err) }

// Set network parameters
if _, err := protocol.BootstrapRewardsClaimIntervalTime(rp, 5 * secondsPerBlock, ownerAccount.GetTransactor()); err != nil { t.Fatal(err) }
if _, err := protocol.BootstrapInflationIntervalTime(rp, 5 * secondsPerBlock, ownerAccount.GetTransactor()); err != nil { t.Fatal(err) }
if _, err := protocol.BootstrapRewardsClaimIntervalTime(rp, rewardInterval, ownerAccount.GetTransactor()); err != nil { t.Fatal(err) }

// Get & check node claims enabled status
if claimsEnabled, err := rewards.GetNodeClaimsEnabled(rp, nil); err != nil {
Expand All @@ -45,9 +44,8 @@ func TestNodeRewards(t *testing.T) {
t.Error("Incorrect initial node claim possible status")
}

// Mine blocks until node claims are possible
if err := evm.MineBlocks(5); err != nil { t.Fatal(err) }
if err := evm.IncreaseTime(5 * secondsPerBlock); err != nil { t.Fatal(err) }
// Increase time until node claims are possible
if err := evm.IncreaseTime(rewardInterval); err != nil { t.Fatal(err) }

// Get & check updated node claim possible status
if nodeClaimPossible, err := rewards.GetNodeClaimPossible(rp, nodeAccount.Address, nil); err != nil {
Expand Down Expand Up @@ -83,13 +81,14 @@ func TestNodeRewards(t *testing.T) {
// Start RPL inflation
if header, err := rp.Client.HeaderByNumber(context.Background(), nil); err != nil {
t.Fatal(err)
} else if _, err := protocol.BootstrapInflationStartTime(rp, (header.Number.Uint64() + 2) * secondsPerBlock, ownerAccount.GetTransactor()); err != nil {
} else if _, err := protocol.BootstrapInflationStartTime(rp, header.Time + oneDay, ownerAccount.GetTransactor()); err != nil {
t.Fatal(err)
}

// Mine blocks until rewards are available
if err := evm.MineBlocks(10); err != nil { t.Fatal(err) }
if err := evm.IncreaseTime(10 * secondsPerBlock); err != nil { t.Fatal(err) }
if err := evm.IncreaseTime(oneDay + oneDay); err != nil {
t.Fatal(err)
}

// Get & check updated node claim rewards amount
if rewardsAmount, err := rewards.GetNodeClaimRewardsAmount(rp, nodeAccount.Address, nil); err != nil {
Expand Down
38 changes: 18 additions & 20 deletions tests/rewards/trusted_node_test.go
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
package rewards

import (
"context"
"math/big"
"testing"

"github.com/rocket-pool/rocketpool-go/rewards"
"github.com/rocket-pool/rocketpool-go/settings/protocol"
"github.com/rocket-pool/rocketpool-go/tokens"

"github.com/rocket-pool/rocketpool-go/tests/testutils/evm"
nodeutils "github.com/rocket-pool/rocketpool-go/tests/testutils/node"
"context"
"github.com/rocket-pool/rocketpool-go/rewards"
"github.com/rocket-pool/rocketpool-go/settings/protocol"
"github.com/rocket-pool/rocketpool-go/tokens"
"math/big"
"testing"

"github.com/rocket-pool/rocketpool-go/tests/testutils/evm"
nodeutils "github.com/rocket-pool/rocketpool-go/tests/testutils/node"
)


func TestTrustedNodeRewards(t *testing.T) {

var secondsPerBlock uint64 = 12

// State snapshotting
if err := evm.TakeSnapshot(); err != nil { t.Fatal(err) }
t.Cleanup(func() { if err := evm.RevertSnapshot(); err != nil { t.Fatal(err) } })

// Constants
oneDay := uint64(24 * 60 * 60)
rewardInterval := oneDay

// Register node
if err := nodeutils.RegisterTrustedNode(rp, ownerAccount, trustedNodeAccount); err != nil { t.Fatal(err) }

// Set network parameters
if _, err := protocol.BootstrapRewardsClaimIntervalTime(rp, 5 * secondsPerBlock, ownerAccount.GetTransactor()); err != nil { t.Fatal(err) }
if _, err := protocol.BootstrapInflationIntervalTime(rp, 5 * secondsPerBlock, ownerAccount.GetTransactor()); err != nil { t.Fatal(err) }
if _, err := protocol.BootstrapRewardsClaimIntervalTime(rp, rewardInterval, ownerAccount.GetTransactor()); err != nil { t.Fatal(err) }

// Get & check trusted node claims enabled status
if claimsEnabled, err := rewards.GetTrustedNodeClaimsEnabled(rp, nil); err != nil {
Expand All @@ -43,9 +43,8 @@ func TestTrustedNodeRewards(t *testing.T) {
t.Error("Incorrect initial trusted node claim possible status")
}

// Mine blocks until trusted node claims are possible
if err := evm.MineBlocks(5); err != nil { t.Fatal(err) }
if err := evm.IncreaseTime(5 * secondsPerBlock); err != nil { t.Fatal(err) }
// Increase time until node claims are possible
if err := evm.IncreaseTime(rewardInterval); err != nil { t.Fatal(err) }

// Get & check updated trusted node claim possible status
if nodeClaimPossible, err := rewards.GetTrustedNodeClaimPossible(rp, trustedNodeAccount.Address, nil); err != nil {
Expand All @@ -71,13 +70,12 @@ func TestTrustedNodeRewards(t *testing.T) {
// Start RPL inflation
if header, err := rp.Client.HeaderByNumber(context.Background(), nil); err != nil {
t.Fatal(err)
} else if _, err := protocol.BootstrapInflationStartTime(rp, (header.Number.Uint64() + 2) * secondsPerBlock, ownerAccount.GetTransactor()); err != nil {
} else if _, err := protocol.BootstrapInflationStartTime(rp, header.Time + oneDay, ownerAccount.GetTransactor()); err != nil {
t.Fatal(err)
}

// Mine blocks until rewards are available
if err := evm.MineBlocks(10); err != nil { t.Fatal(err) }
if err := evm.IncreaseTime(10 * secondsPerBlock); err != nil { t.Fatal(err) }
if err := evm.IncreaseTime(oneDay + oneDay); err != nil { t.Fatal(err) }

// Get & check updated trusted node claim rewards amount
if rewardsAmount, err := rewards.GetTrustedNodeClaimRewardsAmount(rp, trustedNodeAccount.Address, nil); err != nil {
Expand Down
17 changes: 3 additions & 14 deletions tests/settings/protocol/inflation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ package protocol

import (
"testing"
"time"

"github.com/rocket-pool/rocketpool-go/settings/protocol"
"github.com/rocket-pool/rocketpool-go/settings/protocol"

"github.com/rocket-pool/rocketpool-go/tests/testutils/evm"
)


func TestInflationSettings(t *testing.T) {

var secondsPerBlock uint64 = 12

// State snapshotting
if err := evm.TakeSnapshot(); err != nil { t.Fatal(err) }
t.Cleanup(func() { if err := evm.RevertSnapshot(); err != nil { t.Fatal(err) } })
Expand All @@ -27,18 +26,8 @@ func TestInflationSettings(t *testing.T) {
t.Error("Incorrect inflation interval rate value")
}

// Set & get inflation interval time
var inflationIntervalTime uint64 = 1 * secondsPerBlock
if _, err := protocol.BootstrapInflationIntervalTime(rp, inflationIntervalTime, ownerAccount.GetTransactor()); err != nil {
t.Error(err)
} else if value, err := protocol.GetInflationIntervalTime(rp, nil); err != nil {
t.Error(err)
} else if value != inflationIntervalTime {
t.Error("Incorrect inflation interval time value")
}

// Set & get inflation start block
var inflationStartTime uint64 = 1000000 * secondsPerBlock
inflationStartTime := uint64(time.Now().Unix()) + 3600
if _, err := protocol.BootstrapInflationStartTime(rp, inflationStartTime, ownerAccount.GetTransactor()); err != nil {
t.Error(err)
} else if value, err := protocol.GetInflationStartTime(rp, nil); err != nil {
Expand Down
1 change: 1 addition & 0 deletions tests/settings/trustednode/members_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func TestProposeMembersSettings(t *testing.T) {

// Set proposal cooldown
if _, err := trustednode.BootstrapProposalCooldown(rp, 0, ownerAccount.GetTransactor()); err != nil { t.Fatal(err) }
if _, err := trustednode.BootstrapProposalVoteDelayBlocks(rp, 5, ownerAccount.GetTransactor()); err != nil { t.Fatal(err) }

// Register trusted node
if err := nodeutils.RegisterTrustedNode(rp, ownerAccount, trustedNodeAccount); err != nil { t.Fatal(err) }
Expand Down
1 change: 1 addition & 0 deletions tests/settings/trustednode/proposals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func TestProposeProposalsSettings(t *testing.T) {

// Set proposal cooldown
if _, err := trustednode.BootstrapProposalCooldown(rp, 0, ownerAccount.GetTransactor()); err != nil { t.Fatal(err) }
if _, err := trustednode.BootstrapProposalVoteDelayBlocks(rp, 5, ownerAccount.GetTransactor()); err != nil { t.Fatal(err) }

// Register trusted node
if err := nodeutils.RegisterTrustedNode(rp, ownerAccount, trustedNodeAccount); err != nil { t.Fatal(err) }
Expand Down
1 change: 1 addition & 0 deletions tests/testutils/evm/mining.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func IncreaseTime(time uint64) error {

// Make RPC calls
if err := client.Call(nil, "evm_increaseTime", time); err != nil { return err }
if err := MineBlocks(1); err != nil { return err }

// Return
return nil
Expand Down
31 changes: 12 additions & 19 deletions tests/tokens/rpl_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package tokens

import (
"context"
"testing"
"testing"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"

"github.com/rocket-pool/rocketpool-go/settings/protocol"
"github.com/rocket-pool/rocketpool-go/tokens"
"github.com/rocket-pool/rocketpool-go/utils/eth"
"github.com/rocket-pool/rocketpool-go/settings/protocol"
"github.com/rocket-pool/rocketpool-go/tokens"
"github.com/rocket-pool/rocketpool-go/utils/eth"

"github.com/rocket-pool/rocketpool-go/tests/testutils/evm"
rplutils "github.com/rocket-pool/rocketpool-go/tests/testutils/tokens/rpl"
"github.com/rocket-pool/rocketpool-go/tests/testutils/evm"
rplutils "github.com/rocket-pool/rocketpool-go/tests/testutils/tokens/rpl"
)


Expand Down Expand Up @@ -111,25 +111,18 @@ func TestTransferFromRPL(t *testing.T) {

func TestMintInflationRPL(t *testing.T) {

var secondsPerBlock uint64 = 12

// State snapshotting
if err := evm.TakeSnapshot(); err != nil { t.Fatal(err) }
t.Cleanup(func() { if err := evm.RevertSnapshot(); err != nil { t.Fatal(err) } })

// Set network parameters
if _, err := protocol.BootstrapInflationIntervalTime(rp, 5 * secondsPerBlock, ownerAccount.GetTransactor()); err != nil { t.Fatal(err) }
// Constants
oneDay := uint64(24 * 60 * 60)

// Start RPL inflation
if header, err := rp.Client.HeaderByNumber(context.Background(), nil); err != nil {
t.Fatal(err)
} else if _, err := protocol.BootstrapInflationStartTime(rp, (header.Number.Uint64() + 2) * secondsPerBlock, ownerAccount.GetTransactor()); err != nil {
t.Fatal(err)
}
if _, err := protocol.BootstrapInflationStartTime(rp, uint64(time.Now().Unix() + 3600), ownerAccount.GetTransactor()); err != nil { t.Fatal(err) }

// Mine blocks until rewards are available
if err := evm.MineBlocks(10); err != nil { t.Fatal(err) }
if err := evm.IncreaseTime(10 * secondsPerBlock); err != nil { t.Fatal(err) }
if err := evm.IncreaseTime(3600 + oneDay); err != nil { t.Fatal(err) }

// Get initial total supply
rplTotalSupply1, err := tokens.GetRPLTotalSupply(rp, nil)
Expand Down

0 comments on commit a8a504f

Please sign in to comment.