Skip to content

Commit

Permalink
861 hip 745 integration tests (#862)
Browse files Browse the repository at this point in the history
* Added more integration test for different transaction types

Signed-off-by: NikolaMirchev <nikola.mirchev@limechain.tech>

* Change

Signed-off-by: NikolaMirchev <nikola.mirchev@limechain.tech>

* fixed build error

Signed-off-by: NikolaMirchev <nikola.mirchev@limechain.tech>

* Refactor

Signed-off-by: NikolaMirchev <nikola.mirchev@limechain.tech>

* Fixed test

Signed-off-by: NikolaMirchev <nikola.mirchev@limechain.tech>

* Implemeted PR suggestions

Signed-off-by: NikolaMirchev <nikola.mirchev@limechain.tech>

* Eddited FileAppendTest

Signed-off-by: NikolaMirchev <nikola.mirchev@limechain.tech>

---------

Signed-off-by: NikolaMirchev <nikola.mirchev@limechain.tech>
  • Loading branch information
NicolaMirchev authored and NikolaMirchev committed Feb 6, 2024
1 parent ee531ed commit 2c0b119
Show file tree
Hide file tree
Showing 4 changed files with 261 additions and 35 deletions.
29 changes: 29 additions & 0 deletions account_create_transaction_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,3 +564,32 @@ func TestIntegrationAccountCreateTransactionWithAliasWithReceiverSigRequiredWith
err = CloseIntegrationTestEnv(env, nil)
require.NoError(t, err)
}

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

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

newBalance := NewHbar(2)

assert.Equal(t, 2*HbarUnits.Hbar._NumberOfTinybar(), newBalance.tinybar)

transactionOriginal := NewAccountCreateTransaction().
SetKey(newKey.PublicKey()).
SetInitialBalance(newBalance)

require.NoError(t, err)
resp, _ := transactionOriginal.ToBytes()

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

transaction := txFromBytes.(AccountCreateTransaction)
_, err = transaction.
SetNodeAccountIDs(env.NodeAccountIDs).
Execute(env.Client)

require.NoError(t, err)
}
11 changes: 6 additions & 5 deletions contract_execute_transaction_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ package hedera
*/

import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -106,15 +107,15 @@ func TestIntegrationContractExecuteTransactionNoContractID(t *testing.T) {
t.Parallel()
env := NewIntegrationTestEnv(t)

_, err := NewContractExecuteTransaction().
resp, err := NewContractExecuteTransaction().
SetGas(100000).
SetNodeAccountIDs(env.NodeAccountIDs).
SetFunction("setMessage", NewContractFunctionParameters().AddString("new message")).
Execute(env.Client)
require.NoError(t, err)
//if err != nil {
// assert.Equal(t, fmt.Sprintf("exceptional precheck status INVALID_CONTRACT_ID received for transaction %s", resp.TransactionID), err.Error())
//}

if err != nil {
assert.Equal(t, fmt.Sprintf("exceptional precheck status INVALID_CONTRACT_ID received for transaction %s", resp.TransactionID), err.Error())
}
}

func TestIntegrationContractExecuteTransactionNoGas(t *testing.T) {
Expand Down
57 changes: 57 additions & 0 deletions file_append_transaction_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,60 @@ func TestIntegrationFileAppendTransactionNothingSet(t *testing.T) {
err = CloseIntegrationTestEnv(env, nil)
require.NoError(t, err)
}
func TestIntegrationFileAppendTransactionCanExecuteAfterSerializationDeserialization(t *testing.T) {
t.Parallel()
env := NewIntegrationTestEnv(t)

resp, err := NewFileCreateTransaction().
SetKeys(env.Client.GetOperatorPublicKey()).
SetNodeAccountIDs(env.NodeAccountIDs).
SetContents([]byte("Hello")).
SetTransactionMemo("go sdk e2e tests").
Execute(env.Client)

require.NoError(t, err)

receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client)
require.NoError(t, err)

fileID := *receipt.FileID
assert.NotNil(t, fileID)

before := NewFileAppendTransaction().
SetFileID(fileID)

bytes, err := before.ToBytes()
require.NoError(t, err)

afterI, err := TransactionFromBytes(bytes)
require.NoError(t, err)

tx := afterI.(FileAppendTransaction)

resp, err = tx.SetNodeAccountIDs([]AccountID{resp.NodeID}).
SetContents([]byte(" world!")).Execute(env.Client)
require.NoError(t, err)

_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
require.NoError(t, err)

contents, err := NewFileContentsQuery().
SetFileID(fileID).
SetNodeAccountIDs([]AccountID{resp.NodeID}).
Execute(env.Client)
require.NoError(t, err)

assert.Equal(t, []byte("Hello world!"), contents)

resp, err = NewFileDeleteTransaction().
SetFileID(fileID).
SetNodeAccountIDs([]AccountID{resp.NodeID}).
Execute(env.Client)
require.NoError(t, err)

_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
require.NoError(t, err)

err = CloseIntegrationTestEnv(env, nil)
require.NoError(t, err)
}
199 changes: 169 additions & 30 deletions serialize_deserialize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,35 +66,6 @@ func TestIntegrationSerializeTransactionDeserializeAndAgainSerializeHasTheSameBy
assert.Equal(t, firstBytes, secondBytes)
}

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

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

