diff --git a/pkg/protocol/engine/mempool/spenddag/spenddagv1/spender_test.go b/pkg/protocol/engine/mempool/spenddag/spenddagv1/spender_test.go index 32c6b4dab..b2bf495b2 100644 --- a/pkg/protocol/engine/mempool/spenddag/spenddagv1/spender_test.go +++ b/pkg/protocol/engine/mempool/spenddag/spenddagv1/spender_test.go @@ -249,7 +249,7 @@ func TestSpendParallel(t *testing.T) { parallelPendingTasks.WaitIsZero() lo.ForEach(lo.Keys(parallelSpenders), func(SpendAlias string) { - assert.EqualValuesf(t, sequentialSpenders[SpendAlias].PreferredInstead().ID, parallelSpenders[SpendAlias].PreferredInstead().ID, "parallel Spend %s prefers %s, but sequential Spend prefers %s", SpendAlias, parallelSpenders[SpendAlias].PreferredInstead().ID, sequentialSpenders[SpendAlias].PreferredInstead().ID) + require.EqualValuesf(t, sequentialSpenders[SpendAlias].PreferredInstead().ID, parallelSpenders[SpendAlias].PreferredInstead().ID, "parallel Spend %s prefers %s, but sequential Spend prefers %s", SpendAlias, parallelSpenders[SpendAlias].PreferredInstead().ID, sequentialSpenders[SpendAlias].PreferredInstead().ID) }) assertCorrectOrder(t, lo.Values(sequentialSpenders)...) diff --git a/pkg/testsuite/attestations.go b/pkg/testsuite/attestations.go index 0ce2aa49f..c108e0571 100644 --- a/pkg/testsuite/attestations.go +++ b/pkg/testsuite/attestations.go @@ -32,7 +32,9 @@ func (t *TestSuite) AssertAttestationsForSlot(slot iotago.SlotIndex, blocks []*b //nolint:revive err = attestationTree.Stream(func(key iotago.AccountID, att *iotago.Attestation) error { blockID, err := att.BlockID() - require.NoError(t.Testing, err) + if err != nil { + return ierrors.Wrapf(err, "failed to stream attestationTree: %s, slot: %d", node.Name, slot) + } storedAttestations = append(storedAttestations, blockID) return nil diff --git a/pkg/testsuite/storage_settings.go b/pkg/testsuite/storage_settings.go index c7e2e83df..d511572b3 100644 --- a/pkg/testsuite/storage_settings.go +++ b/pkg/testsuite/storage_settings.go @@ -3,8 +3,6 @@ package testsuite import ( "context" - "github.com/stretchr/testify/require" - "github.com/iotaledger/hive.go/ierrors" "github.com/iotaledger/iota-core/pkg/testsuite/mock" iotago "github.com/iotaledger/iota.go/v4" @@ -56,14 +54,17 @@ func (t *TestSuite) AssertCommitmentSlotIndexExists(slot iotago.SlotIndex, clien for _, client := range clients { t.Eventually(func() error { latestCommitment, err := client.CommitmentByID(context.Background(), iotago.EmptyCommitmentID) - require.NoError(t.Testing, err) + if err != nil { + return ierrors.Errorf("AssertCommitmentSlotIndexExists: %s: error loading latest commitment: %w", client.Name(), err) + } + if latestCommitment.Slot < slot { return ierrors.Errorf("AssertCommitmentSlotIndexExists: %s: commitment with at least %v not found in settings.LatestCommitment()", client.Name(), slot) } cm, err := client.CommitmentBySlot(context.Background(), slot) if err != nil { - return ierrors.Errorf("AssertCommitmentSlotIndexExists: %s: expected %v, got error %v", client.Name(), slot, err) + return ierrors.Errorf("AssertCommitmentSlotIndexExists: %s: expected %v, got error %w", client.Name(), slot, err) } if cm == nil { diff --git a/pkg/testsuite/sybilprotection.go b/pkg/testsuite/sybilprotection.go index 85da211ff..0bca507df 100644 --- a/pkg/testsuite/sybilprotection.go +++ b/pkg/testsuite/sybilprotection.go @@ -2,7 +2,6 @@ package testsuite import ( "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/iotaledger/hive.go/ierrors" "github.com/iotaledger/hive.go/lo" @@ -89,7 +88,9 @@ func (t *TestSuite) AssertSybilProtectionRegisteredValidators(epoch iotago.Epoch candidateIDs := lo.Map(candidates, func(candidate *api.ValidatorResponse) string { return candidate.AddressBech32 }) - require.NoError(t.Testing, err) + if err != nil { + return ierrors.Wrapf(err, "AssertSybilProtectionRegisteredValidators: %s: failed to get registered validators in epoch %d", node.Name, epoch) + } if !assert.ElementsMatch(t.fakeTesting, expectedAccounts, candidateIDs) { return ierrors.Errorf("AssertSybilProtectionRegisteredValidators: %s: expected %s, got %s", node.Name, expectedAccounts, candidateIDs) @@ -113,7 +114,9 @@ func (t *TestSuite) AssertSybilProtectionCandidates(epoch iotago.EpochIndex, exp candidateIDs := lo.Map(candidates, func(candidate *accounts.AccountData) iotago.AccountID { return candidate.ID }) - require.NoError(t.Testing, err) + if err != nil { + return ierrors.Wrapf(err, "AssertSybilProtectionCandidates: %s: failed to get eligible validators in epoch %d", node.Name, epoch) + } if !assert.ElementsMatch(t.fakeTesting, expectedAccounts, candidateIDs) { return ierrors.Errorf("AssertSybilProtectionCandidates: %s: expected %s, got %s", node.Name, expectedAccounts, candidateIDs) diff --git a/pkg/testsuite/testsuite.go b/pkg/testsuite/testsuite.go index 6a7bb6e68..87fd477a7 100644 --- a/pkg/testsuite/testsuite.go +++ b/pkg/testsuite/testsuite.go @@ -54,7 +54,8 @@ func WithWalletBlockIssuanceCredits(blockIssuanceCredits iotago.BlockIssuanceCre } type TestSuite struct { - Testing *testing.T + Testing *testing.T + // we use the fake testing so that actual tests don't fail if an assertion fails fakeTesting *testing.T network *mock.Network diff --git a/pkg/testsuite/transactions.go b/pkg/testsuite/transactions.go index 80ee7c702..d7333d04d 100644 --- a/pkg/testsuite/transactions.go +++ b/pkg/testsuite/transactions.go @@ -38,8 +38,6 @@ func (t *TestSuite) AssertTransaction(transaction *iotago.Transaction, node *moc return ierrors.Errorf("AssertTransaction: %s: expected Transaction type %T, got %T", node.Name, transaction, loadedTransactionMetadata.Transaction()) } - // TODO: fix this in another PR - // if !assert.Equal(t.fakeTesting, transaction.Outputs, typedTransaction.Outputs) { api := t.DefaultWallet().Client.APIForSlot(transactionID.Slot()) expected, _ := api.Encode(transaction.Outputs) actual, _ := api.Encode(typedTransaction.Outputs) diff --git a/tools/docker-network/tests/dockerframework.go b/tools/docker-network/tests/dockerframework.go index e2a0d3c76..0130f1b50 100644 --- a/tools/docker-network/tests/dockerframework.go +++ b/tools/docker-network/tests/dockerframework.go @@ -68,6 +68,8 @@ func (n *Node) AccountAddress(t *testing.T) *iotago.AccountAddress { type DockerTestFramework struct { Testing *testing.T + // we use the fake testing so that actual tests don't fail if an assertion fails + fakeTesting *testing.T nodes map[string]*Node nodesLock syncutils.RWMutex @@ -88,6 +90,7 @@ type DockerTestFramework struct { func NewDockerTestFramework(t *testing.T, opts ...options.Option[DockerTestFramework]) *DockerTestFramework { return options.Apply(&DockerTestFramework{ Testing: t, + fakeTesting: &testing.T{}, nodes: make(map[string]*Node), wallet: NewDockerWallet(t), optsWaitForSync: 5 * time.Minute, @@ -223,13 +226,19 @@ func (d *DockerTestFramework) WaitUntilFaucetHealthy() { d.Eventually(func() error { req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, d.optsFaucetURL+"/health", nil) - require.NoError(d.Testing, err) + if err != nil { + return err + } res, err := http.DefaultClient.Do(req) - require.NoError(d.Testing, err) + if err != nil { + return err + } defer res.Body.Close() - require.Equal(d.Testing, http.StatusOK, res.StatusCode) + if res.StatusCode != http.StatusOK { + return ierrors.Errorf("faucet is not healthy, status code: %d", res.StatusCode) + } return nil }, true) diff --git a/tools/docker-network/tests/utils.go b/tools/docker-network/tests/utils.go index 244ceeb50..b21f4c2b4 100644 --- a/tools/docker-network/tests/utils.go +++ b/tools/docker-network/tests/utils.go @@ -15,6 +15,7 @@ import ( "strconv" "time" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/iotaledger/hive.go/ierrors" @@ -70,8 +71,8 @@ func (d *DockerTestFramework) AssertIndexerAccount(account *mock.AccountData) { return err } - require.EqualValues(d.Testing, account.OutputID, *outputID) - require.EqualValues(d.Testing, account.Output, output) + assert.EqualValues(d.fakeTesting, account.OutputID, *outputID) + assert.EqualValues(d.fakeTesting, account.Output, output) return nil })