Skip to content

Commit

Permalink
chore: create more tests and fix transactions (#1227)
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Ivanov <[email protected]>
  • Loading branch information
0xivanov authored Jan 22, 2025
1 parent da301d8 commit 8ea1bba
Show file tree
Hide file tree
Showing 22 changed files with 302 additions and 24 deletions.
12 changes: 12 additions & 0 deletions sdk/token_delete_transaction_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,15 @@ func TestUnitTokenDeleteTransactionMock(t *testing.T) {
_, err = freez.Sign(newKey).Execute(client)
require.NoError(t, err)
}

func TestUnitTokenDeleteTransactionFromToBytes(t *testing.T) {
tx := NewTokenDeleteTransaction()

txBytes, err := tx.ToBytes()
require.NoError(t, err)

txFromBytes, err := TransactionFromBytes(txBytes)
require.NoError(t, err)

assert.Equal(t, tx.buildProtoBody(), txFromBytes.(TokenDeleteTransaction).buildProtoBody())
}
12 changes: 12 additions & 0 deletions sdk/token_dissociate_transaction_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,15 @@ func TestUnitTokenDissociateTransactionMock(t *testing.T) {
Execute(client)
require.NoError(t, err)
}

func TestUnitTokenDissociateTransactionFromToBytes(t *testing.T) {
tx := NewTokenDissociateTransaction()

txBytes, err := tx.ToBytes()
require.NoError(t, err)

txFromBytes, err := TransactionFromBytes(txBytes)
require.NoError(t, err)

assert.Equal(t, tx.buildProtoBody(), txFromBytes.(TokenDissociateTransaction).buildProtoBody())
}
12 changes: 12 additions & 0 deletions sdk/token_fee_schedule_update_transaction_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,15 @@ func TestUnitTokenFeeScheduleUpdateTransactionMock(t *testing.T) {
_, err = freez.Sign(newKey).Execute(client)
require.NoError(t, err)
}

func TestUnitTokenFeeScheduleUpdateTransactionFromToBytes(t *testing.T) {
tx := NewTokenFeeScheduleUpdateTransaction()

txBytes, err := tx.ToBytes()
require.NoError(t, err)

txFromBytes, err := TransactionFromBytes(txBytes)
require.NoError(t, err)

assert.Equal(t, tx.buildProtoBody(), txFromBytes.(TokenFeeScheduleUpdateTransaction).buildProtoBody())
}
12 changes: 12 additions & 0 deletions sdk/token_freeze_transaction_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,15 @@ func TestUnitTokenFreezeTransactionMock(t *testing.T) {
_, err = freez.Sign(newKey).Execute(client)
require.NoError(t, err)
}

func TestUnitTokenFreezeTransactionFromToBytes(t *testing.T) {
tx := NewTokenFreezeTransaction()

txBytes, err := tx.ToBytes()
require.NoError(t, err)

txFromBytes, err := TransactionFromBytes(txBytes)
require.NoError(t, err)

assert.Equal(t, tx.buildProtoBody(), txFromBytes.(TokenFreezeTransaction).buildProtoBody())
}
12 changes: 12 additions & 0 deletions sdk/token_grant_kyc_transaction_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,15 @@ func TestUnitTokenGrantKycTransactionMock(t *testing.T) {
_, err = freez.Sign(newKey).Execute(client)
require.NoError(t, err)
}

func TestUnitTokenGrantKycTransactionFromToBytes(t *testing.T) {
tx := NewTokenGrantKycTransaction()

txBytes, err := tx.ToBytes()
require.NoError(t, err)

txFromBytes, err := TransactionFromBytes(txBytes)
require.NoError(t, err)

assert.Equal(t, tx.buildProtoBody(), txFromBytes.(TokenGrantKycTransaction).buildProtoBody())
}
12 changes: 12 additions & 0 deletions sdk/token_mint_transaction_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,15 @@ func TestUnitTokenMintTransactionMock(t *testing.T) {
_, err = freez.Sign(newKey).Execute(client)
require.NoError(t, err)
}

func TestUnitTokenMintTransactionFromToBytes(t *testing.T) {
tx := NewTokenMintTransaction()

txBytes, err := tx.ToBytes()
require.NoError(t, err)

txFromBytes, err := TransactionFromBytes(txBytes)
require.NoError(t, err)

assert.Equal(t, tx.buildProtoBody(), txFromBytes.(TokenMintTransaction).buildProtoBody())
}
12 changes: 12 additions & 0 deletions sdk/token_pause_transaction_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,3 +478,15 @@ func TestUnitTokenPauseTransaction_SetLogLevel(t *testing.T) {
level := transaction.GetLogLevel()
require.Equal(t, LoggerLevelDebug, *level)
}

func TestUnitTokenPauseTransactionFromToBytes(t *testing.T) {
tx := NewTokenPauseTransaction()

txBytes, err := tx.ToBytes()
require.NoError(t, err)

txFromBytes, err := TransactionFromBytes(txBytes)
require.NoError(t, err)

assert.Equal(t, tx.buildProtoBody(), txFromBytes.(TokenPauseTransaction).buildProtoBody())
}
12 changes: 12 additions & 0 deletions sdk/token_reject_transaction_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,15 @@ func TestUnitTokenRejectTransactionCoverage(t *testing.T) {
b.AddSignature(newKey.PublicKey(), sig)
}
}

