Skip to content

Commit

Permalink
Added time advancing to the unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jclapis committed May 13, 2021
1 parent e313519 commit a6a1634
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
4 changes: 3 additions & 1 deletion tests/rewards/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ func TestNodeRewards(t *testing.T) {
}

// Mine blocks until node claims are possible
if err := evm.MineBlocks(10); err != nil { t.Fatal(err) }
if err := evm.MineBlocks(5); err != nil { t.Fatal(err) }
if err := evm.IncreaseTime(5 * secondsPerBlock); 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 @@ -88,6 +89,7 @@ func TestNodeRewards(t *testing.T) {

// 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) }

// Get & check updated node claim rewards amount
if rewardsAmount, err := rewards.GetNodeClaimRewardsAmount(rp, nodeAccount.Address, nil); err != nil {
Expand Down
2 changes: 2 additions & 0 deletions tests/rewards/trusted_node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func TestTrustedNodeRewards(t *testing.T) {

// 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) }

// Get & check updated trusted node claim possible status
if nodeClaimPossible, err := rewards.GetTrustedNodeClaimPossible(rp, trustedNodeAccount.Address, nil); err != nil {
Expand Down Expand Up @@ -76,6 +77,7 @@ func TestTrustedNodeRewards(t *testing.T) {

// 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) }

// Get & check updated trusted node claim rewards amount
if rewardsAmount, err := rewards.GetTrustedNodeClaimRewardsAmount(rp, trustedNodeAccount.Address, nil); err != nil {
Expand Down
21 changes: 18 additions & 3 deletions tests/testutils/evm/mining.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package evm

import (
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/rpc"

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


// Mine a number of blocks
func MineBlocks(numBlocks int) error {

Expand All @@ -24,3 +23,19 @@ func MineBlocks(numBlocks int) error {

}


// Fast forward to some number of seconds
func IncreaseTime(time uint64) error {

// Initialize RPC client
client, err := rpc.Dial(tests.Eth1ProviderAddress)
if err != nil { return err }

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

// Return
return nil

}

1 change: 1 addition & 0 deletions tests/tokens/rpl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ func TestMintInflationRPL(t *testing.T) {

// 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) }

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

0 comments on commit a6a1634

Please sign in to comment.