Skip to content

Commit f11ca3b

Browse files
committed
rename v8Test to RewardsTest
1 parent 607048e commit f11ca3b

File tree

4 files changed

+16
-412
lines changed

4 files changed

+16
-412
lines changed

shared/services/rewards/generator-v8_test.go

Lines changed: 6 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,21 @@ package rewards
22

33
import (
44
"fmt"
5-
"math/big"
65
"os"
76
"path/filepath"
87
"testing"
98

10-
"github.com/ethereum/go-ethereum/common"
11-
"github.com/ethereum/go-ethereum/core/types"
12-
"github.com/fatih/color"
13-
"github.com/rocket-pool/smartnode/shared/services/beacon"
149
"github.com/rocket-pool/smartnode/shared/services/rewards/test"
15-
"github.com/rocket-pool/smartnode/shared/services/rewards/test/assets"
1610
"github.com/rocket-pool/smartnode/shared/services/state"
17-
"github.com/rocket-pool/smartnode/shared/utils/log"
1811
)
1912

20-
type v8Test struct {
13+
type RewardsTest struct {
2114
*testing.T
2215
rp *test.MockRocketPool
2316
bc *test.MockBeaconClient
2417
}
2518

26-
func (t *v8Test) saveArtifacts(prefix string, result *GenerateTreeResult) {
19+
func (t *RewardsTest) saveArtifacts(prefix string, result *GenerateTreeResult) {
2720
tmpDir, err := os.MkdirTemp("", fmt.Sprintf("artifacts-%s", t.Name()))
2821
t.failIf(err)
2922
rewardsLocalFile := LocalFile[IRewardsFile]{
@@ -42,23 +35,23 @@ func (t *v8Test) saveArtifacts(prefix string, result *GenerateTreeResult) {
4235
t.Logf("wrote artifacts to %s\n", tmpDir)
4336
}
4437

45-
func newV8Test(t *testing.T, index uint64) *v8Test {
38+
func newRewardsTest(t *testing.T, index uint64) *RewardsTest {
4639
rp := test.NewMockRocketPool(t, index)
47-
out := &v8Test{
40+
out := &RewardsTest{
4841
T: t,
4942
rp: rp,
5043
bc: test.NewMockBeaconClient(t),
5144
}
5245
return out
5346
}
5447

55-
func (t *v8Test) failIf(err error) {
48+
func (t *RewardsTest) failIf(err error) {
5649
if err != nil {
5750
t.Fatal(err)
5851
}
5952
}
6053

61-
func (t *v8Test) SetMinipoolPerformance(canonicalMinipoolPerformance IPerformanceFile, networkState *state.NetworkState) {
54+
func (t *RewardsTest) SetMinipoolPerformance(canonicalMinipoolPerformance IPerformanceFile, networkState *state.NetworkState) {
6255
addresses := canonicalMinipoolPerformance.GetMinipoolAddresses()
6356
for _, address := range addresses {
6457

@@ -79,75 +72,3 @@ func (t *v8Test) SetMinipoolPerformance(canonicalMinipoolPerformance IPerformanc
7972
t.bc.SetMinipoolPerformance(validatorStatus.Index, missedSlots)
8073
}
8174
}
82-
83-
// TestV8Mainnet builds a tree using serialized state for a mainnet interval that used v8
84-
// and checks that the resulting artifacts match their canonical values.
85-
func TestV8Mainnet(tt *testing.T) {
86-
state := assets.GetMainnet20RewardsState()
87-
88-
t := newV8Test(tt, state.NetworkDetails.RewardIndex)
89-
90-
canonical, err := DeserializeRewardsFile(assets.GetMainnet20RewardsJSON())
91-
t.failIf(err)
92-
93-
canonicalPerformance, err := DeserializeMinipoolPerformanceFile(assets.GetMainnet20MinipoolPerformanceJSON())
94-
t.failIf(err)
95-
96-
t.Logf("pending rpl rewards: %s", state.NetworkDetails.PendingRPLRewards.String())
97-
98-
t.bc.SetState(state)
99-
100-
// Some interval info needed for mocks
101-
consensusStartBlock := canonical.GetConsensusStartBlock()
102-
executionStartBlock := canonical.GetExecutionStartBlock()
103-
consensusEndBlock := canonical.GetConsensusEndBlock()
104-
105-
// Create a new treeGeneratorImpl_v8
106-
logger := log.NewColorLogger(color.Faint)
107-
generator := newTreeGeneratorImpl_v8(
108-
&logger,
109-
t.Name(),
110-
state.NetworkDetails.RewardIndex,
111-
canonical.GetStartTime(),
112-
canonical.GetEndTime(),
113-
consensusEndBlock,
114-
&types.Header{
115-
Number: big.NewInt(int64(canonical.GetExecutionEndBlock())),
116-
Time: assets.Mainnet20ELHeaderTime,
117-
},
118-
canonical.GetIntervalsPassed(),
119-
state,
120-
)
121-
122-
// Load the mock up
123-
t.rp.SetRewardSnapshotEvent(assets.GetRewardSnapshotEventInterval19())
124-
t.bc.SetBeaconBlock(fmt.Sprint(consensusStartBlock-1), beacon.BeaconBlock{ExecutionBlockNumber: executionStartBlock - 1})
125-
t.bc.SetBeaconBlock(fmt.Sprint(consensusStartBlock), beacon.BeaconBlock{ExecutionBlockNumber: executionStartBlock})
126-
t.rp.SetHeaderByNumber(big.NewInt(int64(executionStartBlock)), &types.Header{Time: uint64(canonical.GetStartTime().Unix())})
127-
128-
// Set the critical duties slots
129-
t.bc.SetCriticalDutiesSlots(assets.GetMainnet20CriticalDutiesSlots())
130-
131-
// Set the minipool performance
132-
t.SetMinipoolPerformance(canonicalPerformance, state)
133-
134-
artifacts, err := generator.generateTree(
135-
t.rp,
136-
"mainnet",
137-
make([]common.Address, 0),
138-
t.bc,
139-
)
140-
t.failIf(err)
141-
142-
// Save the artifacts if verbose mode is enabled
143-
if testing.Verbose() {
144-
t.saveArtifacts("", artifacts)
145-
}
146-
147-
t.Logf("merkle root: %s\n", artifacts.RewardsFile.GetMerkleRoot())
148-
if artifacts.RewardsFile.GetMerkleRoot() != canonical.GetMerkleRoot() {
149-
t.Fatalf("Merkle root does not match %s", canonical.GetMerkleRoot())
150-
} else {
151-
t.Logf("merkle root matches %s", canonical.GetMerkleRoot())
152-
}
153-
}

0 commit comments

Comments
 (0)