newBalance := NewHbar(2)

assert.Equal(t, 2*HbarUnits.Hbar._NumberOfTinybar(), newBalance.tinybar)

transactionOriginal := NewAccountCreateTransaction().
SetKey(newKey.PublicKey()).
SetInitialBalance(newBalance)

require.NoError(t, err)
resp, _ := transactionOriginal.ToBytes()

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

transaction := txFromBytes.(AccountCreateTransaction)
_, err = transaction.
SetNodeAccountIDs(env.NodeAccountIDs).
Execute(env.Client)

require.NoError(t, err)
}

func TestIntegrationAddSignatureSerializeDeserializeAddAnotherSignatureExecute(t *testing.T) {
t.Parallel()
env := NewIntegrationTestEnv(t)
Expand Down Expand Up @@ -128,8 +99,176 @@ func TestIntegrationAddSignatureSerializeDeserializeAddAnotherSignatureExecute(t
panic(err)
}
receipt, err = executed.GetReceipt(env.Client)
assert.Equal(t, receipt.Status, StatusSuccess)
if err != nil {
panic(err)
}
fmt.Println("Tx successfully executed. Here is receipt:", receipt)
}

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

// Prepare and sign the tx and send it to be signed by another actor
txBefore := NewTransferTransaction().SetTransactionMemo("Serialize/Deserialize transaction test").AddHbarTransfer(env.OperatorID, NewHbar(-1)).
Sign(env.OperatorKey)

bytes, err := txBefore.ToBytes()

FromBytes, err := TransactionFromBytes(bytes)
if err != nil {
panic(err)
}
txFromBytes := FromBytes.(TransferTransaction)
// Assert the fields are the same:
assert.Equal(t, txFromBytes.signedTransactions._Length(), txBefore.signedTransactions._Length())
assert.Equal(t, txFromBytes.memo, txBefore.memo)

_, err = txFromBytes.Execute(env.Client)
assert.Error(t, err)
}

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

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

resp, err := NewAccountCreateTransaction().
SetKey(newKey.PublicKey()).
SetNodeAccountIDs(env.NodeAccountIDs).
Execute(env.Client)
require.NoError(t, err)

receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client)
require.NoError(t, err)

tx, err := NewAccountDeleteTransaction().
SetNodeAccountIDs([]AccountID{resp.NodeID}).
SetAccountID(*receipt.AccountID).
SetTransferAccountID(env.Client.GetOperatorAccountID()).
FreezeWith(env.Client)
require.NoError(t, err)
updateBytes, err := tx.ToBytes()
require.NoError(t, err)

sig1, err := newKey.SignTransaction(&tx.Transaction)
require.NoError(t, err)

tx2, err := TransactionFromBytes(updateBytes)
require.NoError(t, err)

if newTx, ok := tx2.(AccountDeleteTransaction); ok {
assert.True(t, newTx.IsFrozen())
resp, err = newTx.AddSignature(newKey.PublicKey(), sig1).Execute(env.Client)
require.NoError(t, err)
}

_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
require.NoError(t, err)

err = CloseIntegrationTestEnv(env, nil)
require.NoError(t, err)

}

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

tx := NewTopicCreateTransaction().
SetAdminKey(env.Client.GetOperatorPublicKey()).
SetSubmitKey(env.Client.GetOperatorPublicKey()).
SetTopicMemo(topicMemo)

// Serialize unfinished transaction
bytes, err := tx.ToBytes()

fromBytes, err := TransactionFromBytes(bytes)
require.NoError(t, err)
// Deserialize and add node accounts transaction
transaction := fromBytes.(TopicCreateTransaction)
resp, err := transaction.SetNodeAccountIDs(env.NodeAccountIDs).Execute(env.Client)
require.NoError(t, err)

receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client)
require.NoError(t, err)

topicID := *receipt.TopicID
assert.NotNil(t, topicID)

info, err := NewTopicInfoQuery().
SetTopicID(topicID).
SetNodeAccountIDs([]AccountID{resp.NodeID}).
SetQueryPayment(NewHbar(1)).
Execute(env.Client)
require.NoError(t, err)
assert.NotNil(t, info)

assert.Equal(t, topicMemo, info.TopicMemo)
assert.Equal(t, uint64(0), info.SequenceNumber)
assert.Equal(t, env.Client.GetOperatorPublicKey().String(), info.AdminKey.String())

resp, err = NewTopicDeleteTransaction().
SetTopicID(topicID).
SetNodeAccountIDs([]AccountID{resp.NodeID}).
Execute(env.Client)
require.NoError(t, err)

_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
require.NoError(t, err)

err = CloseIntegrationTestEnv(env, nil)
require.NoError(t, err)
}

func TestIntegrationTopicSubmitTransactionSerializationDeserialization(t *testing.T) {
const bigContents2 = `
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur aliquam augue sem, ut mattis dui laoreet a. Curabitur consequat est euismod, scelerisque metus et, tristique dui. Nulla commodo mauris ut faucibus ultricies. Quisque venenatis nisl nec augue tempus, at efficitur elit eleifend. Duis pharetra felis metus, sed dapibus urna vehicula id. Duis non venenatis turpis, sit amet ornare orci. Donec non interdum quam. Sed finibus nunc et risus finibus, non sagittis lorem cursus. Proin pellentesque tempor aliquam. Sed congue nisl in enim bibendum, condimentum vehicula nisi feugiat.
Suspendisse non sodales arcu. Suspendisse sodales, lorem ac mollis blandit, ipsum neque porttitor nulla, et sodales arcu ante fermentum tellus. Integer sagittis dolor sed augue fringilla accumsan. Cras vitae finibus arcu, sit amet varius dolor. Etiam id finibus dolor, vitae luctus velit. Proin efficitur augue nec pharetra accumsan. Aliquam lobortis nisl diam, vel fermentum purus finibus id. Etiam at finibus orci, et tincidunt turpis. Aliquam imperdiet congue lacus vel facilisis. Phasellus id magna vitae enim dapibus vestibulum vitae quis augue. Morbi eu consequat enim. Maecenas neque nulla, pulvinar sit amet consequat sed, tempor sed magna. Mauris lacinia sem feugiat faucibus aliquet. Etiam congue non turpis at commodo. Nulla facilisi.
Nunc velit turpis, cursus ornare fringilla eu, lacinia posuere leo. Mauris rutrum ultricies dui et suscipit. Curabitur in euismod ligula. Curabitur vitae faucibus orci. Phasellus volutpat vestibulum diam sit amet vestibulum. In vel purus leo. Nulla condimentum lectus vestibulum lectus faucibus, id lobortis eros consequat. Proin mollis libero elit, vel aliquet nisi imperdiet et. Morbi ornare est velit, in vehicula nunc malesuada quis. Donec vehicula convallis interdum.
`

t.Parallel()
env := NewIntegrationTestEnv(t)

tx := NewTopicCreateTransaction().
SetAdminKey(env.Client.GetOperatorPublicKey()).
SetSubmitKey(env.Client.GetOperatorPublicKey()).
SetTopicMemo(topicMemo)

// Serialize unfinished transaction
bytes, err := tx.ToBytes()

fromBytes, err := TransactionFromBytes(bytes)
require.NoError(t, err)
// Deserialize and add node accounts transaction
transaction := fromBytes.(TopicCreateTransaction)
resp, err := transaction.SetNodeAccountIDs(env.NodeAccountIDs).Execute(env.Client)
require.NoError(t, err)

receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client)
require.NoError(t, err)

topicID := *receipt.TopicID
assert.NotNil(t, topicID)

submitBytes, err := NewTopicMessageSubmitTransaction().
SetNodeAccountIDs([]AccountID{{Account: 3}}).
SetMessage([]byte(bigContents2)).
SetTopicID(topicID).ToBytes()
require.NoError(t, err)

fromBytes, err = TransactionFromBytes(submitBytes)
require.NoError(t, err)

topicSubmitTx := fromBytes.(TopicMessageSubmitTransaction)
_, err = topicSubmitTx.Execute(env.Client)
require.NoError(t, err)

err = CloseIntegrationTestEnv(env, nil)
require.NoError(t, err)
}

0 comments on commit 2c0b119

Please sign in to comment.