Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
insumity committed Mar 28, 2024
1 parent a6989bf commit 9901d8c
Show file tree
Hide file tree
Showing 4 changed files with 599 additions and 3 deletions.
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
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
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
12 changes: 12 additions & 0 deletions 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
Loading

0 comments on commit 9901d8c

Please sign in to comment.