Skip to content

Commit

Permalink
chore: truncate time to microseconds for all tests
Browse files Browse the repository at this point in the history
Signed-off-by: Pat Losoponkul <pat.losoponkul@iohk.io>
  • Loading branch information
Pat Losoponkul authored and Anton Baliasnikov committed Oct 23, 2023
1 parent 0103fdf commit 96dbd23
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ object ConnectionRepositorySpecSuite {
maxRetries,
Some(Instant.now),
None
)
).withTruncatedTimestamp()

private def connectionRequest = ConnectionRequest(
from = DidId("did:prism:aaa"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@ 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,
walletId: WalletId,
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 =
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ object CredentialRepositorySpecSuite {
metaRetries = maxRetries,
metaNextRetry = Some(Instant.now()),
metaLastFailure = None,
)
).withTruncatedTimestamp()

private def requestCredential = RequestCredential(
from = DidId("did:prism:aaa"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ object PresentationRepositorySpecSuite {
metaRetries = maxRetries,
metaNextRetry = Some(Instant.now()),
metaLastFailure = None,
)
).withTruncatedTimestamp()

private def requestPresentation = RequestPresentation(
from = DidId("did:prism:aaa"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -12,17 +13,22 @@ 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 {

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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand All @@ -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()
}

0 comments on commit 96dbd23

Please sign in to comment.