|
| 1 | +package rewards |
| 2 | + |
| 3 | +// This file contains treegen tests which use mock history. |
| 4 | +// These mocks are faster to process than real history, and are useful for |
| 5 | +// testing new features and refactoring. |
| 6 | + |
| 7 | +import ( |
| 8 | + "fmt" |
| 9 | + "math/big" |
| 10 | + "strings" |
| 11 | + "testing" |
| 12 | + |
| 13 | + "github.com/ethereum/go-ethereum/common" |
| 14 | + "github.com/ethereum/go-ethereum/core/types" |
| 15 | + "github.com/fatih/color" |
| 16 | + "github.com/rocket-pool/smartnode/shared/services/beacon" |
| 17 | + "github.com/rocket-pool/smartnode/shared/services/rewards/test" |
| 18 | + "github.com/rocket-pool/smartnode/shared/services/rewards/test/assets" |
| 19 | + "github.com/rocket-pool/smartnode/shared/utils/log" |
| 20 | +) |
| 21 | + |
| 22 | +func TestMockIntervalDefaultsTreegenv8v9(tt *testing.T) { |
| 23 | + t := newV8Test(tt) |
| 24 | + |
| 25 | + history := test.NewDefaultMockHistory() |
| 26 | + state := history.GetEndNetworkState() |
| 27 | + |
| 28 | + t.bc.SetState(state) |
| 29 | + |
| 30 | + consensusStartBlock := history.GetConsensusStartBlock() |
| 31 | + executionStartBlock := history.GetExecutionStartBlock() |
| 32 | + consensusEndBlock := history.GetConsensusEndBlock() |
| 33 | + executionEndBlock := history.GetExecutionEndBlock() |
| 34 | + |
| 35 | + logger := log.NewColorLogger(color.Faint) |
| 36 | + generator := newTreeGeneratorImpl_v8( |
| 37 | + &logger, |
| 38 | + t.Name(), |
| 39 | + state.NetworkDetails.RewardIndex, |
| 40 | + history.GetStartTime(), |
| 41 | + history.GetEndTime(), |
| 42 | + consensusEndBlock, |
| 43 | + &types.Header{ |
| 44 | + Number: big.NewInt(int64(history.GetExecutionEndBlock())), |
| 45 | + Time: assets.Mainnet20ELHeaderTime, |
| 46 | + }, |
| 47 | + /* intervalsPassed= */ 1, |
| 48 | + state, |
| 49 | + ) |
| 50 | + |
| 51 | + t.rp.SetRewardSnapshotEvent(history.GetPreviousRewardSnapshotEvent()) |
| 52 | + t.bc.SetBeaconBlock(fmt.Sprint(consensusStartBlock-1), beacon.BeaconBlock{ExecutionBlockNumber: executionStartBlock - 1}) |
| 53 | + t.bc.SetBeaconBlock(fmt.Sprint(consensusStartBlock), beacon.BeaconBlock{ExecutionBlockNumber: executionStartBlock}) |
| 54 | + t.rp.SetHeaderByNumber(big.NewInt(int64(executionStartBlock)), &types.Header{Time: uint64(history.GetStartTime().Unix())}) |
| 55 | + |
| 56 | + for _, validator := range state.ValidatorDetails { |
| 57 | + t.bc.SetMinipoolPerformance(validator.Index, make([]uint64, 0)) |
| 58 | + } |
| 59 | + |
| 60 | + v8Artifacts, err := generator.generateTree( |
| 61 | + t.rp, |
| 62 | + "mainnet", |
| 63 | + make([]common.Address, 0), |
| 64 | + t.bc, |
| 65 | + ) |
| 66 | + t.failIf(err) |
| 67 | + |
| 68 | + if testing.Verbose() { |
| 69 | + t.saveArtifacts("v8", v8Artifacts) |
| 70 | + } |
| 71 | + generatorv9 := newTreeGeneratorImpl_v9( |
| 72 | + &logger, |
| 73 | + t.Name(), |
| 74 | + state.NetworkDetails.RewardIndex, |
| 75 | + &SnapshotEnd{ |
| 76 | + Slot: consensusEndBlock, |
| 77 | + ConsensusBlock: consensusEndBlock, |
| 78 | + ExecutionBlock: executionEndBlock, |
| 79 | + }, |
| 80 | + &types.Header{ |
| 81 | + Number: big.NewInt(int64(history.GetExecutionEndBlock())), |
| 82 | + Time: assets.Mainnet20ELHeaderTime, |
| 83 | + }, |
| 84 | + /* intervalsPassed= */ 1, |
| 85 | + state, |
| 86 | + ) |
| 87 | + |
| 88 | + v9Artifacts, err := generatorv9.generateTree( |
| 89 | + t.rp, |
| 90 | + "mainnet", |
| 91 | + make([]common.Address, 0), |
| 92 | + t.bc, |
| 93 | + ) |
| 94 | + t.failIf(err) |
| 95 | + |
| 96 | + if testing.Verbose() { |
| 97 | + t.saveArtifacts("v9", v9Artifacts) |
| 98 | + } |
| 99 | + |
| 100 | + v8MerkleRoot := v8Artifacts.RewardsFile.GetMerkleRoot() |
| 101 | + v9MerkleRoot := v9Artifacts.RewardsFile.GetMerkleRoot() |
| 102 | + |
| 103 | + if !strings.EqualFold(v8MerkleRoot, v9MerkleRoot) { |
| 104 | + t.Fatalf("Merkle root does not match %s != %s", v8MerkleRoot, v9MerkleRoot) |
| 105 | + } else { |
| 106 | + t.Logf("v8/v9 Merkle root matches %s", v8MerkleRoot) |
| 107 | + } |
| 108 | +} |
0 commit comments