Skip to content

Commit

Permalink
[Utility] Foundational bugs, tests, code cleanup and improvements (1 …
Browse files Browse the repository at this point in the history
…/ 2) (#503)

## Description

This is the first of several changes necessary to refactor and improve the utility module to enable implementation of future, more complex, interfaces.

## Issue

Fixes #475

## Type of change

Please mark the relevant option(s):

- [ ] New feature, functionality or library
- [x] Bug fix
- [x] Code health or cleanup
- [ ] Major breaking change
- [x] Documentation
- [ ] Other <!-- add details here if it a different type of change -->

## List of changes

### Changes

**Utility**
- Add a `Validatable` type for basic validation
- Split business logic specific to certain actors (e.g. validator reward, app relays, message handling) into separate files
- Reduce the scope of functions and types that shouldn’t be exposed
- Upgraded the actors tests - a lot went here to help with understanding what’s going on but it’s still just a start
- Remove the `Context` struct; unnecessary abstraction
- Added comments and guidance on message, transaction and signature validation
- Added `ITransaction`, an interface for the `Transaction` protocol to help capture the functionality it adds to the core type

**Code Confusion**
- Remove `IUnstakingActor` and use `UnstakingActor` directly. Guideline for removing future unnecessary types (e.g. TxResult)
- Delineate between unstaking & unbonding in a few places throughout the codebase

**Bugs**
- Avoid unstaking all actors when intending to UnstakeMsg paused actors only (major bug in persistence sql query)
- `tx.Equals` was comparing the same transaction against itself (major bug)
- Staking status enums in utility did not reflect the same protocol as in persistence (needs to be consolidated)

**Code optimization**
- Avoid redundant `byte` <-> `string` conversions in several places
- Avoid redundant `bigInt` <-> `string` conversions in several places

**Code health**
- Add comments explaining the use/responsibility of various types
- Consolidate BigInt/String converters used in other parts of the codebase
- Consolidate some types used everywhere (e.g. `actorTypes`)
- Reduce the code footprint of the `codec` package & add some TODOs
- Removed unused double sign code (moved to #432 for reference)

### Files focused on

utility
- [x] ├── account.go
- [x] ├── account_test.go
- [x] ├── actor.go
- [x] ├── actor_test.go
- [ ] ├── application.go
- [ ] ├── application_test.go
- [ ] ├── block.go
- [ ] ├── block_test.go
- [ ] ├── context.go
- [ ] ├── doc
- [ ] │   ├── CHANGELOG.md
- [ ] │   ├── PROTOCOL_RELAY.md
- [ ] │   ├── PROTOCOL_SESSION.md
- [ ] │   └── README.md
- [ ] ├── gov.go
- [ ] ├── gov_test.go
- [ ] ├── message_handler.go
- [ ] ├── message_test.go
- [ ] ├── module.go
- [ ] ├── module_test.go
- [ ] ├── service
- [ ] │   └── service.go
- [ ] ├── session.go
- [ ] ├── transaction.go
- [ ] ├── transaction_test.go
- [ ] ├── types
- [x] │   ├── constants.go
- [x] │   ├── error.go
- [x] │   ├── gov.go
- [x] │   ├── message.go
- [x] │   ├── message_staking.go
- [x] │   ├── message_test.go
- [ ] │   ├── proto
- [ ] │   │   ├── message.proto
- [ ] │   │   ├── stake_status.proto
- [ ] │   │   ├── transaction.proto
- [ ] │   │   ├── tx_result.proto
- [ ] │   │   └── utility_messages.proto
- [x] │   ├── relay_chain.go
- [x] │   ├── relay_chain_test.go
- [x] │   ├── signature.go
- [ ] │   ├── transaction.go
- [ ] │   ├── transaction_test.go
- [x] │   ├── tx_fifo_mempool.go
- [x] │   ├── tx_fifo_mempool_test.go
- [ ] │   ├── tx_result.go
- [x] │   └── validatable.go
- [ ] └── validator.go

## Testing

- [x] `make develop_test`
- [x] [LocalNet](https://github.com/pokt-network/pocket/blob/main/docs/development/README.md) w/ all of the steps outlined in the `README`

## Required Checklist

- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have tested my changes using the available tooling
- [ ] I have updated the corresponding CHANGELOG

### If Applicable Checklist

- [x] I have updated the corresponding README(s); local and/or global
- [ ] I have added tests that prove my fix is effective or that my feature works
- [ ] I have added, or updated, [mermaid.js](https://mermaid-js.github.io) diagrams in the corresponding README(s)
- [ ] I have added, or updated, documentation and [mermaid.js](https://mermaid-js.github.io) diagrams in `shared/docs/*` if I updated `shared/*`README(s)


Co-authored-by: Alessandro De Blasis <alex@deblasis.net>
  • Loading branch information
Olshansk and deblasis authored Feb 14, 2023
1 parent 4568296 commit c167ad4
Show file tree
Hide file tree
Showing 87 changed files with 3,028 additions and 3,221 deletions.
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 @@ -94,7 +94,7 @@ func prepareTxBytes(msg typesUtil.Message, pk crypto.PrivateKey) ([]byte, error)
Nonce: fmt.Sprintf("%d", crypto.GetNonce()),
}

signBytes, err := tx.SignBytes()
signBytes, err := tx.SignableBytes()
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -151,7 +151,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 @@ -20,7 +20,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
2 changes: 1 addition & 1 deletion persistence/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (p *persistenceModule) TransactionExists(transactionHash string) (bool, err
func (p *PostgresContext) GetMinimumBlockHeight() (latestHeight uint64, err error) {
ctx, tx := p.getCtxAndTx()

err = tx.QueryRow(ctx, types.GetMinimumlockHeightQuery()).Scan(&latestHeight)
err = tx.QueryRow(ctx, types.GetMinimumBlockHeightQuery()).Scan(&latestHeight)
return
}

Expand Down
7 changes: 7 additions & 0 deletions persistence/docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.0.0.34] - 2023-02-14

- Remove `IUnstakingActor` and use `UnstakingActor` directly; guideline for removing future unnecessary types (e.g. TxResult)
- Typo in `GetMinimumBlockHeightQuery`
- Reduce unnecessary `string` <-> `[]byte` conversion in a few places
- Fix bug in `updateUnstakedHeightIfPausedBefore` that was unstaking all actors

## [0.0.0.33] - 2023-02-09

- Added mock generation to the `kvstore/kvstore.go`.
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
Loading

0 comments on commit c167ad4

Please sign in to comment.