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

Executable refactor #840

Merged
merged 77 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
1b9fdee
Created base structures and interfaces (executable & transaction) and…
Nov 20, 2023
8c49c0e
Refactored transaction struct and interfaces names, because we should…
Nov 20, 2023
718eb6c
Renamed Terminal -> terminal in more files
Nov 22, 2023
1d95165
Moved common getters inside executable.go. Edited account_create_tran…
Nov 22, 2023
6e7aa4e
Implemented default executable methods inside
Nov 22, 2023
37dff40
Refactored transaction struct name in some functions to match the new…
Nov 27, 2023
f3d8788
Refactored query root struct and file_contents_query.go to match the …
Nov 27, 2023
f1fbbf8
Refactored account_balance_query.go to use the new style
Nov 27, 2023
d63451f
Removed 'build' from executable, because query and transaction build …
Nov 27, 2023
dca4e05
Recatored tests to use new function method, added public function for…
Nov 27, 2023
79a3b86
Refactored account_info.go to use the new design
Nov 27, 2023
d659284
Refactored account_records_query.go to use the new design
Nov 27, 2023
c9146de
Refactored account_stakers_query.go
Nov 27, 2023
12d8d2b
Refactored contract_bytecode_query.go to use the new design style
Nov 27, 2023
19d31ee
Refactored contracy_bytecode_query.go to match the new design style
Nov 27, 2023
fba0a5b
Changed method names inside address_book_query.go to match the method…
Nov 27, 2023
5b8e2e0
Refactored contract_info_query.go to match the new design style
Nov 27, 2023
17ced26
Refactored file_info_query.go to match the new design style
Nov 27, 2023
87a3019
Refactored live_hash_query.go to match the new design style
Nov 27, 2023
5295edd
Refactored network_version_info_query.go to match the new design style
Nov 27, 2023
3d556c5
Refactored schedule_info_query.go to match the new design style
Nov 27, 2023
762cb5f
Refactored token_info_query.go to match the new design style
Nov 27, 2023
a94dcba
Refactored token_nft_query.go to match the new design style
Nov 27, 2023
18534db
Refactored topic_info_query.go to match the new design style
Nov 27, 2023
0593ccf
Refactored private function names inside topic_message_query.go to ma…
Nov 27, 2023
83e375c
Refactored transaction_receipt_query.go to match the new design style
Nov 27, 2023
4ee2832
Refactored transaction_record_query.go to match the new design style
Nov 27, 2023
8e8b25b
Refactored account_allowance_approve_transaction.go to use the new de…
Nov 29, 2023
c0feade
Refactored account_allowance_approve_transaction.go to match the new …
Nov 29, 2023
5280ab5
Refactored account_allowance_delete_transaction.go to match the new d…
Nov 29, 2023
2816e1a
Refactored account_delete_transaction.go to match the new design style
Nov 29, 2023
fc5df78
Refactored account_update_transaction.go to match the new design style
Nov 29, 2023
1bee7f6
Refactored contract_create_transaction.go to match the new design style
Nov 29, 2023
8f89ec0
Refactored contract_delete_transaction.go to match the new design style
Nov 29, 2023
3fe25a0
Refactored contract_execute_transaction.go to match the new design style
Nov 29, 2023
1d67a9e
Refactored contract_update_transaction.go to match the new design style
Nov 29, 2023
809bcb9
Refactored ethereum_transaction.go to match the new design style
Nov 29, 2023
5caa287
Refactored file_append_transaction.go to match the new design style
Nov 29, 2023
3ffc1d5
Refactored file_create_transaction.go to match the new design style
Nov 29, 2023
91d8566
Refactored file_delete_transaction.go to match the new design style
Nov 29, 2023
744b005
Refactored file_update_transaction.go to match the new design style
Nov 29, 2023
26ab800
Refactored freeze_transaction.go to match the new design style
Nov 29, 2023
dcc9d7f
Refactored live_has_add_transaction.go to match the new design style
Nov 29, 2023
57708ed
Refactored transaction.go with Schedule function inside. Refactored f…
Nov 30, 2023
0ee4dcb
Remove getLogId, because I have getName()
Nov 30, 2023
d362d93
Updated token, topic, transfer, system and schedule transactions (#837)
rokn Nov 30, 2023
61bcadd
Renamed this -> tx
Nov 30, 2023
646f77e
Fixed unit test running
rokn Nov 30, 2023
08a48f5
Refactored all transaction instances to have buildProtoBody & _Constr…
Dec 1, 2023
767ecc0
Renamed query receivers -> 'q'
Dec 1, 2023
cd531e9
Edited executable functions
Dec 4, 2023
e59b6eb
Fix freeze functionality
rokn Dec 4, 2023
a7f98f9
Refactored 'execute' in Executable and added get Request type, so we …
Dec 4, 2023
9b0fbca
Refactored executable
Dec 4, 2023
15a797c
Fixed query execution
rokn Dec 5, 2023
db394a8
Implemented validateOnNetworkId for file_create_transaction.go
Dec 5, 2023
12279f8
Changed Transaction struct and interface names
Dec 6, 2023
62cad8e
Fix token create account renew
rokn Dec 7, 2023
9a75d0f
Fix query test problems and executable commented code
rokn Dec 7, 2023
20ef8c7
Changed return type on 'fromBytes'. No we pass reference, isntead of …
Dec 12, 2023
f0ecd1b
Fixed some tests
Dec 12, 2023
d581832
Added contract_append_transaction custom execute logic
Dec 12, 2023
d784d38
Fixed all unit tests, which are using 'Transaction.fromBytes'
Dec 12, 2023
9f30118
Fixed query execute to check whether query = AccountBalanceQuery
Dec 13, 2023
f098997
Eddited account_balance_query custom execute
Dec 13, 2023
876aef2
Refactored code to pass lint checks
Dec 13, 2023
4705b97
Fix TransactionFromBytes, removing e in executable
rokn Dec 14, 2023
bb2d9c6
Fix license
rokn Dec 14, 2023
55b12d4
Clean up
rokn Dec 14, 2023
9aee7d5
Fix linting issues
rokn Dec 14, 2023
642145a
Fix failing tests cause of TransactionFromBytes
rokn Dec 15, 2023
6e73369
Removed unnecessary logic
rokn Dec 18, 2023
a1addd7
Added getLogID function back to query/transaction to match the new style
Dec 18, 2023
f88cbf6
Raised gas on test to test it in pipeline
Dec 20, 2023
b72c91d
Commented some assets regarding balance query and added more gas for …
Dec 20, 2023
912f3e7
Commented test, which is failing because of testnet
Dec 21, 2023
4372b82
Fix failing tests from testnet
rokn Dec 21, 2023
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
510 changes: 164 additions & 346 deletions account_allowance_adjust_transaction.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion account_allowance_adjust_transaction_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func TestUnitAccountAllowanceAdjustTransactionGet(t *testing.T) {
require.Equal(t, 1, tx.GetMaxRetry())
require.Equal(t, time.Second*120, tx.GetMaxBackoff())
require.Equal(t, time.Second*1, tx.GetMinBackoff())
require.Equal(t, fmt.Sprintf("AccountAllowanceAdjustTransaction:%v", transactionID.ValidStart.UnixNano()), tx._GetLogID())
require.Equal(t, fmt.Sprint("AccountAllowanceAdjustTransaction"), tx.getName())
gsstoykov marked this conversation as resolved.
Show resolved Hide resolved
}

func TestUnitAccountAllowanceAdjustTransactionGrantHbarAllowance(t *testing.T) {
Expand Down
612 changes: 216 additions & 396 deletions account_allowance_approve_transaction.go

Large diffs are not rendered by default.

173 changes: 15 additions & 158 deletions account_allowance_approve_transaction_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,10 @@ package hedera
*/

import (
"testing"
"time"

protobuf "google.golang.org/protobuf/proto"

"github.com/hashgraph/hedera-protobufs-go/services"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/types/known/wrapperspb"
"testing"
)

var tokenID1 = TokenID{Token: 1}
Expand Down Expand Up @@ -64,7 +60,7 @@ func TestUnitAccountAllowanceApproveTransaction(t *testing.T) {
Freeze()
require.NoError(t, err)

data := transaction._Build()
data := transaction.build()

switch d := data.Data.(type) {
case *services.TransactionBody_CryptoApproveAllowance:
Expand Down Expand Up @@ -111,27 +107,26 @@ func TestUnitAccountAllowanceApproveTransaction(t *testing.T) {
})
}
}
func TestUnit_ValidateNetworkOnIDs(t *testing.T){
func TestUnitvalidateNetworkOnIDs(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()
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)
e := transaction.validateNetworkOnIDs(client)
require.NoError(t, e)
}
func TestUnitAccountAllowanceApproveTransactionGet(t *testing.T) {
Expand Down Expand Up @@ -193,33 +188,6 @@ func TestUnitAccountAllowanceApproveTransactionSetNothing(t *testing.T) {
require.NoError(t, err)
}

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

token := TokenID{Token: 3}
nodeAccountID := []AccountID{{Account: 10}, {Account: 11}, {Account: 12}}
transactionID := TransactionIDGenerate(AccountID{Account: 324})

transaction, err := NewAccountAllowanceDeleteTransaction().
SetTransactionID(transactionID).
SetNodeAccountIDs(nodeAccountID).
DeleteAllTokenNftAllowances(token.Nft(4), &AccountID{Account: 3}).
Freeze()
require.NoError(t, err)

transaction.GetTransactionID()
transaction.GetNodeAccountIDs()

_, err = transaction.GetTransactionHash()
require.NoError(t, err)
transaction.GetAllTokenNftDeleteAllowances()
transaction.GetMaxTransactionFee()
transaction.GetTransactionMemo()
transaction.GetRegenerateTransactionID()
_, err = transaction.GetSignatures()
require.NoError(t, err)
}

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

Expand All @@ -236,7 +204,7 @@ func TestUnitAccountAllowanceApproveTransactionFromProtobuf(t *testing.T) {
Freeze()
require.NoError(t, err)

txFromProto := _AccountAllowanceApproveTransactionFromProtobuf(tx.Transaction, tx._Build())
txFromProto := _AccountAllowanceApproveTransactionFromProtobuf(tx.Transaction, tx.build())
require.Equal(t, tx, txFromProto)
}

Expand Down Expand Up @@ -296,118 +264,7 @@ func TestUnitAccountAllowanceApproveTransactionScheduleProtobuf(t *testing.T) {
},
},
}
actual, err := tx._ConstructScheduleProtobuf()
actual, err := tx.buildScheduled()
require.NoError(t, err)
require.Equal(t, expected.String(), actual.String())
}

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

