Skip to content
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

Adding extra unit tests for DistributeRewards #3256

Open
wants to merge 32 commits into
base: sprint-1.15
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
79776e4
Adding extra unit tests for DistributeRewards
shohan2001 Apr 23, 2024
07683c1
Merge branch 'sprint-1.14' into feat/distributeRewardTests
shohan2001 Apr 23, 2024
e514d4d
Temporary commit for saving state
shohan2001 Apr 25, 2024
c4d6f6b
test
shohan2001 Apr 27, 2024
c74db72
Merge branch 'sprint-1.14' into feat/distributeRewardTests
shohan2001 Apr 28, 2024
6f29512
Merge branch 'sprint-1.14' into feat/distributeRewardTests
shohan2001 Apr 28, 2024
f13123f
undo changes
shohan2001 Apr 30, 2024
45a6c6f
Merge branch 'fix/testbalance-events' into feat/distributeRewardTests
shohan2001 Apr 30, 2024
09254b4
adding event save check
shohan2001 Apr 30, 2024
e817111
Adding test for distributeRewardsRandN
shohan2001 May 2, 2024
af2e59c
Merge branch 'sprint-1.14' into feat/distributeRewardTests
shohan2001 May 2, 2024
55a89f7
fixing error
shohan2001 May 2, 2024
06f53c7
undo
shohan2001 May 2, 2024
fb20aeb
redo
shohan2001 May 2, 2024
06a542f
fix
shohan2001 May 2, 2024
c587078
fixed
shohan2001 May 2, 2024
47472ce
adding data check for distributeRewards
shohan2001 May 12, 2024
7931257
fix
shohan2001 May 12, 2024
8ef7534
added randomness check for distributeRewardsRandN
shohan2001 May 14, 2024
98eadf7
fix
shohan2001 May 14, 2024
eef2fd7
totalRewards fix
shohan2001 May 14, 2024
0d144de
editing tolerance
shohan2001 May 14, 2024
9367d31
changing number of selections for tests
shohan2001 May 15, 2024
da416af
fix
shohan2001 May 15, 2024
112fa88
changing expected reward
shohan2001 May 15, 2024
fcf09e2
Merge branch 'sprint-1.15' into feat/distributeRewardTests
shohan2001 May 17, 2024
f8d9acb
adding expected value calculation
shohan2001 May 19, 2024
cc29ee8
Merge branch 'sprint-1.15' into feat/distributeRewardTests
shohan2001 May 24, 2024
cc5d63a
using unix timestamp as seed
shohan2001 May 26, 2024
932d5f6
fixing getRandPools
shohan2001 May 31, 2024
3995f21
Merge branch 'sprint-1.15' into feat/distributeRewardTests
shohan2001 May 31, 2024
28f3b6b
Update tolerance
shohan2001 May 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 19 additions & 3 deletions code/go/0chain.net/smartcontract/stakepool/balances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package stakepool

import (
"context"

"os"
"path/filepath"
"sync"
Expand Down Expand Up @@ -36,12 +35,14 @@ type testBalances struct {
tree map[datastore.Key]util.MPTSerializable
block *block.Block
tc *statecache.TransactionCache
events []event.Event

mpts *mptStore // use for benchmarks
skipMerge bool // don't merge for now
}

func newTestBalances(t testing.TB, mpts bool) (tb *testBalances) {

tb = &testBalances{
balances: make(map[datastore.Key]currency.Coin),
tree: make(map[datastore.Key]util.MPTSerializable),
Expand Down Expand Up @@ -86,10 +87,25 @@ func (tb *testBalances) SetMagicBlock(block *block.MagicBlock) {}
func (tb *testBalances) AddSignedTransfer(st *state.SignedTransfer) {}
func (tb *testBalances) GetSignedTransfers() []*state.SignedTransfer { return nil }
func (tb *testBalances) GetEventDB() *event.EventDb { return nil }
func (tb *testBalances) EmitEvent(event.EventType, event.EventTag, string, interface{}, ...cstate.Appender) {
func (tb *testBalances) EmitEvent(eventType event.EventType, tag event.EventTag, index string, data interface{}, appenders ...cstate.Appender) {
tb.RWMutex.Lock()
defer tb.RWMutex.Unlock()
e := event.Event{
BlockNumber: tb.block.Round,
TxHash: tb.txn.Hash,
Type: eventType,
Tag: tag,
Index: index,
Data: data,
}
if len(appenders) != 0 {
tb.events = appenders[0](tb.events, e)
} else {
tb.events = append(tb.events, e)
}
}
func (tb *testBalances) EmitError(error) {}
func (tb *testBalances) GetEvents() []event.Event { return nil }
func (tb *testBalances) GetEvents() []event.Event { return tb.events }
func (tb *testBalances) GetChainCurrentMagicBlock() *block.MagicBlock { return nil }
func (tb *testBalances) GetLatestFinalizedBlock() *block.Block { return nil }
func (tb *testBalances) DeleteTrieNode(key datastore.Key) (datastore.Key, error) {
Expand Down