-
Notifications
You must be signed in to change notification settings - Fork 870
Validate Concurrent Messages + Update BankSend #345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
97b4c7b
Slowly checkout changes
BrandonWeng 69f49fd
Run from latest sei-cosmos
BrandonWeng 1637692
Use Auth Type
BrandonWeng d7ef111
Event Emitting
BrandonWeng 47bc126
Validate but dont fail + branch cache
BrandonWeng be271f8
pass validation and add failover logic
BrandonWeng 785af58
return err on validation
BrandonWeng e141a8e
metrics
BrandonWeng 08ef036
lint
BrandonWeng e3dbe8d
Hard coded prefix mapping
BrandonWeng 222ba84
most test passing
BrandonWeng 0b48333
fix
BrandonWeng 95fb890
lint
BrandonWeng a6118cb
testing start
BrandonWeng 66ee21a
tidy
BrandonWeng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,158 @@ | ||
| package aclbankmapping | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" | ||
| "github.com/cosmos/cosmos-sdk/simapp" | ||
| sdk "github.com/cosmos/cosmos-sdk/types" | ||
| sdkacltypes "github.com/cosmos/cosmos-sdk/types/accesscontrol" | ||
| acltypes "github.com/cosmos/cosmos-sdk/x/accesscontrol/types" | ||
| authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" | ||
| "github.com/cosmos/cosmos-sdk/x/bank" | ||
| "github.com/cosmos/cosmos-sdk/x/bank/types" | ||
| banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" | ||
| aclutils "github.com/sei-protocol/sei-chain/aclmapping/utils" | ||
| oracletypes "github.com/sei-protocol/sei-chain/x/oracle/types" | ||
| "github.com/stretchr/testify/require" | ||
| tmproto "github.com/tendermint/tendermint/proto/tendermint/types" | ||
| ) | ||
|
|
||
|
|
||
| func cacheTxContext(ctx sdk.Context) (sdk.Context, sdk.CacheMultiStore) { | ||
| ms := ctx.MultiStore() | ||
| msCache := ms.CacheMultiStore() | ||
| return ctx.WithMultiStore(msCache), msCache | ||
| } | ||
|
|
||
| func TestMsgBankSendAclOps(t *testing.T) { | ||
| priv1 := secp256k1.GenPrivKey() | ||
| addr1 := sdk.AccAddress(priv1.PubKey().Address()) | ||
| priv2 := secp256k1.GenPrivKey() | ||
| addr2 := sdk.AccAddress(priv2.PubKey().Address()) | ||
| coins := sdk.Coins{sdk.NewInt64Coin("foocoin", 10)} | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| expectedError error | ||
| msg *types.MsgSend | ||
| dynamicDep bool | ||
| }{ | ||
| { | ||
| name: "default send", | ||
| msg: types.NewMsgSend(addr1, addr2, coins), | ||
| expectedError: nil, | ||
| dynamicDep: true, | ||
| }, | ||
| { | ||
| name: "dont check synchronous", | ||
| msg: types.NewMsgSend(addr1, addr2, coins), | ||
| expectedError: nil, | ||
| dynamicDep: false, | ||
| }, | ||
| } | ||
|
|
||
| acc1 := &authtypes.BaseAccount{ | ||
| Address: addr1.String(), | ||
| } | ||
| acc2 := &authtypes.BaseAccount{ | ||
| Address: addr2.String(), | ||
| } | ||
| accs := authtypes.GenesisAccounts{acc1, acc2} | ||
| balances := []types.Balance{ | ||
| { | ||
| Address: addr1.String(), | ||
| Coins: coins, | ||
| }, | ||
| { | ||
| Address: addr2.String(), | ||
| Coins: coins, | ||
| }, | ||
| } | ||
|
|
||
| app := simapp.SetupWithGenesisAccounts(accs, balances...) | ||
| ctx := app.BaseApp.NewContext(false, tmproto.Header{}) | ||
|
|
||
| handler := bank.NewHandler(app.BankKeeper) | ||
| msgValidator := sdkacltypes.NewMsgValidator(aclutils.StoreKeyToResourceTypePrefixMap) | ||
| ctx = ctx.WithMsgValidator(msgValidator) | ||
|
|
||
| for _, tc := range tests { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| handlerCtx, cms := cacheTxContext(ctx) | ||
|
|
||
| _, err := handler(handlerCtx, tc.msg) | ||
|
|
||
| depdenencies , _ := MsgSendDependencyGenerator(app.AccessControlKeeper, handlerCtx, tc.msg) | ||
|
|
||
| if !tc.dynamicDep { | ||
| depdenencies = sdkacltypes.SynchronousAccessOps() | ||
| } | ||
|
|
||
| if tc.expectedError != nil { | ||
| require.EqualError(t, err, tc.expectedError.Error()) | ||
| } else { | ||
| require.NoError(t, err) | ||
| } | ||
| missing := handlerCtx.MsgValidator().ValidateAccessOperations(depdenencies, cms.GetEvents()) | ||
| require.Empty(t, missing) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestGeneratorInvalidMessageTypes(t *testing.T) { | ||
| accs := authtypes.GenesisAccounts{} | ||
| balances := []types.Balance{} | ||
|
|
||
| app := simapp.SetupWithGenesisAccounts(accs, balances...) | ||
| ctx := app.BaseApp.NewContext(false, tmproto.Header{}) | ||
|
|
||
| oracleVote := oracletypes.MsgAggregateExchangeRateVote{ | ||
| ExchangeRates: "1usei", | ||
| Feeder: "test", | ||
| Validator: "validator", | ||
| } | ||
|
|
||
| _, err := MsgSendDependencyGenerator(app.AccessControlKeeper, ctx, &oracleVote) | ||
| require.Error(t, err) | ||
| } | ||
|
|
||
| func TestMsgBeginBankSendGenerator(t *testing.T) { | ||
| priv1 := secp256k1.GenPrivKey() | ||
| addr1 := sdk.AccAddress(priv1.PubKey().Address()) | ||
| priv2 := secp256k1.GenPrivKey() | ||
| addr2 := sdk.AccAddress(priv2.PubKey().Address()) | ||
| coins := sdk.Coins{sdk.NewInt64Coin("foocoin", 10)} | ||
|
|
||
| acc1 := &authtypes.BaseAccount{ | ||
| Address: addr1.String(), | ||
| } | ||
| acc2 := &authtypes.BaseAccount{ | ||
| Address: addr2.String(), | ||
| } | ||
| accs := authtypes.GenesisAccounts{acc1, acc2} | ||
| balances := []types.Balance{ | ||
| { | ||
| Address: addr1.String(), | ||
| Coins: coins, | ||
| }, | ||
| { | ||
| Address: addr2.String(), | ||
| Coins: coins, | ||
| }, | ||
| } | ||
|
|
||
| app := simapp.SetupWithGenesisAccounts(accs, balances...) | ||
| ctx := app.BaseApp.NewContext(false, tmproto.Header{}) | ||
|
|
||
| sendMsg := banktypes.MsgSend{ | ||
| FromAddress: addr1.String(), | ||
| ToAddress: addr2.String(), | ||
| Amount: coins, | ||
| } | ||
|
|
||
| accessOps, err := MsgSendDependencyGenerator(app.AccessControlKeeper, ctx, &sendMsg) | ||
| require.NoError(t, err) | ||
| err = acltypes.ValidateAccessOps(accessOps) | ||
| require.NoError(t, err) | ||
| } |
This file contains hidden or 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 util | ||
| package utils | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
This file contains hidden or 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 utils | ||
|
|
||
| import ( | ||
| aclsdktypes "github.com/cosmos/cosmos-sdk/types/accesscontrol" | ||
| authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" | ||
| banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" | ||
| stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" | ||
| dextypes "github.com/sei-protocol/sei-chain/x/dex/types" | ||
| epochtypes "github.com/sei-protocol/sei-chain/x/epoch/types" | ||
| oracletypes "github.com/sei-protocol/sei-chain/x/oracle/types" | ||
| tokenfactorytypes "github.com/sei-protocol/sei-chain/x/tokenfactory/types" | ||
| ) | ||
|
|
||
| var StoreKeyToResourceTypePrefixMap = aclsdktypes.StoreKeyToResourceTypePrefixMap{ | ||
| aclsdktypes.ParentNodeKey: { | ||
| aclsdktypes.ResourceType_ANY: aclsdktypes.EmptyPrefix, | ||
| aclsdktypes.ResourceType_KV: aclsdktypes.EmptyPrefix, | ||
| aclsdktypes.ResourceType_Mem: aclsdktypes.EmptyPrefix, | ||
| }, | ||
| dextypes.StoreKey: { | ||
| aclsdktypes.ResourceType_KV_DEX: aclsdktypes.EmptyPrefix, | ||
| aclsdktypes.ResourceType_DexMem: aclsdktypes.EmptyPrefix, | ||
| }, | ||
| banktypes.StoreKey: { | ||
| aclsdktypes.ResourceType_KV_BANK: aclsdktypes.EmptyPrefix, | ||
| aclsdktypes.ResourceType_KV_BANK_BALANCES: banktypes.BalancesPrefix, | ||
| aclsdktypes.ResourceType_KV_BANK_SUPPLY: banktypes.SupplyKey, | ||
| aclsdktypes.ResourceType_KV_BANK_DENOM: banktypes.DenomMetadataPrefix, | ||
| }, | ||
| authtypes.StoreKey: { | ||
| aclsdktypes.ResourceType_KV_AUTH: aclsdktypes.EmptyPrefix, | ||
| aclsdktypes.ResourceType_KV_AUTH_ADDRESS_STORE: authtypes.AddressStoreKeyPrefix, | ||
| }, | ||
| oracletypes.StoreKey: { | ||
| aclsdktypes.ResourceType_KV_ORACLE: aclsdktypes.EmptyPrefix, | ||
| aclsdktypes.ResourceType_KV_ORACLE_VOTE_TARGETS: oracletypes.VoteTargetKey, | ||
| aclsdktypes.ResourceType_KV_ORACLE_AGGREGATE_VOTES: oracletypes.AggregateExchangeRateVoteKey, | ||
| aclsdktypes.ResourceType_KV_ORACLE_FEEDERS: oracletypes.FeederDelegationKey, | ||
| }, | ||
| stakingtypes.StoreKey: { | ||
| aclsdktypes.ResourceType_KV_STAKING: aclsdktypes.EmptyPrefix, | ||
| aclsdktypes.ResourceType_KV_STAKING_DELEGATION: stakingtypes.DelegationKey, | ||
| aclsdktypes.ResourceType_KV_STAKING_VALIDATOR: stakingtypes.ValidatorsKey, | ||
| }, | ||
| tokenfactorytypes.StoreKey: { | ||
| aclsdktypes.ResourceType_KV_TOKENFACTORY: aclsdktypes.EmptyPrefix, | ||
| }, | ||
| epochtypes.StoreKey: { | ||
| aclsdktypes.ResourceType_KV_EPOCH: aclsdktypes.EmptyPrefix, | ||
| }, | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for the
ToAddress, there is a write access but for theFromAddressthere is no write access, only read. Just want to make sure it wasn't missed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeee, I believe it has to exist already based (If it doesn't exist then there's no money to be sent) on the logic we only create accounts for the receiver if it doesn't exist