Skip to content

Commit

Permalink
chore: add secondary api to plumb codec opts in test encoding conf (#5)
Browse files Browse the repository at this point in the history
* chore: add secondary api to plumb codec opts in test encoding conf

* chore: update changelog
  • Loading branch information
damiannolan authored Feb 18, 2025
1 parent 926f94b commit 32f0754
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (baseapp) [#1](https://github.com/01builders/cosmos-sdk/pull/1) `SetProtocolVersion` has been renamed to `SetAppVersion`. It now updates the consensus params in baseapp's `ParamStore`.
* (baseapp) [#2](https://github.com/01builders/cosmos-sdk/pull/2) Re-add query router for custom abci queries.
* (x/auth/vesting) [#3](https://github.com/01builders/cosmos-sdk/pull/3) Add start time for continuous vesting accounts.
* (testing) [#5](https://github.com/01builders/cosmos-sdk/pull/5) Add `MakeTestEncodingConfigWithOpts` to pass `testutil.CodecOptions` when creating `TestEncodingConfig`.

## [v0.50.11](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.11) - 2024-12-16

Expand Down
28 changes: 28 additions & 0 deletions types/module/testutil/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,40 @@ func MakeTestEncodingConfig(modules ...module.AppModuleBasic) TestEncodingConfig
return encCfg
}

func MakeTestEncodingConfigWithOpts(codecOpts testutil.CodecOptions, modules ...module.AppModuleBasic) TestEncodingConfig {
aminoCodec := codec.NewLegacyAmino()
interfaceRegistry := codecOpts.NewInterfaceRegistry()
codec := codec.NewProtoCodec(interfaceRegistry)

encCfg := TestEncodingConfig{
InterfaceRegistry: interfaceRegistry,
Codec: codec,
TxConfig: tx.NewTxConfig(codec, tx.DefaultSignModes),
Amino: aminoCodec,
}

mb := module.NewBasicManager(modules...)

std.RegisterLegacyAminoCodec(encCfg.Amino)
std.RegisterInterfaces(encCfg.InterfaceRegistry)
mb.RegisterLegacyAminoCodec(encCfg.Amino)
mb.RegisterInterfaces(encCfg.InterfaceRegistry)

return encCfg
}

func MakeTestTxConfig() client.TxConfig {
interfaceRegistry := testutil.CodecOptions{}.NewInterfaceRegistry()
cdc := codec.NewProtoCodec(interfaceRegistry)
return tx.NewTxConfig(cdc, tx.DefaultSignModes)
}

func MakeTestTxConfigWithOpts(codecOpts testutil.CodecOptions) client.TxConfig {
interfaceRegistry := codecOpts.NewInterfaceRegistry()
cdc := codec.NewProtoCodec(interfaceRegistry)
return tx.NewTxConfig(cdc, tx.DefaultSignModes)
}

type TestBuilderTxConfig struct {
client.TxConfig
TxBuilder *TestTxBuilder
Expand Down

0 comments on commit 32f0754

Please sign in to comment.