Skip to content

Commit

Permalink
wip checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
MSalopek committed Nov 27, 2022
1 parent a84eb5e commit 825274b
Show file tree
Hide file tree
Showing 10 changed files with 301 additions and 200 deletions.
117 changes: 93 additions & 24 deletions tests/integration/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ func (tr TestRun) startChain(
PrivValidatorKey string `json:"priv_validator_key"`
NodeKey string `json:"node_key"`
IpSuffix string `json:"ip_suffix"`

ConsumerMnemonic string `json:"consumer_mnemonic"`
ConsumerPrivValidatorKey string `json:"consumer_priv_validator_key"`
StartWithConsumerKey bool `json:"start_with_consumer_key"`
}

var validators []jsonValAttrs
Expand All @@ -91,7 +95,28 @@ func (tr TestRun) startChain(
Allocation: fmt.Sprint(val.allocation) + "stake",
Stake: fmt.Sprint(val.stake) + "stake",
IpSuffix: tr.validatorConfigs[val.id].ipSuffix,

ConsumerMnemonic: tr.validatorConfigs[val.id].consumerMnemonic,
ConsumerPrivValidatorKey: tr.validatorConfigs[val.id].consumerPrivValidatorKey,
// if true node will be started with consumer key for each consumer chain
StartWithConsumerKey: tr.validatorConfigs[val.id].useConsumerKey,
})
a := jsonValAttrs{
Mnemonic: tr.validatorConfigs[val.id].mnemonic,
NodeKey: tr.validatorConfigs[val.id].nodeKey,
ValId: fmt.Sprint(val.id),
PrivValidatorKey: tr.validatorConfigs[val.id].privValidatorKey,
Allocation: fmt.Sprint(val.allocation) + "stake",
Stake: fmt.Sprint(val.stake) + "stake",
IpSuffix: tr.validatorConfigs[val.id].ipSuffix,

ConsumerMnemonic: tr.validatorConfigs[val.id].consumerMnemonic,
ConsumerPrivValidatorKey: tr.validatorConfigs[val.id].consumerPrivValidatorKey,
// if true node will be started with consumer key for each consumer chain
StartWithConsumerKey: tr.validatorConfigs[val.id].useConsumerKey,
}
m, _ := json.MarshalIndent(a, "", " ")
fmt.Println("#### VALIDATOR", val, "\n", string(m))
}

vals, err := json.Marshal(validators)
Expand Down Expand Up @@ -776,21 +801,26 @@ func (tr TestRun) relayRewardPacketsToProvider(
}

type delegateTokensAction struct {
chain chainID
from validatorID
to validatorID
amount uint
chain chainID
from validatorID
to validatorID
amount uint
useConsumerKey bool
}

