Skip to content

Commit

Permalink
[Testing] refactor: E2E param test helpers (#821)
Browse files Browse the repository at this point in the history
## Summary

- Rename `paramMap` type to `paramAnyMap` to improve readability and
avoid local variable name collisions
- Add missing parameter update assertion steps
- Refactor event waiting E2E helpers

## Depends on

- #815 

## Dependents

- #820 
- #826

## Issue

Mitigates silently failing parameter update steps.

- #799

## Type of change

Select one or more from the following:

- [ ] 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

- [ ] 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
- [ ] I have left TODOs throughout the codebase, if applicable

---------

Co-authored-by: Daniel Olshansky <[email protected]>
  • Loading branch information
bryanchriswhite and Olshansk authored Sep 24, 2024
1 parent 5a8e4e5 commit 76a140a
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 26 deletions.
8 changes: 6 additions & 2 deletions e2e/tests/0_settlement.feature
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ Feature: Tokenomics Namespace
| proof_requirement_threshold | 839 | coin |
| proof_missing_penalty | 320 | coin |
| proof_submission_fee | 1000000 | coin |
And the "tokenomics" module parameters are set as follows
And all "proof" module params should be updated
And the "shared" module parameters are set as follows
| compute_units_to_tokens_multiplier | 42 | int64 |
And all "shared" module params should be updated
When the supplier "supplier1" has serviced a session with "20" relays for service "anvil" for application "app1"
# Wait for the Claim & Proof lifecycle
And the user should wait for the "proof" module "CreateClaim" Message to be submitted
Expand Down Expand Up @@ -58,8 +60,10 @@ Feature: Tokenomics Namespace
| proof_requirement_threshold | 421 | coin |
| proof_missing_penalty | 320 | coin |
| proof_submission_fee | 1000000 | coin |
And the "tokenomics" module parameters are set as follows
And all "proof" module params should be updated
And the "shared" module parameters are set as follows
| compute_units_to_tokens_multiplier | 42 | int64 |
And all "shared" module params should be updated
# Start servicing
When the supplier "supplier1" has serviced a session with "10" relays for service "anvil" for application "app1"
# Wait for the Claim & Proof lifecycle
Expand Down
10 changes: 10 additions & 0 deletions e2e/tests/params_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ func (s *suite) sendAuthzExecTx(signingKeyName, txJSONFilePath string) {

// TODO_IMPROVE: wait for the tx to be committed using an events query client
// instead of sleeping for a specific amount of time.
//
// First attempt:
// eventAttrMatchFn := newEventAttributeMatchFn("action", "/cosmos.authz.v1beta1.MsgExec")
// s.waitForTxResultEvent(eventAttrMatchFn)
//
// This resulted in observing many more events than expected, even accounting
// for those corresponding to the param reset step, which is automatically
// registered in a s.Cleanup() below. There are no useful attributes on these
// events such that we can filter out the noise.

s.Logf("waiting %d seconds for the authz exec tx to be committed...", txDelaySeconds)
time.Sleep(txDelaySeconds * time.Second)

Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/params_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type (
paramNameKey = string
)

// paramsAnyMap is a map of param names to param values.
// paramsAnyMap is a map of param names to param any values.
type paramsAnyMap map[paramNameKey]paramAny

// moduleParamsMap is a map of module names to params maps.
Expand Down
4 changes: 3 additions & 1 deletion e2e/tests/session.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ Feature: Session Namespace
| proof_requirement_threshold | 209 | coin |
| proof_missing_penalty | 320 | coin |
| proof_submission_fee | 1000000 | coin |
And the "tokenomics" module parameters are set as follows
And all "proof" module params should be updated
And the "shared" module parameters are set as follows
| compute_units_to_tokens_multiplier | 42 | int64 |
And all "shared" module params should be updated
When the supplier "supplier1" has serviced a session with "5" relays for service "anvil" for application "app1"
And the user should wait for the "proof" module "CreateClaim" Message to be submitted
And the user should wait for the "proof" module "ClaimCreated" tx event to be broadcast
Expand Down
61 changes: 39 additions & 22 deletions e2e/tests/session_steps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,7 @@ func (s *suite) waitForTxResultEvent(eventIsMatch func(*abci.Event) bool) (match
ctx, cancel := context.WithCancel(s.ctx)

// For each observed event, **asynchronously** check if it contains the given action.
channel.ForEach[*abci.TxResult](
ctx, s.txResultReplayClient.EventsSequence(ctx),
s.forEachTxResult(ctx,
func(_ context.Context, txResult *abci.TxResult) {
if txResult == nil {
return
Expand All @@ -225,13 +224,6 @@ func (s *suite) waitForTxResultEvent(eventIsMatch func(*abci.Event) bool) (match
},
)

select {
case <-time.After(eventTimeout):
s.Fatalf("ERROR: timed out waiting for tx result event")
case <-ctx.Done():
s.Log("Success; message detected before timeout.")
}

return matchedEvent
}

Expand All @@ -245,8 +237,7 @@ func (s *suite) waitForNewBlockEvent(
ctx, done := context.WithCancel(s.ctx)

// For each observed event, **asynchronously** check if it contains the given action.
channel.ForEach[*block.CometNewBlockEvent](
ctx, s.newBlockEventsReplayClient.EventsSequence(ctx),
s.forEachBlockEvent(ctx,
func(_ context.Context, newBlockEvent *block.CometNewBlockEvent) {
if newBlockEvent == nil {
return
Expand All @@ -264,13 +255,6 @@ func (s *suite) waitForNewBlockEvent(
}
},
)

select {
case <-time.After(eventTimeout):
s.Fatalf("ERROR: timed out waiting for NewBlock event")
case <-ctx.Done():
s.Log("Success; message detected before timeout.")
}
}

// waitForBlockHeight waits for a NewBlock event to be observed whose height is
Expand All @@ -280,8 +264,7 @@ func (s *suite) waitForBlockHeight(targetHeight int64) {

// For each observed event, **asynchronously** check if it is greater than
// or equal to the target height
channel.ForEach[*block.CometNewBlockEvent](
ctx, s.newBlockEventsReplayClient.EventsSequence(ctx),
s.forEachBlockEvent(ctx,
func(_ context.Context, newBlockEvent *block.CometNewBlockEvent) {
if newBlockEvent == nil {
return
Expand All @@ -293,12 +276,46 @@ func (s *suite) waitForBlockHeight(targetHeight int64) {
}
},
)
}

// forEachBlockEvent calls blockEventFn for each observed block event **asynchronously**
// and blocks on waiting for the given context to be cancelled. If the context is
// not cancelled before eventTimeout, the test will fail.
func (s *suite) forEachBlockEvent(
ctx context.Context,
blockEventFn func(_ context.Context, newBlockEvent *block.CometNewBlockEvent),
) {
channel.ForEach[*block.CometNewBlockEvent](ctx,
s.newBlockEventsReplayClient.EventsSequence(ctx),
blockEventFn,
)

select {
case <-time.After(eventTimeout):
s.Fatalf("ERROR: timed out waiting new block event")
case <-ctx.Done():
s.Log("Success; new block event detected before timeout.")
}
}

// forEachTxResult calls txResult for each observed tx result **asynchronously**
// and blocks on waiting for the given context to be cancelled. If the context is
// not cancelled before eventTimeout, the test will fail.
func (s *suite) forEachTxResult(
ctx context.Context,
txResultFn func(_ context.Context, txResult *abci.TxResult),
) {

channel.ForEach[*abci.TxResult](ctx,
s.txResultReplayClient.EventsSequence(ctx),
txResultFn,
)

select {
case <-time.After(eventTimeout):
s.Fatalf("ERROR: timed out waiting for block height", targetHeight)
s.Fatalf("ERROR: timed out waiting for tx result")
case <-ctx.Done():
s.Log("Success; height detected before timeout.")
s.Log("Success; tx result detected before timeout.")
}
}

Expand Down

0 comments on commit 76a140a

Please sign in to comment.