github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/token_allowance_unit_test.go (about) 1 //go:build all || unit 2 // +build all unit 3 4 package hedera 5 6 /*- 7 * 8 * Hedera Go SDK 9 * 10 * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC 11 * 12 * Licensed under the Apache License, Version 2.0 (the "License"); 13 * you may not use this file except in compliance with the License. 14 * You may obtain a copy of the License at 15 * 16 * http://www.apache.org/licenses/LICENSE-2.0 17 * 18 * Unless required by applicable law or agreed to in writing, software 19 * distributed under the License is distributed on an "AS IS" BASIS, 20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 * See the License for the specific language governing permissions and 22 * limitations under the License. 23 * 24 */ 25 26 import ( 27 "testing" 28 29 "github.com/stretchr/testify/assert" 30 ) 31 32 func TestUnitNewTokenAllowance(t *testing.T) { 33 t.Parallel() 34 35 tokID := TokenID{Token: 3} 36 owner := AccountID{Account: 5} 37 spender := AccountID{Account: 6} 38 amount := int64(100) 39 40 allowance := NewTokenAllowance(tokID, owner, spender, amount) 41 42 newAllowance := TokenAllowance{ 43 TokenID: &tokID, 44 SpenderAccountID: &spender, 45 OwnerAccountID: &owner, 46 Amount: amount, 47 } 48 49 assert.Equal(t, newAllowance, allowance) 50 } 51 52 func TestUnitTokenAllowanceFromProtobuf(t *testing.T) { 53 t.Parallel() 54 55 tokID := TokenID{Token: 3} 56 owner := AccountID{Account: 5} 57 spender := AccountID{Account: 6} 58 amount := int64(100) 59 60 allowance := NewTokenAllowance(tokID, owner, spender, amount) 61 62 pb := allowance._ToProtobuf() 63 assert.NotNil(t, pb) 64 65 allowance2 := _TokenAllowanceFromProtobuf(pb) 66 assert.Equal(t, allowance, allowance2) 67 } 68 69 func TestUnitTokenAllowance_String(t *testing.T) { 70 t.Parallel() 71 72 tokID := TokenID{Token: 3} 73 owner := AccountID{Account: 5} 74 spender := AccountID{Account: 6} 75 amount := int64(100) 76 77 allowance := NewTokenAllowance(tokID, owner, spender, amount) 78 79 assert.Equal(t, "OwnerAccountID: 0.0.5, SpenderAccountID: 0.0.6, TokenID: 0.0.3, Amount: 100 tℏ", allowance.String()) 80 }