Skip to content

Commit

Permalink
test: Add driver for PSS (#1636)
Browse files Browse the repository at this point in the history
* Port key assignment to MBT driver

* Add PSS trace generation

* Add PSS trace gen to longer trace gen

* Start handling top N parameter for new consumers

* Finish merge

* Add handling for optin/optout steps

* Remove expected error from OptIn, which should not error

* set top N parameter during path setup

* Add comment to setup.go
  • Loading branch information
p-offtermatt authored and sainoe committed Mar 12, 2024
1 parent 7b0afcd commit 64f5651
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 10 deletions.
28 changes: 28 additions & 0 deletions tests/mbt/driver/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,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 @@ -314,14 +314,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 @@ -340,7 +343,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 @@ -415,8 +419,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
12 changes: 10 additions & 2 deletions tests/mbt/driver/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ func newChain(
// Creates a path for cross-chain validation from the consumer to the provider and configures the channel config of the endpoints
// as well as the clients.
// this function stops when there is an initialized, ready-to-relay channel between the provider and consumer.
func (s *Driver) ConfigureNewPath(consumerChain, providerChain *ibctesting.TestChain, params ModelParams) *ibctesting.Path {
func (s *Driver) ConfigureNewPath(consumerChain, providerChain *ibctesting.TestChain, params ModelParams, topN uint32) *ibctesting.Path {
consumerChainId := ChainId(consumerChain.ChainID)

path := ibctesting.NewPath(consumerChain, providerChain)
Expand Down Expand Up @@ -382,6 +382,11 @@ func (s *Driver) ConfigureNewPath(consumerChain, providerChain *ibctesting.TestC
consumerGenesisForProvider)
require.NoError(s.t, err, "Error setting consumer genesis on provider for chain %v", consumerChain.ChainID)

// set the top N percentage
// needs to be done before the provider queues the first vsc packet to the consumer
// TODO: might be able to move this into setupConsumer, need to test once more logic is here
s.providerKeeper().SetTopN(providerChain.GetContext(), consumerChain.ChainID, topN)

// Client ID is set in InitGenesis and we treat it as a black box. So
// must query it to use it with the endpoint.
clientID, _ := s.consumerKeeper(consumerChainId).GetProviderClientID(s.ctx(consumerChainId))
Expand Down Expand Up @@ -437,17 +442,20 @@ 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)

// TODO: reuse the partial set computation logic to compute the initial validator set
// for top N chains
initValUpdates := cmttypes.TM2PB.ValidatorUpdates(valSet)

// start consumer chains
s.t.Logf("Creating consumer chain %v", chain)
consumerChain := newChain(s.t, params, s.coordinator, icstestingutils.ConsumerAppIniter(initValUpdates), chain, valSet, signers, nodes, valNames)
s.coordinator.Chains[chain] = consumerChain

path := s.ConfigureNewPath(consumerChain, providerChain, params)
path := s.ConfigureNewPath(consumerChain, providerChain, params, uint32(topN))
s.simibcs[ChainId(chain)] = simibc.MakeRelayedPath(s.t, path)
}

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,
expectedError: res.error
validator: validator
}
),
params' = params,
Expand Down

0 comments on commit 64f5651

Please sign in to comment.