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

Lift coverage to 70 #826

Closed
wants to merge 11 commits into from
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
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{},
}
}
55 changes: 55 additions & 0 deletions contract_create_flow_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ package hedera

import (
"testing"
"time"

"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -95,3 +96,57 @@ func TestIntegrationContractCreateFlowSmallContractCanExecute(t *testing.T) {
err = CloseIntegrationTestEnv(env, nil)
require.NoError(t, err)
}

func TestIntegrationContractCreateFlowGettersAndSetters(t *testing.T) {
t.Parallel()
env := NewIntegrationTestEnv(t)

testContractByteCode := "608060405234801561001057600080fd5b506040516104d73803806104d78339818101604052602081101561003357600080fd5b810190808051604051939291908464010000000082111561005357600080fd5b90830190602082018581111561006857600080fd5b825164010000000081118282018810171561008257600080fd5b82525081516020918201929091019080838360005b838110156100af578181015183820152602001610097565b50505050905090810190601f1680156100dc5780820380516001836020036101000a031916815260200191505b506040525050600080546001600160a01b0319163317905550805161010890600190602084019061010f565b50506101aa565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061015057805160ff191683800117855561017d565b8280016001018555821561017d579182015b8281111561017d578251825591602001919060010190610162565b5061018992915061018d565b5090565b6101a791905b808211156101895760008155600101610193565b90565b61031e806101b96000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063368b87721461004657806341c0e1b5146100ee578063ce6d41de146100f6575b600080fd5b6100ec6004803603602081101561005c57600080fd5b81019060208101813564010000000081111561007757600080fd5b82018360208201111561008957600080fd5b803590602001918460018302840111640100000000831117156100ab57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610173945050505050565b005b6100ec6101a2565b6100fe6101ba565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610138578181015183820152602001610120565b50505050905090810190601f1680156101655780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000546001600160a01b0316331461018a5761019f565b805161019d906001906020840190610250565b505b50565b6000546001600160a01b03163314156101b85733ff5b565b60018054604080516020601f600260001961010087891615020190951694909404938401819004810282018101909252828152606093909290918301828280156102455780601f1061021a57610100808354040283529160200191610245565b820191906000526020600020905b81548152906001019060200180831161022857829003601f168201915b505050505090505b90565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061029157805160ff19168380011785556102be565b828001600101855582156102be579182015b828111156102be5782518255916020019190600101906102a3565b506102ca9291506102ce565b5090565b61024d91905b808211156102ca57600081556001016102d456fea264697066735822122084964d4c3f6bc912a9d20e14e449721012d625aa3c8a12de41ae5519752fc89064736f6c63430006000033"
testOperatorKey := env.OperatorKey
testGas := int64(100000)
testMemo := "[e2e::ContractCreateFlow]"
testInitialBalance := HbarFromTinybar(1000000000000000000)
autoRenewPeriod := 131500 * time.Minute
testProxyAccountID := AccountID{Account: 3}
testAutoTokenAssociations := int32(10)
testMaxChuncks := uint64(4)
testNodeAccountID := AccountID{Account: 55}

constructorFuncName := "constructor"
constructorParams := ContractFunctionParameters{
function: ContractFunctionSelector{
function: &constructorFuncName,
params: "wooow",
paramTypes: []_Solidity{}},
arguments: []Argument{Argument{
value: []byte("hello from hedera"),
dynamic: false,
}}}

createChain := NewContractCreateFlow().
SetBytecodeWithString(testContractByteCode).
SetAdminKey(env.OperatorKey).
SetGas(100000).
SetConstructorParameters(NewContractFunctionParameters().AddString("hello from hedera")).
SetContractMemo("[e2e::ContractCreateFlow]").
SetInitialBalance(testInitialBalance).
SetProxyAccountID(testProxyAccountID).
SetConstructorParameters(&constructorParams).
SetAutoRenewAccountID(testProxyAccountID).
SetMaxAutomaticTokenAssociations(testAutoTokenAssociations).
SetMaxChunks(testMaxChuncks).
SetNodeAccountIDs([]AccountID{testNodeAccountID, testProxyAccountID})

require.Equal(t, createChain.GetBytecode(), testContractByteCode)
require.Equal(t, createChain.GetAdminKey(), testOperatorKey)
require.Equal(t, createChain.GetGas(), testGas)
require.Equal(t, createChain.GetContractMemo(), testMemo)
require.Equal(t, createChain.GetInitialBalance(), testInitialBalance)
require.Equal(t, createChain.GetAutoRenewPeriod(), autoRenewPeriod)
require.Equal(t, createChain.GetProxyAccountID(), testProxyAccountID)
require.Equal(t, createChain.GetAutoRenewAccountID(), testProxyAccountID)
require.Equal(t, createChain.GetMaxAutomaticTokenAssociations(), testAutoTokenAssociations)
require.Equal(t, createChain.GetMaxChunks(), testMaxChuncks)
require.Equal(t, createChain.GetNodeAccountIDs(), []AccountID{testNodeAccountID, testProxyAccountID})

}
Loading