Skip to content

Commit

Permalink
Merge branch 'main' into publish-solidity-contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
dwertent authored Feb 20, 2025
2 parents ab4c6de + 024df22 commit b94120f
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions core/go/internal/privatetxnmgr/private_txn_mgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1887,7 +1887,7 @@ func TestPrivateTxManagerDependantTransactionEndorsedOutOfOrder(t *testing.T) {
}
}).Times(2).Return(nil)

sentEndorsementRequest := make(chan string, 1)
sentEndorsementRequest := make(chan string, 2)
aliceEngineMocks.transportManager.On("Send", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Run(func(args mock.Arguments) {
send := args.Get(1).(*components.FireAndForgetMessageSend)
endorsementRequest := &pbEngine.EndorsementRequest{}
Expand All @@ -1896,9 +1896,9 @@ func TestPrivateTxManagerDependantTransactionEndorsedOutOfOrder(t *testing.T) {
log.L(ctx).Errorf("Failed to unmarshal endorsement request: %s", err)
return
}

log.L(ctx).Debugf("Sending endorsement request for %s", endorsementRequest.IdempotencyKey)
sentEndorsementRequest <- endorsementRequest.IdempotencyKey
}).Return(nil).Maybe()
}).Times(2).Return(nil)

aliceEngineMocks.domainSmartContract.On("EndorseTransaction", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(&components.EndorsementResult{
Result: prototk.EndorseTransactionResponse_SIGN,
Expand Down Expand Up @@ -1943,6 +1943,7 @@ func TestPrivateTxManagerDependantTransactionEndorsedOutOfOrder(t *testing.T) {

err := aliceEngine.Start()
require.NoError(t, err)
defer aliceEngine.Stop()

tx1 := &components.ValidatedTransaction{
ResolvedTransaction: components.ResolvedTransaction{
Expand Down Expand Up @@ -2012,9 +2013,20 @@ func TestPrivateTxManagerDependantTransactionEndorsedOutOfOrder(t *testing.T) {
attestationResultAny, err := anypb.New(&attestationResult)
require.NoError(t, err)

//wait for both transactions to send an endorsement request each
idempotencyKey1 := <-sentEndorsementRequest
idempotencyKey2 := <-sentEndorsementRequest
// Wait for both transactions to send an endorsement request each with timeout
var idempotencyKey1, idempotencyKey2 string
select {
case idempotencyKey1 = <-sentEndorsementRequest:
// Proceed with key
case <-time.After(30 * time.Second):
t.Fatal("Timed out waiting for first endorsement request")
}
select {
case idempotencyKey2 = <-sentEndorsementRequest:
// Proceed with key
case <-time.After(30 * time.Second):
t.Fatal("Timed out waiting for second endorsement request")
}

// endorse transaction 2 before 1 and check that 2 is not dispatched before 1
endorsementResponse2 := &pbEngine.EndorsementResponse{
Expand Down Expand Up @@ -2069,10 +2081,10 @@ func TestPrivateTxManagerDependantTransactionEndorsedOutOfOrder(t *testing.T) {
// at this point we should get a flush of the states
dcFlushed := mockDCFlushWithWaiter(aliceEngineMocks)

status := pollForStatus(ctx, t, "dispatched", aliceEngine, domainAddressString, testTransactionID1.String(), 200*time.Second)
status := pollForStatus(ctx, t, "dispatched", aliceEngine, domainAddressString, testTransactionID1.String(), 30*time.Second)
assert.Equal(t, "dispatched", status)

status = pollForStatus(ctx, t, "dispatched", aliceEngine, domainAddressString, testTransactionID2.String(), 200*time.Second)
status = pollForStatus(ctx, t, "dispatched", aliceEngine, domainAddressString, testTransactionID2.String(), 30*time.Second)
assert.Equal(t, "dispatched", status)

<-dcFlushed
Expand Down

0 comments on commit b94120f

Please sign in to comment.