diff --git a/settings/protocol/inflation.go b/settings/protocol/inflation.go index abf01901..9687e7b0 100644 --- a/settings/protocol/inflation.go +++ b/settings/protocol/inflation.go @@ -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) diff --git a/tests/dao/proposals_test.go b/tests/dao/proposals_test.go index 5c7a1a85..543ae028 100644 --- a/tests/dao/proposals_test.go +++ b/tests/dao/proposals_test.go @@ -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) } diff --git a/tests/dao/trustednode/proposals_test.go b/tests/dao/trustednode/proposals_test.go index dd4012bb..1a41e38a 100644 --- a/tests/dao/trustednode/proposals_test.go +++ b/tests/dao/trustednode/proposals_test.go @@ -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) } @@ -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) } @@ -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) } @@ -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) } diff --git a/tests/rewards/node_test.go b/tests/rewards/node_test.go index 1ab1c2e4..1025d208 100644 --- a/tests/rewards/node_test.go +++ b/tests/rewards/node_test.go @@ -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 { @@ -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 { @@ -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 { diff --git a/tests/rewards/trusted_node_test.go b/tests/rewards/trusted_node_test.go index be087792..210de3ea 100644 --- a/tests/rewards/trusted_node_test.go +++ b/tests/rewards/trusted_node_test.go @@ -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 { @@ -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 { @@ -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 { diff --git a/tests/settings/protocol/inflation_test.go b/tests/settings/protocol/inflation_test.go index 59fee7d3..df30e8b0 100644 --- a/tests/settings/protocol/inflation_test.go +++ b/tests/settings/protocol/inflation_test.go @@ -2,8 +2,9 @@ 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" ) @@ -11,8 +12,6 @@ import ( 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) } }) @@ -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 { diff --git a/tests/settings/trustednode/members_test.go b/tests/settings/trustednode/members_test.go index 77c5dd14..8dbde2e0 100644 --- a/tests/settings/trustednode/members_test.go +++ b/tests/settings/trustednode/members_test.go @@ -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) } diff --git a/tests/settings/trustednode/proposals_test.go b/tests/settings/trustednode/proposals_test.go index 55a526d0..2f518ad0 100644 --- a/tests/settings/trustednode/proposals_test.go +++ b/tests/settings/trustednode/proposals_test.go @@ -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) } diff --git a/tests/testutils/evm/mining.go b/tests/testutils/evm/mining.go index e205482e..998d5fd5 100644 --- a/tests/testutils/evm/mining.go +++ b/tests/testutils/evm/mining.go @@ -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 diff --git a/tests/tokens/rpl_test.go b/tests/tokens/rpl_test.go index c397558d..390edb87 100644 --- a/tests/tokens/rpl_test.go +++ b/tests/tokens/rpl_test.go @@ -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" ) @@ -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)