-
Notifications
You must be signed in to change notification settings - Fork 215
Integration test rewards Andromeda #6875
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
b8c614a
0c39446
c8fd097
853973c
e01e07a
79732a6
e02814e
6264b00
9d8c039
fcbd839
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,178 @@ | ||||||
| package rewards | ||||||
|
|
||||||
| import ( | ||||||
| "encoding/hex" | ||||||
| "encoding/json" | ||||||
| "fmt" | ||||||
| "math/big" | ||||||
| "os" | ||||||
| "path" | ||||||
| "testing" | ||||||
| "time" | ||||||
|
|
||||||
| "github.com/multiversx/mx-chain-core-go/core" | ||||||
| apiCore "github.com/multiversx/mx-chain-core-go/data/api" | ||||||
| "github.com/multiversx/mx-chain-core-go/data/block" | ||||||
| "github.com/multiversx/mx-chain-go/config" | ||||||
| "github.com/multiversx/mx-chain-go/node/chainSimulator" | ||||||
| "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" | ||||||
| "github.com/stretchr/testify/require" | ||||||
| ) | ||||||
|
|
||||||
| const ( | ||||||
| defaultPathToInitialConfig = "../../../cmd/node/config/" | ||||||
| ) | ||||||
|
|
||||||
| func TestRewardsTxsAfterEquivalentMessages(t *testing.T) { | ||||||
| startTime := time.Now().Unix() | ||||||
| roundDurationInMillis := uint64(6000) | ||||||
| roundsPerEpoch := core.OptionalUint64{ | ||||||
| HasValue: true, | ||||||
| Value: 200, | ||||||
| } | ||||||
|
|
||||||
| numOfShards := uint32(3) | ||||||
|
|
||||||
| tempDir := t.TempDir() | ||||||
| cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ | ||||||
| BypassTxSignatureCheck: true, | ||||||
| TempDir: tempDir, | ||||||
| PathToInitialConfig: defaultPathToInitialConfig, | ||||||
| NumOfShards: numOfShards, | ||||||
| GenesisTimestamp: startTime, | ||||||
| RoundDurationInMillis: roundDurationInMillis, | ||||||
| RoundsPerEpoch: roundsPerEpoch, | ||||||
| ApiInterface: api.NewNoApiInterface(), | ||||||
| MinNodesPerShard: 3, | ||||||
| MetaChainMinNodes: 3, | ||||||
| AlterConfigsFunction: func(cfg *config.Configs) { | ||||||
|
||||||
| }, | ||||||
| }) | ||||||
| require.Nil(t, err) | ||||||
| require.NotNil(t, cs) | ||||||
| defer cs.Close() | ||||||
|
|
||||||
| targetEpoch := 9 | ||||||
| for i := 0; i < targetEpoch; i++ { | ||||||
| if i == 8 { | ||||||
| fmt.Println("here") | ||||||
| } | ||||||
| err = cs.ForceChangeOfEpoch() | ||||||
| require.Nil(t, err) | ||||||
| } | ||||||
|
|
||||||
| err = cs.GenerateBlocks(210) | ||||||
| require.Nil(t, err) | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this needed? or
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I use that function, more blocks will be generated until I reach epoch 9, with this method, only 30 blocks are generated.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe remove if i == 8 {
fmt.Println("here")
} |
||||||
|
|
||||||
| metaFacadeHandler := cs.GetNodeHandler(core.MetachainShardId).GetFacadeHandler() | ||||||
|
|
||||||
| nodesSetupFile := path.Join(tempDir, "config", "nodesSetup.json") | ||||||
| validators, err := readValidatorsAndOwners(nodesSetupFile) | ||||||
| require.Nil(t, err) | ||||||
| fmt.Println(validators) | ||||||
|
||||||
|
|
||||||
| // find block with rewards transactions, in this range we should find the epoch start block | ||||||
| var metaBlock *apiCore.Block | ||||||
| found := false | ||||||
| for nonce := uint64(210); nonce < 235; nonce++ { | ||||||
| metaBlock, err = metaFacadeHandler.GetBlockByNonce(nonce, apiCore.BlockQueryOptions{ | ||||||
| WithTransactions: true, | ||||||
| }) | ||||||
| require.Nil(t, err) | ||||||
|
|
||||||
| isEpochStart := metaBlock.EpochStartInfo != nil | ||||||
| if !isEpochStart { | ||||||
| continue | ||||||
| } | ||||||
|
|
||||||
| found = true | ||||||
| break | ||||||
| } | ||||||
| require.True(t, found) | ||||||
| require.NotNil(t, metaBlock) | ||||||
|
|
||||||
| nodesCoordinator := cs.GetNodeHandler(0).GetProcessComponents().NodesCoordinator() | ||||||
|
|
||||||
| shards := []uint32{0, 1, 2, core.MetachainShardId} | ||||||
|
|
||||||
| rewardsPerShard := make(map[uint32]*big.Int) | ||||||
| for _, shardID := range shards { | ||||||
AdoAdoAdo marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| validatorsPerShard, errG := nodesCoordinator.GetAllEligibleValidatorsPublicKeysForShard(8, shardID) | ||||||
| require.Nil(t, errG) | ||||||
|
|
||||||
| for _, validator := range validatorsPerShard { | ||||||
| owner, ok := validators[hex.EncodeToString([]byte(validator))] | ||||||
| if !ok { | ||||||
| continue | ||||||
| } | ||||||
|
|
||||||
| for _, mb := range metaBlock.MiniBlocks { | ||||||
| if mb.Type != block.RewardsBlock.String() { | ||||||
| continue | ||||||
| } | ||||||
|
|
||||||
| for _, tx := range mb.Transactions { | ||||||
| if tx.Receiver != owner { | ||||||
| continue | ||||||
| } | ||||||
| _, ok = rewardsPerShard[shardID] | ||||||
| if !ok { | ||||||
| rewardsPerShard[shardID] = big.NewInt(0) | ||||||
| } | ||||||
|
|
||||||
| valueBig, okR := rewardsPerShard[shardID].SetString(tx.Value, 10) | ||||||
|
||||||
| valueBig, okR := rewardsPerShard[shardID].SetString(tx.Value, 10) | |
| valueBig, okR := big.NewInt(0).SetString(tx.Value, 10) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
otherwise it will also set rewardsPerShard[shardID]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can use m[0] as expectedValue instead of these 2 variables
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refactored
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -6,6 +6,7 @@ import ( | |||||
| "encoding/hex" | ||||||
| "errors" | ||||||
| "fmt" | ||||||
|
|
||||||
| "math/big" | ||||||
| "sync" | ||||||
| "time" | ||||||
|
|
@@ -22,6 +23,7 @@ import ( | |||||
| "github.com/multiversx/mx-chain-core-go/core/check" | ||||||
| "github.com/multiversx/mx-chain-core-go/core/sharding" | ||||||
| "github.com/multiversx/mx-chain-core-go/data/api" | ||||||
| "github.com/multiversx/mx-chain-core-go/data/block" | ||||||
| "github.com/multiversx/mx-chain-core-go/data/endProcess" | ||||||
| "github.com/multiversx/mx-chain-core-go/data/transaction" | ||||||
| crypto "github.com/multiversx/mx-chain-crypto-go" | ||||||
|
|
@@ -181,6 +183,8 @@ func (s *simulator) createChainHandlers(args ArgsBaseChainSimulator) error { | |||||
| s.initialWalletKeys = outputConfigs.InitialWallets | ||||||
| s.validatorsPrivateKeys = outputConfigs.ValidatorsPrivateKeys | ||||||
|
|
||||||
| s.addProofs() | ||||||
|
|
||||||
| log.Info("running the chain simulator with the following parameters", | ||||||
| "number of shards (including meta)", args.NumOfShards+1, | ||||||
| "round per epoch", outputConfigs.Configs.GeneralConfig.EpochStartConfig.RoundsPerEpoch, | ||||||
|
|
@@ -192,6 +196,26 @@ func (s *simulator) createChainHandlers(args ArgsBaseChainSimulator) error { | |||||
| return nil | ||||||
| } | ||||||
|
|
||||||
| func (s *simulator) addProofs() { | ||||||
| proofs := make([]*block.HeaderProof, 0) | ||||||
|
||||||
| proofs := make([]*block.HeaderProof, 0) | |
| proofs := make([]*block.HeaderProof, 0, len(s.nodes)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extract s.GetNodeHandler(core.MetachainShardId).GetDataComponents().Datapool().Proofs() outside of the for loop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we consider this a long test as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, changed