test(x/tx): add amino JSON pretty bytes demonstration test (#21935)

This commit is contained in:
Matt Kocubinski 2024-09-26 15:10:25 -05:00 committed by GitHub
parent 2c8569404c
commit e4240b6bef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 184 additions and 74 deletions

View File

@ -2,7 +2,6 @@ version: v1
directories:
- proto
- x/accounts/proto
- x/auth/proto
- x/authz/proto
- x/bank/proto
- x/circuit/proto

View File

@ -32,19 +32,20 @@ message ABitOfEverything {
repeated int32 repeated = 6;
string str = 7;
bool bool = 8;
bytes bytes = 9;
int32 i32 = 10;
fixed32 f32 = 11;
uint32 u32 = 12;
sint32 si32 = 13;
sfixed32 sf32 = 14;
int64 i64 = 15;
fixed64 f64 = 16;
uint64 u64 = 17;
sint64 si64 = 18;
sfixed64 sf64 = 19;
string str = 7;
bool bool = 8;
bytes bytes = 9;
int32 i32 = 10;
fixed32 f32 = 11;
uint32 u32 = 12;
sint32 si32 = 13;
sfixed32 sf32 = 14;
int64 i64 = 15;
fixed64 f64 = 16;
uint64 u64 = 17;
sint64 si64 = 18;
sfixed64 sf64 = 19;
bytes pretty_bytes = 20 [(amino.encoding) = "hex"];
// The following types are not tested here because they are treated fundamentally differently in
// gogoproto. They are tested fully in /tests/integration/aminojson/aminojson_test.go

View File

@ -1755,23 +1755,24 @@ func (x *_ABitOfEverything_6_list) IsValid() bool {
}
var (
md_ABitOfEverything protoreflect.MessageDescriptor
fd_ABitOfEverything_message protoreflect.FieldDescriptor
fd_ABitOfEverything_enum protoreflect.FieldDescriptor
fd_ABitOfEverything_repeated protoreflect.FieldDescriptor
fd_ABitOfEverything_str protoreflect.FieldDescriptor
fd_ABitOfEverything_bool protoreflect.FieldDescriptor
fd_ABitOfEverything_bytes protoreflect.FieldDescriptor
fd_ABitOfEverything_i32 protoreflect.FieldDescriptor
fd_ABitOfEverything_f32 protoreflect.FieldDescriptor
fd_ABitOfEverything_u32 protoreflect.FieldDescriptor
fd_ABitOfEverything_si32 protoreflect.FieldDescriptor
fd_ABitOfEverything_sf32 protoreflect.FieldDescriptor
fd_ABitOfEverything_i64 protoreflect.FieldDescriptor
fd_ABitOfEverything_f64 protoreflect.FieldDescriptor
fd_ABitOfEverything_u64 protoreflect.FieldDescriptor
fd_ABitOfEverything_si64 protoreflect.FieldDescriptor
fd_ABitOfEverything_sf64 protoreflect.FieldDescriptor
md_ABitOfEverything protoreflect.MessageDescriptor
fd_ABitOfEverything_message protoreflect.FieldDescriptor
fd_ABitOfEverything_enum protoreflect.FieldDescriptor
fd_ABitOfEverything_repeated protoreflect.FieldDescriptor
fd_ABitOfEverything_str protoreflect.FieldDescriptor
fd_ABitOfEverything_bool protoreflect.FieldDescriptor
fd_ABitOfEverything_bytes protoreflect.FieldDescriptor
fd_ABitOfEverything_i32 protoreflect.FieldDescriptor
fd_ABitOfEverything_f32 protoreflect.FieldDescriptor
fd_ABitOfEverything_u32 protoreflect.FieldDescriptor
fd_ABitOfEverything_si32 protoreflect.FieldDescriptor
fd_ABitOfEverything_sf32 protoreflect.FieldDescriptor
fd_ABitOfEverything_i64 protoreflect.FieldDescriptor
fd_ABitOfEverything_f64 protoreflect.FieldDescriptor
fd_ABitOfEverything_u64 protoreflect.FieldDescriptor
fd_ABitOfEverything_si64 protoreflect.FieldDescriptor
fd_ABitOfEverything_sf64 protoreflect.FieldDescriptor
fd_ABitOfEverything_pretty_bytes protoreflect.FieldDescriptor
)
func init() {
@ -1793,6 +1794,7 @@ func init() {
fd_ABitOfEverything_u64 = md_ABitOfEverything.Fields().ByName("u64")
fd_ABitOfEverything_si64 = md_ABitOfEverything.Fields().ByName("si64")
fd_ABitOfEverything_sf64 = md_ABitOfEverything.Fields().ByName("sf64")
fd_ABitOfEverything_pretty_bytes = md_ABitOfEverything.Fields().ByName("pretty_bytes")
}
var _ protoreflect.Message = (*fastReflection_ABitOfEverything)(nil)
@ -1956,6 +1958,12 @@ func (x *fastReflection_ABitOfEverything) Range(f func(protoreflect.FieldDescrip
return
}
}
if len(x.PrettyBytes) != 0 {
value := protoreflect.ValueOfBytes(x.PrettyBytes)
if !f(fd_ABitOfEverything_pretty_bytes, value) {
return
}
}
}
// Has reports whether a field is populated.
@ -2003,6 +2011,8 @@ func (x *fastReflection_ABitOfEverything) Has(fd protoreflect.FieldDescriptor) b
return x.Si64 != int64(0)
case "testpb.ABitOfEverything.sf64":
return x.Sf64 != int64(0)
case "testpb.ABitOfEverything.pretty_bytes":
return len(x.PrettyBytes) != 0
default:
if fd.IsExtension() {
panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.ABitOfEverything"))
@ -2051,6 +2061,8 @@ func (x *fastReflection_ABitOfEverything) Clear(fd protoreflect.FieldDescriptor)
x.Si64 = int64(0)
case "testpb.ABitOfEverything.sf64":
x.Sf64 = int64(0)
case "testpb.ABitOfEverything.pretty_bytes":
x.PrettyBytes = nil
default:
if fd.IsExtension() {
panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.ABitOfEverything"))
@ -2118,6 +2130,9 @@ func (x *fastReflection_ABitOfEverything) Get(descriptor protoreflect.FieldDescr
case "testpb.ABitOfEverything.sf64":
value := x.Sf64
return protoreflect.ValueOfInt64(value)
case "testpb.ABitOfEverything.pretty_bytes":
value := x.PrettyBytes
return protoreflect.ValueOfBytes(value)
default:
if descriptor.IsExtension() {
panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.ABitOfEverything"))
@ -2172,6 +2187,8 @@ func (x *fastReflection_ABitOfEverything) Set(fd protoreflect.FieldDescriptor, v
x.Si64 = value.Int()
case "testpb.ABitOfEverything.sf64":
x.Sf64 = value.Int()
case "testpb.ABitOfEverything.pretty_bytes":
x.PrettyBytes = value.Bytes()
default:
if fd.IsExtension() {
panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.ABitOfEverything"))
@ -2231,6 +2248,8 @@ func (x *fastReflection_ABitOfEverything) Mutable(fd protoreflect.FieldDescripto
panic(fmt.Errorf("field si64 of message testpb.ABitOfEverything is not mutable"))
case "testpb.ABitOfEverything.sf64":
panic(fmt.Errorf("field sf64 of message testpb.ABitOfEverything is not mutable"))
case "testpb.ABitOfEverything.pretty_bytes":
panic(fmt.Errorf("field pretty_bytes of message testpb.ABitOfEverything is not mutable"))
default:
if fd.IsExtension() {
panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.ABitOfEverything"))
@ -2278,6 +2297,8 @@ func (x *fastReflection_ABitOfEverything) NewField(fd protoreflect.FieldDescript
return protoreflect.ValueOfInt64(int64(0))
case "testpb.ABitOfEverything.sf64":
return protoreflect.ValueOfInt64(int64(0))
case "testpb.ABitOfEverything.pretty_bytes":
return protoreflect.ValueOfBytes(nil)
default:
if fd.IsExtension() {
panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.ABitOfEverything"))
@ -2402,6 +2423,10 @@ func (x *fastReflection_ABitOfEverything) ProtoMethods() *protoiface.Methods {
if x.Sf64 != 0 {
n += 10
}
l = len(x.PrettyBytes)
if l > 0 {
n += 2 + l + runtime.Sov(uint64(l))
}
if x.unknownFields != nil {
n += len(x.unknownFields)
}
@ -2431,6 +2456,15 @@ func (x *fastReflection_ABitOfEverything) ProtoMethods() *protoiface.Methods {
i -= len(x.unknownFields)
copy(dAtA[i:], x.unknownFields)
}
if len(x.PrettyBytes) > 0 {
i -= len(x.PrettyBytes)
copy(dAtA[i:], x.PrettyBytes)
i = runtime.EncodeVarint(dAtA, i, uint64(len(x.PrettyBytes)))
i--
dAtA[i] = 0x1
i--
dAtA[i] = 0xa2
}
if x.Sf64 != 0 {
i -= 8
binary.LittleEndian.PutUint64(dAtA[i:], uint64(x.Sf64))
@ -2981,6 +3015,40 @@ func (x *fastReflection_ABitOfEverything) ProtoMethods() *protoiface.Methods {
}
x.Sf64 = int64(binary.LittleEndian.Uint64(dAtA[iNdEx:]))
iNdEx += 8
case 20:
if wireType != 2 {
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field PrettyBytes", wireType)
}
var byteLen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow
}
if iNdEx >= l {
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
byteLen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if byteLen < 0 {
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength
}
postIndex := iNdEx + byteLen
if postIndex < 0 {
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength
}
if postIndex > l {
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF
}
x.PrettyBytes = append(x.PrettyBytes[:0], dAtA[iNdEx:postIndex]...)
if x.PrettyBytes == nil {
x.PrettyBytes = []byte{}
}
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := runtime.Skip(dAtA[iNdEx:])
@ -4178,22 +4246,23 @@ type ABitOfEverything struct {
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Message *NestedMessage `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"`
Enum AnEnum `protobuf:"varint,2,opt,name=enum,proto3,enum=testpb.AnEnum" json:"enum,omitempty"`
Repeated []int32 `protobuf:"varint,6,rep,packed,name=repeated,proto3" json:"repeated,omitempty"`
Str string `protobuf:"bytes,7,opt,name=str,proto3" json:"str,omitempty"`
Bool bool `protobuf:"varint,8,opt,name=bool,proto3" json:"bool,omitempty"`
Bytes []byte `protobuf:"bytes,9,opt,name=bytes,proto3" json:"bytes,omitempty"`
I32 int32 `protobuf:"varint,10,opt,name=i32,proto3" json:"i32,omitempty"`
F32 uint32 `protobuf:"fixed32,11,opt,name=f32,proto3" json:"f32,omitempty"`
U32 uint32 `protobuf:"varint,12,opt,name=u32,proto3" json:"u32,omitempty"`
Si32 int32 `protobuf:"zigzag32,13,opt,name=si32,proto3" json:"si32,omitempty"`
Sf32 int32 `protobuf:"fixed32,14,opt,name=sf32,proto3" json:"sf32,omitempty"`
I64 int64 `protobuf:"varint,15,opt,name=i64,proto3" json:"i64,omitempty"`
F64 uint64 `protobuf:"fixed64,16,opt,name=f64,proto3" json:"f64,omitempty"`
U64 uint64 `protobuf:"varint,17,opt,name=u64,proto3" json:"u64,omitempty"`
Si64 int64 `protobuf:"zigzag64,18,opt,name=si64,proto3" json:"si64,omitempty"`
Sf64 int64 `protobuf:"fixed64,19,opt,name=sf64,proto3" json:"sf64,omitempty"`
Message *NestedMessage `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"`
Enum AnEnum `protobuf:"varint,2,opt,name=enum,proto3,enum=testpb.AnEnum" json:"enum,omitempty"`
Repeated []int32 `protobuf:"varint,6,rep,packed,name=repeated,proto3" json:"repeated,omitempty"`
Str string `protobuf:"bytes,7,opt,name=str,proto3" json:"str,omitempty"`
Bool bool `protobuf:"varint,8,opt,name=bool,proto3" json:"bool,omitempty"`
Bytes []byte `protobuf:"bytes,9,opt,name=bytes,proto3" json:"bytes,omitempty"`
I32 int32 `protobuf:"varint,10,opt,name=i32,proto3" json:"i32,omitempty"`
F32 uint32 `protobuf:"fixed32,11,opt,name=f32,proto3" json:"f32,omitempty"`
U32 uint32 `protobuf:"varint,12,opt,name=u32,proto3" json:"u32,omitempty"`
Si32 int32 `protobuf:"zigzag32,13,opt,name=si32,proto3" json:"si32,omitempty"`
Sf32 int32 `protobuf:"fixed32,14,opt,name=sf32,proto3" json:"sf32,omitempty"`
I64 int64 `protobuf:"varint,15,opt,name=i64,proto3" json:"i64,omitempty"`
F64 uint64 `protobuf:"fixed64,16,opt,name=f64,proto3" json:"f64,omitempty"`
U64 uint64 `protobuf:"varint,17,opt,name=u64,proto3" json:"u64,omitempty"`
Si64 int64 `protobuf:"zigzag64,18,opt,name=si64,proto3" json:"si64,omitempty"`
Sf64 int64 `protobuf:"fixed64,19,opt,name=sf64,proto3" json:"sf64,omitempty"`
PrettyBytes []byte `protobuf:"bytes,20,opt,name=pretty_bytes,json=prettyBytes,proto3" json:"pretty_bytes,omitempty"`
}
func (x *ABitOfEverything) Reset() {
@ -4328,6 +4397,13 @@ func (x *ABitOfEverything) GetSf64() int64 {
return 0
}
func (x *ABitOfEverything) GetPrettyBytes() []byte {
if x != nil {
return x.PrettyBytes
}
return nil
}
type Duration struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
@ -4450,7 +4526,7 @@ var file_testpb_test_proto_rawDesc = []byte{
0x09, 0x57, 0x69, 0x74, 0x68, 0x41, 0x4a, 0x73, 0x6f, 0x6e, 0x12, 0x28, 0x0a, 0x06, 0x66, 0x69,
0x65, 0x6c, 0x64, 0x31, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x42, 0x10, 0x9a, 0xe7, 0xb0, 0x2a,
0x0b, 0x69, 0x6e, 0x6c, 0x69, 0x6e, 0x65, 0x5f, 0x6a, 0x73, 0x6f, 0x6e, 0x52, 0x06, 0x66, 0x69,
0x65, 0x6c, 0x64, 0x31, 0x22, 0x92, 0x03, 0x0a, 0x10, 0x41, 0x42, 0x69, 0x74, 0x4f, 0x66, 0x45,
0x65, 0x6c, 0x64, 0x31, 0x22, 0xbf, 0x03, 0x0a, 0x10, 0x41, 0x42, 0x69, 0x74, 0x4f, 0x66, 0x45,
0x76, 0x65, 0x72, 0x79, 0x74, 0x68, 0x69, 0x6e, 0x67, 0x12, 0x2f, 0x0a, 0x07, 0x6d, 0x65, 0x73,
0x73, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x74, 0x65, 0x73,
0x74, 0x70, 0x62, 0x2e, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67,
@ -4474,32 +4550,35 @@ var file_testpb_test_proto_rawDesc = []byte{
0x11, 0x20, 0x01, 0x28, 0x04, 0x52, 0x03, 0x75, 0x36, 0x34, 0x12, 0x12, 0x0a, 0x04, 0x73, 0x69,
0x36, 0x34, 0x18, 0x12, 0x20, 0x01, 0x28, 0x12, 0x52, 0x04, 0x73, 0x69, 0x36, 0x34, 0x12, 0x12,
0x0a, 0x04, 0x73, 0x66, 0x36, 0x34, 0x18, 0x13, 0x20, 0x01, 0x28, 0x10, 0x52, 0x04, 0x73, 0x66,
0x36, 0x34, 0x3a, 0x15, 0x8a, 0xe7, 0xb0, 0x2a, 0x10, 0x41, 0x42, 0x69, 0x74, 0x4f, 0x66, 0x45,
0x76, 0x65, 0x72, 0x79, 0x74, 0x68, 0x69, 0x6e, 0x67, 0x22, 0x7b, 0x0a, 0x08, 0x44, 0x75, 0x72,
0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x35, 0x0a, 0x08, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f,
0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65,
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69,
0x6f, 0x6e, 0x52, 0x08, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x38, 0x0a, 0x09,
0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32,
0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75,
0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x74, 0x69, 0x6d,
0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x22, 0x47, 0x0a, 0x0d, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64,
0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x66, 0x6f, 0x6f, 0x18, 0x01,
0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x66, 0x6f, 0x6f, 0x12, 0x10, 0x0a, 0x03, 0x62, 0x61, 0x72,
0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x62, 0x61, 0x72, 0x3a, 0x12, 0x8a, 0xe7, 0xb0,
0x2a, 0x0d, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2a,
0x29, 0x0a, 0x06, 0x41, 0x6e, 0x45, 0x6e, 0x75, 0x6d, 0x12, 0x0d, 0x0a, 0x09, 0x55, 0x4e, 0x44,
0x45, 0x46, 0x49, 0x4e, 0x45, 0x44, 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03, 0x4f, 0x4e, 0x45, 0x10,
0x01, 0x12, 0x07, 0x0a, 0x03, 0x54, 0x57, 0x4f, 0x10, 0x02, 0x42, 0x83, 0x01, 0x0a, 0x0a, 0x63,
0x6f, 0x6d, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x42, 0x09, 0x54, 0x65, 0x73, 0x74, 0x50,
0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x32, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64,
0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x78, 0x2f, 0x74, 0x78, 0x2f, 0x61, 0x6d, 0x69, 0x6e, 0x6f, 0x6a,
0x73, 0x6f, 0x6e, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x74, 0x65, 0x73,
0x74, 0x70, 0x62, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0xa2, 0x02, 0x03, 0x54, 0x58, 0x58,
0xaa, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0xca, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74,
0x70, 0x62, 0xe2, 0x02, 0x12, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0x5c, 0x47, 0x50, 0x42, 0x4d,
0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62,
0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x36, 0x34, 0x12, 0x2b, 0x0a, 0x0c, 0x70, 0x72, 0x65, 0x74, 0x74, 0x79, 0x5f, 0x62, 0x79, 0x74,
0x65, 0x73, 0x18, 0x14, 0x20, 0x01, 0x28, 0x0c, 0x42, 0x08, 0x9a, 0xe7, 0xb0, 0x2a, 0x03, 0x68,
0x65, 0x78, 0x52, 0x0b, 0x70, 0x72, 0x65, 0x74, 0x74, 0x79, 0x42, 0x79, 0x74, 0x65, 0x73, 0x3a,
0x15, 0x8a, 0xe7, 0xb0, 0x2a, 0x10, 0x41, 0x42, 0x69, 0x74, 0x4f, 0x66, 0x45, 0x76, 0x65, 0x72,
0x79, 0x74, 0x68, 0x69, 0x6e, 0x67, 0x22, 0x7b, 0x0a, 0x08, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69,
0x6f, 0x6e, 0x12, 0x35, 0x0a, 0x08, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x01,
0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52,
0x08, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x38, 0x0a, 0x09, 0x74, 0x69, 0x6d,
0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67,
0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54,
0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74,
0x61, 0x6d, 0x70, 0x22, 0x47, 0x0a, 0x0d, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x4d, 0x65, 0x73,
0x73, 0x61, 0x67, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x66, 0x6f, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28,
0x09, 0x52, 0x03, 0x66, 0x6f, 0x6f, 0x12, 0x10, 0x0a, 0x03, 0x62, 0x61, 0x72, 0x18, 0x02, 0x20,
0x01, 0x28, 0x05, 0x52, 0x03, 0x62, 0x61, 0x72, 0x3a, 0x12, 0x8a, 0xe7, 0xb0, 0x2a, 0x0d, 0x4e,
0x65, 0x73, 0x74, 0x65, 0x64, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2a, 0x29, 0x0a, 0x06,
0x41, 0x6e, 0x45, 0x6e, 0x75, 0x6d, 0x12, 0x0d, 0x0a, 0x09, 0x55, 0x4e, 0x44, 0x45, 0x46, 0x49,
0x4e, 0x45, 0x44, 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03, 0x4f, 0x4e, 0x45, 0x10, 0x01, 0x12, 0x07,
0x0a, 0x03, 0x54, 0x57, 0x4f, 0x10, 0x02, 0x42, 0x83, 0x01, 0x0a, 0x0a, 0x63, 0x6f, 0x6d, 0x2e,
0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x42, 0x09, 0x54, 0x65, 0x73, 0x74, 0x50, 0x72, 0x6f, 0x74,
0x6f, 0x50, 0x01, 0x5a, 0x32, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69,
0x6f, 0x2f, 0x78, 0x2f, 0x74, 0x78, 0x2f, 0x61, 0x6d, 0x69, 0x6e, 0x6f, 0x6a, 0x73, 0x6f, 0x6e,
0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62,
0x2f, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0xa2, 0x02, 0x03, 0x54, 0x58, 0x58, 0xaa, 0x02, 0x06,
0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0xca, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0xe2,
0x02, 0x12, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61,
0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0x62, 0x06, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (

View File

@ -1,6 +1,7 @@
package aminojson_test
import (
"crypto/sha256"
"encoding/json"
"errors"
"fmt"
@ -414,3 +415,33 @@ func TestAminoNameAsTypeURL(t *testing.T) {
}
}`, string(bz))
}
func TestCustomBytesEncoder(t *testing.T) {
cdc := amino.NewCodec()
cdc.RegisterConcrete(&testpb.ABitOfEverything{}, "ABitOfEverything", nil)
encoder := aminojson.NewEncoder(aminojson.EncoderOptions{})
bz := sha256.Sum256([]byte("test"))
msg := &testpb.ABitOfEverything{
Bytes: bz[:],
PrettyBytes: bz[:],
}
legacyJSON, err := cdc.MarshalJSON(msg)
require.NoError(t, err)
aminoJSON, err := encoder.Marshal(msg)
require.NoError(t, err)
require.Equal(t, string(legacyJSON), string(aminoJSON))
encoder.DefineFieldEncoding(
"hex",
func(enc *aminojson.Encoder, v protoreflect.Value, w io.Writer) error {
_, err := fmt.Fprintf(w, "\"%x\"", v.Bytes())
return err
})
aminoJSON, err = encoder.Marshal(msg)
require.NoError(t, err)
require.NotEqual(t, string(legacyJSON), string(aminoJSON))
t.Logf("hex encoded bytes: %s", string(aminoJSON))
}