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

[Code Health] Harden settlement (part 2: (non-)halting settlement error alignment) #904

Draft
wants to merge 2 commits into
base: issues/881/refactor/settlement
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion tests/integration/application/min_stake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestApplicationMinStakeTestSuite(t *testing.T) {
}

func (s *applicationMinStakeTestSuite) SetupTest() {
s.keepers, s.ctx = keeper.NewTokenomicsModuleKeepers(s.T(), cosmoslog.NewNopLogger(), keeper.WithProofRequirement(false))
s.keepers, s.ctx = keeper.NewTokenomicsModuleKeepers(s.T(), cosmoslog.NewNopLogger(), keeper.WithProofRequirement(prooftypes.ProofRequirementReason_NOT_REQUIRED))

proofParams := prooftypes.DefaultParams()
proofParams.ProofRequestProbability = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestComputeNewDifficultyHash_RewardsReflectWorkCompleted(t *testing.T) {
testutils.WithService(service),
testutils.WithApplication(application),
testutils.WithSupplier(supplier),
testutils.WithProofRequirement(false),
testutils.WithProofRequirement(prooftypes.ProofRequirementReason_NOT_REQUIRED),
)
sdkCtx := sdk.UnwrapSDKContext(ctx)
sdkCtx = sdkCtx.WithBlockHeight(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"strings"
"testing"

"cosmossdk.io/log"
"github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
Expand All @@ -17,7 +16,6 @@ import (
"github.com/pokt-network/poktroll/testutil/sample"
apptypes "github.com/pokt-network/poktroll/x/application/types"
prooftypes "github.com/pokt-network/poktroll/x/proof/types"
sharedtypes "github.com/pokt-network/poktroll/x/shared/types"
suppliertypes "github.com/pokt-network/poktroll/x/supplier/types"
tlm "github.com/pokt-network/poktroll/x/tokenomics/token_logic_module"
tokenomicstypes "github.com/pokt-network/poktroll/x/tokenomics/types"
Expand All @@ -43,6 +41,8 @@ func (s *tokenLogicModuleTestSuite) TestTLMProcessorsAreCommutative() {
numTLMOrderPermutations := factorial(len(tokenLogicModules))
require.Equal(s.T(), numTLMOrderPermutations, len(tlmOrderPermutations))

proofNeverRequiredOpt := keeper.WithProofRequirement(prooftypes.ProofRequirementReason_NOT_REQUIRED)

for i, tlmPermutation := range tlmOrderPermutations {
var tlmIds []string
for _, tokenLogicModule := range tlmPermutation {
Expand All @@ -58,13 +58,13 @@ func (s *tokenLogicModuleTestSuite) TestTLMProcessorsAreCommutative() {
)

s.T().Run(testDesc, func(t *testing.T) {
s.setupKeepers(t, keeper.WithTokenLogicModules(tlmPermutation))
s.setupKeepers(t, keeper.WithTokenLogicModules(tlmPermutation), proofNeverRequiredOpt)

// Assert that no pre-existing claims are present.
numExistingClaims := len(s.keepers.GetAllClaims(s.ctx))
require.Equal(t, 0, numExistingClaims)

s.createClaims(&s.keepers, 1000)
s.createClaims(1000)
settledResults, expiredResults := s.settleClaims(t)

// First iteration only.
Expand All @@ -81,38 +81,6 @@ func (s *tokenLogicModuleTestSuite) TestTLMProcessorsAreCommutative() {
}
}

// setupKeepers initializes a new instance of TokenomicsModuleKeepers and context
// with the given options, and creates the suite's service, application, and supplier
// from SetupTest(). It also sets the block height to 1 and the proposer address to
// the proposer address from SetupTest().
func (s *tokenLogicModuleTestSuite) setupKeepers(t *testing.T, opts ...keeper.TokenomicsModuleKeepersOptFn) {
defaultOpts := []keeper.TokenomicsModuleKeepersOptFn{
keeper.WithService(*s.service),
keeper.WithApplication(*s.app),
keeper.WithSupplier(*s.supplier),
keeper.WithModuleParams(map[string]types.Msg{
// TODO_MAINNET(@bryanchriswhite): Set tokenomics mint allocation params to maximize coverage, once available.

// Set the proof params such that proofs are NEVER required.
prooftypes.ModuleName: s.getProofParams(),
// Set the CUTTM to simplify calculating settlement amount expectstions.
sharedtypes.ModuleName: s.getSharedParams(),
// Set the dao_reward_address for settlement rewards.
tokenomicstypes.ModuleName: s.getTokenomicsParams(),
}),
}

s.keepers, s.ctx = keeper.NewTokenomicsModuleKeepers(
t, log.NewNopLogger(),
append(defaultOpts, opts...)...,
)

// Increment the block height to 1; valid session height and set the proposer address.
s.ctx = types.UnwrapSDKContext(s.ctx).
WithBlockHeight(1).
WithProposer(s.proposerConsAddr)
}

// setExpectedSettlementState sets the expected settlement state on the suite based
// on the current network state and the given settledResults and expiredResults.
func (s *tokenLogicModuleTestSuite) setExpectedSettlementState(
Expand Down Expand Up @@ -145,7 +113,7 @@ func (s *tokenLogicModuleTestSuite) getSettlementState(t *testing.T) *settlement
supplierOwnerBalance: s.getBalance(t, s.supplier.GetOwnerAddress()),
proposerBalance: s.getBalance(t, proposerBech32),
daoBalance: s.getBalance(t, s.daoRewardAddr),
sourceOwnerBalance: s.getBalance(t, s.sourceOwnerBech32),
sourceOwnerBalance: s.getBalance(t, s.sourceOwnerAddr),
}
}

Expand Down Expand Up @@ -197,7 +165,7 @@ func (s *tokenLogicModuleTestSuite) assertExpectedSettlementState(
actualSettlementState := s.getSettlementState(t)

// Assert that app stake and rewardee balances are non-zero.
coinIsZeroMsg := "coin has zero amount"
coinIsZeroMsg := "Coin has zero amount"
require.NotEqual(t, &zerouPOKT, actualSettlementState.appStake, coinIsZeroMsg)
require.NotEqual(t, &zerouPOKT, actualSettlementState.supplierOwnerBalance, coinIsZeroMsg)
require.NotEqual(t, &zerouPOKT, actualSettlementState.proposerBalance, coinIsZeroMsg)
Expand Down
Loading
Loading