func TestUnitTokenRejectTransactionFromToBytes(t *testing.T) {
tx := NewTokenRejectTransaction()

txBytes, err := tx.ToBytes()
require.NoError(t, err)

txFromBytes, err := TransactionFromBytes(txBytes)
require.NoError(t, err)

assert.Equal(t, tx.buildProtoBody(), txFromBytes.(TokenRejectTransaction).buildProtoBody())
}
12 changes: 12 additions & 0 deletions sdk/token_revoke_kys_transaction_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,15 @@ func TestUnitTokenRevokeKycTransactionMock(t *testing.T) {
_, err = freez.Sign(newKey).Execute(client)
require.NoError(t, err)
}

func TestUnitTokenRevokeKycTransactionFromToBytes(t *testing.T) {
tx := NewTokenRevokeKycTransaction()

txBytes, err := tx.ToBytes()
require.NoError(t, err)

txFromBytes, err := TransactionFromBytes(txBytes)
require.NoError(t, err)

assert.Equal(t, tx.buildProtoBody(), txFromBytes.(TokenRevokeKycTransaction).buildProtoBody())
}
12 changes: 12 additions & 0 deletions sdk/token_transfer_transaction_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,15 @@ func TestUnitTokenTransferEncodeDecode(t *testing.T) {
require.NoError(t, err)
require.Equal(t, transfer, decoded)
}

func TestUnitTokenTransferTransactionFromToBytes(t *testing.T) {
tx := NewTransferTransaction()

txBytes, err := tx.ToBytes()
require.NoError(t, err)

txFromBytes, err := TransactionFromBytes(txBytes)
require.NoError(t, err)

assert.Equal(t, tx.buildProtoBody(), txFromBytes.(TransferTransaction).buildProtoBody())
}
12 changes: 12 additions & 0 deletions sdk/token_unfreeze_transaction_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,15 @@ func TestUnitTokenUnfreezeTransactionMock(t *testing.T) {
_, err = freez.Sign(newKey).Execute(client)
require.NoError(t, err)
}

func TestUnitTokenUnfreezeTransactionFromToBytes(t *testing.T) {
tx := NewTokenUnfreezeTransaction()

txBytes, err := tx.ToBytes()
require.NoError(t, err)

txFromBytes, err := TransactionFromBytes(txBytes)
require.NoError(t, err)

assert.Equal(t, tx.buildProtoBody(), txFromBytes.(TokenUnfreezeTransaction).buildProtoBody())
}
12 changes: 12 additions & 0 deletions sdk/token_update_nfts_transaction_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,15 @@ func TestUnitTokenUpdateNftsTransactionSignWithOperator(t *testing.T) {
_, err = tokenUpdate.SignWithOperator(client)
require.NoError(t, err)
}

func TestUnitTokenUpdateNftsTransactionFromToBytes(t *testing.T) {
tx := NewTokenUpdateNftsTransaction()

txBytes, err := tx.ToBytes()
require.NoError(t, err)

txFromBytes, err := TransactionFromBytes(txBytes)
require.NoError(t, err)

assert.Equal(t, tx.buildProtoBody(), txFromBytes.(TokenUpdateNfts).buildProtoBody())
}
57 changes: 45 additions & 12 deletions sdk/token_update_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,51 @@ func NewTokenUpdateTransaction() *TokenUpdateTransaction {
}

