refactor: rename Assertion to Account and update related code

This commit is contained in:
Prad Nukala
2024-11-26 00:07:45 -05:00
parent 9e7f70c455
commit 179a69df1c
47 changed files with 2781 additions and 25381 deletions
-31
View File
@@ -1,31 +0,0 @@
package keeper_test
import (
"testing"
apiv1 "github.com/onsonr/sonr/api/dwn/v1"
"github.com/stretchr/testify/require"
)
func TestORM(t *testing.T) {
f := SetupTest(t)
dt := f.k.OrmDB.ExampleDataTable()
acc := []byte("test_acc")
amt := uint64(7)
err := dt.Insert(f.ctx, &apiv1.ExampleData{
Account: acc,
Amount: amt,
})
require.NoError(t, err)
d, err := dt.Has(f.ctx, []byte("test_acc"))
require.NoError(t, err)
require.True(t, d)
res, err := dt.Get(f.ctx, []byte("test_acc"))
require.NoError(t, err)
require.NotNil(t, res)
require.EqualValues(t, amt, res.Amount)
}
+243 -35
View File
@@ -23,23 +23,23 @@ var _ = math.Inf
// proto package needs to be updated.
const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
type ExampleData struct {
type Credential struct {
Account []byte `protobuf:"bytes,1,opt,name=account,proto3" json:"account,omitempty"`
Amount uint64 `protobuf:"varint,2,opt,name=amount,proto3" json:"amount,omitempty"`
}
func (m *ExampleData) Reset() { *m = ExampleData{} }
func (m *ExampleData) String() string { return proto.CompactTextString(m) }
func (*ExampleData) ProtoMessage() {}
func (*ExampleData) Descriptor() ([]byte, []int) {
func (m *Credential) Reset() { *m = Credential{} }
func (m *Credential) String() string { return proto.CompactTextString(m) }
func (*Credential) ProtoMessage() {}
func (*Credential) Descriptor() ([]byte, []int) {
return fileDescriptor_040a9b061177db90, []int{0}
}
func (m *ExampleData) XXX_Unmarshal(b []byte) error {
func (m *Credential) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
func (m *ExampleData) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
func (m *Credential) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_ExampleData.Marshal(b, m, deterministic)
return xxx_messageInfo_Credential.Marshal(b, m, deterministic)
} else {
b = b[:cap(b)]
n, err := m.MarshalToSizedBuffer(b)
@@ -49,26 +49,78 @@ func (m *ExampleData) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
return b[:n], nil
}
}
func (m *ExampleData) XXX_Merge(src proto.Message) {
xxx_messageInfo_ExampleData.Merge(m, src)
func (m *Credential) XXX_Merge(src proto.Message) {
xxx_messageInfo_Credential.Merge(m, src)
}
func (m *ExampleData) XXX_Size() int {
func (m *Credential) XXX_Size() int {
return m.Size()
}
func (m *ExampleData) XXX_DiscardUnknown() {
xxx_messageInfo_ExampleData.DiscardUnknown(m)
func (m *Credential) XXX_DiscardUnknown() {
xxx_messageInfo_Credential.DiscardUnknown(m)
}
var xxx_messageInfo_ExampleData proto.InternalMessageInfo
var xxx_messageInfo_Credential proto.InternalMessageInfo
func (m *ExampleData) GetAccount() []byte {
func (m *Credential) GetAccount() []byte {
if m != nil {
return m.Account
}
return nil
}
func (m *ExampleData) GetAmount() uint64 {
func (m *Credential) GetAmount() uint64 {
if m != nil {
return m.Amount
}
return 0
}
type Profile struct {
Account []byte `protobuf:"bytes,1,opt,name=account,proto3" json:"account,omitempty"`
Amount uint64 `protobuf:"varint,2,opt,name=amount,proto3" json:"amount,omitempty"`
}
func (m *Profile) Reset() { *m = Profile{} }
func (m *Profile) String() string { return proto.CompactTextString(m) }
func (*Profile) ProtoMessage() {}
func (*Profile) Descriptor() ([]byte, []int) {
return fileDescriptor_040a9b061177db90, []int{1}
}
func (m *Profile) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
func (m *Profile) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_Profile.Marshal(b, m, deterministic)
} else {
b = b[:cap(b)]
n, err := m.MarshalToSizedBuffer(b)
if err != nil {
return nil, err
}
return b[:n], nil
}
}
func (m *Profile) XXX_Merge(src proto.Message) {
xxx_messageInfo_Profile.Merge(m, src)
}
func (m *Profile) XXX_Size() int {
return m.Size()
}
func (m *Profile) XXX_DiscardUnknown() {
xxx_messageInfo_Profile.DiscardUnknown(m)
}
var xxx_messageInfo_Profile proto.InternalMessageInfo
func (m *Profile) GetAccount() []byte {
if m != nil {
return m.Account
}
return nil
}
func (m *Profile) GetAmount() uint64 {
if m != nil {
return m.Amount
}
@@ -76,29 +128,31 @@ func (m *ExampleData) GetAmount() uint64 {
}
func init() {
proto.RegisterType((*ExampleData)(nil), "dwn.v1.ExampleData")
proto.RegisterType((*Credential)(nil), "dwn.v1.Credential")
proto.RegisterType((*Profile)(nil), "dwn.v1.Profile")
}
func init() { proto.RegisterFile("dwn/v1/state.proto", fileDescriptor_040a9b061177db90) }
var fileDescriptor_040a9b061177db90 = []byte{
// 205 bytes of a gzipped FileDescriptorProto
// 219 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x4a, 0x29, 0xcf, 0xd3,
0x2f, 0x33, 0xd4, 0x2f, 0x2e, 0x49, 0x2c, 0x49, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62,
0x4b, 0x29, 0xcf, 0xd3, 0x2b, 0x33, 0x94, 0x12, 0x4f, 0xce, 0x2f, 0xce, 0xcd, 0x2f, 0xd6, 0xcf,
0x2f, 0xca, 0x05, 0x29, 0xc9, 0x2f, 0xca, 0x85, 0x28, 0x50, 0x4a, 0xe0, 0xe2, 0x76, 0xad, 0x48,
0xcc, 0x2d, 0xc8, 0x49, 0x75, 0x49, 0x2c, 0x49, 0x14, 0x92, 0xe0, 0x62, 0x4f, 0x4c, 0x4e, 0xce,
0x2f, 0xcd, 0x2b, 0x91, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x09, 0x82, 0x71, 0x85, 0xc4, 0xb8, 0xd8,
0x12, 0x73, 0xc1, 0x12, 0x4c, 0x0a, 0x8c, 0x1a, 0x2c, 0x41, 0x50, 0x9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 0x52, 0xa9, 0x6f, 0x3a, 0x93, 0x93, 0xcd,
0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x38, 0xe1, 0xb1, 0x1c,
0xc3, 0x85, 0xc7, 0x72, 0x0c, 0x37, 0x1e, 0xcb, 0x31, 0x44, 0x29, 0xa5, 0x67, 0x96, 0x64, 0x94,
0x26, 0xe9, 0x25, 0xe7, 0xe7, 0xea, 0xe7, 0xe7, 0x15, 0xe7, 0xe7, 0x15, 0xe9, 0x83, 0x89, 0x0a,
0x7d, 0x50, 0x30, 0x95, 0x54, 0x16, 0xa4, 0x16, 0x27, 0xb1, 0x81, 0xc3, 0xc0, 0x18, 0x10, 0x00,
0x00, 0xff, 0xff, 0x14, 0x0b, 0x56, 0x1c, 0x3a, 0x01, 0x00, 0x00,
}
func (m *ExampleData) Marshal() (dAtA []byte, err error) {
func (m *Credential) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalToSizedBuffer(dAtA[:size])
@@ -108,12 +162,47 @@ func (m *ExampleData) Marshal() (dAtA []byte, err error) {
return dAtA[:n], nil
}
func (m *ExampleData) MarshalTo(dAtA []byte) (int, error) {
func (m *Credential) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *ExampleData) MarshalToSizedBuffer(dAtA []byte) (int, error) {
func (m *Credential) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
if m.Amount != 0 {
i = encodeVarintState(dAtA, i, uint64(m.Amount))
i--
dAtA[i] = 0x10
}
if len(m.Account) > 0 {
i -= len(m.Account)
copy(dAtA[i:], m.Account)
i = encodeVarintState(dAtA, i, uint64(len(m.Account)))
i--
dAtA[i] = 0xa
}
return len(dAtA) - i, nil
}
func (m *Profile) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalToSizedBuffer(dAtA[:size])
if err != nil {
return nil, err
}
return dAtA[:n], nil
}
func (m *Profile) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *Profile) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
@@ -144,7 +233,23 @@ func encodeVarintState(dAtA []byte, offset int, v uint64) int {
dAtA[offset] = uint8(v)
return base
}
func (m *ExampleData) Size() (n int) {
func (m *Credential) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
l = len(m.Account)
if l > 0 {
n += 1 + l + sovState(uint64(l))
}
if m.Amount != 0 {
n += 1 + sovState(uint64(m.Amount))
}
return n
}
func (m *Profile) Size() (n int) {
if m == nil {
return 0
}
@@ -166,7 +271,7 @@ func sovState(x uint64) (n int) {
func sozState(x uint64) (n int) {
return sovState(uint64((x << 1) ^ uint64((int64(x) >> 63))))
}
func (m *ExampleData) Unmarshal(dAtA []byte) error {
func (m *Credential) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
@@ -189,10 +294,113 @@ func (m *ExampleData) Unmarshal(dAtA []byte) error {
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: ExampleData: wiretype end group for non-group")
return fmt.Errorf("proto: Credential: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: ExampleData: illegal tag %d (wire type %d)", fieldNum, wire)
return fmt.Errorf("proto: Credential: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Account", wireType)
}
var byteLen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowState
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
byteLen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if byteLen < 0 {
return ErrInvalidLengthState
}
postIndex := iNdEx + byteLen
if postIndex < 0 {
return ErrInvalidLengthState
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Account = append(m.Account[:0], dAtA[iNdEx:postIndex]...)
if m.Account == nil {
m.Account = []byte{}
}
iNdEx = postIndex
case 2:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType)
}
m.Amount = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowState
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.Amount |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
default:
iNdEx = preIndex
skippy, err := skipState(dAtA[iNdEx:])
if err != nil {
return err
}
if (skippy < 0) || (iNdEx+skippy) < 0 {
return ErrInvalidLengthState
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func (m *Profile) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowState
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: Profile: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: Profile: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1: