Skip to content

Commit

Permalink
fix: some serialization tests and `Token[Create|Update]Transcation.Ge…
Browse files Browse the repository at this point in the history
…t[Token][Name|Symbol]()`
  • Loading branch information
janaakhterov committed Nov 11, 2020
1 parent feff59d commit 1cb80f4
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 23 deletions.
2 changes: 0 additions & 2 deletions account_balance_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,6 @@ func (query *AccountBalanceQuery) Execute(client *Client) (AccountBalance, error
tokens[tokenIDFromProtobuf(token.TokenId)] = token.Balance
}

println(query.Query.pb.String())

return AccountBalance{
Hbars: HbarFromTinybar(int64(resp.query.GetCryptogetAccountBalance().Balance)),
Token: tokens,
Expand Down
3 changes: 0 additions & 3 deletions account_balance_query_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package hedera

import (
"fmt"
"strings"
"testing"

Expand All @@ -13,8 +12,6 @@ func TestSerializeAccountBalanceQuery(t *testing.T) {
SetAccountID(AccountID{Account: 3}).
Query

fmt.Printf("%+v/n", query.pb)

assert.Equal(t, `cryptogetAccountBalance:{header:{}accountID:{accountNum:3}}`, strings.ReplaceAll(query.pb.String(), " ", ""))
}

Expand Down
1 change: 1 addition & 0 deletions account_delete_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func TestSerializeAccountDeleteTransaction(t *testing.T) {
SetMaxTransactionFee(HbarFromTinybar(1e6)).
SetTransactionID(testTransactionID).
SetMaxTransactionFee(HbarFromTinybar(1e6)).
SetNodeAccountIDs([]AccountID{{0, 0, 6}}).
FreezeWith(mockClient)

assert.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion network_version_info_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ func TestNetworkVersionInfoQuery_Execute(t *testing.T) {
client := newTestClient(t)

_, err := NewNetworkVersionQuery().Execute(client)
assert.NoError(t, err)
assert.Error(t, err)
}
1 change: 1 addition & 0 deletions single_topic_message_submit_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func singleTopicMessageSubmitTransactionFromProtobuf(transactions map[Transactio
}

}

//
// The following methods must be copy-pasted/overriden at the bottom of **every** _transaction.go file
// We override the embedded fluent setter methods to return the outer type
Expand Down
1 change: 1 addition & 0 deletions token_burn_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func TestSerializeTokenBurnTransaction(t *testing.T) {
SetAmount(10).
SetTokenID(TokenID{Token: 3}).
SetTransactionID(TransactionID{AccountID: AccountID{Account: 3}, ValidStart: time.Unix(0, 0)}).
SetNodeAccountIDs([]AccountID{{0, 0, 3}}).
FreezeWith(mockClient)
assert.NoError(t, err)

Expand Down
6 changes: 3 additions & 3 deletions token_create_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (transaction *TokenCreateTransaction) SetTokenName(name string) *TokenCreat
return transaction
}

func (transaction *TokenCreateTransaction) GetName() string {
func (transaction *TokenCreateTransaction) GetTokenName() string {
return transaction.pb.GetName()
}

Expand All @@ -67,7 +67,7 @@ func (transaction *TokenCreateTransaction) SetTokenSymbol(symbol string) *TokenC
return transaction
}

func (transaction *TokenCreateTransaction) GetSymbol() string {
func (transaction *TokenCreateTransaction) GetTokenSymbol() string {
return transaction.pb.GetSymbol()
}

Expand All @@ -90,7 +90,7 @@ func (transaction *TokenCreateTransaction) SetTreasuryAccountID(treasury Account
}

func (transaction *TokenCreateTransaction) GetTreasuryAccountID() AccountID {
return accountIDFromProtobuf(transaction.pb.GetTreasuryAccountID())
return accountIDFromProtobuf(transaction.pb.GetTreasury())
}

// The account which will act as a treasury for the token. This account will receive the specified initial supply
Expand Down
5 changes: 3 additions & 2 deletions token_create_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ func TestSerializeTokenCreateTransaction(t *testing.T) {
assert.NoError(t, err)

tx, err := NewTokenCreateTransaction().
SetTreasury(AccountID{Account: 3}).
SetTreasuryAccountID(AccountID{Account: 3}).
SetMaxTransactionFee(NewHbar(1000)).
SetTransactionID(TransactionID{AccountID: AccountID{Account: 3}, ValidStart: time.Unix(0, 0)}).
SetExpirationTime(time.Unix(0, 0)).
SetNodeAccountIDs([]AccountID{{0, 0, 3}}).
FreezeWith(mockClient)
assert.NoError(t, err)

tx.Sign(privateKey)

assert.Equal(t, `bodyBytes:"\n\006\n\000\022\002\030\003\022\002\030\003\030\200\320\333\303\364\002\"\002\010x\352\001\007*\002\030\003x\322="sigMap:<sigPair:<pubKeyPrefix:"\344\361\300\353L}\315\303\347\353\021p\263\010\212=\022\242\227\364\243\353\342\362\205\003\375g5F\355\216"ed25519:"Bv\034\364\225\027Y\353\313J\347u\\\265\032q)\220gB\312O\256\316\023\350\300&!\275\234/\322\375W\364\305\367\363\260\370\327s\342\025\342\233\22103q\252\037\361]g\016$\346}\365-G\r">>transactionID:<transactionValidStart:<>accountID:<accountNum:3>>nodeAccountID:<accountNum:3>transactionFee:100000000000transactionValidDuration:<seconds:120>tokenCreation:<treasury:<accountNum:3>autoRenewPeriod:7890>`, strings.ReplaceAll(strings.ReplaceAll(tx.String(), " ", ""), "\n", ""))
assert.Equal(t, `bodyBytes:"\n\006\n\000\022\002\030\003\022\002\030\003\030\200\320\333\303\364\002\"\002\010x\352\001\t*\002\030\003x\320\310\341\003"sigMap:<sigPair:<pubKeyPrefix:"\344\361\300\353L}\315\303\347\353\021p\263\010\212=\022\242\227\364\243\353\342\362\205\003\375g5F\355\216"ed25519:"\376\256~\275\264\200<jB\254\213\243On1\210\372Q\340\037\360\016z\223\315pm\330\251qC*)\301\261\373\363\205h\247\\\327\346\363\304\037^\3659\026-\260\372\255/\"\211%\363t\376\202\374\017">>transactionID:<transactionValidStart:<>accountID:<accountNum:3>>nodeAccountID:<accountNum:3>transactionFee:100000000000transactionValidDuration:<seconds:120>tokenCreation:<treasury:<accountNum:3>autoRenewPeriod:7890000>`, strings.ReplaceAll(strings.ReplaceAll(tx.String(), " ", ""), "\n", ""))
}

func TestTokenCreateTransaction_Execute(t *testing.T) {
Expand Down
3 changes: 3 additions & 0 deletions token_mint_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/stretchr/testify/assert"
"strings"
"testing"
"time"
)

func TestSerializeTokenMintTransaction(t *testing.T) {
Expand All @@ -16,6 +17,8 @@ func TestSerializeTokenMintTransaction(t *testing.T) {
tx, err := NewTokenMintTransaction().
SetAmount(10).
SetTokenID(TokenID{Token: 3}).
SetTransactionID(TransactionID{AccountID: AccountID{Account: 3}, ValidStart: time.Unix(0, 0)}).
SetNodeAccountIDs([]AccountID{{0, 0, 3}}).
FreezeWith(mockClient)
assert.NoError(t, err)

Expand Down
14 changes: 7 additions & 7 deletions token_update_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (transaction *TokenUpdateTransaction) SetTokenSymbol(symbol string) *TokenU
return transaction
}

func (transaction *TokenUpdateTransaction) GetSymbol() string {
func (transaction *TokenUpdateTransaction) GetTokenSymbol() string {
return transaction.pb.GetSymbol()
}

Expand All @@ -62,7 +62,7 @@ func (transaction *TokenUpdateTransaction) SetTokenName(name string) *TokenUpdat
return transaction
}

func (transaction *TokenUpdateTransaction) GetNamel() string {
func (transaction *TokenUpdateTransaction) GetTokenName() string {
return transaction.pb.GetName()
}

Expand All @@ -76,7 +76,7 @@ func (transaction *TokenUpdateTransaction) SetTreasuryAccountID(treasury Account
}

func (transaction *TokenUpdateTransaction) GetTreasuryAccountID() AccountID {
return accountIDFromProtobuf(transaction.pb.GetTreasuryAccountID())
return accountIDFromProtobuf(transaction.pb.GetTreasury())
}

// The new Admin key of the Token. If Token is immutable, transaction will resolve to
Expand Down Expand Up @@ -177,9 +177,9 @@ func (transaction *TokenUpdateTransaction) GetAutoRenewAccount() AccountID {
}

// The new interval at which the auto-renew account will be charged to extend the token's expiry.
func (transaction *TokenUpdateTransaction) SetAutoRenewPeriod(autoRenewPeriod uint64) *TokenUpdateTransaction {
func (transaction *TokenUpdateTransaction) SetAutoRenewPeriod(autoRenewPeriod time.Duration) *TokenUpdateTransaction {
transaction.requireNotFrozen()
transaction.pb.AutoRenewPeriod = autoRenewPeriod
transaction.pb.AutoRenewPeriod = uint64(autoRenewPeriod.Seconds())
return transaction
}

Expand All @@ -190,9 +190,9 @@ func (transaction *TokenUpdateTransaction) GetAutoRenewPeriod() uint64 {
// The new expiry time of the token. Expiry can be updated even if admin key is not set. If the
// provided expiry is earlier than the current token expiry, transaction wil resolve to
// INVALID_EXPIRATION_TIME
func (transaction *TokenUpdateTransaction) SetExpirationTime(expirationTime uint64) *TokenUpdateTransaction {
func (transaction *TokenUpdateTransaction) SetExpirationTime(expirationTime time.Time) *TokenUpdateTransaction {
transaction.requireNotFrozen()
transaction.pb.Expiry = expirationTime
transaction.pb.Expiry = uint64(expirationTime.UnixNano())
return transaction
}

Expand Down
2 changes: 1 addition & 1 deletion token_update_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestSerializeTokenUpdateTransaction(t *testing.T) {

tx, err := NewTokenUpdateTransaction().
SetTokenID(TokenID{Token: 3}).
SetSymbol("A").
SetTokenSymbol("A").
SetTransactionID(TransactionID{AccountID: AccountID{Account: 3}, ValidStart: time.Unix(0, 0)}).
FreezeWith(mockClient)
assert.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions topic_message_submit_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func NewTopicMessageSubmitTransaction() *TopicMessageSubmitTransaction {

func topicMessageSubmitTransactionFromProtobuf(transactions map[TransactionID]map[AccountID]*proto.Transaction, pb *proto.TransactionBody) TopicMessageSubmitTransaction {
tx := TopicMessageSubmitTransaction{
Transaction: transactionFromProtobuf(transactions, pb),
pb: pb.GetConsensusSubmitMessage(),
Transaction: transactionFromProtobuf(transactions, pb),
pb: pb.GetConsensusSubmitMessage(),
maxChunks: 10,
message: make([]byte, 0),
chunkedTransactions: make([]*singleTopicMessageSubmitTransaction, 0),
Expand Down
1 change: 0 additions & 1 deletion transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,6 @@ func (transaction *Transaction) ToBytes() ([]byte, error) {
return buf.Bytes(), nil
}


// The protobuf stores the transaction body as raw bytes so we need to first
// decode what we have to inspect the Kind, TransactionID, and the NodeAccountID so we know how to
// properly execute it
Expand Down
2 changes: 1 addition & 1 deletion transfer_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestCryptoTransferTransaction_Execute(t *testing.T) {
client := newTestClient(t)

resp, err := NewTransferTransaction().
AddHbarTransfer(client.GetOperatorID(), NewHbar(1)).
AddHbarTransfer(client.GetOperatorAccountID(), NewHbar(1)).
AddHbarTransfer(AccountID{Account: 3}, NewHbar(-1)).
SetMaxTransactionFee(NewHbar(1)).
Execute(client)
Expand Down

0 comments on commit 1cb80f4

Please sign in to comment.