func _TokenUpdateTransactionFromProtobuf(tx Transaction[*TokenUpdateTransaction], pb *services.TransactionBody) TokenUpdateTransaction {
adminKey, _ := _KeyFromProtobuf(pb.GetTokenUpdate().GetAdminKey())
kycKey, _ := _KeyFromProtobuf(pb.GetTokenUpdate().GetKycKey())
freezeKey, _ := _KeyFromProtobuf(pb.GetTokenUpdate().GetFreezeKey())
wipeKey, _ := _KeyFromProtobuf(pb.GetTokenUpdate().GetWipeKey())
scheduleKey, _ := _KeyFromProtobuf(pb.GetTokenUpdate().GetFeeScheduleKey())
supplyKey, _ := _KeyFromProtobuf(pb.GetTokenUpdate().GetSupplyKey())
pauseKey, _ := _KeyFromProtobuf(pb.GetTokenUpdate().GetPauseKey())
metadataKey, _ := _KeyFromProtobuf(pb.GetTokenUpdate().GetMetadataKey())
var adminKey Key
if pb.GetTokenUpdate().GetAdminKey() != nil {
adminKey, _ = _KeyFromProtobuf(pb.GetTokenUpdate().GetAdminKey())
}
var kycKey Key
if pb.GetTokenUpdate().GetKycKey() != nil {
kycKey, _ = _KeyFromProtobuf(pb.GetTokenUpdate().GetKycKey())
}
var freezeKey Key
if pb.GetTokenUpdate().GetFreezeKey() != nil {
freezeKey, _ = _KeyFromProtobuf(pb.GetTokenUpdate().GetFreezeKey())
}
var wipeKey Key
if pb.GetTokenUpdate().GetWipeKey() != nil {
wipeKey, _ = _KeyFromProtobuf(pb.GetTokenUpdate().GetWipeKey())
}
var scheduleKey Key
if pb.GetTokenUpdate().GetFeeScheduleKey() != nil {
scheduleKey, _ = _KeyFromProtobuf(pb.GetTokenUpdate().GetFeeScheduleKey())
}
var supplyKey Key
if pb.GetTokenUpdate().GetSupplyKey() != nil {
supplyKey, _ = _KeyFromProtobuf(pb.GetTokenUpdate().GetSupplyKey())
}
var pauseKey Key
if pb.GetTokenUpdate().GetPauseKey() != nil {
pauseKey, _ = _KeyFromProtobuf(pb.GetTokenUpdate().GetPauseKey())
}
var metadataKey Key
if pb.GetTokenUpdate().GetMetadataKey() != nil {
metadataKey, _ = _KeyFromProtobuf(pb.GetTokenUpdate().GetMetadataKey())
}

keyVerificationMode := pb.GetTokenUpdate().GetKeyVerificationMode()

expirationTime := _TimeFromProtobuf(pb.GetTokenUpdate().GetExpiry())
autoRenew := _DurationFromProtobuf(pb.GetTokenUpdate().GetAutoRenewPeriod())
var expirationTime *time.Time
if pb.GetTokenUpdate().GetExpiry() != nil {
expirationTimeVal := _TimeFromProtobuf(pb.GetTokenUpdate().GetExpiry())
expirationTime = &expirationTimeVal
}
var autoRenew *time.Duration
if pb.GetTokenUpdate().GetAutoRenewPeriod() != nil {
autoRenewVal := _DurationFromProtobuf(pb.GetTokenUpdate().GetAutoRenewPeriod())
autoRenew = &autoRenewVal
}

var memo *string
if m := pb.GetTokenUpdate().GetMemo(); m != nil {
Expand Down Expand Up @@ -124,8 +157,8 @@ func _TokenUpdateTransactionFromProtobuf(tx Transaction[*TokenUpdateTransaction]
pauseKey: pauseKey,
metadataKey: metadataKey,
tokenKeyVerificationMode: TokenKeyValidation(keyVerificationMode),
expirationTime: &expirationTime,
autoRenewPeriod: &autoRenew,
expirationTime: expirationTime,
autoRenewPeriod: autoRenew,
}

tx.childTransaction = &tokenUpdateTransaction
Expand Down
12 changes: 12 additions & 0 deletions sdk/token_update_transaction_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,15 @@ func TestUnitTokenUpdateTransactionMock(t *testing.T) {
_, err = freez.Sign(newKey).Execute(client)
require.NoError(t, err)
}

func TestUnitTokenUpdateTransactionFromToBytes(t *testing.T) {
tx := NewTokenUpdateTransaction()

txBytes, err := tx.ToBytes()
require.NoError(t, err)

txFromBytes, err := TransactionFromBytes(txBytes)
require.NoError(t, err)

assert.Equal(t, tx.buildProtoBody(), txFromBytes.(TokenUpdateTransaction).buildProtoBody())
}
12 changes: 12 additions & 0 deletions sdk/token_wipe_transaction_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,15 @@ func TestUnitTokenWipeTransactionMock(t *testing.T) {
_, err = freez.Sign(newKey).Execute(client)
require.NoError(t, err)
}

func TestUnitTokenWipeTransactionFromToBytes(t *testing.T) {
tx := NewTokenWipeTransaction()

txBytes, err := tx.ToBytes()
require.NoError(t, err)

txFromBytes, err := TransactionFromBytes(txBytes)
require.NoError(t, err)

assert.Equal(t, tx.buildProtoBody(), txFromBytes.(TokenWipeTransaction).buildProtoBody())
}
19 changes: 14 additions & 5 deletions sdk/topic_create_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,25 @@ func NewTopicCreateTransaction() *TopicCreateTransaction {
}

func _TopicCreateTransactionFromProtobuf(tx Transaction[*TopicCreateTransaction], pb *services.TransactionBody) TopicCreateTransaction {
adminKey, _ := _KeyFromProtobuf(pb.GetConsensusCreateTopic().GetAdminKey())
submitKey, _ := _KeyFromProtobuf(pb.GetConsensusCreateTopic().GetSubmitKey())

autoRenew := _DurationFromProtobuf(pb.GetConsensusCreateTopic().GetAutoRenewPeriod())
var adminKey Key
if pb.GetConsensusCreateTopic().GetAdminKey() != nil {
adminKey, _ = _KeyFromProtobuf(pb.GetConsensusCreateTopic().GetAdminKey())
}
var submitKey Key
if pb.GetConsensusCreateTopic().GetSubmitKey() != nil {
submitKey, _ = _KeyFromProtobuf(pb.GetConsensusCreateTopic().GetSubmitKey())
}
var autoRenew *time.Duration
if pb.GetConsensusCreateTopic().GetAutoRenewPeriod() != nil {
autoRenewVal := _DurationFromProtobuf(pb.GetConsensusCreateTopic().GetAutoRenewPeriod())
autoRenew = &autoRenewVal
}
topicCreateTransaction := TopicCreateTransaction{
autoRenewAccountID: _AccountIDFromProtobuf(pb.GetConsensusCreateTopic().GetAutoRenewAccount()),
adminKey: adminKey,
submitKey: submitKey,
memo: pb.GetConsensusCreateTopic().GetMemo(),
autoRenewPeriod: &autoRenew,
autoRenewPeriod: autoRenew,
}

tx.childTransaction = &topicCreateTransaction
Expand Down
12 changes: 12 additions & 0 deletions sdk/topic_create_transaction_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,3 +319,15 @@ func TestUnitTopicCreateTransactionSerialization(t *testing.T) {
submitKey, _ := result.GetSubmitKey()
require.Equal(t, newKey.PublicKey(), submitKey)
}

func TestUnitTopicCreateTransactionFromToBytes(t *testing.T) {
tx := NewTopicCreateTransaction()

txBytes, err := tx.ToBytes()
require.NoError(t, err)

txFromBytes, err := TransactionFromBytes(txBytes)
require.NoError(t, err)

assert.Equal(t, tx.buildProtoBody(), txFromBytes.(TopicCreateTransaction).buildProtoBody())
}
12 changes: 12 additions & 0 deletions sdk/topic_delete_transaction_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,15 @@ func TestUnitTopicDeleteTransactionMock(t *testing.T) {
_, err = freez.Sign(newKey).Execute(client)
require.NoError(t, err)
}

func TestUnitTopicDeleteTransactionFromToBytes(t *testing.T) {
tx := NewTopicDeleteTransaction()

txBytes, err := tx.ToBytes()
require.NoError(t, err)

txFromBytes, err := TransactionFromBytes(txBytes)
require.NoError(t, err)

assert.Equal(t, tx.buildProtoBody(), txFromBytes.(TopicDeleteTransaction).buildProtoBody())
}
6 changes: 5 additions & 1 deletion sdk/topic_message_submit_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ func NewTopicMessageSubmitTransaction() *TopicMessageSubmitTransaction {
}

func _TopicMessageSubmitTransactionFromProtobuf(tx Transaction[*TopicMessageSubmitTransaction], pb *services.TransactionBody) TopicMessageSubmitTransaction {
var message = make([]byte, 0)
if pb.GetConsensusSubmitMessage().GetMessage() != nil {
message = pb.GetConsensusSubmitMessage().GetMessage()
}
topicMessageSubmitTransaction := TopicMessageSubmitTransaction{
maxChunks: 20,
message: pb.GetConsensusSubmitMessage().GetMessage(),
message: message,
topicID: _TopicIDFromProtobuf(pb.GetConsensusSubmitMessage().GetTopicID()),
}

Expand Down
13 changes: 13 additions & 0 deletions sdk/topic_message_submit_transaction_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

"github.com/hiero-ledger/hiero-sdk-go/v2/proto/services"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
protobuf "google.golang.org/protobuf/proto"
)
Expand Down Expand Up @@ -333,3 +334,15 @@ func TestUnitTopicMessageSubmitTransactionSetMessage(t *testing.T) {

require.Equal(t, []byte{}, transaction.GetMessage())
}

func TestUnitTopicMessageSubmitTransactionFromToBytes(t *testing.T) {
tx := NewTopicMessageSubmitTransaction()

txBytes, err := tx.ToBytes()
require.NoError(t, err)

txFromBytes, err := TransactionFromBytes(txBytes)
require.NoError(t, err)

assert.Equal(t, tx.buildProtoBody(), txFromBytes.(TopicMessageSubmitTransaction).buildProtoBody())
}
Loading

0 comments on commit 8ea1bba

Please sign in to comment.