Skip to content

Commit

Permalink
Add test for new diversifier for solomachine (#1860)
Browse files Browse the repository at this point in the history
* add test for successful new diversifier

* add changelog entry

* fix tests
  • Loading branch information
colin-axner committed Aug 2, 2022
1 parent 4cb9308 commit 8bfdfdb
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Bug Fixes

* (light-clients/solomachine) [#1839](https://github.com/cosmos/ibc-go/issues/1839) Fixed usage of the new diversifier in validation of changing diversifiers for the solo machine. The current diversifier must sign over the new diversifier.
* (modules/core/04-channel) [\#1130](https://github.com/cosmos/ibc-go/pull/1130) Call `packet.GetSequence()` rather than passing func in `WriteAcknowledgement` log output
* (apps/29-fee) [\#1278](https://github.com/cosmos/ibc-go/pull/1278) The URI path for the query to get all incentivized packets for a specifc channel did not follow the same format as the rest of queries.
* (07-tendermint) [\#1674](https://github.com/cosmos/ibc-go/pull/1674) Submitted ClientState is zeroed out before checking the proof in order to prevent the proposal from containing information governance is not actually voting on.
Expand Down
2 changes: 1 addition & 1 deletion modules/core/02-client/types/codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (suite *TypesTestSuite) TestPackClientMessage() {
}{
{
"solo machine header",
ibctesting.NewSolomachine(suite.T(), suite.chainA.Codec, "solomachine", "", 2).CreateHeader(),
ibctesting.NewSolomachine(suite.T(), suite.chainA.Codec, "solomachine", "", 2).CreateHeader("solomachine"),
true,
},
{
Expand Down
5 changes: 3 additions & 2 deletions modules/core/02-client/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func (suite *TypesTestSuite) TestMarshalMsgUpdateClient() {
{
"solo machine client", func() {
soloMachine := ibctesting.NewSolomachine(suite.T(), suite.chainA.Codec, "solomachine", "", 2)
msg, err = types.NewMsgUpdateClient(soloMachine.ClientID, soloMachine.CreateHeader(), suite.chainA.SenderAccount.GetAddress().String())
msg, err = types.NewMsgUpdateClient(soloMachine.ClientID, soloMachine.CreateHeader(soloMachine.Diversifier), suite.chainA.SenderAccount.GetAddress().String())
suite.Require().NoError(err)
},
},
Expand Down Expand Up @@ -293,7 +293,8 @@ func (suite *TypesTestSuite) TestMsgUpdateClient_ValidateBasic() {
"valid - solomachine header",
func() {
soloMachine := ibctesting.NewSolomachine(suite.T(), suite.chainA.Codec, "solomachine", "", 2)
msg, err = types.NewMsgUpdateClient(soloMachine.ClientID, soloMachine.CreateHeader(), suite.chainA.SenderAccount.GetAddress().String())
msg, err = types.NewMsgUpdateClient(soloMachine.ClientID, soloMachine.CreateHeader(soloMachine.Diversifier), suite.chainA.SenderAccount.GetAddress().String())

suite.Require().NoError(err)
},
true,
Expand Down
2 changes: 1 addition & 1 deletion modules/light-clients/06-solomachine/header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func (suite *SoloMachineTestSuite) TestHeaderValidateBasic() {
// test singlesig and multisig public keys
for _, sm := range []*ibctesting.Solomachine{suite.solomachine, suite.solomachineMulti} {

header := sm.CreateHeader()
header := sm.CreateHeader(sm.Diversifier)

cases := []struct {
name string
Expand Down
31 changes: 19 additions & 12 deletions modules/light-clients/06-solomachine/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ func (suite *SoloMachineTestSuite) TestVerifyClientMessageHeader() {
{
"successful header",
func() {
clientMsg = sm.CreateHeader()
clientMsg = sm.CreateHeader(sm.Diversifier)
},
true,
},
{
"successful header with new diversifier",
func() {
clientMsg = sm.CreateHeader(sm.Diversifier + "0")
},
true,
},
Expand All @@ -51,7 +58,7 @@ func (suite *SoloMachineTestSuite) TestVerifyClientMessageHeader() {
"wrong sequence in header",
func() {
// store in temp before assigning to interface type
h := sm.CreateHeader()
h := sm.CreateHeader(sm.Diversifier)
h.Sequence++
clientMsg = h
},
Expand All @@ -60,15 +67,15 @@ func (suite *SoloMachineTestSuite) TestVerifyClientMessageHeader() {
{
"invalid header Signature",
func() {
h := sm.CreateHeader()
h := sm.CreateHeader(sm.Diversifier)
h.Signature = suite.GetInvalidProof()
clientMsg = h
}, false,
},
{
"invalid timestamp in header",
func() {
h := sm.CreateHeader()
h := sm.CreateHeader(sm.Diversifier)
h.Timestamp--
clientMsg = h
}, false,
Expand All @@ -78,7 +85,7 @@ func (suite *SoloMachineTestSuite) TestVerifyClientMessageHeader() {
func() {

sm.Sequence++
clientMsg = sm.CreateHeader()
clientMsg = sm.CreateHeader(sm.Diversifier)
},
false,
},
Expand All @@ -87,7 +94,7 @@ func (suite *SoloMachineTestSuite) TestVerifyClientMessageHeader() {
func() {
// store in temp before assinging to interface type
cs := sm.ClientState()
h := sm.CreateHeader()
h := sm.CreateHeader(sm.Diversifier)

publicKey, err := codectypes.NewAnyWithValue(sm.PublicKey)
suite.NoError(err)
Expand Down Expand Up @@ -128,7 +135,7 @@ func (suite *SoloMachineTestSuite) TestVerifyClientMessageHeader() {
// store in temp before assinging to interface type
cs := sm.ClientState()
oldPubKey := sm.PublicKey
h := sm.CreateHeader()
h := sm.CreateHeader(sm.Diversifier)

// generate invalid signature
data := append(sdk.Uint64ToBigEndian(cs.Sequence), oldPubKey.Bytes()...)
Expand All @@ -144,7 +151,7 @@ func (suite *SoloMachineTestSuite) TestVerifyClientMessageHeader() {
"consensus state public key is nil - header",
func() {
clientState.ConsensusState.PublicKey = nil
clientMsg = sm.CreateHeader()
clientMsg = sm.CreateHeader(sm.Diversifier)
},
false,
},
Expand Down Expand Up @@ -309,7 +316,7 @@ func (suite *SoloMachineTestSuite) TestVerifyClientMessageMisbehaviour() {
badMisbehaviour := sm.CreateMisbehaviour()

// update public key to a new one
sm.CreateHeader()
sm.CreateHeader(sm.Diversifier)
m := sm.CreateMisbehaviour()

// set SignatureOne to use the wrong signature
Expand All @@ -323,7 +330,7 @@ func (suite *SoloMachineTestSuite) TestVerifyClientMessageMisbehaviour() {
badMisbehaviour := sm.CreateMisbehaviour()

// update public key to a new one
sm.CreateHeader()
sm.CreateHeader(sm.Diversifier)
m := sm.CreateMisbehaviour()

// set SignatureTwo to use the wrong signature
Expand Down Expand Up @@ -421,7 +428,7 @@ func (suite *SoloMachineTestSuite) TestUpdateState() {
"successful update",
func() {
clientState = sm.ClientState()
clientMsg = sm.CreateHeader()
clientMsg = sm.CreateHeader(sm.Diversifier)
},
true,
},
Expand Down Expand Up @@ -491,7 +498,7 @@ func (suite *SoloMachineTestSuite) TestCheckForMisbehaviour() {
{
"normal header returns false",
func() {
clientMsg = sm.CreateHeader()
clientMsg = sm.CreateHeader(sm.Diversifier)
},
false,
},
Expand Down
8 changes: 5 additions & 3 deletions testing/solomachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ func (solo *Solomachine) GetHeight() exported.Height {

// CreateHeader generates a new private/public key pair and creates the
// necessary signature to construct a valid solo machine header.
func (solo *Solomachine) CreateHeader() *solomachinetypes.Header {
// A new diversifier will be used as well
func (solo *Solomachine) CreateHeader(newDiversifier string) *solomachinetypes.Header {
// generate new private keys and signature for header
newPrivKeys, newPubKeys, newPubKey := GenerateKeys(solo.t, uint64(len(solo.PrivateKeys)))

Expand All @@ -116,7 +117,7 @@ func (solo *Solomachine) CreateHeader() *solomachinetypes.Header {

data := &solomachinetypes.HeaderData{
NewPubKey: publicKey,
NewDiversifier: solo.Diversifier,
NewDiversifier: newDiversifier,
}

dataBz, err := solo.cdc.Marshal(data)
Expand All @@ -140,14 +141,15 @@ func (solo *Solomachine) CreateHeader() *solomachinetypes.Header {
Timestamp: solo.Time,
Signature: sig,
NewPublicKey: publicKey,
NewDiversifier: solo.Diversifier,
NewDiversifier: newDiversifier,
}

// assumes successful header update
solo.Sequence++
solo.PrivateKeys = newPrivKeys
solo.PublicKeys = newPubKeys
solo.PublicKey = newPubKey
solo.Diversifier = newDiversifier

return header
}
Expand Down

0 comments on commit 8bfdfdb

Please sign in to comment.