-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into sanaz/block-height-check-prepareproposal
- Loading branch information
Showing
8 changed files
with
95 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,3 +28,4 @@ jobs: | |
uses: celestiaorg/.github/.github/workflows/[email protected] | ||
with: | ||
dockerfile: docker/Dockerfile_txsim | ||
packageName: txsim |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package errors | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"strconv" | ||
|
||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
) | ||
|
||
// IsNonceMismatch checks if the error is due to a sequence mismatch. | ||
func IsNonceMismatch(err error) bool { | ||
return errors.Is(err, sdkerrors.ErrWrongSequence) | ||
} | ||
|
||
// ParseNonceMismatch extracts the expected sequence number from the | ||
// ErrWrongSequence error. | ||
func ParseNonceMismatch(err error) (uint64, error) { | ||
if !IsNonceMismatch(err) { | ||
return 0, errors.New("error is not a sequence mismatch") | ||
} | ||
|
||
numbers := regexpInt.FindAllString(err.Error(), -1) | ||
if len(numbers) != 2 { | ||
return 0, fmt.Errorf("unexpected wrong sequence error: %w", err) | ||
} | ||
|
||
// the first number is the expected sequence number | ||
return strconv.ParseUint(numbers[0], 10, 64) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package errors_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/celestiaorg/celestia-app/app" | ||
"github.com/celestiaorg/celestia-app/app/encoding" | ||
apperr "github.com/celestiaorg/celestia-app/app/errors" | ||
"github.com/celestiaorg/celestia-app/pkg/appconsts" | ||
"github.com/celestiaorg/celestia-app/pkg/namespace" | ||
testutil "github.com/celestiaorg/celestia-app/test/util" | ||
blob "github.com/celestiaorg/celestia-app/x/blob/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/auth/ante" | ||
"github.com/stretchr/testify/require" | ||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types" | ||
) | ||
|
||
// This will detect any changes to the DeductFeeDecorator which may cause a | ||
// different error message that does not match the regexp. | ||
func TestNonceMismatchIntegration(t *testing.T) { | ||
account := "test" | ||
testApp, kr := testutil.SetupTestAppWithGenesisValSet(app.DefaultConsensusParams(), account) | ||
encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...) | ||
minGasPrice, err := sdk.ParseDecCoins(fmt.Sprintf("%v%s", appconsts.DefaultMinGasPrice, app.BondDenom)) | ||
require.NoError(t, err) | ||
ctx := testApp.NewContext(true, tmproto.Header{}).WithMinGasPrices(minGasPrice) | ||
signer := blob.NewKeyringSigner(kr, account, testutil.ChainID) | ||
// set the sequence to an incorrect value | ||
signer.SetSequence(2) | ||
builder := signer.NewTxBuilder() | ||
|
||
address, err := signer.GetSignerInfo().GetAddress() | ||
require.NoError(t, err) | ||
|
||
b, err := blob.NewBlob(namespace.RandomNamespace(), []byte("hello world"), 0) | ||
require.NoError(t, err) | ||
|
||
pfb, err := blob.NewMsgPayForBlobs(address.String(), b) | ||
require.NoError(t, err, address) | ||
|
||
tx, err := signer.BuildSignedTx(builder, pfb) | ||
require.NoError(t, err) | ||
|
||
decorator := ante.NewSigVerificationDecorator(testApp.AccountKeeper, encCfg.TxConfig.SignModeHandler()) | ||
anteHandler := sdk.ChainAnteDecorators(decorator) | ||
|
||
// We set simulate to true here to bypass having to initialize the | ||
// accounts public key. | ||
_, err = anteHandler(ctx, tx, true) | ||
require.True(t, apperr.IsNonceMismatch(err), err) | ||
expectedNonce, err := apperr.ParseNonceMismatch(err) | ||
require.NoError(t, err) | ||
require.EqualValues(t, 0, expectedNonce, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters