-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finish up tests for at least 65% test coverage for token prefixed fil…
…es (#773) * Finish up 65% test coverage for token prefixed files --------- Signed-off-by: Coiling-Dragon <[email protected]>
- Loading branch information
1 parent
b0298b7
commit ee7a8d6
Showing
5 changed files
with
293 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
//go:build all || unit | ||
// +build all unit | ||
|
||
package hedera | ||
|
||
/*- | ||
* | ||
* Hedera Go SDK | ||
* | ||
* Copyright (C) 2020 - 2022 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 ( | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestUnitNewTokenNftAllowance(t *testing.T) { | ||
tokenID := TokenID{Token: 1} | ||
owner := AccountID{Account: 2} | ||
spender := AccountID{Account: 3} | ||
serialNumbers := []int64{1, 2, 3} | ||
approvedForAll := true | ||
delegatingSpender := AccountID{Account: 4} | ||
|
||
allowance := NewTokenNftAllowance(tokenID, owner, spender, serialNumbers, approvedForAll, delegatingSpender) | ||
|
||
assert.Equal(t, &tokenID, allowance.TokenID) | ||
assert.Equal(t, &owner, allowance.OwnerAccountID) | ||
assert.Equal(t, &spender, allowance.SpenderAccountID) | ||
assert.Equal(t, serialNumbers, allowance.SerialNumbers) | ||
assert.Equal(t, approvedForAll, allowance.AllSerials) | ||
assert.Equal(t, &delegatingSpender, allowance.DelegatingSpender) | ||
} | ||
|
||
func TestUnitTokenNftAllowance_String(t *testing.T) { | ||
approval := TokenNftAllowance{ | ||
TokenID: &TokenID{Token: 1}, | ||
SpenderAccountID: &AccountID{Account: 2}, | ||
OwnerAccountID: &AccountID{Account: 3}, | ||
SerialNumbers: []int64{1, 2, 3}, | ||
AllSerials: true, | ||
DelegatingSpender: &AccountID{Account: 4}, | ||
} | ||
|
||
assert.Equal(t, "OwnerAccountID: 0.0.3, SpenderAccountID: 0.0.2, TokenID: 0.0.1, Serials: 1, 2, 3, , ApprovedForAll: true", approval.String()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
//go:build all || unit | ||
// +build all unit | ||
|
||
package hedera | ||
|
||
/*- | ||
* | ||
* Hedera Go SDK | ||
* | ||
* Copyright (C) 2020 - 2022 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" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// testinf func (transfer TokenNftTransfer) ToBytes() and func NftTransferFromBytes(data []byte) | ||
func TestUnitTokenNftTransferToBytes(t *testing.T) { | ||
t.Parallel() | ||
|
||
transfer := TokenNftTransfer{ | ||
SenderAccountID: AccountID{Account: 3}, | ||
ReceiverAccountID: AccountID{Account: 4}, | ||
SerialNumber: 5, | ||
IsApproved: true, | ||
} | ||
|
||
transferBytes := transfer.ToBytes() | ||
transferFromBytes, err := NftTransferFromBytes(transferBytes) | ||
|
||
assert.NoError(t, err) | ||
assert.Equal(t, transfer, transferFromBytes) | ||
|
||
// test invalid data from and to bytes | ||
_, err = NftTransferFromBytes([]byte{1, 2, 3}) | ||
assert.Error(t, err) | ||
|
||
// test nil data from bytes and to bytes | ||
_, err = NftTransferFromBytes(nil) | ||
assert.Error(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters