-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(accounts): Add codec.BinaryCodec and Gas to dependencies. (#19068)
Co-authored-by: unknown unknown <unknown@unknown>
- Loading branch information
1 parent
822d90c
commit 498cd6a
Showing
14 changed files
with
1,773 additions
and
93 deletions.
There are no files selected for viewing
1,141 changes: 1,102 additions & 39 deletions
1,141
api/cosmos/accounts/testing/counter/v1/counter.pulsar.go
Large diffs are not rendered by default.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package runtime | ||
|
||
import ( | ||
"context" | ||
|
||
"cosmossdk.io/core/gas" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
var _ gas.Service = (*GasService)(nil) | ||
|
||
type GasService struct{} | ||
|
||
func (g GasService) GetGasMeter(ctx context.Context) gas.Meter { | ||
sdkCtx := sdk.UnwrapSDKContext(ctx) | ||
return sdkCtx.GasMeter() | ||
} | ||
|
||
func (g GasService) GetBlockGasMeter(ctx context.Context) gas.Meter { | ||
return sdk.UnwrapSDKContext(ctx).BlockGasMeter() | ||
} | ||
|
||
func (g GasService) WithGasMeter(ctx context.Context, meter gas.Meter) context.Context { | ||
return sdk.UnwrapSDKContext(ctx).WithGasMeter(meter) | ||
} | ||
|
||
func (g GasService) WithBlockGasMeter(ctx context.Context, meter gas.Meter) context.Context { | ||
return sdk.UnwrapSDKContext(ctx).WithBlockGasMeter(meter) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
//go:build app_v1 | ||
|
||
package accounts | ||
|
||
import ( | ||
"testing" | ||
|
||
"cosmossdk.io/core/header" | ||
counterv1 "cosmossdk.io/x/accounts/testing/counter/v1" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// TestDependencies aims to test wiring between different account components, | ||
// inherited from the runtime, specifically: | ||
// - address codec | ||
// - binary codec | ||
// - header service | ||
// - gas service | ||
func TestDependencies(t *testing.T) { | ||
app := setupApp(t) | ||
ak := app.AccountsKeeper | ||
ctx := sdk.NewContext(app.CommitMultiStore(), false, app.Logger()).WithHeaderInfo(header.Info{ChainID: "chain-id"}) | ||
|
||
_, counterAddr, err := ak.Init(ctx, "counter", accCreator, &counterv1.MsgInit{ | ||
InitialValue: 0, | ||
}) | ||
require.NoError(t, err) | ||
// test dependencies | ||
r, err := ak.Execute(ctx, counterAddr, []byte("test"), &counterv1.MsgTestDependencies{}) | ||
require.NoError(t, err) | ||
res := r.(*counterv1.MsgTestDependenciesResponse) | ||
|
||
// test gas | ||
require.NotZero(t, res.BeforeGas) | ||
require.NotZero(t, res.AfterGas) | ||
require.Equal(t, uint64(10), res.AfterGas-res.BeforeGas) | ||
|
||
// test header service | ||
require.Equal(t, ctx.HeaderInfo().ChainID, res.ChainId) | ||
|
||
// test address codec | ||
wantAddr, err := app.AuthKeeper.AddressCodec().BytesToString(counterAddr) | ||
require.NoError(t, err) | ||
require.Equal(t, wantAddr, res.Address) | ||
} |
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 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
Oops, something went wrong.