github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/token_nft_transfer_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 // testinf func (transfer TokenNftTransfer) ToBytes() and func NftTransferFromBytes(data []byte) 33 func TestUnitTokenNftTransferToBytes(t *testing.T) { 34 t.Parallel() 35 36 transfer := _TokenNftTransfer{ 37 SenderAccountID: AccountID{Account: 3}, 38 ReceiverAccountID: AccountID{Account: 4}, 39 SerialNumber: 5, 40 IsApproved: true, 41 } 42 43 transferBytes := transfer.ToBytes() 44 transferFromBytes, err := NftTransferFromBytes(transferBytes) 45 46 assert.NoError(t, err) 47 assert.Equal(t, transfer, transferFromBytes) 48 49 // test invalid data from and to bytes 50 _, err = NftTransferFromBytes([]byte{1, 2, 3}) 51 assert.Error(t, err) 52 53 // test nil data from bytes and to bytes 54 _, err = NftTransferFromBytes(nil) 55 assert.Error(t, err) 56 }