From 36fdd1cab41ce6e1b583c4cd98a4a4e326f5c56c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Federico=20Kunze=20K=C3=BCllmer?=
 <federico.kunze94@gmail.com>
Date: Wed, 9 Feb 2022 12:09:28 -0300
Subject: [PATCH 1/3] fix: support custom keys for testing

---
 testing/app.go         | 18 +++++++++++-------
 testing/chain.go       | 17 ++++++++++-------
 testing/coordinator.go |  2 --
 3 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/testing/app.go b/testing/app.go
index 1c5bbe7c88a..487e0569ba2 100644
--- a/testing/app.go
+++ b/testing/app.go
@@ -126,13 +126,17 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs
 
 	// commit genesis changes
 	app.Commit()
-	app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{
-		ChainID:            chainID,
-		Height:             app.LastBlockHeight() + 1,
-		AppHash:            app.LastCommitID().Hash,
-		ValidatorsHash:     valSet.Hash(),
-		NextValidatorsHash: valSet.Hash(),
-	}})
+	app.BeginBlock(
+		abci.RequestBeginBlock{
+			Header: tmproto.Header{
+				ChainID:            chainID,
+				Height:             app.LastBlockHeight() + 1,
+				AppHash:            app.LastCommitID().Hash,
+				ValidatorsHash:     valSet.Hash(),
+				NextValidatorsHash: valSet.Hash(),
+			},
+		},
+	)
 
 	return app
 }
diff --git a/testing/chain.go b/testing/chain.go
index 281782f7837..fc5d4e1681e 100644
--- a/testing/chain.go
+++ b/testing/chain.go
@@ -56,18 +56,23 @@ type TestChain struct {
 	Vals    *tmtypes.ValidatorSet
 	Signers []tmtypes.PrivValidator
 
-	senderPrivKey cryptotypes.PrivKey
+	// autogenerated sender private key
+	SenderPrivKey cryptotypes.PrivKey
 	SenderAccount authtypes.AccountI
 }
 
 // NewTestChain initializes a new TestChain instance with a single validator set using a
-// generated private key. It also creates a sender account to be used for delivering transactions.
+// generated secp256k1 Tendermint private key. It also creates a sender BaseAccount to be used for
+// delivering transactions.
 //
 // The first block height is committed to state in order to allow for client creations on
 // counterparty chains. The TestChain will return with a block height starting at 2.
 //
 // Time management is handled by the Coordinator in order to ensure synchrony between chains.
 // Each update of any chain increments the block header time for all chains by 5 seconds.
