@@ -71,6 +71,8 @@ import Concordium.Types.Option
7171import Concordium.Types.Parameters
7272import Concordium.Types.TransactionOutcomes
7373import Concordium.Types.Transactions
74+ import Concordium.Types.Updates
75+ import Concordium.Utils
7476
7577import Concordium.GlobalState.Transactions
7678import Concordium.KonsensusV1.Transactions
@@ -329,8 +331,8 @@ dummyAccountAddress = fst $ randomAccountAddress (mkStdGen 42)
329331-- relation to the tree state in this test, hence
330332-- when processed it will fail on looking up the sender.
331333-- Note. that the signature is not correct either.
332- dummyTransaction :: Transaction
333- dummyTransaction =
334+ dummyNormalTransaction :: Transaction
335+ dummyNormalTransaction =
334336 addMetadata NormalTransaction 0 $
335337 makeAccountTransaction
336338 dummyTransactionSignature
@@ -347,9 +349,73 @@ dummyTransaction =
347349 }
348350 payload = encodePayload $ Transfer dummyAccountAddress 10
349351
350- -- | The block item for 'dummyTransaction'.
351- dummyTransactionBI :: BlockItem
352- dummyTransactionBI = normalTransaction dummyTransaction
352+ -- | A dummy update instruction.
353+ dummyUpdateInstruction :: TransactionTime -> WithMetadata UpdateInstruction
354+ dummyUpdateInstruction effTime =
355+ addMetadata ChainUpdate 0 $
356+ makeUpdateInstruction
357+ RawUpdateInstruction
358+ { ruiSeqNumber = 1 ,
359+ ruiEffectiveTime = effTime,
360+ ruiTimeout = 2 ,
361+ ruiPayload = cplt
362+ }
363+ (Map. singleton 0 dummyAuthorizationKeyPair)
364+ where
365+ cplt =
366+ CreatePLTUpdatePayload $
367+ CreatePLT
368+ { _cpltTokenId = TokenId " dummyToken" ,
369+ _cpltTokenModule = TokenModuleRef $ Hash. hash " dummyToken" ,
370+ _cpltDecimals = 4 ,
371+ _cpltInitializationParameters = TokenParameter " "
372+ }
373+
374+ -- | The block item for 'dummyNormalTransaction'.
375+ dummyNormalTransactionBI :: BlockItem
376+ dummyNormalTransactionBI = normalTransaction dummyNormalTransaction
377+
378+ -- | The block item for 'dummyUpdateInstruction'.
379+ dummyChainUpdateBI :: TransactionTime -> BlockItem
380+ dummyChainUpdateBI effTime = chainUpdate $ dummyUpdateInstruction effTime
381+
382+ -- | Test for transaction verification
383+ testTransactionVerification ::
384+ forall pv .
385+ (IsConsensusV1 pv , IsProtocolVersion pv , PVSupportsPLT pv ) =>
386+ SProtocolVersion pv ->
387+ Spec
388+ testTransactionVerification _ = describe " transaction verification" $ do
389+ it " ChainUpdate: CreatePLT: Ok" $ do
390+ (verResult, _) <- runMyTestMonad @ pv myIdentityProviders theTime $
391+ do
392+ t <- utcTimeToTimestamp <$> currentTime
393+ ctx <- getCtx
394+ verifyBlockItem t (dummyChainUpdateBI 0 ) ctx
395+ assertEqual
396+ " A correct transaction should be verified"
397+ (TVer. Ok TVer. ChainUpdateSuccess {keysHash = getHash (dummyKeyCollection @ (AuthorizationsVersionFor pv )), seqNumber = 1 })
398+ verResult
399+ it " ChainUpdate: CreatePLT: Non-zero effective time for CreatePLT" $ do
400+ (verResult, _) <- runMyTestMonad @ pv myIdentityProviders theTime $
401+ do
402+ t <- utcTimeToTimestamp <$> currentTime
403+ ctx <- getCtx
404+ verifyBlockItem t (dummyChainUpdateBI 1 ) ctx
405+ assertEqual
406+ " A CreatePLT update with non-zero effective time should be rejected"
407+ (TVer. NotOk TVer. ChainUpdateEffectiveTimeNonZeroForCreatePLT )
408+ verResult
409+ where
410+ -- Create a context suitable for verifying a transaction within a 'Individual' context.
411+ getCtx = do
412+ _ctxBs <- bpState <$> gets' _lastFinalized
413+ let chainParams = dummyChainParameters @ (ChainParametersVersionFor pv )
414+ let _ctxMaxBlockEnergy = chainParams ^. cpConsensusParameters . cpBlockEnergyLimit
415+ return $! Context {_ctxTransactionOrigin = TVer. Individual , .. }
416+
417+ theTime :: UTCTime
418+ theTime = posixSecondsToUTCTime 1 -- after genesis
353419
354420-- | Testing various cases for processing a block item individually.
355421testProcessBlockItem ::
@@ -384,7 +450,7 @@ testProcessBlockItem _ = describe "processBlockItem" $ do
384450 it " MaybeOk transaction" $ do
385451 -- We use a normal transfer transaction here with an invalid sender as it will yield a
386452 -- 'MaybeOk' verification result.
387- (pbiRes, sd') <- runMyTestMonad @ pv dummyIdentityProviders theTime (processBlockItem dummyTransactionBI )
453+ (pbiRes, sd') <- runMyTestMonad @ pv dummyIdentityProviders theTime (processBlockItem dummyNormalTransactionBI )
388454 assertEqual
389455 " The credential deployment should be rejected (the identity provider has correct id but wrong keys used for the credential deployment)"
390456 (NotAdded $ TVer. MaybeOk $ TVer. NormalTransactionInvalidSender dummyAccountAddress)
@@ -454,7 +520,7 @@ testProcessBlockItems sProtocolVersion = describe "processBlockItems" $ do
454520 it " A non verifiable transaction first in the block makes it fail and stop processing the rest" $ do
455521 (processed, sd') <-
456522 runMyTestMonad dummyIdentityProviders theTime $
457- processBlockItems (blockToProcess [dummyCredentialDeployment, dummyTransactionBI ]) =<< _lastFinalized <$> get
523+ processBlockItems (blockToProcess [dummyCredentialDeployment, dummyNormalTransactionBI ]) =<< _lastFinalized <$> get
458524 assertBool
459525 " Block should not have been successfully processed"
460526 (null processed)
@@ -465,7 +531,7 @@ testProcessBlockItems sProtocolVersion = describe "processBlockItems" $ do
465531 it " A non verifiable transaction last in the block makes it fail but the valid ones have been put into the state." $ do
466532 (processed, sd') <-
467533 runMyTestMonad dummyIdentityProviders theTime $
468- processBlockItems (blockToProcess [dummyTransactionBI , dummyCredentialDeployment]) =<< _lastFinalized <$> get
534+ processBlockItems (blockToProcess [dummyNormalTransactionBI , dummyCredentialDeployment]) =<< _lastFinalized <$> get
469535 assertBool
470536 " Block should not have been successfully processed"
471537 (null processed)
@@ -476,7 +542,7 @@ testProcessBlockItems sProtocolVersion = describe "processBlockItems" $ do
476542 it " A block consisting of verifiable transactions only is accepted" $ do
477543 (processed, sd') <-
478544 runMyTestMonad myIdentityProviders theTime $
479- processBlockItems (blockToProcess [dummyTransactionBI , dummyCredentialDeployment]) =<< _lastFinalized <$> get
545+ processBlockItems (blockToProcess [dummyNormalTransactionBI , dummyCredentialDeployment]) =<< _lastFinalized <$> get
480546 assertBool
481547 " Block should have been successfully processed"
482548 (isJust processed)
@@ -550,3 +616,6 @@ tests = describe "KonsensusV1.TransactionProcessing" $ do
550616 testProcessBlockItem spv
551617 describe " Batch transaction processing" $ do
552618 testProcessBlockItems spv
619+ describe " P9" $ do
620+ describe " Transaction verification" $
621+ testTransactionVerification SP9
0 commit comments