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

[Utility] Foundational bugs, tests, code cleanup and improvements (1 / 2) #503

Merged
merged 66 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
8993edf
WIP - just looking through code
Olshansk Jan 26, 2023
58543f0
Merge branch 'main' into issue/443-consolidate-utility-messages
Olshansk Jan 26, 2023
d42af7d
Delete DoubleSign
Olshansk Jan 26, 2023
05b369f
Removed all the message double signing stuff
Olshansk Jan 26, 2023
6f652ac
Moved utility tests alongside their acutal files
Olshansk Jan 26, 2023
75f2f8e
Reducing scope of context & utility structs
Olshansk Jan 26, 2023
feecc82
Delete PersistenceRWContext
Olshansk Jan 26, 2023
aae0713
Minro cleanup to default values in utility/module_test.go
Olshansk Jan 26, 2023
642c9a4
Move ActorTypes into a shared library
Olshansk Jan 27, 2023
a0cbeb7
WIP - Cleaning up code as I move through transactions.go and its depe…
Olshansk Jan 27, 2023
d34f5ca
Update codec
Olshansk Jan 27, 2023
3ecfb5c
Moved constants into a separate file
Olshansk Jan 27, 2023
01163f2
Fixed all calls to GetStoreAndHeight
Olshansk Jan 27, 2023
5c5b14d
Cleaned up gov.go
Olshansk Jan 27, 2023
8f962a6
Removed shared num_utils from the utility package
Olshansk Jan 28, 2023
0feb32a
Minor upates to some of the utility type files
Olshansk Jan 29, 2023
d4ae7da
Propogate error in string to int conversion
Olshansk Jan 29, 2023
926d35b
Cleaned up message.go
Olshansk Jan 29, 2023
0366f3e
Review tx.go and split tx_result.go into a separate file
Olshansk Jan 29, 2023
62ca5be
Moved TransactionResult into tx_result.go
Olshansk Jan 29, 2023
f551e10
Reviewed account.go and account_test.go
Olshansk Jan 29, 2023
1d92544
Upadting actor.go in progress
Olshansk Jan 29, 2023
7049909
Fixed broken tests
Olshansk Jan 29, 2023
eb54700
Introduces module shared proto types and remove the UnstakingActor in…
Olshansk Jan 29, 2023
d6c3eae
s/address/addr in actor.go
Olshansk Jan 29, 2023
c144e18
Deleted getLatestBlockHeight
Olshansk Jan 29, 2023
f03af89
Reviewer actor.go but actor_test.go is still in progress
Olshansk Jan 30, 2023
d845844
Merge branch 'main' into issue/443-consolidate-utility-messages
Olshansk Jan 30, 2023
7f9091c
Merge with main
Olshansk Feb 7, 2023
f573fae
All unit tests passing again
Olshansk Feb 7, 2023
a3d2d47
Re-reviewer account and account_test.go
Olshansk Feb 7, 2023
60b8030
Mostly passing actor_test.go
Olshansk Feb 8, 2023
e84feb9
Merge branch 'main' into issue/443-consolidate-utility-messages
Olshansk Feb 8, 2023
699de80
Cleaning up actor_test.go
Olshansk Feb 8, 2023
d2624b2
One unit test still failing
Olshansk Feb 9, 2023
00db25a
Fixed bug in persistence
Olshansk Feb 9, 2023
568140b
Self review
Olshansk Feb 9, 2023
c9681e6
Reduce scope of internal functions
Olshansk Feb 9, 2023
c3114e8
minor followup fix
Olshansk Feb 9, 2023
1108b85
All tests passing
Olshansk Feb 9, 2023
dd816e4
Linter nits
Olshansk Feb 9, 2023
d0b142c
Merge with main
Olshansk Feb 9, 2023
c11b901
Fix persitence test
Olshansk Feb 9, 2023
084b8b9
Update go_lint
Olshansk Feb 9, 2023
f0902cc
Added send_local_tx
Olshansk Feb 9, 2023
407a447
Add TODOs to the development/README
Olshansk Feb 9, 2023
1f96171
Update utility/application.go
Olshansk Feb 12, 2023
cc7385b
[P2P] Logger module registration in p2p and network bugfix (#502)
deblasis Feb 10, 2023
decf7b4
Update deps
Olshansk Feb 12, 2023
8fb056a
Remove ICodec
Olshansk Feb 12, 2023
6ebaf86
Add comment to GetHashStringFromBytes
Olshansk Feb 12, 2023
78af99e
Clarify modules/types/README
Olshansk Feb 12, 2023
d94f0ab
Update comment in unstaking_actor.proto
Olshansk Feb 12, 2023
dde0731
s/withBus/setBus
Olshansk Feb 12, 2023
e0336ea
Update comments
Olshansk Feb 12, 2023
7b0f8c0
Reply to remaining comments
Olshansk Feb 12, 2023
1bf9830
Merge branch 'main' into issues/475/utility_module_foundation
Olshansk Feb 13, 2023
8ef29da
s/transaction/tx
Olshansk Feb 13, 2023
56c9a14
Typo in GetMinimumBlockHeightQuery
Olshansk Feb 13, 2023
de2b264
Merge branch 'main' into issues/475/utility_module_foundation
Olshansk Feb 14, 2023
b8d5a94
Add comment to Transaction
Olshansk Feb 14, 2023
6733ec4
Removed redundant ActorTypes array
Olshansk Feb 14, 2023
a267a4e
Remove CodecType
Olshansk Feb 14, 2023
d88bc18
Update all the changelogs
Olshansk Feb 14, 2023
f829d5c
Merge branch 'main' into issues/475/utility_module_foundation
Olshansk Feb 14, 2023
91ae601
Update changelogs dates
Olshansk Feb 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ go_clean_deps: ## Runs `go mod tidy` && `go mod vendor`

.PHONY: go_lint
go_lint: ## Run all linters that are triggered by the CI pipeline
golangci-lint run ./...
docker run -t --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.51.1 golangci-lint run -v

.PHONY: gofmt
gofmt: ## Format all the .go files in the project in place.
Expand Down Expand Up @@ -222,15 +222,15 @@ mockgen: clean_mocks ## Use `mockgen` to generate mocks used for testing purpose
$(eval modules_dir = "shared/modules")
go generate ./${modules_dir}
echo "Mocks generated in ${modules_dir}/mocks"

$(eval DIRS = p2p persistence)
for dir in $(DIRS); do \
echo "Processing $$dir mocks..."; \
find $$dir/types/mocks -type f ! -name "mocks.go" -exec rm {} \;; \
go generate ./${dir_name}/...; \
echo "$$dir mocks generated in $$dir/types/mocks"; \
done

# TODO(team): Tested locally with `protoc` version `libprotoc 3.19.4`. In the near future, only the Dockerfiles will be used to compile protos.

.PHONY: protogen_show
Expand All @@ -248,9 +248,10 @@ PROTOC_SHARED = $(PROTOC) -I=./shared
.PHONY: protogen_local
protogen_local: go_protoc-go-inject-tag ## Generate go structures for all of the protobufs
# Shared
$(PROTOC) -I=./shared/core/types/proto --go_out=./shared/core/types ./shared/core/types/proto/*.proto
$(PROTOC) -I=./shared/messaging/proto --go_out=./shared/messaging ./shared/messaging/proto/*.proto
$(PROTOC) -I=./shared/codec/proto --go_out=./shared/codec ./shared/codec/proto/*.proto
$(PROTOC) -I=./shared/core/types/proto --go_out=./shared/core/types ./shared/core/types/proto/*.proto
$(PROTOC) -I=./shared/modules/types/proto --go_out=./shared/modules/types ./shared/modules/types/proto/*.proto
$(PROTOC) -I=./shared/messaging/proto --go_out=./shared/messaging ./shared/messaging/proto/*.proto
$(PROTOC) -I=./shared/codec/proto --go_out=./shared/codec ./shared/codec/proto/*.proto

# Runtime
$(PROTOC) -I=./runtime/configs/types/proto --go_out=./runtime/configs/types ./runtime/configs/types/proto/*.proto
Expand All @@ -260,8 +261,6 @@ protogen_local: go_protoc-go-inject-tag ## Generate go structures for all of the

# Persistence
$(PROTOC_SHARED) -I=./persistence/indexer/proto --go_out=./persistence/indexer ./persistence/indexer/proto/*.proto
$(PROTOC_SHARED) -I=./persistence/proto --go_out=./persistence/types ./persistence/proto/*.proto
protoc-go-inject-tag -input="./persistence/types/*.pb.go"

# Utility
$(PROTOC_SHARED) -I=./utility/types/proto --go_out=./utility/types ./utility/types/proto/*.proto
Expand Down Expand Up @@ -497,3 +496,7 @@ check_cross_module_imports: ## Lists cross-module imports
echo "-----------------------"
echo "runtime:\n"
grep ${exclude_common} --exclude-dir=runtime -r "github.com/pokt-network/pocket/runtime" || echo "✅ OK!"

.PHONY: send_local_tx
send_local_tx: ## A hardcoded send tx to make LocalNet debugging easier
p1 --path_to_private_key_file=build/pkeys/val1.json Account Send 6f66574e1f50f0ef72dff748c3f11b9e0e89d32a 67eb3f0a50ae459fecf666be0e93176e92441317 1000
4 changes: 2 additions & 2 deletions app/client/cli/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func prepareTxBytes(msg typesUtil.Message, pk crypto.Ed25519PrivateKey) ([]byte,
Nonce: fmt.Sprintf("%d", crypto.GetNonce()),
}

signBytes, err := tx.SignBytes()
signBytes, err := tx.SignableBytes()
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -163,7 +163,7 @@ func validateStakeAmount(amount string) error {
}

sr := big.NewInt(stakingRecommendationAmount)
if typesUtil.BigIntLessThan(am, sr) {
if converters.BigIntLessThan(am, sr) {
fmt.Printf("The amount you are staking for is below the recommendation of %d POKT, would you still like to continue? y|n\n", sr.Div(sr, oneMillion).Int64())
if !confirmation(pwd) {
return fmt.Errorf("aborted")
Expand Down
2 changes: 1 addition & 1 deletion app/client/doc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [0.0.0.10] - 2023-02-07

- Added GITHUB_WIKI tags where it was missing
- Added GH_WIKI tags where it was missing

## [0.0.0.9] - 2023-02-06

Expand Down
4 changes: 2 additions & 2 deletions docs/demos/iteration_3_end_to_end_tx.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

The first video of this demo can be accessed [here](https://drive.google.com/file/d/1IOrzq-XJP04BJjyqPPpPu873aSfwrnur/view?usp=sharing).

<img width="842" alt="Screenshot 2022-12-05 at 9 02 28 PM" src="https://user-images.githubusercontent.com/1892194/205820691-26e801e4-ff79-4132-a7a1-358860ca2335.png">
![Demo Goals](https://user-images.githubusercontent.com/1892194/205820691-26e801e4-ff79-4132-a7a1-358860ca2335.png)

### Features

Expand Down Expand Up @@ -91,7 +91,7 @@ select * from pool;

### Available Commands

Show all the commands available in the CLI:
Show all the commands available in the CLI by running `p1` or:

```bash
go run app/client/*.go
Expand Down
17 changes: 17 additions & 0 deletions docs/development/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Please note that this repository is under very active development and breaking c
- [Running LocalNet](#running-localnet)
- [\[Advanced\] Kubernetes](#advanced-kubernetes)
- [\[Basic\] Docker Compose](#basic-docker-compose)
- [TODO: Improvements to be added by the core team](#todo-improvements-to-be-added-by-the-core-team)
- [Profiling](#profiling)
- [Code Organization](#code-organization)
- [Maintaining Documentation](#maintaining-documentation)
Expand Down Expand Up @@ -217,6 +218,22 @@ make client_start && make client_connect
✔ TriggerNextView # Let it rip!
```

9. Send a transaction (and trigger the next view)

```bash
make send_local_tx
```

### TODO: Improvements to be added by the core team

A lot of features have been added since this doc was first added. See `docs/demo`. We should update it to:

1. Show k8s LocalNet
2. Add more details related to transactions
3. Add details related to the keybase
4. Add state sync tooling
5. Add P2P tooling

### Profiling

If you need to profile the node for CPU and/or memory usage, you can use the `pprof` tool.
Expand Down
4 changes: 2 additions & 2 deletions persistence/actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
)

// TODO (#399): All of the functions below following a structure similar to `GetAll<Actor>`
// can easily be refactored and condensed into a single function using a generic type or a common
// interface.
// can easily be refactored and condensed into a single function using a generic type or a common
// interface.
func (p *PostgresContext) GetAllApps(height int64) (apps []*coreTypes.Actor, err error) {
ctx, tx := p.getCtxAndTx()
rows, err := tx.Query(ctx, types.ApplicationActor.GetAllQuery(height))
Expand Down
17 changes: 6 additions & 11 deletions persistence/actor_shared_sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import (
"github.com/jackc/pgx/v5"
"github.com/pokt-network/pocket/persistence/types"
coreTypes "github.com/pokt-network/pocket/shared/core/types"
"github.com/pokt-network/pocket/shared/modules"
moduleTypes "github.com/pokt-network/pocket/shared/modules/types"
)

// IMPROVE(team): Move this into a proto enum. We are not using `iota` for the time being
// for the purpose of being explicit: https://github.com/pokt-network/pocket/pull/140#discussion_r939731342
// TODO Cleanup with #149
// TODO: Consolidate with proto enum in the utility module
const (
UndefinedStakingStatus = int32(0)
UnstakingStatus = int32(1)
Expand Down Expand Up @@ -174,7 +174,7 @@ func (p *PostgresContext) UpdateActor(actorSchema types.ProtocolActorSchema, act
return nil
}

func (p *PostgresContext) GetActorsReadyToUnstake(actorSchema types.ProtocolActorSchema, height int64) (actors []modules.IUnstakingActor, err error) {
func (p *PostgresContext) GetActorsReadyToUnstake(actorSchema types.ProtocolActorSchema, height int64) (actors []*moduleTypes.UnstakingActor, err error) {
ctx, tx := p.getCtxAndTx()

rows, err := tx.Query(ctx, actorSchema.GetReadyToUnstakeQuery(height))
Expand All @@ -184,15 +184,11 @@ func (p *PostgresContext) GetActorsReadyToUnstake(actorSchema types.ProtocolActo
defer rows.Close()

for rows.Next() {
unstakingActor := &types.UnstakingActor{}
var addr, output, stakeAmount string
if err = rows.Scan(&addr, &stakeAmount, &output); err != nil {
actor := &moduleTypes.UnstakingActor{}
if err = rows.Scan(&actor.Address, &actor.StakeAmount, &actor.OutputAddress); err != nil {
return
}
unstakingActor.SetAddress(addr)
unstakingActor.SetStakeAmount(stakeAmount)
unstakingActor.SetOutputAddress(output)
actors = append(actors, unstakingActor)
actors = append(actors, actor)
}
return
}
Expand Down Expand Up @@ -244,7 +240,6 @@ func (p *PostgresContext) SetActorStatusAndUnstakingHeightIfPausedBefore(actorSc
if err != nil {
return err
}

_, err = tx.Exec(ctx, actorSchema.UpdateUnstakedHeightIfPausedBeforeQuery(pausedBeforeHeight, unstakingHeight, currentHeight))
return err
}
Expand Down
4 changes: 2 additions & 2 deletions persistence/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/pokt-network/pocket/persistence/types"
coreTypes "github.com/pokt-network/pocket/shared/core/types"
"github.com/pokt-network/pocket/shared/modules"
moduleTypes "github.com/pokt-network/pocket/shared/modules/types"
)

func (p *PostgresContext) GetAppExists(address []byte, height int64) (exists bool, err error) {
Expand Down Expand Up @@ -61,7 +61,7 @@ func (p *PostgresContext) SetAppStakeAmount(address []byte, stakeAmount string)
return p.setActorStakeAmount(types.ApplicationActor, address, stakeAmount)
}

func (p *PostgresContext) GetAppsReadyToUnstake(height int64, _ int32) ([]modules.IUnstakingActor, error) {
func (p *PostgresContext) GetAppsReadyToUnstake(height int64, _ int32) ([]*moduleTypes.UnstakingActor, error) {
return p.GetActorsReadyToUnstake(types.ApplicationActor, height)
}

Expand Down
1 change: 1 addition & 0 deletions persistence/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
coreTypes "github.com/pokt-network/pocket/shared/core/types"
)

// INCOMPLETE: Need to think through how we will handle pruned vs non-pruned txIndexers
Olshansk marked this conversation as resolved.
Show resolved Hide resolved
func (p *persistenceModule) TransactionExists(transactionHash string) (bool, error) {
hash, err := hex.DecodeString(transactionHash)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions persistence/fisherman.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/pokt-network/pocket/persistence/types"
coreTypes "github.com/pokt-network/pocket/shared/core/types"
"github.com/pokt-network/pocket/shared/modules"
moduleTypes "github.com/pokt-network/pocket/shared/modules/types"
)

func (p *PostgresContext) GetFishermanExists(address []byte, height int64) (exists bool, err error) {
Expand Down Expand Up @@ -58,7 +58,7 @@ func (p *PostgresContext) SetFishermanStakeAmount(address []byte, stakeAmount st
return p.setActorStakeAmount(types.FishermanActor, address, stakeAmount)
}

func (p *PostgresContext) GetFishermenReadyToUnstake(height int64, status int32) ([]modules.IUnstakingActor, error) {
func (p *PostgresContext) GetFishermenReadyToUnstake(height int64, status int32) ([]*moduleTypes.UnstakingActor, error) {
return p.GetActorsReadyToUnstake(types.FishermanActor, height)
}

Expand Down
4 changes: 2 additions & 2 deletions persistence/indexer/indexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func FuzzTxIndexer(f *testing.F) {

f.Fuzz(func(t *testing.T, op string) {
// seed random
rand.Seed(int64(time.Now().Nanosecond()))
rand.Seed(int64(time.Now().Nanosecond())) //nolint:staticcheck // G404 - Weak random source is okay here
// set height ordering to descending 50% of time
isDescending := rand.Intn(2) == 0 //nolint:gosec // G404 - Weak random source is okay in unit tests
// select a height 0 - 9 to index
Expand Down Expand Up @@ -266,7 +266,7 @@ func randomErr() (code int32, err string) {
//nolint:gosec // G404 - Weak random source is okay in unit tests
func randLetterBytes() []byte {
randBytes := make([]byte, 50)
rand.Read(randBytes)
rand.Read(randBytes) //nolint:staticcheck // G404 - Weak random source is okay here
return randBytes
}

Expand Down
10 changes: 0 additions & 10 deletions persistence/proto/unstaking.proto

This file was deleted.

4 changes: 2 additions & 2 deletions persistence/service_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/pokt-network/pocket/persistence/types"
coreTypes "github.com/pokt-network/pocket/shared/core/types"
"github.com/pokt-network/pocket/shared/modules"
moduleTypes "github.com/pokt-network/pocket/shared/modules/types"
)

func (p *PostgresContext) GetServiceNodeExists(address []byte, height int64) (exists bool, err error) {
Expand Down Expand Up @@ -62,7 +62,7 @@ func (p *PostgresContext) GetServiceNodeCount(chain string, height int64) (int,
panic("GetServiceNodeCount not implemented")
}

func (p *PostgresContext) GetServiceNodesReadyToUnstake(height int64, status int32) ([]modules.IUnstakingActor, error) {
func (p *PostgresContext) GetServiceNodesReadyToUnstake(height int64, status int32) ([]*moduleTypes.UnstakingActor, error) {
return p.GetActorsReadyToUnstake(types.ServiceNodeActor, height)
}

Expand Down
4 changes: 2 additions & 2 deletions persistence/test/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ func TestGetAppsReadyToUnstake(t *testing.T) {
unstakingApps, err := db.GetAppsReadyToUnstake(0, persistence.UnstakingStatus)
require.NoError(t, err)
require.Equal(t, 1, len(unstakingApps), "wrong number of actors ready to unstake at height 0")
require.Equal(t, app.Address, hex.EncodeToString(unstakingApps[0].GetAddress()), "unexpected application actor returned")
require.Equal(t, app.Address, unstakingApps[0].GetAddress(), "unexpected application actor returned")

// Check unstaking apps at height 1
unstakingApps, err = db.GetAppsReadyToUnstake(1, persistence.UnstakingStatus)
require.NoError(t, err)
require.Equal(t, 2, len(unstakingApps), "wrong number of actors ready to unstake at height 1")
require.ElementsMatch(t, [][]byte{addrBz2, addrBz3}, [][]byte{unstakingApps[0].GetAddress(), unstakingApps[1].GetAddress()})
require.ElementsMatch(t, []string{app2.Address, app3.Address}, []string{unstakingApps[0].Address, unstakingApps[1].Address})
}

func TestGetAppStatus(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions persistence/test/fisherman_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ func TestGetFishermenReadyToUnstake(t *testing.T) {
unstakingFishermen, err := db.GetFishermenReadyToUnstake(0, persistence.UnstakingStatus)
require.NoError(t, err)
require.Equal(t, 1, len(unstakingFishermen), "wrong number of actors ready to unstake at height 0")
require.Equal(t, fisherman.Address, hex.EncodeToString(unstakingFishermen[0].GetAddress()), "unexpected fishermanlication actor returned")
require.Equal(t, fisherman.Address, unstakingFishermen[0].GetAddress(), "unexpected fishermanlication actor returned")

// Check unstaking fishermans at height 1
unstakingFishermen, err = db.GetFishermenReadyToUnstake(1, persistence.UnstakingStatus)
require.NoError(t, err)
require.Equal(t, 2, len(unstakingFishermen), "wrong number of actors ready to unstake at height 1")
require.ElementsMatch(t, [][]byte{addrBz2, addrBz3}, [][]byte{unstakingFishermen[0].GetAddress(), unstakingFishermen[1].GetAddress()})
require.ElementsMatch(t, []string{fisherman2.Address, fisherman3.Address}, []string{unstakingFishermen[0].Address, unstakingFishermen[1].Address})
}

func TestGetFishermanStatus(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions persistence/test/service_node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ func TestGetServiceNodesReadyToUnstake(t *testing.T) {
unstakingServiceNodes, err := db.GetServiceNodesReadyToUnstake(0, persistence.UnstakingStatus)
require.NoError(t, err)
require.Equal(t, 1, len(unstakingServiceNodes), "wrong number of actors ready to unstake at height 0")
require.Equal(t, serviceNode.Address, hex.EncodeToString(unstakingServiceNodes[0].GetAddress()), "unexpected serviceNodelication actor returned")
require.Equal(t, serviceNode.Address, unstakingServiceNodes[0].Address, "unexpected serviceNodelication actor returned")

// Check unstaking serviceNodes at height 1
unstakingServiceNodes, err = db.GetServiceNodesReadyToUnstake(1, persistence.UnstakingStatus)
require.NoError(t, err)
require.Equal(t, 2, len(unstakingServiceNodes), "wrong number of actors ready to unstake at height 1")
require.ElementsMatch(t, [][]byte{addrBz2, addrBz3}, [][]byte{unstakingServiceNodes[0].GetAddress(), unstakingServiceNodes[1].GetAddress()})
require.ElementsMatch(t, []string{serviceNode2.Address, serviceNode3.Address}, []string{unstakingServiceNodes[0].Address, unstakingServiceNodes[1].Address})
}

func TestGetServiceNodeStatus(t *testing.T) {
Expand Down
13 changes: 7 additions & 6 deletions persistence/test/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
coreTypes "github.com/pokt-network/pocket/shared/core/types"
"github.com/pokt-network/pocket/shared/messaging"
"github.com/pokt-network/pocket/shared/modules"
moduleTypes "github.com/pokt-network/pocket/shared/modules/types"
"github.com/stretchr/testify/require"
"golang.org/x/exp/slices"
)
Expand All @@ -42,8 +43,8 @@ var (
StakeToUpdate = converters.BigIntToString((&big.Int{}).Add(DefaultStakeBig, DefaultDeltaBig))

DefaultStakeStatus = int32(persistence.StakedStatus)
DefaultPauseHeight = int64(-1)
DefaultUnstakingHeight = int64(-1)
DefaultPauseHeight = int64(-1) // pauseHeight=-1 means not paused
DefaultUnstakingHeight = int64(-1) // pauseHeight=-1 means not unstaking

OlshanskyURL = "https://olshansky.info"
OlshanskyChains = []string{"OLSH"}
Expand Down Expand Up @@ -235,8 +236,8 @@ func fuzzSingleProtocolActor(
if originalActor.UnstakingHeight != db.Height { // Not ready to unstake
require.Nil(t, unstakingActors)
} else {
idx := slices.IndexFunc(unstakingActors, func(a modules.IUnstakingActor) bool {
return originalActor.Address == hex.EncodeToString(a.GetAddress())
idx := slices.IndexFunc(unstakingActors, func(a *moduleTypes.UnstakingActor) bool {
return originalActor.Address == a.Address
})
require.NotEqual(t, idx, -1, fmt.Sprintf("actor that is unstaking was not found %+v", originalActor))
}
Expand Down Expand Up @@ -285,8 +286,8 @@ func fuzzSingleProtocolActor(
newActor, err := getTestActor(db, originalActor.Address)
require.NoError(t, err)

if db.Height > originalActor.PausedHeight { // isPausedAndReadyToUnstake
require.Equal(t, newActor.UnstakingHeight, newUnstakingHeight, "setPausedToUnstaking")
if db.Height > originalActor.PausedHeight && originalActor.PausedHeight != DefaultPauseHeight { // isPausedAndReadyToUnstake
require.Equal(t, newUnstakingHeight, newActor.UnstakingHeight, "setPausedToUnstaking")
}
case "GetActorOutputAddr":
outputAddr, err := db.GetActorOutputAddress(protocolActorSchema, addr, db.Height)
Expand Down
5 changes: 3 additions & 2 deletions persistence/test/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,14 @@ func TestGetValidatorsReadyToUnstake(t *testing.T) {
unstakingValidators, err := db.GetValidatorsReadyToUnstake(0, persistence.UnstakingStatus)
require.NoError(t, err)
require.Equal(t, 1, len(unstakingValidators), "wrong number of actors ready to unstake at height 0")
require.Equal(t, validator.Address, hex.EncodeToString(unstakingValidators[0].GetAddress()), "unexpected validatorlication actor returned")

require.Equal(t, validator.Address, unstakingValidators[0].GetAddress(), "unexpected unstaking validator returned")

// Check unstaking validators at height 1
unstakingValidators, err = db.GetValidatorsReadyToUnstake(1, persistence.UnstakingStatus)
require.NoError(t, err)
require.Equal(t, 2, len(unstakingValidators), "wrong number of actors ready to unstake at height 1")
require.ElementsMatch(t, [][]byte{addrBz2, addrBz3}, [][]byte{unstakingValidators[0].GetAddress(), unstakingValidators[1].GetAddress()})
require.ElementsMatch(t, []string{validator2.Address, validator3.Address}, []string{unstakingValidators[0].Address, unstakingValidators[1].Address})
}

func TestGetValidatorStatus(t *testing.T) {
Expand Down
Loading