+//
+// NOTE: to use a custom sender privkey and account for testing purposes (i.e not), replace and
+// modify this constructor.
 func NewTestChain(t *testing.T, coord *Coordinator, chainID string) *TestChain {
 	// generate validator private/public key
 	privVal := mock.NewPV()
@@ -113,7 +118,7 @@ func NewTestChain(t *testing.T, coord *Coordinator, chainID string) *TestChain {
 		Codec:         app.AppCodec(),
 		Vals:          valSet,
 		Signers:       signers,
-		senderPrivKey: senderPrivKey,
+		SenderPrivKey: senderPrivKey,
 		SenderAccount: acc,
 	}
 
@@ -237,7 +242,6 @@ func (chain *TestChain) sendMsgs(msgs ...sdk.Msg) error {
 // number and updates the TestChain's headers. It returns the result and error if one
 // occurred.
 func (chain *TestChain) SendMsgs(msgs ...sdk.Msg) (*sdk.Result, error) {
-
 	// ensure the chain has the latest time
 	chain.Coordinator.UpdateTimeForChain(chain)
 
@@ -250,7 +254,7 @@ func (chain *TestChain) SendMsgs(msgs ...sdk.Msg) (*sdk.Result, error) {
 		chain.ChainID,
 		[]uint64{chain.SenderAccount.GetAccountNumber()},
 		[]uint64{chain.SenderAccount.GetSequence()},
-		true, true, chain.senderPrivKey,
+		true, true, chain.SenderPrivKey,
 	)
 	if err != nil {
 		return nil, err
@@ -357,7 +361,6 @@ func (chain *TestChain) ConstructUpdateTMClientHeaderWithTrustedHeight(counterpa
 	header.TrustedValidators = trustedVals
 
 	return header, nil
-
 }
 
 // ExpireClient fast forwards the chain's block time by the provided amount of time which will
@@ -468,7 +471,7 @@ func CreateSortedSignerArray(altPrivVal, suitePrivVal tmtypes.PrivValidator,
 
 // CreatePortCapability binds and claims a capability for the given portID if it does not
 // already exist. This function will fail testing on any resulting error.
-// NOTE: only creation of a capbility for a transfer or mock port is supported
+// NOTE: only creation of a capability for a transfer or mock port is supported
 // Other applications must bind to the port in InitGenesis or modify this code.
 func (chain *TestChain) CreatePortCapability(scopedKeeper capabilitykeeper.ScopedKeeper, portID string) {
 	// check if the portId is already binded, if not bind it
diff --git a/testing/coordinator.go b/testing/coordinator.go
index 615bd830ced..be308c790d5 100644
--- a/testing/coordinator.go
+++ b/testing/coordinator.go
@@ -55,7 +55,6 @@ func (coord *Coordinator) IncrementTime() {
 func (coord *Coordinator) IncrementTimeBy(increment time.Duration) {
 	coord.CurrentTime = coord.CurrentTime.Add(increment).UTC()
 	coord.UpdateTime()
-
 }
 
 // UpdateTime updates all clocks for the TestChains to the current global time.
@@ -105,7 +104,6 @@ func (coord *Coordinator) SetupConnections(path *Path) {
 // are returned within a TestConnection struct. The function expects the connections to be
 // successfully opened otherwise testing will fail.
 func (coord *Coordinator) CreateConnections(path *Path) {
-
 	err := path.EndpointA.ConnOpenInit()
 	require.NoError(coord.t, err)
 

From 659dae43bb6d754a8c3d11597286553377022da7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Federico=20Kunze=20K=C3=BCllmer?=
 <federico.kunze94@gmail.com>
Date: Wed, 9 Feb 2022 12:11:15 -0300
Subject: [PATCH 2/3] changelog

---
 CHANGELOG.md | 1 +
 1 file changed, 1 insertion(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3c65af32a02..4606340dde0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -61,6 +61,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
 
 ### Improvements
 
+* (testing) [\#893](https://github.com/cosmos/ibc-go/pull/893) Support custom private keys for testing.
 * (testing) [\#810](https://github.com/cosmos/ibc-go/pull/810) Additional testing function added to `Endpoint` type called `RecvPacketWithResult`. Performs the same functionality as the existing `RecvPacket` function but also returns the message result. `path.RelayPacket` no longer uses the provided acknowledgement argument and instead obtains the acknowledgement via MsgRecvPacket events.
 * (connection) [\#721](https://github.com/cosmos/ibc-go/pull/721) Simplify connection handshake error messages when unpacking client state.
 * (channel) [\#692](https://github.com/cosmos/ibc-go/pull/692) Minimize channel logging by only emitting the packet sequence, source port/channel, destination port/channel upon packet receives, acknowledgements and timeouts.

From fc6c4a229582532974aa8c2f2e10a296813e6b7c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Federico=20Kunze=20K=C3=BCllmer?=
 <federico.kunze94@gmail.com>
Date: Wed, 9 Feb 2022 12:12:30 -0300
Subject: [PATCH 3/3] update comment

---
 testing/chain.go | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/testing/chain.go b/testing/chain.go
index fc5d4e1681e..8dfe4b8fb27 100644
--- a/testing/chain.go
+++ b/testing/chain.go
@@ -71,8 +71,8 @@ type TestChain struct {
 // Time management is handled by the Coordinator in order to ensure synchrony between chains.
 // Each update of any chain increments the block header time for all chains by 5 seconds.
 //
-// NOTE: to use a custom sender privkey and account for testing purposes (i.e not), replace and
-// modify this constructor.
+// NOTE: to use a custom sender privkey and account for testing purposes, replace and modify this
+// constructor function.
 func NewTestChain(t *testing.T, coord *Coordinator, chainID string) *TestChain {
 	// generate validator private/public key
 	privVal := mock.NewPV()