checksum := "dmqui"
token := TokenID{Token: 3, checksum: &checksum}
account := AccountID{Account: 3, checksum: &checksum}
nodeAccountID := []AccountID{{Account: 10}}
transactionID := TransactionIDGenerate(AccountID{Account: 324})

newKey, err := PrivateKeyGenerateEd25519()
require.NoError(t, err)

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

transaction, err := NewAccountAllowanceDeleteTransaction().
SetTransactionID(transactionID).
SetNodeAccountIDs(nodeAccountID).
DeleteAllTokenNftAllowances(token.Nft(4), &account).
DeleteAllTokenNftAllowances(token.Nft(5), &account).
SetMaxTransactionFee(NewHbar(3)).
SetMaxRetry(3).
DeleteAllHbarAllowances(&account).
DeleteAllTokenAllowances(token, &account).
SetMaxBackoff(time.Second * 30).
SetMinBackoff(time.Second * 10).
SetTransactionMemo("no").
SetTransactionValidDuration(time.Second * 30).
SetRegenerateTransactionID(false).
Freeze()
require.NoError(t, err)

transaction._ValidateNetworkOnIDs(client)

_, err = transaction.Schedule()
require.NoError(t, err)
transaction.GetTransactionID()
transaction.GetNodeAccountIDs()
transaction.GetMaxRetry()
transaction.GetMaxTransactionFee()
transaction.GetMaxBackoff()
transaction.GetMinBackoff()
transaction.GetRegenerateTransactionID()
byt, err := transaction.ToBytes()
require.NoError(t, err)
txFromBytesI, err := TransactionFromBytes(byt)
require.NoError(t, err)
txFromBytes, ok := txFromBytesI.(AccountAllowanceDeleteTransaction)
require.Equal(t, true, ok)
sig, err := newKey.SignTransaction(&transaction.Transaction)
require.NoError(t, err)

