From 5161593313cae8427685a9750baff7240d7df5cd Mon Sep 17 00:00:00 2001 From: Shawn Reuland Date: Mon, 4 Apr 2022 21:59:04 -0700 Subject: [PATCH 1/4] #4305: added integration test for extra signers using tx preconditions --- .../transaction_preconditions_test.go | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/services/horizon/internal/integration/transaction_preconditions_test.go b/services/horizon/internal/integration/transaction_preconditions_test.go index 8efdf1240d..220341b7ae 100644 --- a/services/horizon/internal/integration/transaction_preconditions_test.go +++ b/services/horizon/internal/integration/transaction_preconditions_test.go @@ -64,6 +64,38 @@ func TestTransactionPreconditionsTimeBounds(t *testing.T) { itest.MustSubmitTransaction(master, txParams) } +func TestTransactionPreconditionsExtraSigners(t *testing.T) { + if integration.GetCoreMaxSupportedProtocol() < 19 { + t.Skip("Can't run with protocol < 19") + } + tt := assert.New(t) + itest := integration.NewTest(t, integration.Config{}) + master := itest.Master() + masterAccount := itest.MasterAccount() + + // create a new signed payload signer + addtlSigners, addtlAccounts := itest.CreateAccounts(1, "1000") + + // build a tx with seqnum based on master.seqNum+1 as source account + latestMasterAccount := itest.MustGetAccount(master) + currentAccountSeq, err := latestMasterAccount.GetSequenceNumber() + tt.NoError(err) + txParams := buildTXParams(master, masterAccount, currentAccountSeq, currentAccountSeq+1) + + // this errors because the tx preconditions require extra signer that + // didn't sign this tx + txParams.Preconditions.ExtraSigners = []string{addtlAccounts[0].GetAccountID()} + _, err = itest.SubmitMultiSigTransaction([]*keypair.Full{master}, txParams) + tt.Error(err) + + // Now the transaction should be submitted without problems, the extra signer specified + // has also signed this transaction. + // TODO - doesn't work yet, need to figure out how + txParams.Preconditions.ExtraSigners = []string{addtlAccounts[0].GetAccountID()} + _, err = itest.SubmitMultiSigTransaction([]*keypair.Full{master, addtlSigners[0]}, txParams) + tt.NoError(err) +} + func buildTXParams(master *keypair.Full, masterAccount txnbuild.Account, sourceAccountSeq int64, txSequence int64) txnbuild.TransactionParams { ops := []txnbuild.Operation{ From 6e063dcfc25fb79046c6d17cfd4139b54720b4e6 Mon Sep 17 00:00:00 2001 From: Shawn Reuland Date: Tue, 5 Apr 2022 10:40:59 -0700 Subject: [PATCH 2/4] #4305: removed obsoleted TODO comment --- .../internal/integration/transaction_preconditions_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/services/horizon/internal/integration/transaction_preconditions_test.go b/services/horizon/internal/integration/transaction_preconditions_test.go index 220341b7ae..9a6e3af216 100644 --- a/services/horizon/internal/integration/transaction_preconditions_test.go +++ b/services/horizon/internal/integration/transaction_preconditions_test.go @@ -90,7 +90,6 @@ func TestTransactionPreconditionsExtraSigners(t *testing.T) { // Now the transaction should be submitted without problems, the extra signer specified // has also signed this transaction. - // TODO - doesn't work yet, need to figure out how txParams.Preconditions.ExtraSigners = []string{addtlAccounts[0].GetAccountID()} _, err = itest.SubmitMultiSigTransaction([]*keypair.Full{master, addtlSigners[0]}, txParams) tt.NoError(err) From ded994277b13cb153cc734be2c352a8ed755f8f4 Mon Sep 17 00:00:00 2001 From: Shawn Reuland Date: Wed, 6 Apr 2022 10:55:44 -0700 Subject: [PATCH 3/4] #4305: added round trip verification by quering preconds on submitted tx per pr feedback --- .../transaction_preconditions_test.go | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/services/horizon/internal/integration/transaction_preconditions_test.go b/services/horizon/internal/integration/transaction_preconditions_test.go index 9a6e3af216..f3b559db9f 100644 --- a/services/horizon/internal/integration/transaction_preconditions_test.go +++ b/services/horizon/internal/integration/transaction_preconditions_test.go @@ -1,6 +1,7 @@ package integration import ( + "fmt" "testing" "time" @@ -31,7 +32,11 @@ func TestTransactionPreconditionsMinSeq(t *testing.T) { // Now the transaction should be submitted without problems txParams.Preconditions.MinSequenceNumber = ¤tAccountSeq - itest.MustSubmitTransaction(master, txParams) + tx := itest.MustSubmitTransaction(master, txParams) + + txHistory, err := itest.Client().TransactionDetail(tx.Hash) + assert.NoError(t, err) + assert.Equal(t, txHistory.Preconditions.MinAccountSequence, fmt.Sprint(*txParams.Preconditions.MinSequenceNumber)) } func TestTransactionPreconditionsTimeBounds(t *testing.T) { @@ -61,7 +66,17 @@ func TestTransactionPreconditionsTimeBounds(t *testing.T) { // Now the transaction should be submitted without problems, min < current tx submit time < max txParams.Preconditions.TimeBounds.MinTime = time.Now().Unix() - 3600 txParams.Preconditions.TimeBounds.MaxTime = time.Now().Unix() + 3600 - itest.MustSubmitTransaction(master, txParams) + tx := itest.MustSubmitTransaction(master, txParams) + + txHistory, err := itest.Client().TransactionDetail(tx.Hash) + assert.NoError(t, err) + historyMaxTime, err := time.Parse(time.RFC3339, txHistory.Preconditions.Timebounds.MaxTime) + assert.NoError(t, err) + historyMinTime, err := time.Parse(time.RFC3339, txHistory.Preconditions.Timebounds.MinTime) + assert.NoError(t, err) + + assert.Equal(t, historyMaxTime.UTC().Unix(), txParams.Preconditions.TimeBounds.MaxTime) + assert.Equal(t, historyMinTime.UTC().Unix(), txParams.Preconditions.TimeBounds.MinTime) } func TestTransactionPreconditionsExtraSigners(t *testing.T) { @@ -91,8 +106,12 @@ func TestTransactionPreconditionsExtraSigners(t *testing.T) { // Now the transaction should be submitted without problems, the extra signer specified // has also signed this transaction. txParams.Preconditions.ExtraSigners = []string{addtlAccounts[0].GetAccountID()} - _, err = itest.SubmitMultiSigTransaction([]*keypair.Full{master, addtlSigners[0]}, txParams) + tx, err := itest.SubmitMultiSigTransaction([]*keypair.Full{master, addtlSigners[0]}, txParams) tt.NoError(err) + + txHistory, err := itest.Client().TransactionDetail(tx.Hash) + assert.NoError(t, err) + assert.ElementsMatch(t, txHistory.Preconditions.ExtraSigners, txParams.Preconditions.ExtraSigners) } func buildTXParams(master *keypair.Full, masterAccount txnbuild.Account, sourceAccountSeq int64, txSequence int64) txnbuild.TransactionParams { From 661b3fb451ba186e7e87d250a650f3c0ae5c4f5c Mon Sep 17 00:00:00 2001 From: Shawn Reuland Date: Wed, 6 Apr 2022 12:11:39 -0700 Subject: [PATCH 4/4] #4305: removed formatting warnings --- .../internal/integration/transaction_preconditions_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/horizon/internal/integration/transaction_preconditions_test.go b/services/horizon/internal/integration/transaction_preconditions_test.go index ba35d74534..a8bb5fd895 100644 --- a/services/horizon/internal/integration/transaction_preconditions_test.go +++ b/services/horizon/internal/integration/transaction_preconditions_test.go @@ -1,14 +1,14 @@ package integration import ( - "strconv" - "testing" - "time" sdk "github.com/stellar/go/clients/horizonclient" "github.com/stellar/go/keypair" "github.com/stellar/go/services/horizon/internal/test/integration" "github.com/stellar/go/txnbuild" "github.com/stretchr/testify/assert" + "strconv" + "testing" + "time" ) func TestTransactionPreconditionsMinSeq(t *testing.T) {