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

test: Add driver for PSS #1636

Merged
merged 10 commits into from
Feb 14, 2024
28 changes: 28 additions & 0 deletions tests/mbt/driver/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,34 @@ func (s *Driver) AssignKey(chain ChainId, valIndex int64, key crypto.PublicKey)
return s.providerKeeper().AssignConsumerKey(s.providerCtx(), string(chain), stakingVal, key)
}

// Opts the given validator into the given consumer chain on the provider.
func (s *Driver) OptIn(chain ChainId, valIndex int64) error {
stakingVal, found := s.stakingValidator(valIndex)
if !found {
return fmt.Errorf("validator with id %v not found on provider", valIndex)
}
consPubKey, err := stakingVal.ConsPubKey()
if err != nil {
return err
}
consAddr := sdk.GetConsAddress(consPubKey)
return s.providerKeeper().HandleOptIn(s.providerCtx(), string(chain), providertypes.NewProviderConsAddress(consAddr), nil)
}

// Opts the given validator out of the given consumer chain on the provider.
func (s *Driver) OptOut(chain ChainId, valIndex int64) error {
stakingVal, found := s.stakingValidator(valIndex)
if !found {
return fmt.Errorf("validator with id %v not found on provider", valIndex)
}
consPubKey, err := stakingVal.ConsPubKey()
if err != nil {
return err
}
consAddr := sdk.GetConsAddress(consPubKey)
return s.providerKeeper().HandleOptOut(s.providerCtx(), string(chain), providertypes.NewProviderConsAddress(consAddr))
}

// DeliverPacketToConsumer delivers a packet from the provider to the given consumer recipient.
// It updates the client before delivering the packet.
// Since the channel is ordered, the packet that is delivered is the first packet in the outbox.
Expand Down
3 changes: 2 additions & 1 deletion tests/mbt/driver/generate_more_traces.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ echo "Generating synced traces with maturations"
go run ./... -modelPath=../model/ccv_sync.qnt -init initSync -step stepSync -invariant CanReceiveMaturations -traceFolder traces/sync_mat -numTraces 20 -numSteps 300 -numSamples 20
echo "Generating long synced traces without invariants"
go run ./... -modelPath=../model/ccv_sync.qnt -init initSync -step stepSync -traceFolder traces/sync_noinv -numTraces 20 -numSteps 500 -numSamples 1
go run ./... -modelPath=../model/ccv_boundeddrift.qnt --step stepBoundedDriftKeyAssignment --traceFolder traces/bound_key -numTraces 20 -numSteps 100 -numSamples 20
go run ./... -modelPath=../model/ccv_boundeddrift.qnt --step stepBoundedDriftKeyAssignment --traceFolder traces/bound_key -numTraces 20 -numSteps 100 -numSamples 20
go run ./... -modelPath=../model/ccv_boundeddrift.qnt --step stepBoundedDriftKeyAndPSS --traceFolder traces/bound_pss -numTraces 20 -numSteps 100 -numSamples 20
3 changes: 2 additions & 1 deletion tests/mbt/driver/generate_traces.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ echo "Generating synced traces with maturations"
go run ./... -modelPath=../model/ccv_sync.qnt -init initSync -step stepSync -invariant CanReceiveMaturations -traceFolder traces/sync_mat -numTraces 1 -numSteps 300 -numSamples 20
echo "Generating long synced traces without invariants"
go run ./... -modelPath=../model/ccv_sync.qnt -init initSync -step stepSync -traceFolder traces/sync_noinv -numTraces 1 -numSteps 500 -numSamples 1
go run ./... -modelPath=../model/ccv_boundeddrift.qnt --step stepBoundedDriftKeyAssignment --traceFolder traces/bound_key -numTraces 1 -numSteps 100 -numSamples 20
go run ./... -modelPath=../model/ccv_boundeddrift.qnt --step stepBoundedDriftKeyAssignment --traceFolder traces/bound_key -numTraces 1 -numSteps 100 -numSamples 20
go run ./... -modelPath=../model/ccv_boundeddrift.qnt --step stepBoundedDriftKeyAndPSS --traceFolder traces/bound_pss -numTraces 1 -numSteps 100 -numSamples 20
37 changes: 33 additions & 4 deletions tests/mbt/driver/mbt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,14 +275,17 @@ func RunItfTrace(t *testing.T, path string) {
driver.coordinator.CurrentTime = driver.runningTime("provider")
// start consumers
for _, consumer := range consumersToStart {
chainId := consumer.Value.(itf.MapExprType)["chain"].Value.(string)
topN := consumer.Value.(itf.MapExprType)["topN"].Value.(int64)
driver.setupConsumer(
consumer.Value.(string),
chainId,
modelParams,
driver.providerChain().Vals,
consumerSigners,
nodes,
valNames,
driver.providerChain(),
topN,
)
}

Expand All @@ -301,7 +304,8 @@ func RunItfTrace(t *testing.T, path string) {
// unless it was the last consumer to be started, in which case it already has the header
// as we called driver.setupConsumer
for _, consumer := range driver.runningConsumers() {
if len(consumersToStart) > 0 && consumer.ChainId == consumersToStart[len(consumersToStart)-1].Value.(string) {
if len(consumersToStart) > 0 &&
consumer.ChainId == consumersToStart[len(consumersToStart)-1].Value.(itf.MapExprType)["chain"].Value.(string) {
continue
}

Expand Down Expand Up @@ -376,8 +380,33 @@ func RunItfTrace(t *testing.T, path string) {
protoPubKey, err := tmencoding.PubKeyToProto(assignedKey)
require.NoError(t, err, "Error converting pubkey to proto")

error := driver.AssignKey(ChainId(consumerChain), int64(valIndex), protoPubKey)
require.NoError(t, error, "Error assigning key")
err = driver.AssignKey(ChainId(consumerChain), int64(valIndex), protoPubKey)
require.NoError(t, err, "Error assigning key")
case "OptIn":
consumerChain := lastAction["consumerChain"].Value.(string)
validator := lastAction["validator"].Value.(string)
t.Log("OptIn", consumerChain, validator)

valIndex := getIndexOfString(validator, valNames)

err := driver.OptIn(ChainId(consumerChain), int64(valIndex))
require.NoError(t, err, "Error opting in")

case "OptOut":
consumerChain := lastAction["consumerChain"].Value.(string)
validator := lastAction["validator"].Value.(string)
expectedError := lastAction["expectedError"].Value.(string)
t.Log("OptOut", consumerChain, validator, expectedError)

valIndex := getIndexOfString(validator, valNames)

err := driver.OptOut(ChainId(consumerChain), int64(valIndex))

if expectedError != "" {
require.Error(t, err, "Expected an error: %v", expectedError)
} else {
require.NoError(t, err, "Error opting out, but expected no error")
}

default:
log.Fatalf("Error loading trace file %s, step %v: do not know action type %s",
Expand Down
1 change: 1 addition & 0 deletions tests/mbt/driver/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ func (s *Driver) setupConsumer(
nodes []*cmttypes.Validator, // the list of nodes, even ones that have no voting power initially
valNames []string,
providerChain *ibctesting.TestChain,
topN int64,
) {
s.t.Logf("Starting consumer %v", chain)

Expand Down
3 changes: 1 addition & 2 deletions tests/mbt/model/ccv_pss_model.qnt
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ module ccv_pss_model {
...emptyAction,
kind: "OptIn",
consumerChain: consumer,
validator: validator,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed because I realized OptIn was never erroring here anyways

expectedError: res.error
validator: validator
}
),
params' = params,
Expand Down
Loading