Skip to content

Commit

Permalink
Fix matchInputOutput's pubkey case with datum #295 (#308)
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgenii Akentev authored Feb 10, 2022
1 parent 3412d47 commit dc04b54
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
25 changes: 23 additions & 2 deletions plutus-contract/test/Spec/Contract.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ import Plutus.Contract.State qualified as State
import Plutus.Contract.Test (Shrinking (DoShrink, DontShrink), TracePredicate, assertAccumState, assertContractError,
assertDone, assertInstanceLog, assertNoFailedTransactions, assertResumableResult,
assertUserLog, checkEmulatorFails, checkPredicateOptions, defaultCheckOptions,
endpointAvailable, minLogLevel, mockWalletPaymentPubKeyHash, not, w1, w2, waitingForSlot,
walletFundsChange, (.&&.))
endpointAvailable, minLogLevel, mockWalletPaymentPubKeyHash, not, w1, w2, w3,
waitingForSlot, walletFundsChange, (.&&.))
import Plutus.Contract.Types (ResumableResult (ResumableResult, _finalState), responses)
import Plutus.Contract.Util (loopM)
import Plutus.Trace qualified as Trace
Expand Down Expand Up @@ -229,6 +229,27 @@ tests =
_ <- activateContract w1 c tag
void (Trace.waitNSlots 2)

-- verify that 'matchInputOutput' doesn't thrown 'InOutTypeMismatch' error
-- in case of two transactions with 'mustPayWithDatumToPubKey'
, let c1 :: Contract [Maybe DatumHash] Schema ContractError () = do
let w2PubKeyHash = mockWalletPaymentPubKeyHash w2
let payment = Constraints.mustPayWithDatumToPubKey w2PubKeyHash datum1 (Ada.adaValueOf 10)
void $ submitTx payment
c2 :: Contract [Maybe DatumHash] Schema ContractError () = do
let w3PubKeyHash = mockWalletPaymentPubKeyHash w3
let payment = Constraints.mustPayWithDatumToPubKey w3PubKeyHash datum2 (Ada.adaValueOf 50)
void $ submitTx payment

datum1 = Datum $ PlutusTx.toBuiltinData (23 :: Integer)
datum2 = Datum $ PlutusTx.toBuiltinData (42 :: Integer)

in run "mustPayWithDatumToPubKey doesn't throw 'InOutTypeMismatch' error"
( assertNoFailedTransactions ) $ do
_ <- activateContract w1 c1 tag
void (Trace.waitNSlots 2)
_ <- activateContract w2 c2 tag
void (Trace.waitNSlots 2)

, let c :: Contract [TxOutStatus] Schema ContractError () = do
-- Submit a payment tx of 10 lovelace to W2.
let w2PubKeyHash = mockWalletPaymentPubKeyHash w2
Expand Down
2 changes: 1 addition & 1 deletion plutus-ledger/src/Ledger/Index.hs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ matchInputOutput txid mp txin txo = case (txInType txin, txOutDatumHash txo, txO
unless (validatorHash v == vh) $ throwError $ InvalidScriptHash v vh

pure $ ScriptMatch (txInRef txin) v r d
(Just ConsumePublicKeyAddress, Nothing, Address{addressCredential=PubKeyCredential pkh}) ->
(Just ConsumePublicKeyAddress, _, Address{addressCredential=PubKeyCredential pkh}) ->
let sigMatches = flip fmap (Map.toList mp) $ \(pk,sig) ->
if pubKeyHash pk == pkh
then Just (PubKeyMatch txid pk sig)
Expand Down

0 comments on commit dc04b54

Please sign in to comment.