Skip to content

Commit

Permalink
fix bug and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-forbes committed Jan 13, 2022
1 parent 887db34 commit f3cc203
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
6 changes: 3 additions & 3 deletions x/payment/types/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
24 changes: 17 additions & 7 deletions x/payment/types/payformessage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))))},
Expand All @@ -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)
Expand All @@ -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),
)
Expand Down

0 comments on commit f3cc203

Please sign in to comment.