Co-authored-by: Julián Toledano <JulianToledano@users.noreply.github.com> Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
co-authored by
Julián Toledano
Julien Robert
parent
5d9c02d7c0
commit
ff18b0ac20
+18
-6
@@ -8,6 +8,7 @@ import (
|
||||
"google.golang.org/protobuf/types/dynamicpb"
|
||||
|
||||
counterv1 "cosmossdk.io/api/cosmos/counter/v1"
|
||||
"cosmossdk.io/core/address"
|
||||
|
||||
codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
@@ -16,21 +17,26 @@ import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
var ac = codectestutil.CodecOptions{}.GetAddressCodec()
|
||||
|
||||
type msgCounterWrapper struct {
|
||||
*countertypes.MsgIncreaseCounter
|
||||
ac address.Codec
|
||||
}
|
||||
|
||||
func (msg msgCounterWrapper) GetSigners() []sdk.AccAddress {
|
||||
fromAddress, _ := sdk.AccAddressFromBech32(msg.Signer)
|
||||
fromAddress, _ := msg.ac.StringToBytes(msg.Signer)
|
||||
return []sdk.AccAddress{fromAddress}
|
||||
}
|
||||
|
||||
func BenchmarkLegacyGetSigners(b *testing.B) {
|
||||
_, _, addr := testdata.KeyTestPubAddr()
|
||||
addrStr, err := ac.BytesToString(addr)
|
||||
require.NoError(b, err)
|
||||
msg := msgCounterWrapper{&countertypes.MsgIncreaseCounter{
|
||||
Signer: addr.String(),
|
||||
Signer: addrStr,
|
||||
Count: 2,
|
||||
}}
|
||||
}, ac}
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
@@ -42,9 +48,11 @@ func BenchmarkProtoreflectGetSigners(b *testing.B) {
|
||||
cdc := codectestutil.CodecOptions{}.NewCodec()
|
||||
signingCtx := cdc.InterfaceRegistry().SigningContext()
|
||||
_, _, addr := testdata.KeyTestPubAddr()
|
||||
addrStr, err := ac.BytesToString(addr)
|
||||
require.NoError(b, err)
|
||||
// use a pulsar message
|
||||
msg := &counterv1.MsgIncreaseCounter{
|
||||
Signer: addr.String(),
|
||||
Signer: addrStr,
|
||||
Count: 1,
|
||||
}
|
||||
|
||||
@@ -60,9 +68,11 @@ func BenchmarkProtoreflectGetSigners(b *testing.B) {
|
||||
func BenchmarkProtoreflectGetSignersWithUnmarshal(b *testing.B) {
|
||||
cdc := codectestutil.CodecOptions{}.NewCodec()
|
||||
_, _, addr := testdata.KeyTestPubAddr()
|
||||
addrStr, err := ac.BytesToString(addr)
|
||||
require.NoError(b, err)
|
||||
// start with a protoreflect message
|
||||
msg := &countertypes.MsgIncreaseCounter{
|
||||
Signer: addr.String(),
|
||||
Signer: addrStr,
|
||||
Count: 1,
|
||||
}
|
||||
// marshal to an any first because this is what we get from the wire
|
||||
@@ -82,8 +92,10 @@ func BenchmarkProtoreflectGetSignersDynamicpb(b *testing.B) {
|
||||
cdc := codectestutil.CodecOptions{}.NewCodec()
|
||||
signingCtx := cdc.InterfaceRegistry().SigningContext()
|
||||
_, _, addr := testdata.KeyTestPubAddr()
|
||||
addrStr, err := ac.BytesToString(addr)
|
||||
require.NoError(b, err)
|
||||
msg := &counterv1.MsgIncreaseCounter{
|
||||
Signer: addr.String(),
|
||||
Signer: addrStr,
|
||||
Count: 1,
|
||||
}
|
||||
bz, err := protov2.Marshal(msg)
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
"cosmossdk.io/x/tx/signing"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil"
|
||||
"github.com/cosmos/cosmos-sdk/codec/types"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/testdata"
|
||||
countertypes "github.com/cosmos/cosmos-sdk/testutil/x/counter/types"
|
||||
@@ -176,17 +177,19 @@ func BenchmarkProtoCodecMarshalLengthPrefixed(b *testing.B) {
|
||||
}
|
||||
|
||||
func TestGetSigners(t *testing.T) {
|
||||
cdcOpts := codectestutil.CodecOptions{}
|
||||
interfaceRegistry, err := types.NewInterfaceRegistryWithOptions(types.InterfaceRegistryOptions{
|
||||
SigningOptions: signing.Options{
|
||||
AddressCodec: testAddressCodec{},
|
||||
ValidatorAddressCodec: testAddressCodec{},
|
||||
AddressCodec: cdcOpts.GetAddressCodec(),
|
||||
ValidatorAddressCodec: cdcOpts.GetValidatorCodec(),
|
||||
},
|
||||
ProtoFiles: protoregistry.GlobalFiles,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
cdc := codec.NewProtoCodec(interfaceRegistry)
|
||||
testAddr := sdk.AccAddress("test")
|
||||
testAddrStr := testAddr.String()
|
||||
testAddrStr, err := cdcOpts.GetAddressCodec().BytesToString(testAddr)
|
||||
require.NoError(t, err)
|
||||
|
||||
msgSendV1 := &countertypes.MsgIncreaseCounter{Signer: testAddrStr, Count: 1}
|
||||
msgSendV2 := &counterv1.MsgIncreaseCounter{Signer: testAddrStr, Count: 1}
|
||||
@@ -207,13 +210,3 @@ func TestGetSigners(t *testing.T) {
|
||||
require.Equal(t, [][]byte{testAddr}, signers)
|
||||
require.True(t, protov2.Equal(msgSendV2, msgSendV2Copy.Interface()))
|
||||
}
|
||||
|
||||
type testAddressCodec struct{}
|
||||
|
||||
func (t testAddressCodec) StringToBytes(text string) ([]byte, error) {
|
||||
return sdk.AccAddressFromBech32(text)
|
||||
}
|
||||
|
||||
func (t testAddressCodec) BytesToString(bz []byte) (string, error) {
|
||||
return sdk.AccAddress(bz).String(), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user