-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1309 from Pylons-tech/faisal/upgrade-handler
Faisal/upgrade handler
- Loading branch information
Showing
34 changed files
with
3,985 additions
and
236 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
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 was deleted.
Oops, something went wrong.
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,16 @@ | ||
package upgrades | ||
|
||
import ( | ||
storetypes "github.com/cosmos/cosmos-sdk/store/types" | ||
) | ||
|
||
// Upgrade defines a struct containing necessary fields that a SoftwareUpgradeProposal | ||
// must have written, in order for the state migration to go smoothly. | ||
// An upgrade must implement this struct, and then set it in the app.go. | ||
// The app.go will then define the handler. | ||
type Upgrade struct { | ||
// Upgrade version name, for the upgrade handler, e.g. `v7` | ||
UpgradeName string | ||
// Store upgrades, should be used for any new modules introduced, new modules deleted, or store names renamed. | ||
StoreUpgrades storetypes.StoreUpgrades | ||
} |
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,18 @@ | ||
package v3 | ||
|
||
import ( | ||
"github.com/Pylons-tech/pylons/app/upgrades" | ||
storetypes "github.com/cosmos/cosmos-sdk/store/types" | ||
icacontrollertypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller/types" | ||
icahosttypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/host/types" | ||
) | ||
|
||
const UpgradeName = "sdk-46" | ||
|
||
var Upgrade = upgrades.Upgrade{ | ||
UpgradeName: UpgradeName, | ||
StoreUpgrades: storetypes.StoreUpgrades{ | ||
Added: []string{icacontrollertypes.StoreKey, icahosttypes.StoreKey}, | ||
Deleted: []string{"epoch"}, | ||
}, | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package upgrade | ||
package v3 | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
|
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,22 @@ | ||
package v4 | ||
|
||
import ( | ||
storetypes "github.com/cosmos/cosmos-sdk/store/types" | ||
|
||
"github.com/Pylons-tech/pylons/app/upgrades" | ||
) | ||
|
||
const ( | ||
// UpgradeName is the shared upgrade plan name for mainnet and testnet | ||
UpgradeName = "mainnet" | ||
) | ||
|
||
// TODO: Update StoreUpgrades | ||
|
||
var Upgrade = upgrades.Upgrade{ | ||
UpgradeName: UpgradeName, | ||
StoreUpgrades: storetypes.StoreUpgrades{ | ||
Added: []string{}, | ||
Deleted: []string{}, | ||
}, | ||
} |
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,51 @@ | ||
package v4 | ||
|
||
import ( | ||
pylonskeeper "github.com/Pylons-tech/pylons/x/pylons/keeper" | ||
pylonstypes "github.com/Pylons-tech/pylons/x/pylons/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" | ||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" | ||
) | ||
|
||
type MsgRestrictUbedrockDecorator struct { | ||
pk pylonskeeper.Keeper | ||
} | ||
|
||
func NewMsgRestrictUbedrockDecorator(pk pylonskeeper.Keeper) MsgRestrictUbedrockDecorator { | ||
return MsgRestrictUbedrockDecorator{ | ||
pk: pk, | ||
} | ||
} | ||
|
||
// AnteDecorator for restrict ubedrock denom used by unallowed address | ||
func (ad MsgRestrictUbedrockDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { | ||
if (ctx.IsCheckTx() || ctx.IsReCheckTx()) && !simulate { | ||
sigTx, ok := tx.(authsigning.SigVerifiableTx) | ||
if !ok { | ||
return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid transaction type") | ||
} | ||
|
||
messages := sigTx.GetMsgs() | ||
if len(messages) == 0 { | ||
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "invalid messages") | ||
} | ||
for _, message := range messages { | ||
msgSend, ok := message.(*banktypes.MsgSend) | ||
if !ok { | ||
continue | ||
} | ||
|
||
ok, _ = msgSend.Amount.Find(pylonstypes.StakingCoinDenom) | ||
if !ok { | ||
continue | ||
} | ||
|
||
if _, kycAccFound := ad.pk.GetPylonsKYC(ctx, msgSend.ToAddress); !kycAccFound { | ||
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "'ubedrock' should only be transferred among allowed address") | ||
} | ||
} | ||
} | ||
return next(ctx, tx, simulate) | ||
} |
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,74 @@ | ||
package v4_test | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/Pylons-tech/pylons/app" | ||
v4 "github.com/Pylons-tech/pylons/app/upgrades/v4" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" | ||
"github.com/stretchr/testify/require" | ||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types" | ||
) | ||
|
||
func noOpAnteDecorator() sdk.AnteHandler { | ||
return func(ctx sdk.Context, _ sdk.Tx, _ bool) (sdk.Context, error) { | ||
return ctx, nil | ||
} | ||
} | ||
|
||
func createTestContext() (sdk.Context, app.PylonsApp) { | ||
pylonsApp := app.Setup(false) | ||
|
||
ctx := pylonsApp.BaseApp.NewContext(true, tmproto.Header{Height: 1, ChainID: "pylons-1", Time: time.Now().UTC()}) | ||
return ctx, *pylonsApp | ||
} | ||
|
||
func TestMsgRestrictUbedrockDecorator(t *testing.T) { | ||
ctx, pylonsApp := createTestContext() | ||
handler := v4.NewMsgRestrictUbedrockDecorator(pylonsApp.PylonsKeeper) | ||
txCfg := app.MakeEncodingConfig().TxConfig | ||
|
||
addr1 := sdk.AccAddress([]byte("address1---------------")) | ||
addr2 := sdk.AccAddress([]byte("address2---------------")) | ||
|
||
testCases := []struct { | ||
name string | ||
ctx sdk.Context | ||
msgs []sdk.Msg | ||
expectErr bool | ||
}{ | ||
{ | ||
name: "Valid account", | ||
ctx: ctx, | ||
msgs: []sdk.Msg{ | ||
banktypes.NewMsgSend(addr1, addr2, sdk.NewCoins(sdk.NewInt64Coin("foo", 5))), | ||
}, | ||
expectErr: false, | ||
}, | ||
{ | ||
name: "Invalid account", | ||
ctx: ctx, | ||
msgs: []sdk.Msg{ | ||
banktypes.NewMsgSend(addr1, addr2, sdk.NewCoins(sdk.NewInt64Coin("ubedrock", 1))), | ||
}, | ||
expectErr: true, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
tc := tc | ||
t.Run(tc.name, func(t *testing.T) { | ||
txBuilder := txCfg.NewTxBuilder() | ||
require.NoError(t, txBuilder.SetMsgs(tc.msgs...)) | ||
|
||
_, err := handler.AnteHandle(tc.ctx, txBuilder.GetTx(), false, noOpAnteDecorator()) | ||
if tc.expectErr { | ||
require.Error(t, err) | ||
} else { | ||
require.NoError(t, err) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.