Skip to content

Commit

Permalink
[Testing] refactor: integration app / feat: add IntegrationAppSuite (
Browse files Browse the repository at this point in the history
…#827)

## Summary

- Refactor integration app base app construction to eliminate duplicate
DB construction.
- Set default params for all poktroll modules, some were omitted.
- Expose integration app's pre-generated account iterator for use by
integration tests.
- Add faucet account to integration app to consolidate funding mechanics
for integration tests.
- Add authz & bank modules to integration app in preparation for param
update test porting/refactoring as integration tests (#826).
- Add IntegrationAppSuite & base implementation.

## Dependents

- #789
- #826

## Issue

- #799

## Type of change

Select one or more from the following:

- [x] New feature, functionality or library
- [ ] Consensus breaking; add the `consensus-breaking` label if so. See
#791 for details
- [ ] Bug fix
- [x] Code health or cleanup
- [ ] Documentation
- [ ] Other (specify)

## Testing

- [ ] **Documentation**: `make docusaurus_start`; only needed if you
make doc changes
- [ ] **Unit Tests**: `make go_develop_and_test`
- [ ] **LocalNet E2E Tests**: `make test_e2e`
- [ ] **DevNet E2E Tests**: Add the `devnet-test-e2e` label to the PR.

## Sanity Checklist

- [x] I have tested my changes using the available tooling
- [x] I have commented my code
- [x] I have performed a self-review of my own code; both comments &
source code
- [ ] I create and reference any new tickets, if applicable
- [x] I have left TODOs throughout the codebase, if applicable

---------

Co-authored-by: red-0ne <[email protected]>
Co-authored-by: Daniel Olshansky <[email protected]>
  • Loading branch information
3 people authored Sep 25, 2024
1 parent bdd925a commit 9e544f3
Show file tree
Hide file tree
Showing 14 changed files with 1,021 additions and 277 deletions.
7 changes: 2 additions & 5 deletions tests/integration/tokenomics/relay_mining_difficulty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,8 @@ func TestUpdateRelayMiningDifficulty_NewServiceSeenForTheFirstTime(t *testing.T)
SessionHeader: session.Header,
RootHash: trie.Root(),
}
result := integrationApp.RunMsg(t,
&createClaimMsg,
integration.WithAutomaticFinalizeBlock(),
integration.WithAutomaticCommit(),
)
result, err := integrationApp.RunMsg(t, &createClaimMsg)
require.NoError(t, err)
require.NotNil(t, result, "unexpected nil result when submitting a MsgCreateClaim tx")

// Wait until the proof window is open
Expand Down
78 changes: 55 additions & 23 deletions tests/integration/tokenomics/relay_mining_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ import (
"context"
"testing"

"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/pokt-network/smt"
"github.com/pokt-network/smt/kvstore/pebble"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"

"github.com/pokt-network/poktroll/app/volatile"
"github.com/pokt-network/poktroll/pkg/crypto/protocol"
"github.com/pokt-network/poktroll/testutil/integration"
"github.com/pokt-network/poktroll/testutil/testrelayer"
Expand All @@ -21,28 +19,57 @@ import (
tokenomicstypes "github.com/pokt-network/poktroll/x/tokenomics/types"
)

func TestComputeNewDifficultyHash_RewardsReflectWorkCompleted(t *testing.T) {
// Test params
globalComputeUnitsToTokensMultiplier := uint64(1) // keeping the math simple
// serviceComputeUnitsPerRelay := uint64(1) // keeping the math simple
var (
// TODO_BETA(#826): Uncomment these
// Test params.
// computeUnitsToTokensMultiplier = uint64(1) // keeping the math simple
// proofRequirementThreshold = sdk.NewInt64Coin(volatile.DenomuPOKT, 1e18)
)

// Prepare the keepers and integration app
integrationApp := integration.NewCompleteIntegrationApp(t)
sdkCtx := integrationApp.GetSdkCtx()
keepers := integrationApp.GetKeepers()
type RelayMiningIntegrationTestSuite struct {
// TODO_BETA(#826): wait for integration app & suites refactor to be merged.
// Once suites.ParamsSuite is available, embed it here. In the meantime, we
// MUST embed suite.Suite to avoid compilation errors.
//
// suites.ParamsSuite
suite.Suite
}

// Set the global tokenomics params
err := keepers.SharedKeeper.SetParams(sdkCtx, sharedtypes.Params{
ComputeUnitsToTokensMultiplier: globalComputeUnitsToTokensMultiplier,
})
require.NoError(t, err)
func (s *RelayMiningIntegrationTestSuite) SetupTest() {
// Construct a fresh integration app for each test.
// TODO_BETA(#826): wait for integration app & suites refactor to be merged.
// s.NewApp(s.T())
// s.SetupTestAccounts()
// s.SetupTestAuthzGrants()
}

// Set the global proof params so we never need a proof (for simplicity of this test)
err = keepers.ProofKeeper.SetParams(sdkCtx, prooftypes.Params{
ProofRequestProbability: 0, // we never need a proof randomly
ProofRequirementThreshold: &sdk.Coin{Denom: volatile.DenomuPOKT, Amount: math.NewInt(1e18)}, // a VERY high threshold
})
require.NoError(t, err)
func (s *RelayMiningIntegrationTestSuite) TestComputeNewDifficultyHash_RewardsReflectWorkCompleted() {
// Set the shared module param compute_units_to_tokens_multiplier.
// TODO_BETA(#826): wait for integration app & suites refactor to be merged.
// _, err := s.RunUpdateParam(s.T(),
// sharedtypes.ModuleName,
// sharedtypes.ParamComputeUnitsToTokensMultiplier,
// computeUnitsToTokensMultiplier,
// )
// require.NoError(s.T(), err)

// Set the proof params so we never need a proof (for simplicity of this test)
// TODO_BETA(#826): wait for integration app & suites refactor to be merged.
// _, err = s.RunUpdateParam(s.T(),
// prooftypes.ModuleName,
// prooftypes.ParamProofRequestProbability,
// float32(0),
// )
// require.NoError(s.T(), err)

// Set the proof requirement threshold to be VERY high.
// TODO_BETA(#826): wait for integration app & suites refactor to be merged.
// _, err = s.RunUpdateParam(s.T(),
// prooftypes.ModuleName,
// prooftypes.ParamProofRequirementThreshold,
// &proofRequirementThreshold,
// )
// require.NoError(s.T(), err)

// TODO(@red-0ne, #781): Implement this test after the business logic is done.

Expand Down Expand Up @@ -84,7 +111,7 @@ func TestComputeNewDifficultyHash_RewardsReflectWorkCompleted(t *testing.T) {
require.NoError(t, err)
// Compute the expected reward
expectedReward := numRelays * serviceComputeUnitsPerRelay * globalComputeUnitsToTokensMultiplier
expectedReward := numRelays * serviceComputeUnitsPerRelay * computeUnitsToTokensMultiplier
fmt.Println("Expected reward:", expectedReward)
// Compute the new difficulty hash
Expand Down Expand Up @@ -154,3 +181,8 @@ func prepareRealClaim(
RootHash: trie.Root(),
}
}

func TestRelayMiningIntegrationSuite(t *testing.T) {
t.Skip("TODO_BETA(#826): wait for integration app & suites refactor to be merged.")
suite.Run(t, new(RelayMiningIntegrationTestSuite))
}
7 changes: 2 additions & 5 deletions tests/integration/tokenomics/tokenomics_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,7 @@ func TestTokenomicsIntegrationExample(t *testing.T) {
}

// Run the message to create the claim
result := integrationApp.RunMsg(t,
&createClaimMsg,
integration.WithAutomaticFinalizeBlock(),
integration.WithAutomaticCommit(),
)
result, err := integrationApp.RunMsg(t, &createClaimMsg)
require.NoError(t, err)
require.NotNil(t, result, "unexpected nil result")
}
22 changes: 22 additions & 0 deletions testutil/events/attributes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package events

import (
"strings"

cosmostypes "github.com/cosmos/cosmos-sdk/types"
)

// GetAttributeValue returns the value of the attribute with the given key in the
// event. The returned attribute value is trimmed of any quotation marks. If the
// attribute does not exist, hasAttr is false.
func GetAttributeValue(
event *cosmostypes.Event,
key string,
) (value string, hasAttr bool) {
attr, hasAttr := event.GetAttribute(key)
if !hasAttr {
return "", false
}

return strings.Trim(attr.GetValue(), "\""), true
}
27 changes: 27 additions & 0 deletions testutil/events/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package events

import (
"strconv"
"strings"
"testing"

abci "github.com/cometbft/cometbft/abci/types"
Expand Down Expand Up @@ -47,3 +48,29 @@ func QuoteEventMode(event *abci.Event) {
}
}
}

// NewMsgEventMatchFn returns a function that matches events whose type equals
// the given event (protobuf message) type URL.
func NewMsgEventMatchFn(matchMsgTypeURL string) func(*cosmostypes.Event) bool {
return func(event *cosmostypes.Event) bool {
if event.Type != "message" {
return false
}

actionAttr, hasActionAttr := event.GetAttribute("action")
if !hasActionAttr {
return false
}

eventMsgTypeURL := strings.Trim(actionAttr.GetValue(), "\"")
return strings.Trim(eventMsgTypeURL, "/") == strings.Trim(matchMsgTypeURL, "/")
}
}

// NewEventTypeMatchFn returns a function that matches events whose type is "message"
// and whose "action" attribute matches the given message (protobuf message) type URL.
func NewEventTypeMatchFn(matchEventType string) func(*cosmostypes.Event) bool {
return func(event *cosmostypes.Event) bool {
return strings.Trim(event.Type, "/") == strings.Trim(matchEventType, "/")
}
}
Loading

0 comments on commit 9e544f3

Please sign in to comment.