diff --git a/abci/proposals/proposals.go b/abci/proposals/proposals.go index 9d14b729f..bef381a1f 100644 --- a/abci/proposals/proposals.go +++ b/abci/proposals/proposals.go @@ -288,6 +288,9 @@ func (h *ProposalHandler) ProcessProposalHandler() sdk.ProcessProposalHandler { "vote_extensions_enabled", voteExtensionsEnabled, ) + // we save the injected tx so we can re-add it to the txs in case it is removed in a wrapped proposal handler. + var injectedTx []byte + if voteExtensionsEnabled { // Ensure that the commit info was correctly injected into the proposal. if len(req.Txs) < slinkyabci.NumInjectedTxs { @@ -331,6 +334,7 @@ func (h *ProposalHandler) ProcessProposalHandler() sdk.ProcessProposalHandler { // Remove the extended commit info from the proposal if required if !h.retainOracleDataInWrappedHandler { + injectedTx = req.Txs[slinkyabci.OracleInfoIndex] req.Txs = req.Txs[slinkyabci.NumInjectedTxs:] } } @@ -345,6 +349,11 @@ func (h *ProposalHandler) ProcessProposalHandler() sdk.ProcessProposalHandler { } } + if !h.retainOracleDataInWrappedHandler && injectedTx != nil { + // Re-inject the extended commit info back into the response if it was removed + req.Txs = append([][]byte{injectedTx}, req.Txs...) + } + wrappedProcessProposalLatency = time.Since(wrappedProcessProposalStartTime) return resp, err } diff --git a/abci/proposals/proposals_test.go b/abci/proposals/proposals_test.go index 0aef1e4d7..52c86038a 100644 --- a/abci/proposals/proposals_test.go +++ b/abci/proposals/proposals_test.go @@ -576,6 +576,7 @@ func (s *ProposalsTestSuite) TestProcessProposal() { currencyPairStrategy func() currencypair.CurrencyPairStrategy expectedError bool expectedResp *cometabci.ResponseProcessProposal + checkTxs func(before, after [][]byte) }{ { name: "returns an error on nil request", @@ -697,6 +698,9 @@ func (s *ProposalsTestSuite) TestProcessProposal() { expectedResp: &cometabci.ResponseProcessProposal{ Status: cometabci.ResponseProcessProposal_ACCEPT, }, + checkTxs: func(before, after [][]byte) { + s.Require().Equal(before, after) + }, }, { name: "can process a block with multiple vote extensions", @@ -936,6 +940,16 @@ func (s *ProposalsTestSuite) TestProcessProposal() { )) } + // make a copy of the txs before we run the proposal + var before [][]byte + if req != nil { // some tests use a nil request. + before = make([][]byte, len(req.Txs)) + for i, tx := range req.Txs { + before[i] = make([]byte, len(tx)) + copy(before[i], tx) + } + } + response, err := s.proposalHandler.ProcessProposalHandler()(s.ctx, req) s.Require().Equal(tc.expectedResp, response) @@ -944,6 +958,10 @@ func (s *ProposalsTestSuite) TestProcessProposal() { } else { s.Require().NoError(err) } + + if tc.checkTxs != nil { + tc.checkTxs(before, req.Txs) + } }) } } diff --git a/pkg/types/currency_pair.go b/pkg/types/currency_pair.go index bb011a020..3f857275d 100644 --- a/pkg/types/currency_pair.go +++ b/pkg/types/currency_pair.go @@ -122,6 +122,10 @@ func ValidateDefiAssetString(asset string) error { return fmt.Errorf("token field %q is invalid: %w", token, err) } + if strings.ToUpper(asset) != asset { + return fmt.Errorf("incorrectly formatted asset string, expected: %q got: %q", strings.ToUpper(asset), asset) + } + return nil } @@ -204,19 +208,7 @@ func CurrencyPairFromString(s string) (CurrencyPair, error) { } func sanitizeAssetString(s string) (string, error) { - if IsLegacyAssetString(s) { - s = strings.ToUpper(s) - } else { - token, address, chainID, err := SplitDefiAssetString(s) - if err != nil { - return "", fmt.Errorf("incorrectly formatted asset: %q: %w", s, err) - } - - token = strings.ToUpper(token) - s = strings.Join([]string{token, address, chainID}, fieldSeparator) - } - - return s, nil + return strings.ToUpper(s), nil } // LegacyDecimals returns the number of decimals that the quote will be reported to. If the quote is Ethereum, then diff --git a/pkg/types/currency_pair_test.go b/pkg/types/currency_pair_test.go index 1f46d831a..ca6625009 100644 --- a/pkg/types/currency_pair_test.go +++ b/pkg/types/currency_pair_test.go @@ -152,27 +152,51 @@ func TestValidateBasic(t *testing.T) { true, }, { - "if Base formatted correctly as defi, Quote standard - pass", + "if Base formatted incorrectly as defi, Quote standard but rest lowercase - fail", slinkytypes.CurrencyPair{ Base: "BB,testAddress,testChain", Quote: "AA", }, - true, + false, }, { - "if Quote formatted correctly as Base, Quote standard - pass", + "if Quote formatted incorrectly as Base, Quote standard but rest lowercase - fail", slinkytypes.CurrencyPair{ Base: "BB", Quote: "AA,testAddress,testChain", }, - true, + false, }, { - "if both Quote + Base are formatted correctly as defi - pass", + "if both Quote + Base are formatted correctly as defi but rest lowercase - fail", slinkytypes.CurrencyPair{ Base: "BB,testAddress,testChain", Quote: "AA,testAddress,testChain", }, + false, + }, + { + "if Base formatted incorrectly as defi, Quote standard - pass", + slinkytypes.CurrencyPair{ + Base: "BB,TESTADDRESS,TESTCHAIN", + Quote: "AA", + }, + true, + }, + { + "if Quote formatted incorrectly as Base, Quote standard - pass", + slinkytypes.CurrencyPair{ + Base: "BB", + Quote: "AA,TESTADDRESS,TESTCHAIN", + }, + true, + }, + { + "if both Quote + Base are formatted correctly as defi - pass", + slinkytypes.CurrencyPair{ + Base: "BB,TESTADDRESS,TESTCHAIN", + Quote: "AA,TESTADDRESS,TESTCHAIN", + }, true, }, } @@ -237,19 +261,19 @@ func TestToFromString(t *testing.T) { { "if the string is not formatted upper-case (defi), return the original CurrencyPair", "a,testAddress,testChain/B", - slinkytypes.CurrencyPair{Base: "A,testAddress,testChain", Quote: "B"}, + slinkytypes.CurrencyPair{Base: "A,TESTADDRESS,TESTCHAIN", Quote: "B"}, true, }, { "if the string is not formatted upper-case (defi), return the original CurrencyPair", "a/b,testAddress,testChain", - slinkytypes.CurrencyPair{Base: "A", Quote: "B,testAddress,testChain"}, + slinkytypes.CurrencyPair{Base: "A", Quote: "B,TESTADDRESS,TESTCHAIN"}, true, }, { "if the string is not formatted upper-case (defi), return the original CurrencyPair", "A,testAddress,testChain/B,testAddress,testChain", - slinkytypes.CurrencyPair{Base: "A,testAddress,testChain", Quote: "B,testAddress,testChain"}, + slinkytypes.CurrencyPair{Base: "A,TESTADDRESS,TESTCHAIN", Quote: "B,TESTADDRESS,TESTCHAIN"}, true, }, }