Skip to content

Commit

Permalink
[CT-1262] add e2e tests for permissioned keys success cases
Browse files Browse the repository at this point in the history
  • Loading branch information
jayy04 committed Oct 8, 2024
1 parent 34c1ea2 commit 04816be
Show file tree
Hide file tree
Showing 6 changed files with 811 additions and 54 deletions.
38 changes: 14 additions & 24 deletions protocol/app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,21 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
),
sigVerification: accountplusante.NewCircuitBreakerDecorator(
options.Codec,
accountplusante.NewAuthenticatorDecorator(
options.Codec,
options.AccountplusKeeper,
options.AccountKeeper,
options.SignModeHandler,
sdk.ChainAnteDecorators(
accountplusante.NewAuthenticatorDecorator(
options.Codec,
options.AccountplusKeeper,
options.AccountKeeper,
options.SignModeHandler,
),
),
customante.NewSigVerificationDecorator(
options.AccountKeeper,
options.SignModeHandler,
sdk.ChainAnteDecorators(
ante.NewSetPubKeyDecorator(options.AccountKeeper),
ante.NewSigGasConsumeDecorator(options.AccountKeeper, options.SigGasConsumer),
customante.NewSigVerificationDecorator(
options.AccountKeeper,
options.SignModeHandler,
),
),
),
consumeTxSizeGas: ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
Expand All @@ -142,8 +148,6 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
options.FeegrantKeeper,
options.TxFeeChecker,
),
setPubKey: ante.NewSetPubKeyDecorator(options.AccountKeeper),
sigGasConsume: ante.NewSigGasConsumeDecorator(options.AccountKeeper, options.SigGasConsumer),
clobRateLimit: clobante.NewRateLimitDecorator(options.ClobKeeper),
clob: clobante.NewClobDecorator(options.ClobKeeper),
marketUpdates: customante.NewValidateMarketUpdateDecorator(
Expand Down Expand Up @@ -175,8 +179,6 @@ type lockingAnteHandler struct {
sigVerification accountplusante.CircuitBreakerDecorator
consumeTxSizeGas ante.ConsumeTxSizeGasDecorator
deductFee ante.DeductFeeDecorator
setPubKey ante.SetPubKeyDecorator
sigGasConsume ante.SigGasConsumeDecorator
clobRateLimit clobante.ClobRateLimitDecorator
clob clobante.ClobDecorator
marketUpdates customante.ValidateMarketUpdateDecorator
Expand Down Expand Up @@ -252,15 +254,9 @@ func (h *lockingAnteHandler) clobAnteHandle(ctx sdk.Context, tx sdk.Tx, simulate
if ctx, err = h.consumeTxSizeGas.AnteHandle(ctx, tx, simulate, noOpAnteHandle); err != nil {
return ctx, err
}
if ctx, err = h.setPubKey.AnteHandle(ctx, tx, simulate, noOpAnteHandle); err != nil {
return ctx, err
}
if ctx, err = h.validateSigCount.AnteHandle(ctx, tx, simulate, noOpAnteHandle); err != nil {
return ctx, err
}
if ctx, err = h.sigGasConsume.AnteHandle(ctx, tx, simulate, noOpAnteHandle); err != nil {
return ctx, err
}
if ctx, err = h.replayProtection.AnteHandle(ctx, tx, simulate, noOpAnteHandle); err != nil {
return ctx, err
}
Expand Down Expand Up @@ -422,15 +418,9 @@ func (h *lockingAnteHandler) otherMsgAnteHandle(ctx sdk.Context, tx sdk.Tx, simu
if ctx, err = h.deductFee.AnteHandle(ctx, tx, simulate, noOpAnteHandle); err != nil {
return ctx, err
}
if ctx, err = h.setPubKey.AnteHandle(ctx, tx, simulate, noOpAnteHandle); err != nil {
return ctx, err
}
if ctx, err = h.validateSigCount.AnteHandle(ctx, tx, simulate, noOpAnteHandle); err != nil {
return ctx, err
}
if ctx, err = h.sigGasConsume.AnteHandle(ctx, tx, simulate, noOpAnteHandle); err != nil {
return ctx, err
}
if ctx, err = h.replayProtection.AnteHandle(ctx, tx, simulate, noOpAnteHandle); err != nil {
return ctx, err
}
Expand Down
44 changes: 22 additions & 22 deletions protocol/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,28 @@ func New(
app.SubaccountsKeeper,
)

// Initialize authenticators
app.AuthenticatorManager = authenticator.NewAuthenticatorManager()
app.AuthenticatorManager.InitializeAuthenticators(
[]accountplusmoduletypes.Authenticator{
authenticator.NewAllOf(app.AuthenticatorManager),
authenticator.NewAnyOf(app.AuthenticatorManager),
authenticator.NewSignatureVerification(app.AccountKeeper),
authenticator.NewMessageFilter(),
authenticator.NewClobPairIdFilter(),
authenticator.NewSubaccountFilter(),
},
)
app.AccountPlusKeeper = *accountplusmodulekeeper.NewKeeper(
appCodec,
keys[accountplusmoduletypes.StoreKey],
app.AuthenticatorManager,
[]string{
lib.GovModuleAddress.String(),
},
)
accountplusModule := accountplusmodule.NewAppModule(appCodec, app.AccountPlusKeeper)

clobFlags := clobflags.GetClobFlagValuesFromOptions(appOpts)
logger.Info("Parsed CLOB flags", "Flags", clobFlags)

Expand Down Expand Up @@ -1231,28 +1253,6 @@ func New(
app.VaultKeeper,
)

// Initialize authenticators
app.AuthenticatorManager = authenticator.NewAuthenticatorManager()
app.AuthenticatorManager.InitializeAuthenticators(
[]accountplusmoduletypes.Authenticator{
authenticator.NewAllOf(app.AuthenticatorManager),
authenticator.NewAnyOf(app.AuthenticatorManager),
authenticator.NewSignatureVerification(app.AccountKeeper),
authenticator.NewMessageFilter(),
authenticator.NewClobPairIdFilter(),
authenticator.NewSubaccountFilter(),
},
)
app.AccountPlusKeeper = *accountplusmodulekeeper.NewKeeper(
appCodec,
keys[accountplusmoduletypes.StoreKey],
app.AuthenticatorManager,
[]string{
lib.GovModuleAddress.String(),
},
)
accountplusModule := accountplusmodule.NewAppModule(appCodec, app.AccountPlusKeeper)

/**** Module Options ****/

// NOTE: we may consider parsing `appOpts` inside module constructors. For the moment
Expand Down
12 changes: 12 additions & 0 deletions protocol/testutil/constants/stateful_orders.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,18 @@ var (
Subticks: 30,
GoodTilOneof: &clobtypes.Order_GoodTilBlockTime{GoodTilBlockTime: 10},
}
LongTermOrder_Bob_Num0_Id0_Clob1_Buy25_Price30_GTBT10 = clobtypes.Order{
OrderId: clobtypes.OrderId{
SubaccountId: Bob_Num0,
ClientId: 0,
OrderFlags: clobtypes.OrderIdFlags_LongTerm,
ClobPairId: 1,
},
Side: clobtypes.Order_SIDE_BUY,
Quantums: 25,
Subticks: 30,
GoodTilOneof: &clobtypes.Order_GoodTilBlockTime{GoodTilBlockTime: 10},
}
LongTermOrder_Bob_Num0_Id0_Clob0_Buy35_Price30_GTBT11 = clobtypes.Order{
OrderId: clobtypes.OrderId{
SubaccountId: Bob_Num0,
Expand Down
12 changes: 6 additions & 6 deletions protocol/x/accountplus/ante/circuit_breaker.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import (
// the existence of `TxExtension`.
type CircuitBreakerDecorator struct {
cdc codec.BinaryCodec
authenticatorAnteHandlerFlow sdk.AnteDecorator
originalAnteHandlerFlow sdk.AnteDecorator
authenticatorAnteHandlerFlow sdk.AnteHandler
originalAnteHandlerFlow sdk.AnteHandler
}

// NewCircuitBreakerDecorator creates a new instance of CircuitBreakerDecorator with the provided parameters.
func NewCircuitBreakerDecorator(
cdc codec.BinaryCodec,
auth sdk.AnteDecorator,
classic sdk.AnteDecorator,
auth sdk.AnteHandler,
classic sdk.AnteHandler,
) CircuitBreakerDecorator {
return CircuitBreakerDecorator{
cdc: cdc,
Expand All @@ -44,9 +44,9 @@ func (ad CircuitBreakerDecorator) AnteHandle(
// Check that the authenticator flow is active
if specified, _ := lib.HasSelectedAuthenticatorTxExtensionSpecified(tx, ad.cdc); specified {
// Return and call the AnteHandle function on all the authenticator decorators.
return ad.authenticatorAnteHandlerFlow.AnteHandle(ctx, tx, simulate, next)
return ad.authenticatorAnteHandlerFlow(ctx, tx, simulate)
}

// Return and call the AnteHandle function on all the original decorators.
return ad.originalAnteHandlerFlow.AnteHandle(ctx, tx, simulate, next)
return ad.originalAnteHandlerFlow(ctx, tx, simulate)
}
4 changes: 2 additions & 2 deletions protocol/x/accountplus/ante/circuit_breaker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ func (s *AuthenticatorCircuitBreakerAnteSuite) TestCircuitBreakerAnte() {
// Create a CircuitBreaker AnteDecorator
cbd := ante.NewCircuitBreakerDecorator(
s.tApp.App.AppCodec(),
mockTestAuthenticator,
mockTestClassic,
sdk.ChainAnteDecorators(mockTestAuthenticator),
sdk.ChainAnteDecorators(mockTestClassic),
)
anteHandler := sdk.ChainAnteDecorators(cbd)

Expand Down
Loading

0 comments on commit 04816be

Please sign in to comment.