Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update main #839

Merged
merged 4 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ vendor/
# Editors
.idea
.env
go.work
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v2.33.0

### Fixed

* Invalid fallback for mirror node insecure port

## v2.32.0

### Added
Expand Down
87 changes: 35 additions & 52 deletions account_allowance_approve_transaction_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,22 @@ import (
"google.golang.org/protobuf/types/known/wrapperspb"
)

var tokenID1 = TokenID{Token: 1}
var tokenID2 = TokenID{Token: 141}
var serialNumber1 = int64(3)
var serialNumber2 = int64(4)
var nftID1 = tokenID2.Nft(serialNumber1)
var nftID2 = tokenID2.Nft(serialNumber2)
var owner = AccountID{Account: 10}
var spenderAccountID1 = AccountID{Account: 7}
var spenderAccountID2 = AccountID{Account: 7890}
var nodeAccountID = []AccountID{{Account: 10}, {Account: 11}, {Account: 12}}
var hbarAmount = HbarFromTinybar(100)
var tokenAmount = int64(101)

func TestUnitAccountAllowanceApproveTransaction(t *testing.T) {
t.Parallel()

tokenID1 := TokenID{Token: 1}
tokenID2 := TokenID{Token: 141}
serialNumber1 := int64(3)
serialNumber2 := int64(4)
nftID1 := tokenID2.Nft(serialNumber1)
nftID2 := tokenID2.Nft(serialNumber2)
owner := AccountID{Account: 10}
spenderAccountID1 := AccountID{Account: 7}
spenderAccountID2 := AccountID{Account: 7890}
nodeAccountID := []AccountID{{Account: 10}, {Account: 11}, {Account: 12}}
hbarAmount := HbarFromTinybar(100)
tokenAmount := int64(101)

transactionID := TransactionIDGenerate(AccountID{Account: 324})

transaction, err := NewAccountAllowanceApproveTransaction().
Expand Down Expand Up @@ -111,23 +111,32 @@ func TestUnitAccountAllowanceApproveTransaction(t *testing.T) {
})
}
}
func TestUnit_ValidateNetworkOnIDs(t *testing.T){
transactionID := TransactionIDGenerate(AccountID{Account: 324})


transaction, err := NewAccountAllowanceApproveTransaction().
SetTransactionID(transactionID).
SetNodeAccountIDs(nodeAccountID).
ApproveHbarAllowance(owner, spenderAccountID1, hbarAmount).
ApproveTokenAllowance(tokenID1, owner, spenderAccountID1, tokenAmount).
ApproveTokenNftAllowance(nftID1, owner, spenderAccountID1).
ApproveTokenNftAllowance(nftID2, owner, spenderAccountID1).
ApproveTokenNftAllowance(nftID2, owner, spenderAccountID2).
AddAllTokenNftApproval(tokenID1, spenderAccountID1).
Freeze()
require.NoError(t, err)

client, err := _NewMockClient()
client.SetLedgerID(*NewLedgerIDTestnet())
require.NoError(t, err)

e := transaction._ValidateNetworkOnIDs(client)
require.NoError(t, e)
}
func TestUnitAccountAllowanceApproveTransactionGet(t *testing.T) {
t.Parallel()

tokenID1 := TokenID{Token: 1}
tokenID2 := TokenID{Token: 141}
serialNumber1 := int64(3)
serialNumber2 := int64(4)
nftID1 := tokenID2.Nft(serialNumber1)
nftID2 := tokenID2.Nft(serialNumber2)
owner := AccountID{Account: 10}
spenderAccountID1 := AccountID{Account: 7}
spenderAccountID2 := AccountID{Account: 7890}
nodeAccountID := []AccountID{{Account: 10}, {Account: 11}, {Account: 12}}
hbarAmount := HbarFromTinybar(100)
tokenAmount := int64(101)

transactionID := TransactionIDGenerate(AccountID{Account: 324})

transaction, err := NewAccountAllowanceApproveTransaction().
Expand Down Expand Up @@ -214,19 +223,6 @@ func TestUnitAccountAllowanceDeleteTransactionSetNothing(t *testing.T) {
func TestUnitAccountAllowanceApproveTransactionFromProtobuf(t *testing.T) {
t.Parallel()

tokenID1 := TokenID{Token: 1}
tokenID2 := TokenID{Token: 141}
serialNumber1 := int64(3)
serialNumber2 := int64(4)
nftID1 := tokenID2.Nft(serialNumber1)
nftID2 := tokenID2.Nft(serialNumber2)
owner := AccountID{Account: 10}
spenderAccountID1 := AccountID{Account: 7}
spenderAccountID2 := AccountID{Account: 7890}
nodeAccountID := []AccountID{{Account: 10}, {Account: 11}, {Account: 12}}
hbarAmount := HbarFromTinybar(100)
tokenAmount := int64(101)

transactionID := TransactionIDGenerate(AccountID{Account: 324})

tx, err := NewAccountAllowanceApproveTransaction().
Expand All @@ -247,19 +243,6 @@ func TestUnitAccountAllowanceApproveTransactionFromProtobuf(t *testing.T) {
func TestUnitAccountAllowanceApproveTransactionScheduleProtobuf(t *testing.T) {
t.Parallel()

tokenID1 := TokenID{Token: 1}
tokenID2 := TokenID{Token: 141}
serialNumber1 := int64(3)
serialNumber2 := int64(4)
nftID1 := tokenID2.Nft(serialNumber1)
nftID2 := tokenID2.Nft(serialNumber2)
owner := AccountID{Account: 10}
spenderAccountID1 := AccountID{Account: 7}
spenderAccountID2 := AccountID{Account: 7890}
nodeAccountID := []AccountID{{Account: 10}, {Account: 11}, {Account: 12}}
hbarAmount := HbarFromTinybar(100)
tokenAmount := int64(101)

transactionID := TransactionIDGenerate(AccountID{Account: 324})

tx, err := NewAccountAllowanceApproveTransaction().
Expand Down
1 change: 0 additions & 1 deletion account_id_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,3 @@ func TestUnitAccountIDPopulateEvmFailWithNoMirrorNetwork(t *testing.T) {
err = id.PopulateEvmAddress(client)
require.Error(t, err)
}

75 changes: 75 additions & 0 deletions account_info_unit_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//go:build all || unit
// +build all unit

package hedera

/*-
*
* Hedera Go SDK
*
* Copyright (C) 2020 - 2023 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

import (
"testing"
"time"

"github.com/stretchr/testify/require"
)

// The function checks the conversation methods on the AccountInfo struct. We check wether it is correctly converted to protobuf and back.
func TestUnitAccountInfoToBytes(t *testing.T) {
t.Parallel()

accInfoOriginal := *_MockAccountInfo()
accInfoBytes := accInfoOriginal.ToBytes()

accInfoFromBytes, err := AccountInfoFromBytes(accInfoBytes)

require.NoError(t, err)
require.Equal(t, accInfoOriginal.AccountID, accInfoFromBytes.AccountID)
require.Equal(t, accInfoOriginal.ContractAccountID, accInfoFromBytes.ContractAccountID)
require.Equal(t, accInfoOriginal.Key, accInfoFromBytes.Key)
require.Equal(t, accInfoOriginal.LedgerID, accInfoFromBytes.LedgerID)
}
func _MockAccountInfo() *AccountInfo {
privateKey, _ := PrivateKeyFromString(mockPrivateKey)
accountID, _ := AccountIDFromString("0.0.123-esxsf")
accountID.checksum = nil

return &AccountInfo{
AccountID: accountID,
ContractAccountID: "",
IsDeleted: false,
ProxyReceived: Hbar{},
Key: privateKey.PublicKey(),
Balance: HbarFromTinybar(100000000000),
GenerateSendRecordThreshold: Hbar{},
GenerateReceiveRecordThreshold: Hbar{},
ReceiverSigRequired: false,
ExpirationTime: time.Date(2222, 2, 2, 2, 2, 2, 2, time.Now().UTC().Location()),
AutoRenewPeriod: time.Duration(time.Duration(5).Seconds()),
LiveHashes: nil,
AccountMemo: "",
OwnedNfts: 0,
MaxAutomaticTokenAssociations: 0,
AliasKey: nil,
LedgerID: *NewLedgerIDTestnet(),
EthereumNonce: 0,
StakingInfo: nil,
}

}
2 changes: 1 addition & 1 deletion assessed_custom_fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (fee *AssessedCustomFee) _ToProtobuf() *services.AssessedCustomFee {
}

var accountID *services.AccountID
if fee.TokenID != nil {
if fee.FeeCollectorAccountId != nil {
accountID = fee.FeeCollectorAccountId._ToProtobuf()
}

Expand Down
51 changes: 51 additions & 0 deletions assessed_custom_fee_unit_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//go:build all || unit
// +build all unit

package hedera

import (
"testing"

"github.com/stretchr/testify/require"
)

/*-
*
* Hedera Go SDK
*
* Copyright (C) 2020 - 2023 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

// The test checks the conversation methods on the AssessedCustomFee struct. We check wether it is correctly converted to protobuf and back.
func TestUnitassessedCustomFee(t *testing.T) {
t.Parallel()
assessedFeeOriginal := _MockAssessedCustomFee()
assessedFeeBytes := assessedFeeOriginal.ToBytes()
assessedFeeFromBytes, err := AssessedCustomFeeFromBytes(assessedFeeBytes)
require.NoError(t, err)
require.Equal(t, assessedFeeOriginal, assessedFeeFromBytes)
}

func _MockAssessedCustomFee() AssessedCustomFee {
accountID, _ := AccountIDFromString("0.0.123-esxsf")
accountID.checksum = nil
return AssessedCustomFee{
Amount: 100,
TokenID: nil,
FeeCollectorAccountId: &accountID,
PayerAccountIDs: []*AccountID{},
}
}
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func ClientForName(name string) (*Client, error) {
case "local", "localhost":
network := make(map[string]AccountID)
network["127.0.0.1:50213"] = AccountID{Account: 3}
mirror := []string{"127.0.0.1:5600"}
mirror := []string{"127.0.0.1:433"}
client := ClientForNetwork(network)
client.SetMirrorNetwork(mirror)
return client, nil
Expand Down
4 changes: 2 additions & 2 deletions client_all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const testClientJSONWrongTypeNetwork string = `{
"accountId": "0.0.3",
"privateKey": "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"
},
"mirrorNetwork": ["hcs.testnet.mirrornode.hedera.com:5600"]
"mirrorNetwork": ["testnet.mirrornode.hedera.com:443"]
}`

const testClientJSONWrongAccountIDNetwork string = `{
Expand All @@ -86,5 +86,5 @@ const testClientJSONWrongAccountIDNetwork string = `{
"accountId": "wrong",
"privateKey": "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"
},
"mirrorNetwork": ["hcs.testnet.mirrornode.hedera.com:5600"]
"mirrorNetwork": ["testnet.mirrornode.hedera.com:443"]
}`
26 changes: 14 additions & 12 deletions client_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,47 +175,49 @@ func TestUnitClientSetNetworkExtensive(t *testing.T) {

func TestUnitClientSetMirrorNetwork(t *testing.T) {
t.Parallel()


mirrorNetworkString := "testnet.mirrornode.hedera.com:443"
mirrorNetwork1String := "testnet1.mirrornode.hedera.com:443"
defaultNetwork := make([]string, 0)
defaultNetwork = append(defaultNetwork, "hcs.testnet.mirrornode.hedera.com:5600")
defaultNetwork = append(defaultNetwork, mirrorNetworkString)
client, err := _NewMockClient()
require.NoError(t, err)
client.SetMirrorNetwork(defaultNetwork)

mirrorNetwork := client.GetMirrorNetwork()
assert.Equal(t, 1, len(mirrorNetwork))
assert.Equal(t, "hcs.testnet.mirrornode.hedera.com:5600", mirrorNetwork[0])
assert.Equal(t, mirrorNetworkString, mirrorNetwork[0])

defaultNetworkWithExtraNode := make([]string, 0)
defaultNetworkWithExtraNode = append(defaultNetworkWithExtraNode, "hcs.testnet.mirrornode.hedera.com:5600")
defaultNetworkWithExtraNode = append(defaultNetworkWithExtraNode, "hcs.testnet1.mirrornode.hedera.com:5600")
defaultNetworkWithExtraNode = append(defaultNetworkWithExtraNode, mirrorNetworkString)
defaultNetworkWithExtraNode = append(defaultNetworkWithExtraNode, mirrorNetwork1String)

client.SetMirrorNetwork(defaultNetworkWithExtraNode)
mirrorNetwork = client.GetMirrorNetwork()
assert.Equal(t, 2, len(mirrorNetwork))
require.True(t, contains(mirrorNetwork, "hcs.testnet.mirrornode.hedera.com:5600"))
require.True(t, contains(mirrorNetwork, "hcs.testnet1.mirrornode.hedera.com:5600"))
require.True(t, contains(mirrorNetwork, mirrorNetworkString))
require.True(t, contains(mirrorNetwork, mirrorNetwork1String))

defaultNetwork = make([]string, 0)
defaultNetwork = append(defaultNetwork, "hcs.testnet1.mirrornode.hedera.com:5600")
defaultNetwork = append(defaultNetwork, mirrorNetwork1String)

client.SetMirrorNetwork(defaultNetwork)
mirrorNetwork = client.GetMirrorNetwork()
assert.Equal(t, 1, len(mirrorNetwork))
assert.Equal(t, "hcs.testnet1.mirrornode.hedera.com:5600", mirrorNetwork[0])
assert.Equal(t, mirrorNetwork1String, mirrorNetwork[0])

defaultNetwork = make([]string, 0)
defaultNetwork = append(defaultNetwork, "hcs.testnet.mirrornode.hedera.com:5600")
defaultNetwork = append(defaultNetwork, mirrorNetworkString)

client.SetMirrorNetwork(defaultNetwork)
mirrorNetwork = client.GetMirrorNetwork()
assert.Equal(t, 1, len(mirrorNetwork))
assert.Equal(t, "hcs.testnet.mirrornode.hedera.com:5600", mirrorNetwork[0])
assert.Equal(t, mirrorNetworkString, mirrorNetwork[0])

client.SetTransportSecurity(true)
mirrorNetwork = client.GetMirrorNetwork()
// SetTransportSecurity is deprecated, so the mirror node should not be updated
assert.Equal(t, "hcs.testnet.mirrornode.hedera.com:5600", mirrorNetwork[0])
assert.Equal(t, mirrorNetworkString, mirrorNetwork[0])

err = client.Close()
require.NoError(t, err)
Expand Down
Loading
Loading