Skip to content

Commit

Permalink
Replace usages of cmp.Equal with assert.Equal and get rid of go-cmp d…
Browse files Browse the repository at this point in the history
…ependency
  • Loading branch information
jonastheis committed Oct 11, 2023
1 parent 9af7b01 commit 91c6998
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 28 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ replace github.com/goccy/go-graphviz => github.com/mranney-dd/go-graphviz v0.0.0
require (
github.com/goccy/go-graphviz v0.1.1
github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/google/go-cmp v0.5.9
github.com/google/uuid v1.3.1
github.com/gorilla/websocket v1.5.0
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
Expand Down
20 changes: 10 additions & 10 deletions pkg/testsuite/accounts.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package testsuite

import (
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/assert"

"github.com/iotaledger/hive.go/ierrors"
"github.com/iotaledger/iota-core/pkg/model"
Expand Down Expand Up @@ -41,7 +41,7 @@ func (t *TestSuite) AssertAccountData(accountData *accounts.AccountData, nodes .
return ierrors.Errorf("AssertAccountData: %s: accountID %s expected expiry slot %s, got %s", node.Name, accountData.ID, accountData.ExpirySlot, actualAccountData.ExpirySlot)
}

if !cmp.Equal(accountData.BlockIssuerKeys, actualAccountData.BlockIssuerKeys) {
if !assert.Equal(t.fakeTesting, accountData.BlockIssuerKeys, actualAccountData.BlockIssuerKeys) {
return ierrors.Errorf("AssertAccountData: %s: accountID %s expected pub keys %s, got %s", node.Name, accountData.ID, accountData.BlockIssuerKeys, actualAccountData.BlockIssuerKeys)
}

Expand Down Expand Up @@ -118,35 +118,35 @@ func (t *TestSuite) AssertAccountDiff(accountID iotago.AccountID, index iotago.S
return ierrors.Errorf("AssertAccountDiff: %s: expected previous output ID %s but actual %s for account %s at slot %d", node.Name, accountDiff.PreviousOutputID, actualAccountDiff.PreviousOutputID, accountID, index)
}

if !cmp.Equal(accountDiff.BlockIssuerKeysAdded, actualAccountDiff.BlockIssuerKeysAdded) {
if !assert.Equal(t.fakeTesting, accountDiff.BlockIssuerKeysAdded, actualAccountDiff.BlockIssuerKeysAdded) {
return ierrors.Errorf("AssertAccountDiff: %s: expected pub keys added %s but actual %s for account %s at slot %d", node.Name, accountDiff.BlockIssuerKeysAdded, actualAccountDiff.BlockIssuerKeysAdded, accountID, index)
}

if !cmp.Equal(accountDiff.BlockIssuerKeysRemoved, actualAccountDiff.BlockIssuerKeysRemoved) {
if !assert.Equal(t.fakeTesting, accountDiff.BlockIssuerKeysRemoved, actualAccountDiff.BlockIssuerKeysRemoved) {
return ierrors.Errorf("AssertAccountDiff: %s: expected pub keys removed %s but actual %s for account %s at slot %d", node.Name, accountDiff.BlockIssuerKeysRemoved, actualAccountDiff.BlockIssuerKeysRemoved, accountID, index)
}

if !cmp.Equal(accountDiff.StakeEndEpochChange, actualAccountDiff.StakeEndEpochChange) {
if !assert.Equal(t.fakeTesting, accountDiff.StakeEndEpochChange, actualAccountDiff.StakeEndEpochChange) {
return ierrors.Errorf("AssertAccountDiff: %s: expected new stake end epoch %d but actual %d for account %s at slot %d", node.Name, accountDiff.StakeEndEpochChange, actualAccountDiff.StakeEndEpochChange, accountID, index)
}

if !cmp.Equal(accountDiff.FixedCostChange, actualAccountDiff.FixedCostChange) {
if !assert.Equal(t.fakeTesting, accountDiff.FixedCostChange, actualAccountDiff.FixedCostChange) {
return ierrors.Errorf("AssertAccountDiff: %s: expected fixed cost change %d but actual %d for account %s at slot %d", node.Name, accountDiff.FixedCostChange, actualAccountDiff.FixedCostChange, accountID, index)
}

if !cmp.Equal(accountDiff.ValidatorStakeChange, actualAccountDiff.ValidatorStakeChange) {
if !assert.Equal(t.fakeTesting, accountDiff.ValidatorStakeChange, actualAccountDiff.ValidatorStakeChange) {
return ierrors.Errorf("AssertAccountDiff: %s: expected validator stake change epoch %d but actual %d for account %s at slot %d", node.Name, accountDiff.ValidatorStakeChange, actualAccountDiff.ValidatorStakeChange, accountID, index)
}

if !cmp.Equal(accountDiff.DelegationStakeChange, actualAccountDiff.DelegationStakeChange) {
if !assert.Equal(t.fakeTesting, accountDiff.DelegationStakeChange, actualAccountDiff.DelegationStakeChange) {
return ierrors.Errorf("AssertAccountDiff: %s: expected delegation stake change epoch %d but actual %d for account %s at slot %d", node.Name, accountDiff.DelegationStakeChange, actualAccountDiff.DelegationStakeChange, accountID, index)
}

if !cmp.Equal(accountDiff.PrevLatestSupportedVersionAndHash, actualAccountDiff.PrevLatestSupportedVersionAndHash) {
if !assert.Equal(t.fakeTesting, accountDiff.PrevLatestSupportedVersionAndHash, actualAccountDiff.PrevLatestSupportedVersionAndHash) {
return ierrors.Errorf("AssertAccountDiff: %s: expected previous latest supported protocol version change %d but actual %d for account %s at slot %d", node.Name, accountDiff.PreviousExpirySlot, actualAccountDiff.PrevLatestSupportedVersionAndHash, accountID, index)
}

if !cmp.Equal(accountDiff.NewLatestSupportedVersionAndHash, actualAccountDiff.NewLatestSupportedVersionAndHash) {
if !assert.Equal(t.fakeTesting, accountDiff.NewLatestSupportedVersionAndHash, actualAccountDiff.NewLatestSupportedVersionAndHash) {
return ierrors.Errorf("AssertAccountDiff: %s: expected new latest supported protocol version change %d but actual %d for account %s at slot %d", node.Name, accountDiff.NewLatestSupportedVersionAndHash, actualAccountDiff.NewLatestSupportedVersionAndHash, accountID, index)
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/testsuite/blocks.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package testsuite

import (
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/assert"

"github.com/iotaledger/hive.go/ds"
"github.com/iotaledger/hive.go/ierrors"
Expand All @@ -24,7 +24,7 @@ func (t *TestSuite) AssertBlock(block *blocks.Block, node *mock.Node) *model.Blo
if block.ID() != loadedBlock.ID() {
return ierrors.Errorf("AssertBlock: %s: expected %s, got %s", node.Name, block.ID(), loadedBlock.ID())
}
if !cmp.Equal(block.ModelBlock().Data(), loadedBlock.Data()) {
if !assert.Equal(t.fakeTesting, block.ModelBlock().Data(), loadedBlock.Data()) {
return ierrors.Errorf("AssertBlock: %s: expected %s, got %s", node.Name, block.ModelBlock().Data(), loadedBlock.Data())
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/testsuite/eviction.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package testsuite

import (
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/assert"

"github.com/iotaledger/hive.go/ierrors"
"github.com/iotaledger/hive.go/lo"
Expand All @@ -22,7 +22,7 @@ func (t *TestSuite) AssertActiveRootBlocks(expectedBlocks []*blocks.Block, nodes
t.Eventually(func() error {
activeRootBlocks := node.Protocol.MainEngineInstance().EvictionState.ActiveRootBlocks()

if !cmp.Equal(expectedRootBlocks, activeRootBlocks) {
if !assert.Equal(t.fakeTesting, expectedRootBlocks, activeRootBlocks) {
return ierrors.Errorf("AssertActiveRootBlocks: %s: expected %v, got %v", node.Name, expectedRootBlocks, activeRootBlocks)
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/testsuite/storage_accountdiffs.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package testsuite

import (
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/assert"

"github.com/iotaledger/hive.go/ierrors"
"github.com/iotaledger/iota-core/pkg/model"
Expand All @@ -24,8 +24,8 @@ func (t *TestSuite) AssertStorageAccountDiffs(slot iotago.SlotIndex, accountDiff
if err != nil {
return ierrors.Wrapf(err, "AssertStorageAccountDiffs: %s: error loading account diff: %s", node.Name, accountID)
}
// todo finish this, connect to other tests, is cmp enough
if !cmp.Equal(diffChange, storedDiffChange) {

if !assert.Equal(t.fakeTesting, diffChange, storedDiffChange) {
return ierrors.Errorf("AssertStorageAccountDiffs: %s: expected %v, got %v", node.Name, diffChange, storedDiffChange)
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/testsuite/storage_blocks.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package testsuite

import (
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/assert"

"github.com/iotaledger/hive.go/ierrors"
"github.com/iotaledger/iota-core/pkg/model"
Expand All @@ -24,7 +24,7 @@ func (t *TestSuite) AssertStorageBlock(block *model.Block, node *mock.Node) {
return ierrors.Errorf("AssertStorageBlock: %s: expected %s, got %s", node.Name, block.ID(), loadedBlock.ID())
}

if cmp.Equal(block.Data(), loadedBlock.Data()) {
if assert.Equal(t.fakeTesting, block.Data(), loadedBlock.Data()) {
return ierrors.Errorf("AssertStorageBlock: %s: expected %s, got %s", node.Name, block.Data(), loadedBlock.Data())
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/testsuite/storage_commitments.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package testsuite

import (
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/assert"

"github.com/iotaledger/hive.go/ierrors"
"github.com/iotaledger/iota-core/pkg/model"
Expand All @@ -20,7 +20,7 @@ func (t *TestSuite) AssertStorageCommitments(commitments []*iotago.Commitment, n
return ierrors.Wrapf(err, "AssertStorageCommitments: %s: error loading commitment: %s", node.Name, commitment.MustID())
}

if !cmp.Equal(*commitment, *storedCommitment.Commitment()) {
if !assert.Equal(t.fakeTesting, *commitment, *storedCommitment.Commitment()) {
return ierrors.Errorf("AssertStorageCommitments: %s: expected %s, got %s", node.Name, commitment, storedCommitment)
}

Expand Down Expand Up @@ -49,7 +49,7 @@ func (t *TestSuite) AssertEqualStoredCommitmentAtIndex(index iotago.SlotIndex, n
continue
}

if !cmp.Equal(*commitment.Commitment(), *storedCommitment.Commitment()) {
if !assert.Equal(t.fakeTesting, *commitment.Commitment(), *storedCommitment.Commitment()) {
return ierrors.Errorf("AssertEqualStoredCommitmentAtIndex: %s: expected %s (from %s), got %s", node.Name, commitment, commitmentNode.Name, storedCommitment)
}
}
Expand Down Expand Up @@ -78,7 +78,7 @@ func (t *TestSuite) AssertStorageCommitmentBlocks(slot iotago.SlotIndex, expecte
return ierrors.Wrapf(err, "AssertStorageCommitmentBlocks: %s: error getting committed blocks for slot: %d", node.Name, slot)
}

if !cmp.Equal(committedBlocks, expectedBlocks) {
if !assert.Equal(t.fakeTesting, committedBlocks, expectedBlocks) {
return ierrors.Errorf("AssertStorageCommitmentBlocks: %s: expected %s, got %s", node.Name, expectedBlocks, committedBlocks)
}
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/testsuite/transactions.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package testsuite

import (
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/iotaledger/hive.go/ds"
Expand All @@ -28,8 +28,8 @@ func (t *TestSuite) AssertTransaction(transaction *iotago.Transaction, node *moc
return ierrors.Errorf("AssertTransaction: %s: expected ID %s, got %s", node.Name, transactionID, loadedTransactionMetadata.ID())
}

//nolint: forcetypeassert // we are in a test and want to assert it anyway
if !cmp.Equal(transaction.TransactionEssence, loadedTransactionMetadata.Transaction().(*iotago.Transaction).TransactionEssence) {
// nolint: forcetypeassert // we are in a test and want to assert it anyway
if !assert.Equal(t.fakeTesting, transaction.TransactionEssence, loadedTransactionMetadata.Transaction().(*iotago.Transaction).TransactionEssence) {
return ierrors.Errorf("AssertTransaction: %s: expected TransactionEssence %v, got %v", node.Name, transaction.TransactionEssence, loadedTransactionMetadata.Transaction().(*iotago.Transaction).TransactionEssence)
}

Expand All @@ -38,7 +38,7 @@ 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())
}

if !cmp.Equal(transaction.Outputs, typedTransaction.Outputs) {
if !assert.Equal(t.fakeTesting, transaction.Outputs, typedTransaction.Outputs) {
return ierrors.Errorf("AssertTransaction: %s: expected Outputs %s, got %s", node.Name, transaction.Outputs, typedTransaction.Outputs)
}

Expand Down

0 comments on commit 91c6998

Please sign in to comment.