From 96dbd23c721a5054f8492d6540a7f2f5b73ce333 Mon Sep 17 00:00:00 2001 From: Pat Losoponkul Date: Wed, 18 Oct 2023 15:53:26 +0700 Subject: [PATCH] chore: truncate time to microseconds for all tests Signed-off-by: Pat Losoponkul --- .../atala/connect/core/model/ConnectionRecord.scala | 9 ++++++++- .../repository/ConnectionRepositorySpecSuite.scala | 2 +- .../event/notification/EventNotificationConfig.scala | 8 ++++++-- .../pollux/core/model/IssueCredentialRecord.scala | 8 ++++++++ .../atala/pollux/core/model/PresentationRecord.scala | 11 ++++++++++- .../repository/CredentialRepositorySpecSuite.scala | 2 +- .../repository/PresentationRepositorySpecSuite.scala | 2 +- .../pollux/sql/model/db/CredentialDefinition.scala | 4 ++++ .../atala/pollux/sql/model/db/CredentialSchema.scala | 5 +++++ .../sql/CredentialDefinitionSqlIntegrationSpec.scala | 2 +- .../sql/CredentialSchemaSqlIntegrationSpec.scala | 2 +- .../atala/pollux/vc/jwt/JWTVerificationTest.scala | 6 +++++- .../io/iohk/atala/agent/walletapi/model/Entity.scala | 12 +++++++++--- .../io/iohk/atala/agent/walletapi/model/Wallet.scala | 9 +++++++-- 14 files changed, 67 insertions(+), 15 deletions(-) diff --git a/connect/lib/core/src/main/scala/io/iohk/atala/connect/core/model/ConnectionRecord.scala b/connect/lib/core/src/main/scala/io/iohk/atala/connect/core/model/ConnectionRecord.scala index b7d3f29036..b2c7964664 100644 --- a/connect/lib/core/src/main/scala/io/iohk/atala/connect/core/model/ConnectionRecord.scala +++ b/connect/lib/core/src/main/scala/io/iohk/atala/connect/core/model/ConnectionRecord.scala @@ -5,6 +5,7 @@ import io.iohk.atala.mercury.protocol.connection.{ConnectionRequest, ConnectionR import io.iohk.atala.mercury.protocol.invitation.v2.Invitation import java.time.Instant +import java.time.temporal.ChronoUnit import java.util.UUID /** @param id @@ -38,7 +39,13 @@ case class ConnectionRecord( metaRetries: Int, metaNextRetry: Option[Instant], metaLastFailure: Option[String] -) +) { + def withTruncatedTimestamp(unit: ChronoUnit = ChronoUnit.MICROS): ConnectionRecord = copy( + createdAt = createdAt.truncatedTo(unit), + updatedAt = updatedAt.map(_.truncatedTo(unit)), + metaNextRetry = metaNextRetry.map(_.truncatedTo(unit)) + ) +} object ConnectionRecord { enum Role: diff --git a/connect/lib/core/src/test/scala/io/iohk/atala/connect/core/repository/ConnectionRepositorySpecSuite.scala b/connect/lib/core/src/test/scala/io/iohk/atala/connect/core/repository/ConnectionRepositorySpecSuite.scala index 0049d0e990..5eef1f5974 100644 --- a/connect/lib/core/src/test/scala/io/iohk/atala/connect/core/repository/ConnectionRepositorySpecSuite.scala +++ b/connect/lib/core/src/test/scala/io/iohk/atala/connect/core/repository/ConnectionRepositorySpecSuite.scala @@ -36,7 +36,7 @@ object ConnectionRepositorySpecSuite { maxRetries, Some(Instant.now), None - ) + ).withTruncatedTimestamp() private def connectionRequest = ConnectionRequest( from = DidId("did:prism:aaa"), diff --git a/event-notification/src/main/scala/io/iohk/atala/event/notification/EventNotificationConfig.scala b/event-notification/src/main/scala/io/iohk/atala/event/notification/EventNotificationConfig.scala index b15bc647b5..39ce4108c9 100644 --- a/event-notification/src/main/scala/io/iohk/atala/event/notification/EventNotificationConfig.scala +++ b/event-notification/src/main/scala/io/iohk/atala/event/notification/EventNotificationConfig.scala @@ -7,6 +7,7 @@ import zio.* import java.net.URL import java.time.Instant import java.util.UUID +import java.time.temporal.ChronoUnit final case class EventNotificationConfig( id: UUID, @@ -14,7 +15,10 @@ final case class EventNotificationConfig( url: URL, customHeaders: Map[String, String], createdAt: Instant -) +) { + def withTruncatedTimestamp(unit: ChronoUnit = ChronoUnit.MICROS): EventNotificationConfig = + copy(createdAt = createdAt.truncatedTo(unit)) +} object EventNotificationConfig { def apply(walletId: WalletId, url: URL, customHeaders: Map[String, String] = Map.empty): EventNotificationConfig = @@ -24,7 +28,7 @@ object EventNotificationConfig { url = url, customHeaders = customHeaders, createdAt = Instant.now - ) + ).withTruncatedTimestamp() def applyWallet(url: URL, customHeaders: Map[String, String]): URIO[WalletAccessContext, EventNotificationConfig] = ZIO.serviceWith[WalletAccessContext](ctx => apply(ctx.walletId, url, customHeaders)) diff --git a/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/model/IssueCredentialRecord.scala b/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/model/IssueCredentialRecord.scala index b867373281..a232e39848 100644 --- a/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/model/IssueCredentialRecord.scala +++ b/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/model/IssueCredentialRecord.scala @@ -13,6 +13,7 @@ import io.iohk.atala.pollux.anoncreds.CredentialRequestMetadata import io.iohk.atala.pollux.core.model.IssueCredentialRecord.* import java.time.Instant +import java.time.temporal.ChronoUnit import java.util.UUID final case class IssueCredentialRecord( @@ -57,7 +58,14 @@ final case class IssueCredentialRecord( case CredentialFormat.AnonCreds => (IssueCredentialIssuedFormat.Anoncred, data) } + def withTruncatedTimestamp(unit: ChronoUnit = ChronoUnit.MICROS): IssueCredentialRecord = + copy( + createdAt = createdAt.truncatedTo(unit), + updatedAt = updatedAt.map(_.truncatedTo(unit)), + metaNextRetry = metaNextRetry.map(_.truncatedTo(unit)), + ) } + final case class ValidIssuedCredentialRecord( id: DidCommID, issuedCredentialRaw: Option[String], diff --git a/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/model/PresentationRecord.scala b/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/model/PresentationRecord.scala index eb2a93d15f..60f35f11ae 100644 --- a/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/model/PresentationRecord.scala +++ b/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/model/PresentationRecord.scala @@ -4,7 +4,9 @@ import io.iohk.atala.mercury.protocol.presentproof.ProposePresentation import io.iohk.atala.mercury.protocol.presentproof.RequestPresentation import io.iohk.atala.mercury.protocol.presentproof.Presentation import io.iohk.atala.mercury.model.DidId + import java.time.Instant +import java.time.temporal.ChronoUnit final case class PresentationRecord( id: DidCommID, @@ -24,7 +26,14 @@ final case class PresentationRecord( metaRetries: Int, metaNextRetry: Option[Instant], metaLastFailure: Option[String], -) +) { + def withTruncatedTimestamp(unit: ChronoUnit = ChronoUnit.MICROS): PresentationRecord = + copy( + createdAt = createdAt.truncatedTo(unit), + updatedAt = updatedAt.map(_.truncatedTo(unit)), + metaNextRetry = metaNextRetry.map(_.truncatedTo(unit)), + ) +} object PresentationRecord { diff --git a/pollux/lib/core/src/test/scala/io/iohk/atala/pollux/core/repository/CredentialRepositorySpecSuite.scala b/pollux/lib/core/src/test/scala/io/iohk/atala/pollux/core/repository/CredentialRepositorySpecSuite.scala index 21219a6366..b363446d36 100644 --- a/pollux/lib/core/src/test/scala/io/iohk/atala/pollux/core/repository/CredentialRepositorySpecSuite.scala +++ b/pollux/lib/core/src/test/scala/io/iohk/atala/pollux/core/repository/CredentialRepositorySpecSuite.scala @@ -39,7 +39,7 @@ object CredentialRepositorySpecSuite { metaRetries = maxRetries, metaNextRetry = Some(Instant.now()), metaLastFailure = None, - ) + ).withTruncatedTimestamp() private def requestCredential = RequestCredential( from = DidId("did:prism:aaa"), diff --git a/pollux/lib/core/src/test/scala/io/iohk/atala/pollux/core/repository/PresentationRepositorySpecSuite.scala b/pollux/lib/core/src/test/scala/io/iohk/atala/pollux/core/repository/PresentationRepositorySpecSuite.scala index f81e509345..f1e0ed5b7d 100644 --- a/pollux/lib/core/src/test/scala/io/iohk/atala/pollux/core/repository/PresentationRepositorySpecSuite.scala +++ b/pollux/lib/core/src/test/scala/io/iohk/atala/pollux/core/repository/PresentationRepositorySpecSuite.scala @@ -34,7 +34,7 @@ object PresentationRepositorySpecSuite { metaRetries = maxRetries, metaNextRetry = Some(Instant.now()), metaLastFailure = None, - ) + ).withTruncatedTimestamp() private def requestPresentation = RequestPresentation( from = DidId("did:prism:aaa"), diff --git a/pollux/lib/sql-doobie/src/main/scala/io/iohk/atala/pollux/sql/model/db/CredentialDefinition.scala b/pollux/lib/sql-doobie/src/main/scala/io/iohk/atala/pollux/sql/model/db/CredentialDefinition.scala index c9ef7e5ceb..224c0a81c9 100644 --- a/pollux/lib/sql-doobie/src/main/scala/io/iohk/atala/pollux/sql/model/db/CredentialDefinition.scala +++ b/pollux/lib/sql-doobie/src/main/scala/io/iohk/atala/pollux/sql/model/db/CredentialDefinition.scala @@ -8,6 +8,7 @@ import io.iohk.atala.pollux.core.model.schema.{CorrectnessProof, Definition} import io.iohk.atala.shared.models.WalletId import java.time.OffsetDateTime +import java.time.temporal.ChronoUnit import java.util.UUID case class CredentialDefinition( @@ -29,6 +30,9 @@ case class CredentialDefinition( walletId: WalletId ) { lazy val uniqueConstraintKey = author + name + version + + def withTruncatedTimestamp(unit: ChronoUnit = ChronoUnit.MICROS): CredentialDefinition = + copy(authored = authored.truncatedTo(unit)) } object CredentialDefinition { diff --git a/pollux/lib/sql-doobie/src/main/scala/io/iohk/atala/pollux/sql/model/db/CredentialSchema.scala b/pollux/lib/sql-doobie/src/main/scala/io/iohk/atala/pollux/sql/model/db/CredentialSchema.scala index afe7066033..54e4dfde32 100644 --- a/pollux/lib/sql-doobie/src/main/scala/io/iohk/atala/pollux/sql/model/db/CredentialSchema.scala +++ b/pollux/lib/sql-doobie/src/main/scala/io/iohk/atala/pollux/sql/model/db/CredentialSchema.scala @@ -8,6 +8,7 @@ import io.iohk.atala.pollux.core.model.schema.Schema import io.iohk.atala.shared.models.WalletId import java.time.OffsetDateTime +import java.time.temporal.ChronoUnit import java.util.UUID case class CredentialSchema( @@ -24,6 +25,10 @@ case class CredentialSchema( walletId: WalletId ) { lazy val uniqueConstraintKey = author + name + version + + def withTruncatedTimestamp(unit: ChronoUnit = ChronoUnit.MICROS): CredentialSchema = + copy(authored = authored.truncatedTo(unit)) + } object CredentialSchema { diff --git a/pollux/lib/sql-doobie/src/test/scala/io/iohk/atala/pollux/sql/CredentialDefinitionSqlIntegrationSpec.scala b/pollux/lib/sql-doobie/src/test/scala/io/iohk/atala/pollux/sql/CredentialDefinitionSqlIntegrationSpec.scala index e959135ce6..8e4b55443f 100644 --- a/pollux/lib/sql-doobie/src/test/scala/io/iohk/atala/pollux/sql/CredentialDefinitionSqlIntegrationSpec.scala +++ b/pollux/lib/sql-doobie/src/test/scala/io/iohk/atala/pollux/sql/CredentialDefinitionSqlIntegrationSpec.scala @@ -110,7 +110,7 @@ object CredentialDefinitionSqlIntegrationSpec extends ZIOSpecDefault with Postgr signatureType = signatureType, supportRevocation = supportRevocation, walletId = walletId - ) + ).withTruncatedTimestamp() private val unique = mutable.Set.empty[String] val credentialDefinitionUnique = for { diff --git a/pollux/lib/sql-doobie/src/test/scala/io/iohk/atala/pollux/sql/CredentialSchemaSqlIntegrationSpec.scala b/pollux/lib/sql-doobie/src/test/scala/io/iohk/atala/pollux/sql/CredentialSchemaSqlIntegrationSpec.scala index 58f8b59100..02d8009d62 100644 --- a/pollux/lib/sql-doobie/src/test/scala/io/iohk/atala/pollux/sql/CredentialSchemaSqlIntegrationSpec.scala +++ b/pollux/lib/sql-doobie/src/test/scala/io/iohk/atala/pollux/sql/CredentialSchemaSqlIntegrationSpec.scala @@ -88,7 +88,7 @@ object CredentialSchemaSqlIntegrationSpec extends ZIOSpecDefault, PostgresTestCo authored = authored, tags = tags, walletId = walletId - ) + ).withTruncatedTimestamp() private val unique = mutable.Set.empty[String] val schemaUnique = for { diff --git a/pollux/lib/vc-jwt/src/test/scala/io/iohk/atala/pollux/vc/jwt/JWTVerificationTest.scala b/pollux/lib/vc-jwt/src/test/scala/io/iohk/atala/pollux/vc/jwt/JWTVerificationTest.scala index 99ae747e12..fe16e9ef64 100644 --- a/pollux/lib/vc-jwt/src/test/scala/io/iohk/atala/pollux/vc/jwt/JWTVerificationTest.scala +++ b/pollux/lib/vc-jwt/src/test/scala/io/iohk/atala/pollux/vc/jwt/JWTVerificationTest.scala @@ -1,7 +1,8 @@ package io.iohk.atala.pollux.vc.jwt -import com.nimbusds.jose.jwk.{Curve, ECKey} +import com.nimbusds.jose.crypto.bc.BouncyCastleProviderSingleton import com.nimbusds.jose.jwk.gen.ECKeyGenerator +import com.nimbusds.jose.jwk.{Curve, ECKey} import io.circe.* import io.circe.syntax.* import io.iohk.atala.castor.core.model.did.VerificationRelationship @@ -10,10 +11,13 @@ import zio.* import zio.test.* import zio.test.Assertion.* +import java.security.Security import java.time.Instant object JWTVerificationTest extends ZIOSpecDefault { + Security.insertProviderAt(BouncyCastleProviderSingleton.getInstance(), 2) + case class IssuerWithKey(issuer: Issuer, key: ECKey) private def createUser(did: DID): IssuerWithKey = { diff --git a/prism-agent/service/wallet-api/src/main/scala/io/iohk/atala/agent/walletapi/model/Entity.scala b/prism-agent/service/wallet-api/src/main/scala/io/iohk/atala/agent/walletapi/model/Entity.scala index 08f87d76eb..1f88ba1e65 100644 --- a/prism-agent/service/wallet-api/src/main/scala/io/iohk/atala/agent/walletapi/model/Entity.scala +++ b/prism-agent/service/wallet-api/src/main/scala/io/iohk/atala/agent/walletapi/model/Entity.scala @@ -4,6 +4,7 @@ import io.iohk.atala.shared.models.{WalletAccessContext, WalletId} import zio.{ULayer, ZLayer} import java.time.Instant +import java.time.temporal.ChronoUnit import java.util.UUID trait BaseEntity { @@ -12,6 +13,8 @@ trait BaseEntity { case class Entity(id: UUID, name: String, walletId: UUID, createdAt: Instant, updatedAt: Instant) extends BaseEntity { def withUpdatedAt(updatedAt: Instant = Instant.now()): Entity = copy(updatedAt = updatedAt) + def withTruncatedTimestamp(unit: ChronoUnit = ChronoUnit.MICROS): Entity = + copy(createdAt = createdAt.truncatedTo(unit), updatedAt.truncatedTo(unit)) } object Entity { @@ -19,10 +22,13 @@ object Entity { val ZeroWalletId: UUID = WalletId.default.toUUID def apply(id: UUID, name: String, walletId: UUID): Entity = - Entity(id, name, walletId, Instant.now(), Instant.now()) + Entity(id, name, walletId, Instant.now(), Instant.now()).withTruncatedTimestamp() + def apply(name: String, walletId: UUID): Entity = - apply(UUID.randomUUID(), name, walletId, Instant.now(), Instant.now()) - def apply(name: String): Entity = Entity(UUID.randomUUID(), name, ZeroWalletId, Instant.now(), Instant.now()) + apply(UUID.randomUUID(), name, walletId, Instant.now(), Instant.now()).withTruncatedTimestamp() + + def apply(name: String): Entity = + Entity(UUID.randomUUID(), name, ZeroWalletId, Instant.now(), Instant.now()).withTruncatedTimestamp() val Default = Entity( diff --git a/prism-agent/service/wallet-api/src/main/scala/io/iohk/atala/agent/walletapi/model/Wallet.scala b/prism-agent/service/wallet-api/src/main/scala/io/iohk/atala/agent/walletapi/model/Wallet.scala index ed4dfd9af6..6e22772f13 100644 --- a/prism-agent/service/wallet-api/src/main/scala/io/iohk/atala/agent/walletapi/model/Wallet.scala +++ b/prism-agent/service/wallet-api/src/main/scala/io/iohk/atala/agent/walletapi/model/Wallet.scala @@ -3,6 +3,7 @@ package io.iohk.atala.agent.walletapi.model import io.iohk.atala.shared.models.WalletId import java.time.Instant +import java.time.temporal.ChronoUnit final case class Wallet( id: WalletId, @@ -11,6 +12,10 @@ final case class Wallet( updatedAt: Instant ) { def withUpdatedAt(updatedAt: Instant): Wallet = copy(updatedAt = updatedAt) + def withTruncatedTimestamp(unit: ChronoUnit = ChronoUnit.MICROS): Wallet = copy( + createdAt = createdAt.truncatedTo(unit), + updatedAt = updatedAt.truncatedTo(unit) + ) } object Wallet { @@ -21,8 +26,8 @@ object Wallet { name = name, createdAt = now, updatedAt = now, - ) + ).withTruncatedTimestamp() } - def apply(name: String): Wallet = apply(name, WalletId.random) + def apply(name: String): Wallet = apply(name, WalletId.random).withTruncatedTimestamp() }