-
Notifications
You must be signed in to change notification settings - Fork 502
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
horizon: Set up protocol 19 integration tests infrastructure (#4312)
Co-authored-by: Shawn Reuland <[email protected]>
- Loading branch information
Showing
12 changed files
with
219 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
services/horizon/internal/integration/transaction_preconditions_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package integration | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stellar/go/keypair" | ||
"github.com/stellar/go/services/horizon/internal/test/integration" | ||
"github.com/stellar/go/txnbuild" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestTransactionPreconditionsMinSeq(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() | ||
currentAccountSeq, err := masterAccount.GetSequenceNumber() | ||
tt.NoError(err) | ||
|
||
// Ensure that the minSequence of the transaction is enough | ||
// but the sequence isn't | ||
txParams := buildTXParams(master, masterAccount, currentAccountSeq, currentAccountSeq+100) | ||
|
||
// this errors because the tx.seqNum is more than +1 from sourceAccoubnt.seqNum | ||
_, err = itest.SubmitTransaction(master, txParams) | ||
tt.Error(err) | ||
|
||
// Now the transaction should be submitted without problems | ||
txParams.Preconditions.MinSequenceNumber = ¤tAccountSeq | ||
itest.MustSubmitTransaction(master, txParams) | ||
} | ||
|
||
func TestTransactionPreconditionsTimeBounds(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() | ||
currentAccountSeq, err := masterAccount.GetSequenceNumber() | ||
tt.NoError(err) | ||
txParams := buildTXParams(master, masterAccount, currentAccountSeq, currentAccountSeq+1) | ||
|
||
// this errors because the min time is > current tx submit time | ||
txParams.Preconditions.TimeBounds.MinTime = time.Now().Unix() + 3600 | ||
txParams.Preconditions.TimeBounds.MaxTime = time.Now().Unix() + 7200 | ||
_, err = itest.SubmitTransaction(master, txParams) | ||
tt.Error(err) | ||
|
||
// this errors because the max time is < current tx submit time | ||
txParams.Preconditions.TimeBounds.MinTime = 0 | ||
txParams.Preconditions.TimeBounds.MaxTime = time.Now().Unix() - 3600 | ||
_, err = itest.SubmitTransaction(master, txParams) | ||
tt.Error(err) | ||
|
||
// 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) | ||
} | ||
|
||
func buildTXParams(master *keypair.Full, masterAccount txnbuild.Account, sourceAccountSeq int64, txSequence int64) txnbuild.TransactionParams { | ||
|
||
ops := []txnbuild.Operation{ | ||
&txnbuild.BumpSequence{ | ||
BumpTo: sourceAccountSeq + 10, | ||
}, | ||
} | ||
|
||
return txnbuild.TransactionParams{ | ||
SourceAccount: &txnbuild.SimpleAccount{ | ||
AccountID: masterAccount.GetAccountID(), | ||
Sequence: txSequence, | ||
}, | ||
// Phony operation to run | ||
Operations: ops, | ||
BaseFee: txnbuild.MinBaseFee, | ||
Memo: nil, | ||
Preconditions: txnbuild.Preconditions{ | ||
TimeBounds: txnbuild.NewInfiniteTimeout(), | ||
}, | ||
} | ||
} |
Oops, something went wrong.