Skip to content
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

fix: add routing for sdk messages for staking/distribution and simulate #399

Merged
merged 2 commits into from May 10, 2023

Conversation

xlab
Copy link
Contributor

@xlab xlab commented May 9, 2023

1. Overview

When adding LSM forked version for default staking and distribution packages, the original SDK messages are not handled and their routing was impossible on the current testnet. The following messages were affected:

From staking:

  • cosmos.staking.v1beta1.MsgCreateValidator
  • cosmos.staking.v1beta1.MsgEditValidator
  • cosmos.staking.v1beta1.MsgDelegate
  • cosmos.staking.v1beta1.MsgBeginRedelegate
  • cosmos.staking.v1beta1.MsgUndelegate
  • cosmos.staking.v1beta1.MsgCancelUnbondingDelegation
  • cosmos.staking.v1beta1.MsgUnbondValidator

From distribution:

  • cosmos.distribution.v1beta1.MsgSetWithdrawAddress
  • cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward
  • cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission
  • cosmos.distribution.v1beta1.MsgFundCommunityPool

2. Implementation details

This PR adds a thin wrapper around MsgServer that routes all "legacy" messages into the new handler, i.e. cosmos.staking.* gets routed as lsnative.staking.*.

It also adds a parallel suite of simulation operations into integration tests to simulate interaction using clients that send usual cosmos.staking.* and cosmos.distribution.* messages - e.g. Keplr

3. How to test/use

Clone the repo, then:

cd x/lsnative/staking
go test -v ./...

cd -; x/lsnative/distribution
go test -v ./...

Without fixes to routing and a wrapper, the simulation tests would fail with errors like this:

--- FAIL: TestSimulateSdkMsgBeginRedelegate (0.00s)
    sdk_operations_test.go:284:
        	Error Trace:	/Users/xlab/dev/persistence/persistence-sdk/x/lsnative/staking/simulation/sdk_operations_test.go:284
        	Error:      	Received unexpected error:

        	            	github.com/cosmos/cosmos-sdk/x/auth/tx.DefaultTxDecoder.func1
        	            		/Users/xlab/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.46.11/x/auth/tx/decoder.go:42
        	            	github.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).runTx
        	            		/Users/xlab/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.46.11/baseapp/baseapp.go:660
        	            	github.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).SimDeliver
        	            		/Users/xlab/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.46.11/baseapp/test_helpers.go:35
        	            	github.com/cosmos/cosmos-sdk/x/simulation.GenAndDeliverTx
        	            		/Users/xlab/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.46.11/x/simulation/util.go:118
        	            	github.com/cosmos/cosmos-sdk/x/simulation.GenAndDeliverTxWithRandFees
        	            		/Users/xlab/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.46.11/x/simulation/util.go:97
        	            	github.com/persistenceOne/persistence-sdk/v2/x/lsnative/staking/simulation.SimulateSdkMsgBeginRedelegate.func1
        	            		/Users/xlab/dev/persistence/persistence-sdk/x/lsnative/staking/simulation/sdk_operations.go:567
        	            	github.com/persistenceOne/persistence-sdk/v2/x/lsnative/staking/simulation_test.TestSimulateSdkMsgBeginRedelegate
        	            		/Users/xlab/dev/persistence/persistence-sdk/x/lsnative/staking/simulation/sdk_operations_test.go:283
        	            	unable to resolve type URL /cosmos.staking.v1beta1.MsgBeginRedelegate: tx parse error
        	Test:       	TestSimulateSdkMsgBeginRedelegate

@xlab xlab requested review from ajeet97 and puneet2019 May 9, 2023 16:43
@xlab
Copy link
Contributor Author

xlab commented May 9, 2023

Update: I realized that we also have cosmos.slashing.MsgUnjail from x/slashing, added a router wrapper and corresponding simulation test for that as well.

cd x/lsnative/slashing
go test -v ./...

@xlab xlab merged commit 0b09ded into f/lsm-tests May 10, 2023
@xlab xlab deleted the f/simulate-legacy-msgs branch May 10, 2023 00:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants