From 76e7be7e822b961b914088b84121251940a0a9c2 Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Thu, 25 Aug 2022 21:58:34 -0400 Subject: [PATCH 01/13] test: invalid share commitments --- x/payment/types/errors.go | 1 + x/payment/types/wirepayfordata_test.go | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/x/payment/types/errors.go b/x/payment/types/errors.go index ebc8cadc02..3c5a3a5516 100644 --- a/x/payment/types/errors.go +++ b/x/payment/types/errors.go @@ -18,4 +18,5 @@ var ( ErrTailPaddingNamespace = sdkerrors.Register(ModuleName, 11118, "cannot use tail padding namespace ID") ErrTxNamespace = sdkerrors.Register(ModuleName, 11119, "cannot use transaction namespace ID") ErrEvidenceNamespace = sdkerrors.Register(ModuleName, 11120, "cannot use evidence namespace ID") + ErrInvalidShareCommitments = sdkerrors.Register(ModuleName, 11121, "invalid share commitments: missing commitment for at least one square size") ) diff --git a/x/payment/types/wirepayfordata_test.go b/x/payment/types/wirepayfordata_test.go index 5d2be5dd8d..f0804e8081 100644 --- a/x/payment/types/wirepayfordata_test.go +++ b/x/payment/types/wirepayfordata_test.go @@ -49,6 +49,10 @@ func TestWirePayForData_ValidateBasic(t *testing.T) { badSquareSizeMsg := validWirePayForData(t) badSquareSizeMsg.MessageShareCommitment[0].K = 4 + // pfd that signs over all squares but the first one + invalidShareCommitments := validWirePayForData(t) + invalidShareCommitments.MessageShareCommitment = invalidShareCommitments.MessageShareCommitment[1:] + tests := []test{ { name: "valid msg", @@ -95,6 +99,11 @@ func TestWirePayForData_ValidateBasic(t *testing.T) { msg: tailPaddingMsg, wantErr: ErrTailPaddingNamespace, }, + { + name: "invalid share commitments", + msg: invalidShareCommitments, + wantErr: ErrInvalidShareCommitments, + }, } for _, tt := range tests { From 8b7746e4a2ad0a609d7796ae6c42e33c60bf602e Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Thu, 25 Aug 2022 23:37:53 -0400 Subject: [PATCH 02/13] chore: validate all relevant square sizes are committed to --- x/payment/types/errors.go | 2 +- x/payment/types/payfordata_test.go | 2 +- x/payment/types/wirepayfordata.go | 39 ++++++++++++++++++++++++++ x/payment/types/wirepayfordata_test.go | 2 +- 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/x/payment/types/errors.go b/x/payment/types/errors.go index 3c5a3a5516..1aabf363da 100644 --- a/x/payment/types/errors.go +++ b/x/payment/types/errors.go @@ -18,5 +18,5 @@ var ( ErrTailPaddingNamespace = sdkerrors.Register(ModuleName, 11118, "cannot use tail padding namespace ID") ErrTxNamespace = sdkerrors.Register(ModuleName, 11119, "cannot use transaction namespace ID") ErrEvidenceNamespace = sdkerrors.Register(ModuleName, 11120, "cannot use evidence namespace ID") - ErrInvalidShareCommitments = sdkerrors.Register(ModuleName, 11121, "invalid share commitments: missing commitment for at least one square size") + ErrInvalidShareCommitments = sdkerrors.Register(ModuleName, 11121, "invalid share commitments: all relevant square sizes must be committed to") ) diff --git a/x/payment/types/payfordata_test.go b/x/payment/types/payfordata_test.go index 5e89708508..63a4e85c7c 100644 --- a/x/payment/types/payfordata_test.go +++ b/x/payment/types/payfordata_test.go @@ -419,7 +419,7 @@ func validWirePayForData(t *testing.T) *MsgWirePayForData { msg, err := NewWirePayForData( []byte{1, 2, 3, 4, 5, 6, 7, 8}, bytes.Repeat([]byte{1}, 2000), - 16, 32, 64, + 4, 8, 16, 32, 64, 128, ) if err != nil { panic(err) diff --git a/x/payment/types/wirepayfordata.go b/x/payment/types/wirepayfordata.go index 7bc598aae7..0b34f3842f 100644 --- a/x/payment/types/wirepayfordata.go +++ b/x/payment/types/wirepayfordata.go @@ -4,6 +4,8 @@ import ( "bytes" "errors" fmt "fmt" + "reflect" + "sort" "github.com/celestiaorg/nmt/namespace" sdkclient "github.com/cosmos/cosmos-sdk/client" @@ -102,6 +104,16 @@ func (msg *MsgWirePayForData) ValidateBasic() error { ) } + if err := msg.ValidateMessageShareCommitments(); err != nil { + return err + } + + return nil +} + +// ValidateMessageShareCommitments returns an error if the message share +// commitments are invalid. +func (msg *MsgWirePayForData) ValidateMessageShareCommitments() error { for idx, commit := range msg.MessageShareCommitment { // check that each commit is valid if !powerOf2(commit.K) { @@ -118,9 +130,36 @@ func (msg *MsgWirePayForData) ValidateBasic() error { } } + if err := msg.ValidateAllSquareSizesCommitedTo(); err != nil { + return err + } + return nil +} + +// ValidateAllSquareSizesCommitedTo returns an error if the list of square sizes +// committed to don't match all squares sizes expected for this message size. +func (msg *MsgWirePayForData) ValidateAllSquareSizesCommitedTo() error { + allSquareSizes := AllSquareSizes(int(msg.MessageSize)) + sort.Slice(allSquareSizes, func(i, j int) bool { return allSquareSizes[i] < allSquareSizes[j] }) + + committedSquareSizes := msg.committedSquareSizes() + sort.Slice(committedSquareSizes, func(i, j int) bool { return committedSquareSizes[i] < committedSquareSizes[j] }) + + if !reflect.DeepEqual(allSquareSizes, committedSquareSizes) { + return ErrInvalidShareCommitments.Wrapf("all square sizes: %v, committed square sizes: %v", allSquareSizes, committedSquareSizes) + } return nil } +// commitedSquareSizes returns a list of square sizes that are present in a +// message's share commitment. +func (msg *MsgWirePayForData) committedSquareSizes() (squareSizes []uint64) { + for _, commit := range msg.MessageShareCommitment { + squareSizes = append(squareSizes, commit.K) + } + return squareSizes +} + // ValidateMessageNamespaceID returns an error if the provided namespace.ID is an invalid or reserved namespace id. func ValidateMessageNamespaceID(ns namespace.ID) error { // ensure that the namespace id is of length == NamespaceIDSize diff --git a/x/payment/types/wirepayfordata_test.go b/x/payment/types/wirepayfordata_test.go index f0804e8081..dffd2c2a7b 100644 --- a/x/payment/types/wirepayfordata_test.go +++ b/x/payment/types/wirepayfordata_test.go @@ -47,7 +47,7 @@ func TestWirePayForData_ValidateBasic(t *testing.T) { // pfd that has a different power of 2 square size badSquareSizeMsg := validWirePayForData(t) - badSquareSizeMsg.MessageShareCommitment[0].K = 4 + badSquareSizeMsg.MessageShareCommitment[0].K = 16 // pfd that signs over all squares but the first one invalidShareCommitments := validWirePayForData(t) From b9d7defedcbe20761df8e0865dd135363514d2e9 Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Thu, 25 Aug 2022 23:40:31 -0400 Subject: [PATCH 03/13] chore: improve variable name in test --- x/payment/types/wirepayfordata_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/x/payment/types/wirepayfordata_test.go b/x/payment/types/wirepayfordata_test.go index dffd2c2a7b..5c2404f5e9 100644 --- a/x/payment/types/wirepayfordata_test.go +++ b/x/payment/types/wirepayfordata_test.go @@ -50,8 +50,8 @@ func TestWirePayForData_ValidateBasic(t *testing.T) { badSquareSizeMsg.MessageShareCommitment[0].K = 16 // pfd that signs over all squares but the first one - invalidShareCommitments := validWirePayForData(t) - invalidShareCommitments.MessageShareCommitment = invalidShareCommitments.MessageShareCommitment[1:] + missingCommitmentForOneSquareSize := validWirePayForData(t) + missingCommitmentForOneSquareSize.MessageShareCommitment = missingCommitmentForOneSquareSize.MessageShareCommitment[1:] tests := []test{ { @@ -100,8 +100,8 @@ func TestWirePayForData_ValidateBasic(t *testing.T) { wantErr: ErrTailPaddingNamespace, }, { - name: "invalid share commitments", - msg: invalidShareCommitments, + name: "missing commitment for one square size", + msg: missingCommitmentForOneSquareSize, wantErr: ErrInvalidShareCommitments, }, } From 403c04854f42b06627844f65f0b614540d050f0d Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Fri, 26 Aug 2022 10:24:35 -0400 Subject: [PATCH 04/13] use isEqual instead of reflect.DeepEqual --- x/payment/types/wirepayfordata.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/x/payment/types/wirepayfordata.go b/x/payment/types/wirepayfordata.go index 0b34f3842f..304c920046 100644 --- a/x/payment/types/wirepayfordata.go +++ b/x/payment/types/wirepayfordata.go @@ -4,7 +4,6 @@ import ( "bytes" "errors" fmt "fmt" - "reflect" "sort" "github.com/celestiaorg/nmt/namespace" @@ -145,12 +144,25 @@ func (msg *MsgWirePayForData) ValidateAllSquareSizesCommitedTo() error { committedSquareSizes := msg.committedSquareSizes() sort.Slice(committedSquareSizes, func(i, j int) bool { return committedSquareSizes[i] < committedSquareSizes[j] }) - if !reflect.DeepEqual(allSquareSizes, committedSquareSizes) { + if !isEqual(allSquareSizes, committedSquareSizes) { return ErrInvalidShareCommitments.Wrapf("all square sizes: %v, committed square sizes: %v", allSquareSizes, committedSquareSizes) } return nil } +// isEqual returns true if the given uint64 slices are equal +func isEqual(a, b []uint64) bool { + if len(a) != len(b) { + return false + } + for i, v := range a { + if v != b[i] { + return false + } + } + return true +} + // commitedSquareSizes returns a list of square sizes that are present in a // message's share commitment. func (msg *MsgWirePayForData) committedSquareSizes() (squareSizes []uint64) { From baa170ba27f64164ec2b9cc5ef446723e3547312 Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Fri, 26 Aug 2022 10:41:47 -0400 Subject: [PATCH 05/13] check length before sorting --- x/payment/types/wirepayfordata.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/x/payment/types/wirepayfordata.go b/x/payment/types/wirepayfordata.go index 304c920046..997599a80e 100644 --- a/x/payment/types/wirepayfordata.go +++ b/x/payment/types/wirepayfordata.go @@ -139,9 +139,13 @@ func (msg *MsgWirePayForData) ValidateMessageShareCommitments() error { // committed to don't match all squares sizes expected for this message size. func (msg *MsgWirePayForData) ValidateAllSquareSizesCommitedTo() error { allSquareSizes := AllSquareSizes(int(msg.MessageSize)) - sort.Slice(allSquareSizes, func(i, j int) bool { return allSquareSizes[i] < allSquareSizes[j] }) - committedSquareSizes := msg.committedSquareSizes() + + if len(allSquareSizes) != len(committedSquareSizes) { + return ErrInvalidShareCommitments.Wrapf("length of all square sizes: %v must equal length of committed square sizes: %v", len(allSquareSizes), len(committedSquareSizes)) + } + + sort.Slice(allSquareSizes, func(i, j int) bool { return allSquareSizes[i] < allSquareSizes[j] }) sort.Slice(committedSquareSizes, func(i, j int) bool { return committedSquareSizes[i] < committedSquareSizes[j] }) if !isEqual(allSquareSizes, committedSquareSizes) { From bdcaf217c242b06a3a8410815cbe1863cfca9981 Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Fri, 26 Aug 2022 10:43:56 -0400 Subject: [PATCH 06/13] fix comment typo --- x/payment/types/wirepayfordata.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/payment/types/wirepayfordata.go b/x/payment/types/wirepayfordata.go index 997599a80e..d0a2320606 100644 --- a/x/payment/types/wirepayfordata.go +++ b/x/payment/types/wirepayfordata.go @@ -136,7 +136,7 @@ func (msg *MsgWirePayForData) ValidateMessageShareCommitments() error { } // ValidateAllSquareSizesCommitedTo returns an error if the list of square sizes -// committed to don't match all squares sizes expected for this message size. +// committed to don't match all square sizes expected for this message size. func (msg *MsgWirePayForData) ValidateAllSquareSizesCommitedTo() error { allSquareSizes := AllSquareSizes(int(msg.MessageSize)) committedSquareSizes := msg.committedSquareSizes() From c19f1117f9c26c1392f746f816b50324305ca3d5 Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Mon, 29 Aug 2022 10:04:49 -0400 Subject: [PATCH 07/13] fix: existing split shares test --- app/test/split_shares_test.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/app/test/split_shares_test.go b/app/test/split_shares_test.go index 46e8a4e786..24ec5c42a1 100644 --- a/app/test/split_shares_test.go +++ b/app/test/split_shares_test.go @@ -4,16 +4,17 @@ import ( "bytes" "testing" - "github.com/celestiaorg/celestia-app/app" - "github.com/celestiaorg/celestia-app/app/encoding" - shares "github.com/celestiaorg/celestia-app/pkg/shares" - "github.com/celestiaorg/celestia-app/testutil" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/pkg/consts" "github.com/tendermint/tendermint/pkg/da" core "github.com/tendermint/tendermint/proto/tendermint/types" coretypes "github.com/tendermint/tendermint/types" + + "github.com/celestiaorg/celestia-app/app" + "github.com/celestiaorg/celestia-app/app/encoding" + shares "github.com/celestiaorg/celestia-app/pkg/shares" + "github.com/celestiaorg/celestia-app/testutil" ) func TestSplitShares(t *testing.T) { @@ -26,18 +27,20 @@ func TestSplitShares(t *testing.T) { } signer := testutil.GenerateKeyringSigner(t, testAccName) + allSquareSizes := []uint64{2, 4, 8, 16, 32, 64, 128} + invalidSquareSizes := []uint64{2, 8, 16, 32, 64, 128} // missing square size: 4 firstNS := []byte{2, 2, 2, 2, 2, 2, 2, 2} firstMessage := bytes.Repeat([]byte{4}, 512) - firstRawTx := generateRawTx(t, encCfg.TxConfig, firstNS, firstMessage, signer, 2, 4, 8) + firstRawTx := generateRawTx(t, encCfg.TxConfig, firstNS, firstMessage, signer, allSquareSizes...) secondNS := []byte{1, 1, 1, 1, 1, 1, 1, 1} secondMessage := []byte{2} - secondRawTx := generateRawTx(t, encCfg.TxConfig, secondNS, secondMessage, signer, 2, 4, 8) + secondRawTx := generateRawTx(t, encCfg.TxConfig, secondNS, secondMessage, signer, allSquareSizes...) thirdNS := []byte{3, 3, 3, 3, 3, 3, 3, 3} thirdMessage := []byte{1} - thirdRawTx := generateRawTx(t, encCfg.TxConfig, thirdNS, thirdMessage, signer, 2, 8) + thirdRawTx := generateRawTx(t, encCfg.TxConfig, thirdNS, thirdMessage, signer, invalidSquareSizes...) tests := []test{ { @@ -65,7 +68,7 @@ func TestSplitShares(t *testing.T) { data: &core.Data{ Txs: [][]byte{firstRawTx, secondRawTx, thirdRawTx}, }, - expectedTxCount: 3, + expectedTxCount: 2, }, { // calculate the square using the same txs but using a square size @@ -75,7 +78,7 @@ func TestSplitShares(t *testing.T) { data: &core.Data{ Txs: [][]byte{firstRawTx, secondRawTx, thirdRawTx}, }, - expectedTxCount: 0, + expectedTxCount: 2, }, } From b56b9c95c378be02d8ac7013e646873df19c8095 Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Mon, 29 Aug 2022 10:06:26 -0400 Subject: [PATCH 08/13] fix comment for square size 16 test case --- app/test/split_shares_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/test/split_shares_test.go b/app/test/split_shares_test.go index 24ec5c42a1..a106e30a8c 100644 --- a/app/test/split_shares_test.go +++ b/app/test/split_shares_test.go @@ -72,8 +72,7 @@ func TestSplitShares(t *testing.T) { }, { // calculate the square using the same txs but using a square size - // of 16, this should remove all of the txs as they weren't signed - // over for that square size + // of 16 squareSize: 16, data: &core.Data{ Txs: [][]byte{firstRawTx, secondRawTx, thirdRawTx}, From 986404dece28a12f7bd7a86fbd87cc01b91e8901 Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Mon, 29 Aug 2022 10:11:03 -0400 Subject: [PATCH 09/13] fix: prepare proposal test --- app/test/prepare_proposal_test.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/app/test/prepare_proposal_test.go b/app/test/prepare_proposal_test.go index f8593d85ab..db475c841a 100644 --- a/app/test/prepare_proposal_test.go +++ b/app/test/prepare_proposal_test.go @@ -4,10 +4,6 @@ import ( "bytes" "testing" - "github.com/celestiaorg/celestia-app/app" - "github.com/celestiaorg/celestia-app/app/encoding" - "github.com/celestiaorg/celestia-app/testutil" - "github.com/celestiaorg/celestia-app/x/payment/types" "github.com/celestiaorg/nmt/namespace" "github.com/cosmos/cosmos-sdk/client" sdk "github.com/cosmos/cosmos-sdk/types" @@ -17,6 +13,11 @@ import ( abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/pkg/consts" core "github.com/tendermint/tendermint/proto/tendermint/types" + + "github.com/celestiaorg/celestia-app/app" + "github.com/celestiaorg/celestia-app/app/encoding" + "github.com/celestiaorg/celestia-app/testutil" + "github.com/celestiaorg/celestia-app/x/payment/types" ) func TestPrepareProposal(t *testing.T) { @@ -25,6 +26,7 @@ func TestPrepareProposal(t *testing.T) { encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...) testApp := testutil.SetupTestAppWithGenesisValSet(t) + allSquareSizes := []uint64{2, 4, 8, 16, 32, 64, 128} type test struct { input abci.RequestPrepareProposal @@ -34,15 +36,15 @@ func TestPrepareProposal(t *testing.T) { firstNS := []byte{2, 2, 2, 2, 2, 2, 2, 2} firstMessage := bytes.Repeat([]byte{4}, 512) - firstRawTx := generateRawTx(t, encCfg.TxConfig, firstNS, firstMessage, signer, 2, 4, 8, 16) + firstRawTx := generateRawTx(t, encCfg.TxConfig, firstNS, firstMessage, signer, allSquareSizes...) secondNS := []byte{1, 1, 1, 1, 1, 1, 1, 1} secondMessage := []byte{2} - secondRawTx := generateRawTx(t, encCfg.TxConfig, secondNS, secondMessage, signer, 2, 4, 8, 16) + secondRawTx := generateRawTx(t, encCfg.TxConfig, secondNS, secondMessage, signer, allSquareSizes...) thirdNS := []byte{3, 3, 3, 3, 3, 3, 3, 3} thirdMessage := []byte{1} - thirdRawTx := generateRawTx(t, encCfg.TxConfig, thirdNS, thirdMessage, signer, 2, 4, 8, 16) + thirdRawTx := generateRawTx(t, encCfg.TxConfig, thirdNS, thirdMessage, signer, allSquareSizes...) tests := []test{ { From 9471e7a3a9862bfac43889d002210a27e217828d Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Mon, 29 Aug 2022 10:17:53 -0400 Subject: [PATCH 10/13] fix: prepare proposal reserved ns test --- app/test/prepare_proposal_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/test/prepare_proposal_test.go b/app/test/prepare_proposal_test.go index db475c841a..7e61bdcafd 100644 --- a/app/test/prepare_proposal_test.go +++ b/app/test/prepare_proposal_test.go @@ -111,6 +111,7 @@ func TestPrepareMessagesWithReservedNamespaces(t *testing.T) { encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...) signer := testutil.GenerateKeyringSigner(t, testAccName) + allSquareSizes := []uint64{2, 4, 8, 16, 32, 64, 128} type test struct { name string @@ -128,7 +129,7 @@ func TestPrepareMessagesWithReservedNamespaces(t *testing.T) { } for _, tt := range tests { - tx := generateRawTx(t, encCfg.TxConfig, tt.namespace, []byte{1}, signer, 2, 4, 8, 16) + tx := generateRawTx(t, encCfg.TxConfig, tt.namespace, []byte{1}, signer, allSquareSizes...) input := abci.RequestPrepareProposal{ BlockData: &core.Data{ Txs: [][]byte{tx}, From 30b8e8e66734a4f6a75e980f4a4ec895ec09328e Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Wed, 31 Aug 2022 11:07:56 -0400 Subject: [PATCH 11/13] perf: preallocate slice length --- x/payment/types/wirepayfordata.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x/payment/types/wirepayfordata.go b/x/payment/types/wirepayfordata.go index 399910359f..80ed106932 100644 --- a/x/payment/types/wirepayfordata.go +++ b/x/payment/types/wirepayfordata.go @@ -174,7 +174,8 @@ func isEqual(a, b []uint64) bool { // commitedSquareSizes returns a list of square sizes that are present in a // message's share commitment. -func (msg *MsgWirePayForData) committedSquareSizes() (squareSizes []uint64) { +func (msg *MsgWirePayForData) committedSquareSizes() []uint64 { + squareSizes := make([]uint64, 0, len(msg.MessageShareCommitment)) for _, commit := range msg.MessageShareCommitment { squareSizes = append(squareSizes, commit.K) } From 639be1c84c7eb1a395e4822a43013f8f0c74165b Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Wed, 31 Aug 2022 11:16:14 -0400 Subject: [PATCH 12/13] Remove sort --- x/payment/types/wirepayfordata.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/x/payment/types/wirepayfordata.go b/x/payment/types/wirepayfordata.go index 80ed106932..5c2aeb61d2 100644 --- a/x/payment/types/wirepayfordata.go +++ b/x/payment/types/wirepayfordata.go @@ -4,7 +4,6 @@ import ( "bytes" "errors" fmt "fmt" - "sort" "github.com/celestiaorg/nmt/namespace" sdkclient "github.com/cosmos/cosmos-sdk/client" @@ -150,9 +149,6 @@ func (msg *MsgWirePayForData) ValidateAllSquareSizesCommitedTo() error { return ErrInvalidShareCommitments.Wrapf("length of all square sizes: %v must equal length of committed square sizes: %v", len(allSquareSizes), len(committedSquareSizes)) } - sort.Slice(allSquareSizes, func(i, j int) bool { return allSquareSizes[i] < allSquareSizes[j] }) - sort.Slice(committedSquareSizes, func(i, j int) bool { return committedSquareSizes[i] < committedSquareSizes[j] }) - if !isEqual(allSquareSizes, committedSquareSizes) { return ErrInvalidShareCommitments.Wrapf("all square sizes: %v, committed square sizes: %v", allSquareSizes, committedSquareSizes) } From e5f55a043174b324b20bc2df04f6fdfad72490c0 Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Wed, 31 Aug 2022 11:29:16 -0400 Subject: [PATCH 13/13] test: use AllSquareSizes --- app/test/prepare_proposal_test.go | 11 +++++------ app/test/split_shares_test.go | 8 ++++---- x/payment/types/payfordata_test.go | 5 +++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/test/prepare_proposal_test.go b/app/test/prepare_proposal_test.go index 7e61bdcafd..7cc737963d 100644 --- a/app/test/prepare_proposal_test.go +++ b/app/test/prepare_proposal_test.go @@ -26,7 +26,6 @@ func TestPrepareProposal(t *testing.T) { encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...) testApp := testutil.SetupTestAppWithGenesisValSet(t) - allSquareSizes := []uint64{2, 4, 8, 16, 32, 64, 128} type test struct { input abci.RequestPrepareProposal @@ -36,15 +35,15 @@ func TestPrepareProposal(t *testing.T) { firstNS := []byte{2, 2, 2, 2, 2, 2, 2, 2} firstMessage := bytes.Repeat([]byte{4}, 512) - firstRawTx := generateRawTx(t, encCfg.TxConfig, firstNS, firstMessage, signer, allSquareSizes...) + firstRawTx := generateRawTx(t, encCfg.TxConfig, firstNS, firstMessage, signer, types.AllSquareSizes(len(firstMessage))...) secondNS := []byte{1, 1, 1, 1, 1, 1, 1, 1} secondMessage := []byte{2} - secondRawTx := generateRawTx(t, encCfg.TxConfig, secondNS, secondMessage, signer, allSquareSizes...) + secondRawTx := generateRawTx(t, encCfg.TxConfig, secondNS, secondMessage, signer, types.AllSquareSizes(len(secondMessage))...) thirdNS := []byte{3, 3, 3, 3, 3, 3, 3, 3} thirdMessage := []byte{1} - thirdRawTx := generateRawTx(t, encCfg.TxConfig, thirdNS, thirdMessage, signer, allSquareSizes...) + thirdRawTx := generateRawTx(t, encCfg.TxConfig, thirdNS, thirdMessage, signer, types.AllSquareSizes(len(thirdMessage))...) tests := []test{ { @@ -111,7 +110,6 @@ func TestPrepareMessagesWithReservedNamespaces(t *testing.T) { encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...) signer := testutil.GenerateKeyringSigner(t, testAccName) - allSquareSizes := []uint64{2, 4, 8, 16, 32, 64, 128} type test struct { name string @@ -129,7 +127,8 @@ func TestPrepareMessagesWithReservedNamespaces(t *testing.T) { } for _, tt := range tests { - tx := generateRawTx(t, encCfg.TxConfig, tt.namespace, []byte{1}, signer, allSquareSizes...) + message := []byte{1} + tx := generateRawTx(t, encCfg.TxConfig, tt.namespace, message, signer, types.AllSquareSizes(len(message))...) input := abci.RequestPrepareProposal{ BlockData: &core.Data{ Txs: [][]byte{tx}, diff --git a/app/test/split_shares_test.go b/app/test/split_shares_test.go index a106e30a8c..3121388bc2 100644 --- a/app/test/split_shares_test.go +++ b/app/test/split_shares_test.go @@ -15,6 +15,7 @@ import ( "github.com/celestiaorg/celestia-app/app/encoding" shares "github.com/celestiaorg/celestia-app/pkg/shares" "github.com/celestiaorg/celestia-app/testutil" + "github.com/celestiaorg/celestia-app/x/payment/types" ) func TestSplitShares(t *testing.T) { @@ -27,19 +28,18 @@ func TestSplitShares(t *testing.T) { } signer := testutil.GenerateKeyringSigner(t, testAccName) - allSquareSizes := []uint64{2, 4, 8, 16, 32, 64, 128} - invalidSquareSizes := []uint64{2, 8, 16, 32, 64, 128} // missing square size: 4 firstNS := []byte{2, 2, 2, 2, 2, 2, 2, 2} firstMessage := bytes.Repeat([]byte{4}, 512) - firstRawTx := generateRawTx(t, encCfg.TxConfig, firstNS, firstMessage, signer, allSquareSizes...) + firstRawTx := generateRawTx(t, encCfg.TxConfig, firstNS, firstMessage, signer, types.AllSquareSizes(len(firstMessage))...) secondNS := []byte{1, 1, 1, 1, 1, 1, 1, 1} secondMessage := []byte{2} - secondRawTx := generateRawTx(t, encCfg.TxConfig, secondNS, secondMessage, signer, allSquareSizes...) + secondRawTx := generateRawTx(t, encCfg.TxConfig, secondNS, secondMessage, signer, types.AllSquareSizes(len(secondMessage))...) thirdNS := []byte{3, 3, 3, 3, 3, 3, 3, 3} thirdMessage := []byte{1} + invalidSquareSizes := []uint64{2, 8, 16, 32, 64, 128} // missing square size: 4 thirdRawTx := generateRawTx(t, encCfg.TxConfig, thirdNS, thirdMessage, signer, invalidSquareSizes...) tests := []test{ diff --git a/x/payment/types/payfordata_test.go b/x/payment/types/payfordata_test.go index cf959d3ca1..8f4c0dc2a0 100644 --- a/x/payment/types/payfordata_test.go +++ b/x/payment/types/payfordata_test.go @@ -425,10 +425,11 @@ func totalMsgSize(size int) int { } func validWirePayForData(t *testing.T) *MsgWirePayForData { + message := bytes.Repeat([]byte{1}, 2000) msg, err := NewWirePayForData( []byte{1, 2, 3, 4, 5, 6, 7, 8}, - bytes.Repeat([]byte{1}, 2000), - 4, 8, 16, 32, 64, 128, + message, + AllSquareSizes(len(message))..., ) if err != nil { panic(err)