func (tr TestRun) delegateTokens(
action delegateTokensAction,
verbose bool,
) {
delegateAddr := tr.validatorConfigs[action.to].valoperAddress
if action.chain != chainID("provi") && action.useConsumerKey {
delegateAddr = tr.validatorConfigs[action.to].consumerValoperAddress
}
//#nosec G204 -- Bypass linter warning for spawning subprocess with cmd arguments.
cmd := exec.Command("docker", "exec", tr.containerConfig.instanceName, tr.chainConfigs[action.chain].binaryName,

"tx", "staking", "delegate",
tr.validatorConfigs[action.to].valoperAddress,
delegateAddr,
fmt.Sprint(action.amount)+`stake`,

`--from`, `validator`+fmt.Sprint(action.from),
Expand All @@ -812,21 +842,26 @@ func (tr TestRun) delegateTokens(
}

type unbondTokensAction struct {
chain chainID
sender validatorID
unbondFrom validatorID
amount uint
chain chainID
sender validatorID
unbondFrom validatorID
amount uint
useFromConsumerKey bool
}

func (tr TestRun) unbondTokens(
action unbondTokensAction,
verbose bool,
) {
unbondFrom := tr.validatorConfigs[action.unbondFrom].valoperAddress
if action.chain != chainID("provi") && action.useFromConsumerKey {
unbondFrom = tr.validatorConfigs[action.unbondFrom].consumerValoperAddress
}
//#nosec G204 -- Bypass linter warning for spawning subprocess with cmd arguments.
cmd := exec.Command("docker", "exec", tr.containerConfig.instanceName, tr.chainConfigs[action.chain].binaryName,

"tx", "staking", "unbond",
tr.validatorConfigs[action.unbondFrom].valoperAddress,
unbondFrom,
fmt.Sprint(action.amount)+`stake`,

`--from`, `validator`+fmt.Sprint(action.sender),
Expand All @@ -849,22 +884,33 @@ func (tr TestRun) unbondTokens(
}

type redelegateTokensAction struct {
chain chainID
src validatorID
dst validatorID
txSender validatorID
amount uint
chain chainID
src validatorID
dst validatorID
txSender validatorID
amount uint
useSrcConsumerKey bool
useDestConsumerKey bool
}

func (tr TestRun) redelegateTokens(action redelegateTokensAction, verbose bool) {
redelegateSrc := tr.validatorConfigs[action.src].valoperAddress
if action.chain != chainID("provi") && action.useSrcConsumerKey {
redelegateSrc = tr.validatorConfigs[action.src].consumerValoperAddress
}

redelegateDst := tr.validatorConfigs[action.dst].valoperAddress
if action.chain != chainID("provi") && action.useDestConsumerKey {
redelegateDst = tr.validatorConfigs[action.dst].consumerValoperAddress
}
//#nosec G204 -- Bypass linter warning for spawning subprocess with cmd arguments.
cmd := exec.Command("docker", "exec",
tr.containerConfig.instanceName,
tr.chainConfigs[action.chain].binaryName,

"tx", "staking", "redelegate",
tr.validatorConfigs[action.src].valoperAddress,
tr.validatorConfigs[action.dst].valoperAddress,
redelegateSrc,
redelegateDst,
fmt.Sprint(action.amount)+`stake`,
`--from`, `validator`+fmt.Sprint(action.txSender),
`--chain-id`, string(tr.chainConfigs[action.chain].chainId),
Expand Down Expand Up @@ -1059,18 +1105,39 @@ func (tr TestRun) invokeDoublesignSlash(
type assignConsumerPubKeyAction struct {
chain chainID
validator validatorID
// obtained using: interchain-security-pd keys add <name> --keyring-backend test
// and copying the 'pubkey' field from terminal output
// {"@type":"/cosmos.crypto.secp256k1.PubKey","key":"AyM+CKzFKY+WwYVYmOShkgshJW4pjwqKVlKKxrQ69yhF"}
consumerPubKey string
// reconfigureNode will change keys the node uses and restart
reconfigureNode bool
}

func (tr TestRun) assignConsumerPubKey(action assignConsumerPubKeyAction, verbose bool) {
bashCommand := fmt.Sprintf(
valCfg := tr.validatorConfigs[action.validator]

// node was started with provider key
// we swap the nodes's keys for consumer keys and restart it
if action.reconfigureNode {
//#nosec G204 -- Bypass linter warning for spawning subprocess with cmd arguments.
configureNodeCmd := exec.Command("docker", "exec", tr.containerConfig.instanceName, "/bin/bash",
"/testnet-scripts/reconfigure-node.sh", tr.chainConfigs[action.chain].binaryName,
string(action.validator), string(action.chain),
tr.chainConfigs[action.chain].ipPrefix, valCfg.ipSuffix,
valCfg.consumerMnemonic, valCfg.consumerPrivValidatorKey,
)
fmt.Println("assignConsumerPubKey - reconfigure node cmd:", configureNodeCmd.String())
if verbose {
fmt.Println("assignConsumerPubKey - reconfigure node cmd:", configureNodeCmd.String())
}

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

assignKey := fmt.Sprintf(
`%s tx provider assign-consensus-key %s '%s' --from validator%s --chain-id %s --home %s --node %s --gas 900000 --keyring-backend test -b block -y`,
tr.chainConfigs[chainID("provi")].binaryName,
string(tr.chainConfigs[action.chain].chainId),
action.consumerPubKey,
valCfg.consumerValPubKey,
action.validator,
tr.chainConfigs[chainID("provi")].chainId,
tr.getValidatorHome(chainID("provi"), action.validator),
Expand All @@ -1080,9 +1147,11 @@ func (tr TestRun) assignConsumerPubKey(action assignConsumerPubKeyAction, verbos
cmd := exec.Command("docker", "exec",
tr.containerConfig.instanceName,
"/bin/bash", "-c",
bashCommand,
assignKey,
)

fmt.Println("assignConsumerPubKey cmd:", cmd.String())

if verbose {
fmt.Println("assignConsumerPubKey cmd:", cmd.String())
}
Expand Down
20 changes: 11 additions & 9 deletions tests/integration/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type ValidatorConfig struct {
consumerValPubKey string
consumerPrivValidatorKey string
consumerNodeKey string
useConsumerKey bool // if true the validator node will start with consumer key
}

// Attributes that are unique to a chain. Allows us to map (part of)
Expand Down Expand Up @@ -84,15 +85,6 @@ func getDefaultValidators() map[validatorID]ValidatorConfig {
privValidatorKey: `{"address":"99BD3A72EF12CD024E7584B3AC900AE3743C6ADF","pub_key":{"type":"tendermint/PubKeyEd25519","value":"mAN6RXYxSM4MNGSIriYiS7pHuwAcOHDQAy9/wnlSzOI="},"priv_key":{"type":"tendermint/PrivKeyEd25519","value":"QePcwfWtOavNK7pBJrtoLMzarHKn6iBWfWPFeyV+IdmYA3pFdjFIzgw0ZIiuJiJLuke7ABw4cNADL3/CeVLM4g=="}}`,
nodeKey: `{"priv_key":{"type":"tendermint/PrivKeyEd25519","value":"TQ4vHcO/vKdzGtWpelkX53WdMQd4kTsWGFrdcatdXFvWyO215Rewn5IRP0FszPLWr2DqPzmuH8WvxYGk5aeOXw=="}}`,
ipSuffix: "5",

// consumer chain assigned key
consumerMnemonic: "clip choose cake west range gun slam cry village receive juice galaxy lend ritual range provide ritual can since verify breeze vacant play dragon",
consumerDelAddress: "cosmos1sx6j9g2rh324a342a5f0rnx7me34r9nwgf0mc7",
consumerValoperAddress: "cosmosvaloper1sx6j9g2rh324a342a5f0rnx7me34r9nwdamw5d",
consumerValconsAddress: "cosmosvalcons1kswr5sq599365kcjmhgufevfps9njf43e4lwdk",
consumerValPubKey: `{"@type":"/cosmos.crypto.ed25519.PubKey","key":"Ui5Gf1+mtWUdH8u3xlmzdKID+F3PK0sfXZ73GZ6q6is="}`,
consumerPrivValidatorKey: `{"address":"B41C3A40142963AA5B12DDD1C4E5890C0B3926B1","pub_key":{"type":"tendermint/PubKeyEd25519","value":"Ui5Gf1+mtWUdH8u3xlmzdKID+F3PK0sfXZ73GZ6q6is="},"priv_key":{"type":"tendermint/PrivKeyEd25519","value":"3YaBAZLA+sl/E73lLfbFbG0u6DYm33ayr/0UpCt/vFBSLkZ/X6a1ZR0fy7fGWbN0ogP4Xc8rSx9dnvcZnqrqKw=="}}`,
consumerNodeKey: `{"priv_key":{"type":"tendermint/PrivKeyEd25519","value":"rxBzFedtD3pqgfJQblbxGusKOr47oBfr8ba0Iz14gobtDRZQZlSZ/UGP4pSHkVf+4vtkrkO1vRHBYJobuiP+7A=="}}`,
},
validatorID("carol"): {
mnemonic: "sight similar better jar bitter laptop solve fashion father jelly scissors chest uniform play unhappy convince silly clump another conduct behave reunion marble animal",
Expand All @@ -102,6 +94,16 @@ func getDefaultValidators() map[validatorID]ValidatorConfig {
privValidatorKey: `{"address":"C888306A908A217B9A943D1DAD8790044D0947A4","pub_key":{"type":"tendermint/PubKeyEd25519","value":"IHo4QEikWZfIKmM0X+N+BjKttz8HOzGs2npyjiba3Xk="},"priv_key":{"type":"tendermint/PrivKeyEd25519","value":"z08bmSB91uFVpVmR3t2ewd/bDjZ/AzwQpe5rKjWiPG0gejhASKRZl8gqYzRf434GMq23Pwc7MazaenKOJtrdeQ=="}}`,
nodeKey: `{"priv_key":{"type":"tendermint/PrivKeyEd25519","value":"WLTcHEjbwB24Wp3z5oBSYTvtGQonz/7IQabOFw85BN0UkkyY5HDf38o8oHlFxVI26f+DFVeICuLbe9aXKGnUeg=="}}`,
ipSuffix: "6",

// consumer chain assigned key
consumerMnemonic: "clip choose cake west range gun slam cry village receive juice galaxy lend ritual range provide ritual can since verify breeze vacant play dragon",
consumerDelAddress: "cosmos1sx6j9g2rh324a342a5f0rnx7me34r9nwgf0mc7",
consumerValoperAddress: "cosmosvaloper1sx6j9g2rh324a342a5f0rnx7me34r9nwdamw5d",
consumerValconsAddress: "cosmosvalcons1kswr5sq599365kcjmhgufevfps9njf43e4lwdk",
consumerValPubKey: `{"@type":"/cosmos.crypto.ed25519.PubKey","key":"Ui5Gf1+mtWUdH8u3xlmzdKID+F3PK0sfXZ73GZ6q6is="}`,
consumerPrivValidatorKey: `{"address":"B41C3A40142963AA5B12DDD1C4E5890C0B3926B1","pub_key":{"type":"tendermint/PubKeyEd25519","value":"Ui5Gf1+mtWUdH8u3xlmzdKID+F3PK0sfXZ73GZ6q6is="},"priv_key":{"type":"tendermint/PrivKeyEd25519","value":"3YaBAZLA+sl/E73lLfbFbG0u6DYm33ayr/0UpCt/vFBSLkZ/X6a1ZR0fy7fGWbN0ogP4Xc8rSx9dnvcZnqrqKw=="}}`,
consumerNodeKey: `{"priv_key":{"type":"tendermint/PrivKeyEd25519","value":"rxBzFedtD3pqgfJQblbxGusKOr47oBfr8ba0Iz14gobtDRZQZlSZ/UGP4pSHkVf+4vtkrkO1vRHBYJobuiP+7A=="}}`,
useConsumerKey: true,
},
}
}
Expand Down
1 change: 0 additions & 1 deletion tests/integration/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,6 @@ func (tr TestRun) getConsumerAddress(consumerChain chainID, validator validatorI
`--node`, tr.getQueryNode(chainID("provi")),
`-o`, `json`,
)

bz, err := cmd.CombinedOutput()
if err != nil {
log.Fatal(err, "\n", string(bz))
Expand Down
Loading

0 comments on commit 825274b

Please sign in to comment.