Skip to content

Commit

Permalink
Democracy chain integration tests, part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
dusan-maksimovic authored and stana-miric committed Sep 9, 2022
1 parent 69c7a4b commit 96905b7
Show file tree
Hide file tree
Showing 9 changed files with 679 additions and 9 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ COPY --from=hermes-builder /usr/bin/hermes /usr/local/bin/

COPY --from=is-builder /go/bin/interchain-security-pd /usr/local/bin/interchain-security-pd
COPY --from=is-builder /go/bin/interchain-security-cd /usr/local/bin/interchain-security-cd
COPY --from=is-builder /go/bin/interchain-security-cdd /usr/local/bin/interchain-security-cdd


# Copy in the shell scripts that run the testnet
Expand Down
1 change: 1 addition & 0 deletions app/consumer-democracy/ante/msg_filter_ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type (
}
)

// TODO Ethernal: remove this, it is duplicated (consumerante does the same thing)
func NewMsgFilterDecorator(k ConsumerKeeper) MsgFilterDecorator {
return MsgFilterDecorator{
ConsumerKeeper: k,
Expand Down
1 change: 1 addition & 0 deletions app/consumer-democracy/ante_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
ante.NewSetUpContextDecorator(),
ante.NewRejectExtensionOptionsDecorator(),
consumerante.NewMsgFilterDecorator(options.ConsumerKeeper),
// TODO Ethernal add handler to disable slashing and evidence messages (issue 115)
ante.NewMempoolFeeDecorator(),
ante.NewValidateBasicDecorator(),
ante.NewTxTimeoutHeightDecorator(),
Expand Down
223 changes: 219 additions & 4 deletions tests/integration/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,77 @@ func (tr TestRun) submitConsumerProposal(
}
}

type submitParamChangeProposalAction struct {
chain chainID
from validatorID
deposit uint
subspace string
key string
value interface{}
}

type paramChangeProposalJSON struct {
Title string `json:"title"`
Description string `json:"description"`
Changes []paramChangeJSON `json:"changes"`
Deposit string `json:"deposit"`
}

type paramChangeJSON struct {
Subspace string `json:"subspace"`
Key string `json:"key"`
Value interface{} `json:"value"`
}

func (tr TestRun) submitParamChangeProposal(
action submitParamChangeProposalAction,
verbose bool,
) {
prop := paramChangeProposalJSON{
Title: "Param change",
Description: "Changing module params",
Changes: []paramChangeJSON{{Subspace: action.subspace, Key: action.key, Value: action.value}},
Deposit: fmt.Sprint(action.deposit) + `stake`,
}

bz, err := json.Marshal(prop)
if err != nil {
log.Fatal(err)
}

jsonStr := string(bz)
if strings.Contains(jsonStr, "'") {
log.Fatal("prop json contains single quote")
}

//#nosec G204 -- Bypass linter warning for spawning subprocess with cmd arguments.
bz, err = exec.Command("docker", "exec", tr.containerConfig.instanceName,
"/bin/bash", "-c", fmt.Sprintf(`echo '%s' > %s`, jsonStr, "/params-proposal.json")).CombinedOutput()

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

//#nosec G204 -- Bypass linter warning for spawning subprocess with cmd arguments.
bz, err = exec.Command("docker", "exec", tr.containerConfig.instanceName, tr.chainConfigs[action.chain].binaryName,

"tx", "gov", "submit-proposal", "param-change",
"/params-proposal.json",

`--from`, `validator`+fmt.Sprint(action.from),
`--chain-id`, string(tr.chainConfigs[action.chain].chainId),
`--home`, tr.getValidatorHome(action.chain, action.from),
`--node`, tr.getValidatorNode(action.chain, action.from),
`--keyring-backend`, `test`,
`-b`, `block`,
`-y`,
).CombinedOutput()

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

type voteGovProposalAction struct {
chain chainID
from []validatorID
Expand Down Expand Up @@ -300,9 +371,10 @@ func (tr TestRun) voteGovProposal(
}

type startConsumerChainAction struct {
consumerChain chainID
providerChain chainID
validators []StartChainValidator
consumerChain chainID
providerChain chainID
genesisChanges string
validators []StartChainValidator
}

func (tr TestRun) startConsumerChain(
Expand All @@ -329,10 +401,15 @@ func (tr TestRun) startConsumerChain(
log.Fatal(err, "\n", string(bz))
}

genesisChanges := ".app_state.ccvconsumer = " + string(bz)
if action.genesisChanges != "" {
genesisChanges = genesisChanges + " | " + action.genesisChanges
}

tr.startChain(StartChainAction{
chain: action.consumerChain,
validators: action.validators,
genesisChanges: ".app_state.ccvconsumer = " + string(bz),
genesisChanges: genesisChanges,
skipGentx: true,
}, verbose)
}
Expand Down Expand Up @@ -518,6 +595,88 @@ func (tr TestRun) addIbcChannel(
}
}

type transferChannelCompleteAction struct {
chainA chainID
chainB chainID
connectionA uint
portA string
portB string
order string
channelA uint
channelB uint
}

func (tr TestRun) transferChannelComplete(
action transferChannelCompleteAction,
verbose bool,
) {
//#nosec G204 -- Bypass linter warning for spawning subprocess with chanOpenTryCmd arguments.
chanOpenTryCmd := exec.Command("docker", "exec", tr.containerConfig.instanceName, "hermes",
"tx", "chan-open-try",
"--dst-chain", string(tr.chainConfigs[action.chainB].chainId),
"--src-chain", string(tr.chainConfigs[action.chainA].chainId),
"--dst-connection", "connection-"+fmt.Sprint(action.connectionA),
"--dst-port", action.portB,
"--src-port", action.portA,
"--src-channel", "channel-"+fmt.Sprint(action.channelA),
)
executeCommand(chanOpenTryCmd, "transferChanOpenTry")

//#nosec G204 -- Bypass linter warning for spawning subprocess with chanOpenAckCmd arguments.
chanOpenAckCmd := exec.Command("docker", "exec", tr.containerConfig.instanceName, "hermes",
"tx", "chan-open-ack",
"--dst-chain", string(tr.chainConfigs[action.chainA].chainId),
"--src-chain", string(tr.chainConfigs[action.chainB].chainId),
"--dst-connection", "connection-"+fmt.Sprint(action.connectionA),
"--dst-port", action.portA,
"--src-port", action.portB,
"--dst-channel", "channel-"+fmt.Sprint(action.channelA),
"--src-channel", "channel-"+fmt.Sprint(action.channelB),
)
executeCommand(chanOpenAckCmd, "transferChanOpenAck")

//#nosec G204 -- Bypass linter warning for spawning subprocess with chanOpenConfirmCmd arguments.
chanOpenConfirmCmd := exec.Command("docker", "exec", tr.containerConfig.instanceName, "hermes",
"tx", "chan-open-confirm",
"--dst-chain", string(tr.chainConfigs[action.chainB].chainId),
"--src-chain", string(tr.chainConfigs[action.chainA].chainId),
"--dst-connection", "connection-"+fmt.Sprint(action.connectionA),
"--dst-port", action.portB,
"--src-port", action.portA,
"--dst-channel", "channel-"+fmt.Sprint(action.channelB),
"--src-channel", "channel-"+fmt.Sprint(action.channelA),
)
executeCommand(chanOpenConfirmCmd, "transferChanOpenConfirm")
}

func executeCommand(cmd *exec.Cmd, cmdName string) {
if verbose {
fmt.Println(cmdName+" cmd:", cmd.String())
}

cmdReader, err := cmd.StdoutPipe()
if err != nil {
log.Fatal(err)
}
cmd.Stderr = cmd.Stdout

if err := cmd.Start(); err != nil {
log.Fatal(err)
}

scanner := bufio.NewScanner(cmdReader)

for scanner.Scan() {
out := scanner.Text()
if verbose {
fmt.Println(cmdName + ": " + out)
}
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
}

type relayPacketsAction struct {
chain chainID
port string
Expand Down Expand Up @@ -736,3 +895,59 @@ func (tr TestRun) unjailValidator(action unjailValidatorAction, verbose bool) {
log.Fatal(err, "\n", string(bz))
}
}

type registerRepresentAction struct {
chain chainID
represents []validatorID
stakes []uint
}

func (tr TestRun) registerRepresent(
action registerRepresentAction,
verbose bool,
) {
var wg sync.WaitGroup
for i, val := range action.represents {
wg.Add(1)
stake := action.stakes[i]
go func(val validatorID, stake uint) {
defer wg.Done()

//#nosec G204 -- Bypass linter warning for spawning subprocess with pubKeycmd arguments.
pubKeycmd := exec.Command("docker", "exec", tr.containerConfig.instanceName, tr.chainConfigs[action.chain].binaryName,
"tendermint", "show-validator",
`--home`, tr.getValidatorHome(action.chain, val),
)

bzPubKey, err := pubKeycmd.CombinedOutput()
if err != nil {
log.Fatal(err, "\n", string(bzPubKey))
}

//#nosec G204 -- Bypass linter warning for spawning subprocess with cmd arguments.
bz, err := exec.Command("docker", "exec", tr.containerConfig.instanceName, tr.chainConfigs[action.chain].binaryName,
"tx", "staking", "create-validator",
`--amount`, fmt.Sprint(stake)+"stake",
`--pubkey`, string(bzPubKey),
`--moniker`, fmt.Sprint(val),
`--commission-rate`, "0.1",
`--commission-max-rate`, "0.2",
`--commission-max-change-rate`, "0.01",
`--min-self-delegation`, "1",
`--from`, `validator`+fmt.Sprint(val),
`--chain-id`, string(tr.chainConfigs[action.chain].chainId),
`--home`, tr.getValidatorHome(action.chain, val),
`--node`, tr.getValidatorNode(action.chain, val),
`--keyring-backend`, `test`,
`-b`, `block`,
`-y`,
).CombinedOutput()

if err != nil {
log.Fatal(err, "\n", string(bz))
}
}(val, stake)
}

wg.Wait()
}
11 changes: 11 additions & 0 deletions tests/integration/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,17 @@ func DefaultTestRun() TestRun {
".app_state.slashing.params.downtime_jail_duration = \"2s\" | " +
".app_state.slashing.params.slash_fraction_downtime = \"0.010000000000000000\"",
},
chainID("democ"): {
chainId: chainID("democ"),
binaryName: "interchain-security-cdd",
ipPrefix: "7.7.9",
votingWaitTime: 10,
genesisChanges: ".app_state.gov.voting_params.voting_period = \"10s\" | " +
".app_state.slashing.params.signed_blocks_window = \"2\" | " +
".app_state.slashing.params.min_signed_per_window = \"0.500000000000000000\" | " +
".app_state.slashing.params.downtime_jail_duration = \"2s\" | " +
".app_state.slashing.params.slash_fraction_downtime = \"0.010000000000000000\"",
},
},
}
}
Expand Down
19 changes: 18 additions & 1 deletion tests/integration/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
var verbose = true

func main() {
fmt.Println("============================================ start happy path tests ============================================")
start := time.Now()
tr := DefaultTestRun()
tr.ParseCLIFlags()
Expand All @@ -24,7 +25,17 @@ func main() {
tr.runStep(step, verbose)
}

fmt.Printf("test successful - time elapsed %v\n", time.Since(start))
fmt.Printf("happy path tests successful - time elapsed %v\n", time.Since(start))

fmt.Println("============================================ start democracy path tests ============================================")
start = time.Now()
tr.startDocker()

for _, step := range democracySteps {
tr.runStep(step, verbose)
}

fmt.Printf("democracy path tests successful - time elapsed %v\n", time.Since(start))
}

func (tr TestRun) runStep(step Step, verbose bool) {
Expand All @@ -38,6 +49,8 @@ func (tr TestRun) runStep(step Step, verbose bool) {
tr.submitTextProposal(action, verbose)
case submitConsumerProposalAction:
tr.submitConsumerProposal(action, verbose)
case submitParamChangeProposalAction:
tr.submitParamChangeProposal(action, verbose)
case voteGovProposalAction:
tr.voteGovProposal(action, verbose)
case startConsumerChainAction:
Expand All @@ -48,6 +61,8 @@ func (tr TestRun) runStep(step Step, verbose bool) {
tr.addIbcConnection(action, verbose)
case addIbcChannelAction:
tr.addIbcChannel(action, verbose)
case transferChannelCompleteAction:
tr.transferChannelComplete(action, verbose)
case relayPacketsAction:
tr.relayPackets(action, verbose)
case delegateTokensAction:
Expand All @@ -60,6 +75,8 @@ func (tr TestRun) runStep(step Step, verbose bool) {
tr.invokeDowntimeSlash(action, verbose)
case unjailValidatorAction:
tr.unjailValidator(action, verbose)
case registerRepresentAction:
tr.registerRepresent(action, verbose)
default:
log.Fatalf(fmt.Sprintf(`unknown action: %#v`, action))
}
Expand Down
Loading

0 comments on commit 96905b7

Please sign in to comment.