From 137c909036fcf11ba551aea25376e81a55f0acce Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Mon, 11 Jul 2022 16:41:50 -0500 Subject: [PATCH] refactor: remove dependency on simapp from codec (#12530) ## Description Closes: #12528 --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable) --- codec/amino_codec_test.go | 8 +++++--- codec/any_test.go | 6 +++--- codec/unknownproto/regression_test.go | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/codec/amino_codec_test.go b/codec/amino_codec_test.go index 460ef8ca4184..914d19de6f37 100644 --- a/codec/amino_codec_test.go +++ b/codec/amino_codec_test.go @@ -9,10 +9,12 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/testutil/testdata" + "github.com/cosmos/cosmos-sdk/types/module/testutil" + "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth/client/cli" "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" + "github.com/cosmos/cosmos-sdk/x/staking" ) func createTestCodec() *codec.LegacyAmino { @@ -121,7 +123,7 @@ func TestAminoCodecUnpackAnyFails(t *testing.T) { func TestAminoCodecFullDecodeAndEncode(t *testing.T) { // This tx comes from https://github.com/cosmos/cosmos-sdk/issues/8117. txSigned := `{"type":"cosmos-sdk/StdTx","value":{"msg":[{"type":"cosmos-sdk/MsgCreateValidator","value":{"description":{"moniker":"fulltest","identity":"satoshi","website":"example.com","details":"example inc"},"commission":{"rate":"0.500000000000000000","max_rate":"1.000000000000000000","max_change_rate":"0.200000000000000000"},"min_self_delegation":"1000000","delegator_address":"cosmos14pt0q5cwf38zt08uu0n6yrstf3rndzr5057jys","validator_address":"cosmosvaloper14pt0q5cwf38zt08uu0n6yrstf3rndzr52q28gr","pubkey":{"type":"tendermint/PubKeyEd25519","value":"CYrOiM3HtS7uv1B1OAkknZnFYSRpQYSYII8AtMMtev0="},"value":{"denom":"umuon","amount":"700000000"}}}],"fee":{"amount":[{"denom":"umuon","amount":"6000"}],"gas":"160000"},"signatures":[{"pub_key":{"type":"tendermint/PubKeySecp256k1","value":"AwAOXeWgNf1FjMaayrSnrOOKz+Fivr6DiI/i0x0sZCHw"},"signature":"RcnfS/u2yl7uIShTrSUlDWvsXo2p2dYu6WJC8VDVHMBLEQZWc8bsINSCjOnlsIVkUNNe1q/WCA9n3Gy1+0zhYA=="}],"memo":"","timeout_height":"0"}}` - legacyCdc := simapp.MakeTestEncodingConfig().Amino + legacyCdc := testutil.MakeTestEncodingConfig(staking.AppModuleBasic{}, auth.AppModuleBasic{}).Amino var tx legacytx.StdTx err := legacyCdc.UnmarshalJSON([]byte(txSigned), &tx) require.NoError(t, err) @@ -129,7 +131,7 @@ func TestAminoCodecFullDecodeAndEncode(t *testing.T) { // Marshalling/unmarshalling the tx should work. marshaledTx, err := legacyCdc.MarshalJSON(tx) require.NoError(t, err) - require.Equal(t, string(marshaledTx), txSigned) + require.Equal(t, txSigned, string(marshaledTx)) // Marshalling/unmarshalling the tx wrapped in a struct should work. txRequest := &cli.BroadcastReq{ diff --git a/codec/any_test.go b/codec/any_test.go index 8b4b96a7fb5b..dfa5276a1d62 100644 --- a/codec/any_test.go +++ b/codec/any_test.go @@ -10,8 +10,8 @@ import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/testutil/testdata" + "github.com/cosmos/cosmos-sdk/types/module/testutil" ) func NewTestInterfaceRegistry() types.InterfaceRegistry { @@ -60,7 +60,7 @@ func TestMarshalAny(t *testing.T) { func TestMarshalProtoPubKey(t *testing.T) { require := require.New(t) - ccfg := simapp.MakeTestEncodingConfig() + ccfg := testutil.MakeTestEncodingConfig() privKey := ed25519.GenPrivKey() pk := privKey.PubKey() @@ -100,7 +100,7 @@ func TestMarshalProtoPubKey(t *testing.T) { // helper functions func TestMarshalProtoInterfacePubKey(t *testing.T) { require := require.New(t) - ccfg := simapp.MakeTestEncodingConfig() + ccfg := testutil.MakeTestEncodingConfig() privKey := ed25519.GenPrivKey() pk := privKey.PubKey() diff --git a/codec/unknownproto/regression_test.go b/codec/unknownproto/regression_test.go index 24c4056fbd39..3473e6481c14 100644 --- a/codec/unknownproto/regression_test.go +++ b/codec/unknownproto/regression_test.go @@ -7,14 +7,14 @@ import ( "github.com/stretchr/testify/require" - "github.com/cosmos/cosmos-sdk/simapp" + "github.com/cosmos/cosmos-sdk/types/module/testutil" ) // Issue #7739: Catch parse errors resulting from unexpected EOF in // protowire.ConsumeFieldValue. Discovered from fuzzing. func TestBadBytesPassedIntoDecoder(t *testing.T) { data, _ := hex.DecodeString("0A9F010A9C200A2D2F6962632E636F72652E636F6E6E656374696F6E2E76312E4D7367436F6E6E656374696F584F75656E496E6974126B0A0D6962637A65726F636C69656E74120B6962637A65726F636F6E6E1A1C0A0C6962636F6E65636C69656E74120A6962636F6E65636F6E6E00002205312E302E302A283235454635364341373935313335453430393336384536444238313130463232413442453035433212080A0612040A0208011A40143342993E25DA936CDDC7BE3D8F603CA6E9661518D536D0C482E18A0154AA096E438A6B9BCADFCFC2F0D689DCCAF55B96399D67A8361B70F5DA13091E2F929") - cfg := simapp.MakeTestEncodingConfig() + cfg := testutil.MakeTestEncodingConfig() decoder := cfg.TxConfig.TxDecoder() tx, err := decoder(data)