github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/custom_fractional_fee_unit_test.go (about) 1 //go:build all || unit 2 // +build all unit 3 4 package hedera 5 6 import ( 7 "testing" 8 9 "github.com/hashgraph/hedera-protobufs-go/services" 10 "github.com/stretchr/testify/require" 11 "google.golang.org/protobuf/proto" 12 ) 13 14 func TestCustomFractionalFee_SettersAndGetters(t *testing.T) { 15 t.Parallel() 16 17 fee := NewCustomFractionalFee() 18 const FeeAssessmentMethod_TRUE FeeAssessmentMethod = true 19 20 fee.SetFeeCollectorAccountID(AccountID{Account: 1234}). 21 SetNumerator(1). 22 SetDenominator(2). 23 SetMin(10). 24 SetMax(100). 25 SetAllCollectorsAreExempt(true). 26 SetAssessmentMethod(FeeAssessmentMethod_TRUE) 27 28 require.Equal(t, AccountID{Account: 1234}, fee.GetFeeCollectorAccountID()) 29 require.Equal(t, int64(1), fee.GetNumerator()) 30 require.Equal(t, int64(2), fee.GetDenominator()) 31 require.Equal(t, int64(10), fee.GetMin()) 32 require.Equal(t, int64(100), fee.GetMax()) 33 require.Equal(t, true, fee.GetAllCollectorsAreExempt()) 34 require.Equal(t, FeeAssessmentMethod_TRUE, fee.GetAssessmentMethod()) 35 } 36 37 func TestCustomFractionalFee_ToBytes(t *testing.T) { 38 t.Parallel() 39 40 fee := NewCustomFractionalFee() 41 const FeeAssessmentMethod_TRUE FeeAssessmentMethod = true 42 43 fee.SetFeeCollectorAccountID(AccountID{Account: 1234}). 44 SetNumerator(1). 45 SetDenominator(2). 46 SetMin(10). 47 SetMax(100). 48 SetAllCollectorsAreExempt(true). 49 SetAssessmentMethod(FeeAssessmentMethod_TRUE) 50 51 bytes := fee.ToBytes() 52 require.NotEmpty(t, bytes) 53 54 protoFee := &services.CustomFee{} 55 err := proto.Unmarshal(bytes, protoFee) 56 require.NoError(t, err) 57 58 require.Equal(t, int64(1), protoFee.GetFractionalFee().GetFractionalAmount().GetNumerator()) 59 require.Equal(t, int64(2), protoFee.GetFractionalFee().GetFractionalAmount().GetDenominator()) 60 require.Equal(t, int64(10), protoFee.GetFractionalFee().GetMinimumAmount()) 61 require.Equal(t, int64(100), protoFee.GetFractionalFee().GetMaximumAmount()) 62 require.Equal(t, true, protoFee.GetFractionalFee().GetNetOfTransfers()) 63 require.Equal(t, int64(1234), protoFee.GetFeeCollectorAccountId().GetAccountNum()) 64 require.Equal(t, true, protoFee.GetAllCollectorsAreExempt()) 65 } 66 67 func TestCustomFractionalFee_ToProtobuf(t *testing.T) { 68 t.Parallel() 69 70 fee := NewCustomFractionalFee() 71 const FeeAssessmentMethod_TRUE FeeAssessmentMethod = true 72 73 fee.SetFeeCollectorAccountID(AccountID{Account: 1234}). 74 SetNumerator(1). 75 SetDenominator(2). 76 SetMin(10). 77 SetMax(100). 78 SetAllCollectorsAreExempt(true). 79 SetAssessmentMethod(FeeAssessmentMethod_TRUE) 80 81 protoFee := fee._ToProtobuf() 82 require.Equal(t, int64(1), protoFee.GetFractionalFee().GetFractionalAmount().GetNumerator()) 83 require.Equal(t, int64(2), protoFee.GetFractionalFee().GetFractionalAmount().GetDenominator()) 84 require.Equal(t, int64(10), protoFee.GetFractionalFee().GetMinimumAmount()) 85 require.Equal(t, int64(100), protoFee.GetFractionalFee().GetMaximumAmount()) 86 require.Equal(t, true, protoFee.GetFractionalFee().GetNetOfTransfers()) 87 require.Equal(t, int64(1234), protoFee.GetFeeCollectorAccountId().GetAccountNum()) 88 require.Equal(t, true, protoFee.GetAllCollectorsAreExempt()) 89 // CustomFeeFromProtobuf calls _CustomFractionalFeeFromProtobuf 90 deserializedFee := _CustomFeeFromProtobuf(protoFee) 91 92 require.Equal(t, *fee, deserializedFee) 93 }