github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/pending_airdrop_id_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/hashgraph/hedera-protobufs-go/services"
    30  	"github.com/stretchr/testify/assert"
    31  	"github.com/stretchr/testify/require"
    32  )
    33  
    34  func TestPendingAirdropId_SettersAndGetters(t *testing.T) {
    35  	t.Parallel()
    36  
    37  	sender := AccountID{Account: 1}
    38  	receiver := AccountID{Account: 2}
    39  	tokenID := TokenID{Token: 3}
    40  	nftID := NftID{TokenID: tokenID, SerialNumber: 1}
    41  
    42  	pendingAirdropId := &PendingAirdropId{}
    43  	pendingAirdropId.SetSender(sender)
    44  	pendingAirdropId.SetReceiver(receiver)
    45  	pendingAirdropId.SetTokenID(tokenID)
    46  	pendingAirdropId.SetNftID(nftID)
    47  
    48  	assert.Equal(t, &sender, pendingAirdropId.GetSender())
    49  	assert.Equal(t, &receiver, pendingAirdropId.GetReceiver())
    50  	assert.Equal(t, &tokenID, pendingAirdropId.GetTokenID())
    51  	assert.Equal(t, &nftID, pendingAirdropId.GetNftID())
    52  }
    53  
    54  func TestPendingAirdropId_FromProtobuf(t *testing.T) {
    55  	t.Parallel()
    56  
    57  	sender := AccountID{Account: 1}
    58  	receiver := AccountID{Account: 2}
    59  	tokenID := TokenID{Token: 3}
    60  	nftID := NftID{TokenID: tokenID, SerialNumber: 1}
    61  
    62  	pb := &services.PendingAirdropId{
    63  		SenderId:   sender._ToProtobuf(),
    64  		ReceiverId: receiver._ToProtobuf(),
    65  		TokenReference: &services.PendingAirdropId_FungibleTokenType{
    66  			FungibleTokenType: tokenID._ToProtobuf(),
    67  		},
    68  	}
    69  
    70  	pendingAirdropId := _PendingAirdropIdFromProtobuf(pb)
    71  	require.NotNil(t, pendingAirdropId)
    72  	assert.Equal(t, &sender, pendingAirdropId.GetSender())
    73  	assert.Equal(t, &receiver, pendingAirdropId.GetReceiver())
    74  	assert.Equal(t, &tokenID, pendingAirdropId.GetTokenID())
    75  	assert.Nil(t, pendingAirdropId.GetNftID())
    76  
    77  	pb = &services.PendingAirdropId{
    78  		SenderId:   sender._ToProtobuf(),
    79  		ReceiverId: receiver._ToProtobuf(),
    80  		TokenReference: &services.PendingAirdropId_NonFungibleToken{
    81  			NonFungibleToken: nftID._ToProtobuf(),
    82  		},
    83  	}
    84  
    85  	pendingAirdropId = _PendingAirdropIdFromProtobuf(pb)
    86  	require.NotNil(t, pendingAirdropId)
    87  	assert.Equal(t, &sender, pendingAirdropId.GetSender())
    88  	assert.Equal(t, &receiver, pendingAirdropId.GetReceiver())
    89  	assert.Nil(t, pendingAirdropId.GetTokenID())
    90  	assert.Equal(t, &nftID, pendingAirdropId.GetNftID())
    91  }
    92  
    93  func TestPendingAirdropId_ToProtobuf(t *testing.T) {
    94  	t.Parallel()
    95  
    96  	sender := AccountID{Account: 1}
    97  	receiver := AccountID{Account: 2}
    98  	tokenID := TokenID{Token: 3}
    99  	nftID := NftID{TokenID: tokenID, SerialNumber: 1}
   100  
   101  	pendingAirdropId := &PendingAirdropId{
   102  		sender:   &sender,
   103  		receiver: &receiver,
   104  		tokenID:  &tokenID,
   105  	}
   106  
   107  	pb := pendingAirdropId._ToProtobuf()
   108  	require.NotNil(t, pb)
   109  	assert.Equal(t, sender._ToProtobuf(), pb.GetSenderId())
   110  	assert.Equal(t, receiver._ToProtobuf(), pb.GetReceiverId())
   111  	assert.Equal(t, tokenID._ToProtobuf(), pb.GetFungibleTokenType())
   112  	assert.Nil(t, pb.GetNonFungibleToken())
   113  
   114  	pendingAirdropId = &PendingAirdropId{
   115  		sender:   &sender,
   116  		receiver: &receiver,
   117  		nftID:    &nftID,
   118  	}
   119  
   120  	pb = pendingAirdropId._ToProtobuf()
   121  	require.NotNil(t, pb)
   122  	assert.Equal(t, sender._ToProtobuf(), pb.GetSenderId())
   123  	assert.Equal(t, receiver._ToProtobuf(), pb.GetReceiverId())
   124  	assert.Nil(t, pb.GetFungibleTokenType())
   125  	assert.Equal(t, nftID._ToProtobuf(), pb.GetNonFungibleToken())
   126  }