_, err = transaction.GetTransactionHash()
require.NoError(t, err)
transaction.GetAllTokenNftDeleteAllowances()
transaction.GetMaxTransactionFee()
transaction.GetTransactionMemo()
transaction.GetRegenerateTransactionID()
_, err = transaction.GetSignatures()
require.NoError(t, err)
transaction.GetAllHbarDeleteAllowances()
transaction.GetAllTokenDeleteAllowances()
transaction._GetLogID()
txFromBytes.AddSignature(newKey.PublicKey(), sig)
}

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

checksum := "dmqui"
token := TokenID{Token: 3, checksum: &checksum}
nodeAccountID := []AccountID{{Account: 3}}
transactionID := TransactionIDGenerate(AccountID{Account: 3})

call := func(request *services.Transaction) *services.TransactionResponse {
require.NotEmpty(t, request.SignedTransactionBytes)
signedTransaction := services.SignedTransaction{}
_ = protobuf.Unmarshal(request.SignedTransactionBytes, &signedTransaction)

require.NotEmpty(t, signedTransaction.BodyBytes)
transactionBody := services.TransactionBody{}
_ = protobuf.Unmarshal(signedTransaction.BodyBytes, &transactionBody)

require.NotNil(t, transactionBody.TransactionID)
transactionId := transactionBody.TransactionID.String()
require.NotEqual(t, "", transactionId)

sigMap := signedTransaction.GetSigMap()
require.NotNil(t, sigMap)

return &services.TransactionResponse{
NodeTransactionPrecheckCode: services.ResponseCodeEnum_OK,
}
}
responses := [][]interface{}{{
call,
}}

client, server := NewMockClientAndServer(responses)
defer server.Close()

_, err := NewAccountAllowanceDeleteTransaction().
SetTransactionID(transactionID).
SetNodeAccountIDs(nodeAccountID).
DeleteAllTokenNftAllowances(token.Nft(4), &AccountID{Account: 3}).
Execute(client)
require.NoError(t, err)
}
Loading