Skip to content

Commit

Permalink
feat: Expanding and adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrix10 committed Dec 11, 2020
1 parent 84d83fa commit f94339d
Show file tree
Hide file tree
Showing 19 changed files with 844 additions and 10 deletions.
2 changes: 0 additions & 2 deletions account_records_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,4 @@ func TestAccountRecordQuery_Execute(t *testing.T) {
assert.NoError(t, err)

assert.Equal(t, 0, len(recordsQuery))

//assert.Equal(t, `cryptoGetAccountRecords:{header:{payment:{bodyBytes:"\n\x0e\n\x08\x08\xdc\xc9\x07\x10۟\t\x12\x02\x18\x03\x12\x02\x18\x03\x18\x80\xc2\xd7/\"\x02\x08xr\x14\n\x12\n\x07\n\x02\x18\x02\x10\xc7\x01\n\x07\n\x02\x18\x03\x10\xc8\x01"sigMap:{sigPair:{pubKeyPrefix:"\xe4\xf1\xc0\xebL}\xcd\xc3\xe7\xeb\x11p\xb3\x08\x8a=\x12\xa2\x97\xf4\xa3\xeb\xe2\xf2\x85\x03\xfdg5F\xed\x8e"ed25519:"\x12&5\x96\xfb\xb4\x1c]P\xbb%\xecP\x9bk͙\x0b߼\xac)\xa6+\xd2<\x97+\xbb\x8c\x8af\xcb\xdai\x17T4{\xf7\xf3UYn\n\x8f\xabep\x04\xf6\x83\x0f\xbaFUP\xa3\xd1/\x1d\x9d\x1a\x0b"}}}}accountID:{accountNum:3}}`, strings.ReplaceAll(query.QueryBuilder.pb.String(), " ", ""))
}
69 changes: 69 additions & 0 deletions account_update_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,72 @@ func TestAccountUpdateTransaction_Execute(t *testing.T) {

assert.NoError(t, err)
}

