From e160b35929f37123cc49e9db6095e87fa451d204 Mon Sep 17 00:00:00 2001 From: Daniel Akhterov Date: Thu, 29 Apr 2021 20:14:44 -0700 Subject: [PATCH] fix: remove `KeyList.AddAllPubKeys()` as it's redundant --- key_list.go | 8 - schedule_create_transaction_test.go | 344 ++++++++++++++-------------- 2 files changed, 172 insertions(+), 180 deletions(-) diff --git a/key_list.go b/key_list.go index 0071e7bb7..7049f1f88 100644 --- a/key_list.go +++ b/key_list.go @@ -27,14 +27,6 @@ func (kl *KeyList) AddAll(keys []PublicKey) *KeyList { return kl } -func (kl *KeyList) AddAllPublicKeys(keys []PublicKey) *KeyList { - for _, key := range keys { - kl.Add(key) - } - - return kl -} - func (kl *KeyList) toProto() *proto.Key { return &proto.Key{Key: &proto.Key_KeyList{KeyList: &proto.KeyList{Keys: kl.keys}}} } diff --git a/schedule_create_transaction_test.go b/schedule_create_transaction_test.go index b61efdb69..8e7f0727e 100644 --- a/schedule_create_transaction_test.go +++ b/schedule_create_transaction_test.go @@ -1,174 +1,174 @@ package hedera -//import ( -// "github.com/stretchr/testify/assert" -// "testing" -//) -// -//func TestScheduleCreateTransaction_Execute(t *testing.T) { -// client := newTestClient(t) -// -// newKey, err := GenerateEd25519PrivateKey() -// assert.NoError(t, err) -// -// newBalance := NewHbar(1) -// -// assert.Equal(t, HbarUnits.Hbar.numberOfTinybar(), newBalance.tinybar) -// -// scheduleTx, err := NewAccountCreateTransaction(). -// SetKey(newKey.PublicKey()). -// SetMaxTransactionFee(NewHbar(2)). -// SetInitialBalance(newBalance). -// Schedule() -// assert.NoError(t, err) -// -// frozen, err := scheduleTx. -// SetPayerAccountID(client.GetOperatorID()). -// SetAdminKey(newKey.PublicKey()). -// Build(client) -// assert.NoError(t, err) -// -// frozen = frozen.Sign(newKey) -// -// txID, err := frozen.Execute(client) -// assert.NoError(t, err) -// -// receipt, err := txID.GetReceipt(client) -// assert.NoError(t, err) -// -// info, err := NewScheduleInfoQuery(). -// SetScheduleID(receipt.GetScheduleID()). -// SetMaxQueryPayment(NewHbar(2)). -// Execute(client) -// assert.NoError(t, err) -// -// infoTx, err := info.GetScheduledTransaction() -// assert.NoError(t, err) -// assert.NotNil(t, infoTx) -// -// assert.False(t, info.ExecutedAt.IsZero()) -//} -// -//func TestScheduleCreateTransaction_SetTransaction_Execute(t *testing.T) { -// client := newTestClient(t) -// -// newKey, err := GenerateEd25519PrivateKey() -// assert.NoError(t, err) -// -// newBalance := NewHbar(1) -// -// assert.Equal(t, HbarUnits.Hbar.numberOfTinybar(), newBalance.tinybar) -// -// tx := NewAccountCreateTransaction(). -// SetKey(newKey.PublicKey()). -// SetMaxTransactionFee(NewHbar(2)). -// SetInitialBalance(newBalance). -// SetNodeAccountID(AccountID{0, 0, 3}) -// -// scheduleTx, err := NewScheduleCreateTransaction(). -// SetScheduledTransaction(&tx) -// assert.NoError(t, err) -// -// txS, err := scheduleTx. -// SetAdminKey(newKey.PublicKey()). -// SetPayerAccountID(client.GetOperatorID()). -// Build(client) -// assert.NoError(t, err) -// -// txS = txS.Sign(newKey) -// -// txID, err := txS.Execute(client) -// assert.NoError(t, err) -// -// receipt, err := txID.GetReceipt(client) -// assert.NoError(t, err) -// -// info, err := NewScheduleInfoQuery(). -// SetScheduleID(receipt.GetScheduleID()). -// Execute(client) -// assert.NoError(t, err) -// -// infoTx, err := info.GetScheduledTransaction() -// assert.NoError(t, err) -// assert.NotNil(t, infoTx) -// -// assert.False(t, info.ExecutedAt.IsZero()) -// -//} -// -//func TestScheduleCreateTransaction_MultiSig_Execute(t *testing.T) { -// client := newTestClient(t) -// -// keys := make([]Ed25519PrivateKey, 3) -// pubKeys := make([]PublicKey, 3) -// -// for i := range keys { -// newKey, err := GenerateEd25519PrivateKey() -// assert.NoError(t, err) -// -// keys[i] = newKey -// pubKeys[i] = newKey.PublicKey() -// } -// -// keyList := NewKeyList(). -// AddAllPublicKeys(pubKeys) -// -// createResponse, err := NewAccountCreateTransaction(). -// SetKey(keyList). -// SetInitialBalance(NewHbar(10)). -// Execute(client) -// assert.NoError(t, err) -// -// transactionReceipt, err := createResponse.GetReceipt(client) -// assert.NoError(t, err) -// -// transactionID := NewTransactionID(client.GetOperatorID()) -// -// newAccountID := transactionReceipt.GetAccountID() -// -// transferTx := NewTransferTransaction(). -// SetTransactionID(transactionID). -// AddHbarTransfer(newAccountID, HbarFrom(-1, HbarUnits.Hbar)). -// AddHbarTransfer(client.GetOperatorID(), HbarFrom(1, HbarUnits.Hbar)) -// -// scheduled, err := transferTx.Schedule() -// assert.NoError(t, err) -// -// scheduleResponse, err := scheduled.Execute(client) -// assert.NoError(t, err) -// -// scheduleReceipt, err := scheduleResponse.GetReceipt(client) -// assert.NoError(t, err) -// -// scheduleID := scheduleReceipt.GetScheduleID() -// -// info, err := NewScheduleInfoQuery(). -// SetScheduleID(scheduleID). -// Execute(client) -// assert.NoError(t, err) -// -// transfer, err := info.GetScheduledTransaction() -// assert.NoError(t, err) -// assert.NotNil(t, transfer) -// -// signTransaction, err := NewScheduleSignTransaction(). -// SetScheduleID(scheduleID). -// Build(client) -// assert.NoError(t, err) -// -// signTransaction.Sign(keys[0]) -// signTransaction.Sign(keys[1]) -// signTransaction.Sign(keys[2]) -// -// resp, err := signTransaction.Execute(client) -// assert.NoError(t, err) -// -// _, err = resp.GetReceipt(client) -// assert.NoError(t, err) -// -// info2, err := NewScheduleInfoQuery(). -// SetScheduleID(scheduleID). -// Execute(client) -// assert.NoError(t, err) -// assert.False(t, info2.ExecutedAt.IsZero()) -//} +import ( + "github.com/stretchr/testify/assert" + "testing" +) + +// func TestScheduleCreateTransaction_Execute(t *testing.T) { +// client := newTestClient(t) + +// newKey, err := GenerateEd25519PrivateKey() +// assert.NoError(t, err) + +// newBalance := NewHbar(1) + +// assert.Equal(t, HbarUnits.Hbar.numberOfTinybar(), newBalance.tinybar) + +// scheduleTx, err := NewAccountCreateTransaction(). +// SetKey(newKey.PublicKey()). +// SetMaxTransactionFee(NewHbar(2)). +// SetInitialBalance(newBalance). +// Schedule() +// assert.NoError(t, err) + +// frozen, err := scheduleTx. +// SetPayerAccountID(client.GetOperatorID()). +// SetAdminKey(newKey.PublicKey()). +// Build(client) +// assert.NoError(t, err) + +// frozen = frozen.Sign(newKey) + +// txID, err := frozen.Execute(client) +// assert.NoError(t, err) + +// receipt, err := txID.GetReceipt(client) +// assert.NoError(t, err) + +// info, err := NewScheduleInfoQuery(). +// SetScheduleID(receipt.GetScheduleID()). +// SetMaxQueryPayment(NewHbar(2)). +// Execute(client) +// assert.NoError(t, err) + +// infoTx, err := info.GetScheduledTransaction() +// assert.NoError(t, err) +// assert.NotNil(t, infoTx) + +// assert.False(t, info.ExecutedAt.IsZero()) +// } + +// func TestScheduleCreateTransaction_SetTransaction_Execute(t *testing.T) { +// client := newTestClient(t) + +// newKey, err := GenerateEd25519PrivateKey() +// assert.NoError(t, err) + +// newBalance := NewHbar(1) + +// assert.Equal(t, HbarUnits.Hbar.numberOfTinybar(), newBalance.tinybar) + +// tx := NewAccountCreateTransaction(). +// SetKey(newKey.PublicKey()). +// SetMaxTransactionFee(NewHbar(2)). +// SetInitialBalance(newBalance). +// SetNodeAccountID(AccountID{0, 0, 3}) + +// scheduleTx, err := NewScheduleCreateTransaction(). +// SetScheduledTransaction(&tx) +// assert.NoError(t, err) + +// txS, err := scheduleTx. +// SetAdminKey(newKey.PublicKey()). +// SetPayerAccountID(client.GetOperatorID()). +// Build(client) +// assert.NoError(t, err) + +// txS = txS.Sign(newKey) + +// txID, err := txS.Execute(client) +// assert.NoError(t, err) + +// receipt, err := txID.GetReceipt(client) +// assert.NoError(t, err) + +// info, err := NewScheduleInfoQuery(). +// SetScheduleID(receipt.GetScheduleID()). +// Execute(client) +// assert.NoError(t, err) + +// infoTx, err := info.GetScheduledTransaction() +// assert.NoError(t, err) +// assert.NotNil(t, infoTx) + +// assert.False(t, info.ExecutedAt.IsZero()) + +// } + +func TestScheduleCreateTransaction_MultiSig_Execute(t *testing.T) { + client := newTestClient(t) + + keys := make([]Ed25519PrivateKey, 3) + pubKeys := make([]PublicKey, 3) + + for i := range keys { + newKey, err := GenerateEd25519PrivateKey() + assert.NoError(t, err) + + keys[i] = newKey + pubKeys[i] = newKey.PublicKey() + } + + keyList := NewKeyList(). + AddAll(pubKeys) + + createResponse, err := NewAccountCreateTransaction(). + SetKey(keyList). + SetInitialBalance(NewHbar(10)). + Execute(client) + assert.NoError(t, err) + + transactionReceipt, err := createResponse.GetReceipt(client) + assert.NoError(t, err) + + transactionID := NewTransactionID(client.GetOperatorID()) + + newAccountID := transactionReceipt.GetAccountID() + + transferTx := NewTransferTransaction(). + SetTransactionID(transactionID). + AddHbarTransfer(newAccountID, HbarFrom(-1, HbarUnits.Hbar)). + AddHbarTransfer(client.GetOperatorID(), HbarFrom(1, HbarUnits.Hbar)) + + scheduled, err := transferTx.Schedule() + assert.NoError(t, err) + + scheduleResponse, err := scheduled.Execute(client) + assert.NoError(t, err) + + scheduleReceipt, err := scheduleResponse.GetReceipt(client) + assert.NoError(t, err) + + scheduleID := scheduleReceipt.GetScheduleID() + + info, err := NewScheduleInfoQuery(). + SetScheduleID(scheduleID). + Execute(client) + assert.NoError(t, err) + + transfer, err := info.GetScheduledTransaction() + assert.NoError(t, err) + assert.NotNil(t, transfer) + + signTransaction, err := NewScheduleSignTransaction(). + SetScheduleID(scheduleID). + Build(client) + assert.NoError(t, err) + + signTransaction.Sign(keys[0]) + signTransaction.Sign(keys[1]) + signTransaction.Sign(keys[2]) + + resp, err := signTransaction.Execute(client) + assert.NoError(t, err) + + _, err = resp.GetReceipt(client) + assert.NoError(t, err) + + info2, err := NewScheduleInfoQuery(). + SetScheduleID(scheduleID). + Execute(client) + assert.NoError(t, err) + assert.False(t, info2.ExecutedAt.IsZero()) +}