diff --git a/x/payment/types/builder_test.go b/x/payment/types/builder_test.go index 097fb69f91..a4554843a1 100644 --- a/x/payment/types/builder_test.go +++ b/x/payment/types/builder_test.go @@ -15,7 +15,7 @@ import ( "google.golang.org/grpc" ) -func TestBuildPayForMessage(t *testing.T) { +func TestBuildWirePayForMessage(t *testing.T) { testRing := generateKeyring(t) info, err := testRing.Key(testAccName) @@ -36,8 +36,8 @@ func TestBuildPayForMessage(t *testing.T) { rawTx, err := makeEncodingConfig().TxConfig.TxEncoder()(signedTx) require.NoError(t, err) - _, _, isChild := coretypes.UnwrapMalleatedTx(rawTx) - require.False(t, isChild) + _, _, isMalleated := coretypes.UnwrapMalleatedTx(rawTx) + require.False(t, isMalleated) sigs, err := signedTx.GetSignaturesV2() require.NoError(t, err) diff --git a/x/payment/types/payformessage_test.go b/x/payment/types/payformessage_test.go index 9c404bc5ac..e071c7bd8e 100644 --- a/x/payment/types/payformessage_test.go +++ b/x/payment/types/payformessage_test.go @@ -139,7 +139,10 @@ func TestPadMessage(t *testing.T) { } } -func TestSignShareCommitments(t *testing.T) { +// TestSignMalleatedTxs checks to see that the signatures that are generated for +// the PayForMessages malleated from the original WirePayForMessage are actually +// valid. +func TestSignMalleatedTxs(t *testing.T) { type test struct { name string ns, msg []byte @@ -156,14 +159,14 @@ func TestSignShareCommitments(t *testing.T) { name: "single share", ns: []byte{1, 1, 1, 1, 1, 1, 1, 1}, msg: bytes.Repeat([]byte{1}, ShareSize-8), - ss: []uint64{2, 4, 8, 16, 64}, + ss: []uint64{2, 4, 8, 16}, options: []TxBuilderOption{SetGasLimit(2000000)}, }, { name: "15 shares", ns: []byte{1, 1, 1, 1, 1, 1, 1, 2}, msg: bytes.Repeat([]byte{2}, ShareSize*12), - ss: []uint64{4, 8, 16, 64, 128}, + ss: []uint64{4, 8, 16, 64}, options: []TxBuilderOption{ SetGasLimit(123456789), SetFeeAmount(sdk.NewCoins(sdk.NewCoin("tio", sdk.NewInt(987654321))))}, @@ -179,10 +182,13 @@ func TestSignShareCommitments(t *testing.T) { // the signature should exist assert.Equal(t, len(wpfm.MessageShareCommitment[0].Signature), 64) - // verify the signature - for _, size := range tt.ss { + // verify the signature for the PayForMessages derived from the + // WirePayForMessage + for i, size := range tt.ss { unsignedPFM, err := wpfm.unsignedPayForMessage(size) require.NoError(t, err) + + // create a new tx builder to create an unsigned PayForMessage builder := applyOptions(signer.NewTxBuilder(), tt.options...) tx, err := signer.BuildSignedTx(builder, unsignedPFM) require.NoError(t, err) @@ -199,10 +205,14 @@ func TestSignShareCommitments(t *testing.T) { ) require.NoError(t, err) - // verify the signature using the public key + // compare the commitments generated by the WirePayForMessage with + // that of independently generated PayForMessage + assert.Equal(t, unsignedPFM.MessageShareCommitment, wpfm.MessageShareCommitment[i].ShareCommitment) + + // verify the signature assert.True(t, signer.GetSignerInfo().GetPubKey().VerifySignature( bytesToSign, - wpfm.MessageShareCommitment[0].Signature, + wpfm.MessageShareCommitment[i].Signature, ), fmt.Sprintf("test: %s size: %d", tt.name, size), )