func TestAccountUpdateTransactionNoSigning_Execute(t *testing.T) {
client := newTestClient(t)

newKey, err := GeneratePrivateKey()
assert.NoError(t, err)

newKey2, err := GeneratePrivateKey()
assert.NoError(t, err)

newBalance := NewHbar(1)

assert.Equal(t, HbarUnits.Hbar.numberOfTinybar(), newBalance.tinybar)

resp, err := NewAccountCreateTransaction().
SetKey(newKey.PublicKey()).
SetMaxTransactionFee(NewHbar(2)).
SetInitialBalance(newBalance).
Execute(client)

assert.NoError(t, err)

receipt, err := resp.GetReceipt(client)
assert.NoError(t, err)

accountID := *receipt.AccountID
assert.NoError(t, err)

nodeIDs := make([]AccountID, 1)
nodeIDs[0] = resp.NodeID

_, err = NewAccountUpdateTransaction().
SetAccountID(accountID).
SetNodeAccountIDs(nodeIDs).
SetKey(newKey2.PublicKey()).
SetMaxTransactionFee(NewHbar(1)).
Execute(client)
assert.NoError(t, err)

_, err = resp.GetReceipt(client)
assert.Error(t, err)

info, err := NewAccountInfoQuery().
SetAccountID(accountID).
SetNodeAccountIDs(nodeIDs).
SetMaxQueryPayment(NewHbar(1)).
Execute(client)
assert.NoError(t, err)

assert.Equal(t, newKey.PublicKey().String(), info.Key.String())

txDelete, err := NewAccountDeleteTransaction().
SetAccountID(accountID).
SetTransferAccountID(client.GetOperatorAccountID()).
SetNodeAccountIDs(nodeIDs).
SetMaxTransactionFee(NewHbar(1)).
FreezeWith(client)

assert.NoError(t, err)

txDelete.Sign(newKey2)

resp, err = txDelete.Execute(client)
assert.NoError(t, err)

_, err = resp.GetReceipt(client)

assert.NoError(t, err)
}
4 changes: 3 additions & 1 deletion contract_bytecode_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ func TestContractBytecodeQuery_Execute(t *testing.T) {
Execute(client)
assert.NoError(t, err)

contractReceipt, err := contractResponse.TransactionID.GetReceipt(client)
contractReceipt, err := contractResponse.GetReceipt(client)
assert.NoError(t, err)

assert.NotNil(t, contractReceipt.ContractID)

assert.True(t, contractReceipt.ContractID.Contract > 0)

contractID := *contractReceipt.ContractID
Expand Down
2 changes: 2 additions & 0 deletions contract_call_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ func TestNewContractCallQuery_Execute(t *testing.T) {

assert.True(t, contractReceipt.ContractID.Contract > 0)

assert.NotNil(t, contractReceipt.ContractID)

contractID := *contractReceipt.ContractID

result, err := NewContractCallQuery().
Expand Down
2 changes: 1 addition & 1 deletion contract_create_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ func TestContractCreateTransaction_Execute(t *testing.T) {
receipt, err = resp.GetReceipt(client)
assert.NoError(t, err)

assert.NotNil(t, receipt.ContractID)
contractID := *receipt.ContractID
assert.NotNil(t, contractID)

resp, err = NewContractDeleteTransaction().
SetContractID(contractID).
Expand Down
2 changes: 1 addition & 1 deletion contract_delete_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ func TestContractDeleteTransaction_Execute(t *testing.T) {
receipt, err = resp.GetReceipt(client)
assert.NoError(t, err)

assert.NotNil(t, receipt.ContractID)
contractID := *receipt.ContractID
assert.NotNil(t, contractID)

resp, err = NewContractDeleteTransaction().
SetContractID(contractID).
Expand Down
2 changes: 1 addition & 1 deletion contract_execute_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ func TestContractExecuteTransaction_Execute(t *testing.T) {
receipt, err = resp.GetReceipt(client)
assert.NoError(t, err)

assert.NotNil(t, receipt.ContractID)
contractID := *receipt.ContractID
assert.NotNil(t, contractID)

resp, err = NewContractExecuteTransaction().
SetContractID(contractID).
Expand Down
2 changes: 1 addition & 1 deletion contract_info_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ func TestContractInfoQuery_Execute(t *testing.T) {
receipt, err = resp.GetReceipt(client)
assert.NoError(t, err)

assert.NotNil(t, receipt.ContractID)
contractID := *receipt.ContractID
assert.NotNil(t, contractID)

info, err := NewContractInfoQuery().
SetContractID(contractID).
Expand Down
11 changes: 8 additions & 3 deletions contract_update_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,25 @@ func TestContractUpdateTransaction_Execute(t *testing.T) {
receipt, err = resp.GetReceipt(client)
assert.NoError(t, err)

assert.NotNil(t, receipt.ContractID)
contractID := *receipt.ContractID
assert.NotNil(t, contractID)

info, err := NewContractInfoQuery().
SetContractID(contractID).
SetNodeAccountIDs([]AccountID{resp.NodeID}).
SetQueryPayment(NewHbar(1)).
Execute(client)
assert.NoError(t, err)

assert.NotNil(t, info)
assert.NotNil(t, info, info.Storage)
assert.NotNil(t, info.ContractID)
assert.Equal(t, info.ContractID, contractID)
assert.NotNil(t, info.AccountID)
assert.Equal(t, info.AccountID.String(), contractID.String())
assert.NotNil(t, info.AdminKey)
assert.Equal(t, info.AdminKey.String(), client.GetOperatorPublicKey().String())
//assert.Equal(t, info.Storage, uint64(926))
assert.Equal(t, info.Storage, uint64(523))
assert.Equal(t, info.ContractMemo, "[e2e::ContractCreateTransaction]")

resp, err = NewContractUpdateTransaction().
Expand All @@ -71,14 +74,16 @@ func TestContractUpdateTransaction_Execute(t *testing.T) {
SetNodeAccountIDs([]AccountID{resp.NodeID}).
SetQueryPayment(NewHbar(5)).
Execute(client)
assert.NoError(t, err)

assert.NotNil(t, info)
assert.NotNil(t, info.ContractID)
assert.Equal(t, info.ContractID, contractID)
assert.NotNil(t, info.AccountID)
assert.Equal(t, info.AccountID.String(), contractID.String())
assert.NotNil(t, info.AdminKey)
assert.Equal(t, info.AdminKey.String(), client.GetOperatorPublicKey().String())
//assert.Equal(t, info.Storage, uint64(926))
assert.Equal(t, info.Storage, uint64(523))
assert.Equal(t, info.ContractMemo, "[e2e::ContractUpdateTransaction]")

resp, err = NewContractDeleteTransaction().
Expand Down
31 changes: 31 additions & 0 deletions file_delete_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,34 @@ func TestFileDeleteTransaction_Execute(t *testing.T) {
_, err = resp.GetReceipt(client)
assert.NoError(t, err)
}

func TestFileDeleteTransactionNothingSet_Execute(t *testing.T) {
client := newTestClient(t)
client.SetMaxTransactionFee(NewHbar(2))

resp, err := NewFileCreateTransaction().
SetKeys(client.GetOperatorPublicKey()).
SetContents([]byte("Hello, World")).
SetTransactionMemo("go sdk e2e tests").
Execute(client)

assert.NoError(t, err)

receipt, err := resp.GetReceipt(client)
assert.NoError(t, err)

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

nodeIDs := make([]AccountID, 1)
nodeIDs[0] = resp.NodeID

resp, err = NewFileDeleteTransaction().
SetFileID(fileID).
SetNodeAccountIDs(nodeIDs).
Execute(client)
assert.NoError(t, err)

_, err = resp.GetReceipt(client)
assert.NoError(t, err)
}
Loading

0 comments on commit f94339d

Please sign in to comment.