Skip to content

Commit

Permalink
Merge branch 'release/v1.x.x' into chore/backport-772
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex | Skip authored Dec 11, 2024
2 parents 92dee88 + 4eb3b95 commit 418deb9
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 21 deletions.
9 changes: 9 additions & 0 deletions abci/proposals/proposals.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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:]
}
}
Expand All @@ -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
}
Expand Down
18 changes: 18 additions & 0 deletions abci/proposals/proposals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand All @@ -944,6 +958,10 @@ func (s *ProposalsTestSuite) TestProcessProposal() {
} else {
s.Require().NoError(err)
}

if tc.checkTxs != nil {
tc.checkTxs(before, req.Txs)
}
})
}
}
Expand Down
18 changes: 5 additions & 13 deletions pkg/types/currency_pair.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down
40 changes: 32 additions & 8 deletions pkg/types/currency_pair_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}
Expand Down Expand Up @@ -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,
},
}
Expand Down

0 comments on commit 418deb9

Please sign in to comment.