Skip to content

Commit

Permalink
Implemeted PR suggestions
Browse files Browse the repository at this point in the history
Signed-off-by: NikolaMirchev <nikola.mirchev@limechain.tech>
  • Loading branch information
NikolaMirchev committed Feb 5, 2024
1 parent 447ffc3 commit 8de4736
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 29 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)
}
55 changes: 55 additions & 0 deletions file_append_transaction_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,58 @@ 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)

resp, err = afterI.(*FileAppendTransaction).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)
}
29 changes: 0 additions & 29 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

0 comments on commit 8de4736

Please sign in to comment.