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 partial-set-security E2E tests #1737

Merged
merged 6 commits into from
Apr 3, 2024
Merged
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
104 changes: 101 additions & 3 deletions tests/e2e/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ type SubmitConsumerAdditionProposalAction struct {
SpawnTime uint
InitialHeight clienttypes.Height
DistributionChannel string
TopN uint32
}

func (tr TestConfig) submitConsumerAdditionProposal(
Expand All @@ -278,7 +279,7 @@ func (tr TestConfig) submitConsumerAdditionProposal(
UnbondingPeriod: params.UnbondingPeriod,
Deposit: fmt.Sprint(action.Deposit) + `stake`,
DistributionTransmissionChannel: action.DistributionChannel,
TopN: 100,
TopN: action.TopN,
}

bz, err := json.Marshal(prop)
Expand All @@ -292,9 +293,14 @@ func (tr TestConfig) submitConsumerAdditionProposal(
}

//#nosec G204 -- bypass unsafe quoting warning (no production code)
bz, err = target.ExecCommand(
cmd := target.ExecCommand(
"/bin/bash", "-c", fmt.Sprintf(`echo '%s' > %s`, jsonStr, "/temp-proposal.json"),
).CombinedOutput()
)
bz, err = cmd.CombinedOutput()

if verbose {
log.Println("submitConsumerAdditionProposal cmd: ", cmd.String())
}

if err != nil {
log.Fatal(err, "\n", string(bz))
Expand Down Expand Up @@ -2292,6 +2298,98 @@ func (tc TestConfig) startConsumerEvidenceDetector(
tc.waitBlocks("provi", 10, 2*time.Minute)
}

type OptInAction struct {
Chain ChainID
Validator ValidatorID
}

func (tr TestConfig) optIn(action OptInAction, target ExecutionTarget, verbose bool) {
// Note: to get error response reported back from this command '--gas auto' needs to be set.
gas := "auto"
// Unfortunately, --gas auto does not work with CometMock. so when using CometMock, just use --gas 9000000 then
if tr.useCometmock {
gas = "9000000"
}

// Use: "opt-in [consumer-chain-id] [consumer-pubkey]",
optIn := fmt.Sprintf(
`%s tx provider opt-in %s --from validator%s --chain-id %s --home %s --node %s --gas %s --keyring-backend test -y -o json`,
tr.chainConfigs[ChainID("provi")].BinaryName,
string(tr.chainConfigs[action.Chain].ChainId),
action.Validator,
tr.chainConfigs[ChainID("provi")].ChainId,
tr.getValidatorHome(ChainID("provi"), action.Validator),
tr.getValidatorNode(ChainID("provi"), action.Validator),
gas,
)

cmd := target.ExecCommand(
"/bin/bash", "-c",
optIn,
)

if verbose {
fmt.Println("optIn cmd:", cmd.String())
}

bz, err := cmd.CombinedOutput()
_, _ = bz, err
Copy link
Contributor

@sainoe sainoe Apr 3, 2024

Choose a reason for hiding this comment

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

Suggested change
_, _ = bz, err
if err != nil {
log.Fatal(err, "\n", string(bz))
}

if !tr.useCometmock { // error report only works with --gas auto, which does not work with CometMock, so ignore
if verbose {
fmt.Printf("got expected error during opt in | err: %s | output: %s \n", err, string(bz))
}
}

// wait for inclusion in a block -> '--broadcast-mode block' is deprecated
tr.waitBlocks(ChainID("provi"), 2, 30*time.Second)
}

type OptOutAction struct {
Chain ChainID
Validator ValidatorID
}

func (tr TestConfig) optOut(action OptOutAction, target ExecutionTarget, verbose bool) {
// Note: to get error response reported back from this command '--gas auto' needs to be set.
gas := "auto"
// Unfortunately, --gas auto does not work with CometMock. so when using CometMock, just use --gas 9000000 then
if tr.useCometmock {
gas = "9000000"
}

// Use: "opt-out [consumer-chain-id]",
optIn := fmt.Sprintf(
`%s tx provider opt-out %s --from validator%s --chain-id %s --home %s --node %s --gas %s --keyring-backend test -y -o json`,
tr.chainConfigs[ChainID("provi")].BinaryName,
string(tr.chainConfigs[action.Chain].ChainId),
action.Validator,
tr.chainConfigs[ChainID("provi")].ChainId,
tr.getValidatorHome(ChainID("provi"), action.Validator),
tr.getValidatorNode(ChainID("provi"), action.Validator),
gas,
)

cmd := target.ExecCommand(
"/bin/bash", "-c",
optIn,
)

if verbose {
fmt.Println("optOut cmd:", cmd.String())
}

bz, err := cmd.CombinedOutput()
_, _ = bz, err
Copy link
Contributor

@sainoe sainoe Apr 3, 2024

Choose a reason for hiding this comment

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

Suggested change
_, _ = bz, err
if err != nil {
log.Fatal(err, "\n", string(bz))
}

if !tr.useCometmock { // error report only works with --gas auto, which does not work with CometMock, so ignore
if verbose {
fmt.Printf("got expected error during opt out | err: %s | output: %s \n", err, string(bz))
}
}

// wait for inclusion in a block -> '--broadcast-mode block' is deprecated
tr.waitBlocks(ChainID("provi"), 2, 30*time.Second)
}

// WaitTime waits for the given duration.
// To make sure that the new timestamp is visible on-chain, it also waits until at least one block has been
// produced on each chain after waiting.
Expand Down
14 changes: 13 additions & 1 deletion tests/e2e/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,18 @@ var stepChoices = map[string]StepChoice{
description: `Minimal set of test steps to perform compatibility tests`,
testConfig: CompatibilityTestCfg,
},
"partial-set-security-opt-in": {
name: "partial-set-security-opt-in",
steps: stepsOptInChain(),
description: "test partial set security for an Opt-In chain",
testConfig: DefaultTestCfg,
},
"partial-set-security-top-n": {
name: "partial-set-security-top-n",
steps: stepsTopNChain(),
description: "test partial set security for a Top-N chain",
testConfig: DefaultTestCfg,
},
}

func getTestCaseUsageString() string {
Expand Down Expand Up @@ -241,7 +253,7 @@ func getTestCases(selectedPredefinedTests, selectedTestFiles TestSet, providerVe
"changeover", "happy-path",
"democracy-reward", "democracy",
"slash-throttle", "consumer-double-sign", "consumer-misbehaviour",
"consumer-double-downtime",
"consumer-double-downtime", "partial-set-security-opt-in", "partial-set-security-top-n",
}
if includeMultiConsumer != nil && *includeMultiConsumer {
selectedPredefinedTests = append(selectedPredefinedTests, "multiconsumer")
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/steps_compatibility.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func compstepsStartConsumerChain(consumerName string, proposalIndex, chainIndex
ConsumerChain: ChainID(consumerName),
SpawnTime: 0,
InitialHeight: clienttypes.Height{RevisionNumber: 0, RevisionHeight: 1},
TopN: 100,
},
State: State{
ChainID("provi"): ChainState{
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/steps_consumer_misbehaviour.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func stepsStartChainsWithSoftOptOut(consumerName string) []Step {
ConsumerChain: ChainID(consumerName),
SpawnTime: 0,
InitialHeight: clienttypes.Height{RevisionNumber: 0, RevisionHeight: 1},
TopN: 100,
},
State: State{
ChainID("provi"): ChainState{
Expand Down
Loading
Loading