cosmos-sdk/x/accounts/internal/implementation/account_test.go
testinginprod 112f6cbdae
feat(accounts): use gogoproto API instead of protov2. (#18653)
Co-authored-by: unknown unknown <unknown@unknown>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2023-12-08 13:17:48 +00:00

56 lines
1.8 KiB
Go

package implementation
import (
"context"
"github.com/cosmos/gogoproto/types"
"cosmossdk.io/collections"
)
var _ Account = (*TestAccount)(nil)
var itemPrefix = collections.NewPrefix([]byte{0})
// NewTestAccount creates a new TestAccount.
func NewTestAccount(sb *collections.SchemaBuilder) (TestAccount, error) {
ta := TestAccount{
Item: collections.NewItem(sb, itemPrefix, "test", collections.Uint64Value),
}
return ta, nil
}
type TestAccount struct {
Item collections.Item[uint64]
}
func (TestAccount) RegisterInitHandler(builder *InitBuilder) {
RegisterInitHandler(builder, func(_ context.Context, req *types.StringValue) (*types.StringValue, error) {
return &types.StringValue{Value: req.Value + "init-echo"}, nil
})
}
func (t TestAccount) RegisterExecuteHandlers(builder *ExecuteBuilder) {
RegisterExecuteHandler(builder, func(_ context.Context, req *types.StringValue) (*types.StringValue, error) {
return &types.StringValue{Value: req.Value + "execute-echo"}, nil
})
RegisterExecuteHandler(builder, func(_ context.Context, req *types.BytesValue) (*types.BytesValue, error) {
return &types.BytesValue{Value: append(req.Value, "bytes-execute-echo"...)}, nil
})
// State tester
RegisterExecuteHandler(builder, func(ctx context.Context, req *types.UInt64Value) (*types.Empty, error) {
return &types.Empty{}, t.Item.Set(ctx, req.Value)
})
}
func (t TestAccount) RegisterQueryHandlers(builder *QueryBuilder) {
RegisterQueryHandler(builder, func(_ context.Context, req *types.StringValue) (*types.StringValue, error) {
return &types.StringValue{Value: req.Value + "query-echo"}, nil
})
RegisterQueryHandler(builder, func(_ context.Context, req *types.BytesValue) (*types.BytesValue, error) {
return &types.BytesValue{Value: append(req.Value, "bytes-query-echo"...)}, nil
})
}