Skip to content

Commit

Permalink
[FAIL] Extend the test blockchain with a Tx that fails script valid…
Browse files Browse the repository at this point in the history
…ation.

This commit extends the 'ModelSpec' test blockchain (an excerpt of the
real mainnet blockchain) with a transaction that is marked as having an
invalid script.

When processing this transaction, the wallet software should:

    - spend inputs within the 'collateralInputs' field
      (i.e., remove entries for "owned" inputs from the wallet's UTxO set)

    - create outputs within the 'collateralOutput' field
      (i.e., insert entries for "owned" outputs into the wallet's UTxO set)

This commit causes the following test failure:

```
Cardano.Wallet.Primitive.Model
  Compare Wallet impl. with Specification
    applyBlock matches the basic model from the specification [x]

Failures:

  test/unit/Cardano/Wallet/Primitive/ModelSpec.hs:221:9:
  1) Cardano.Wallet.Primitive.Model, Compare Wallet impl. with Specification,
     applyBlock matches the basic model from the specification
       Falsified (after 3 tests and 1 shrink):
         WalletState
            { _ourAddresses = fromList [82d81858...aebb3709]
            , _discoveredAddresses = fromList []
            }
         - input: 1st 39633666
           output:
             address: 82d81858...aebb3709
             coin: 3823755.953610
             tokens: []
         - input: 2nd 74782d63
           output:
             address: 82d81858...aebb3709
             coin: 19999.799999
             tokens: []
          /= []
```
  • Loading branch information
jonathanknowles committed Jun 21, 2022
1 parent 0cdd1b7 commit ce940ba
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions lib/core/test/unit/Cardano/Wallet/Primitive/ModelSpec.hs
Expand Up @@ -1926,6 +1926,58 @@ blockchain =
]
, delegations = []
}

-- After this point, all blocks and transactions are constructed by hand,
-- in order to simulate various interesting scenarios:

, Block
{ header = BlockHeader
{ slotNo = slot 14 20
, blockHeight = Quantity 302378
, headerHash = Hash "unused"
, parentHeaderHash = Just $ Hash "unused"
}
, transactions =
-- This transaction is marked as having an invalid script.
-- It spends a single collateral input and creates a single
-- collateral output:
[ Tx
{ txId = Hash "tx-create-collateral-output"
, fee = Just (Coin 1)
, resolvedInputs =
[ ( TxIn
{ inputId = Hash "9c6fed8fef3b296d4dee6e62ca72b180bf0ed1c13eb5f0445099b2a146235e77"
, inputIx = 0
}
, Coin 3823755953610
)
]
, resolvedCollateralInputs =
[ ( TxIn
{ inputId = Hash "9c6fed8fef3b296d4dee6e62ca72b180bf0ed1c13eb5f0445099b2a146235e77"
, inputIx = 1
}
, Coin 19999800000
)
]
, outputs =
[ TxOut
{ address = Address "\130\216\CANXB\131X\FS\147\ACKn\246.n\DLE\233Y\166)\207c\v\248\183\235\212\EOTV\243h\192\190T\150'\196\161\SOHX\RSX\FS\202>U<\156c\197&\DC3S\235C\198\245\163\204=\214fa\201\t\205\248\204\226r%\NUL\SUB\174\187\&7\t"
, tokens = coinToBundle (3823755953610 - 1)
}
]
, collateralOutput = Just
TxOut
{ address = Address "\130\216\CANXB\131X\FS\147\ACKn\246.n\DLE\233Y\166)\207c\v\248\183\235\212\EOTV\243h\192\190T\150'\196\161\SOHX\RSX\FS\202>U<\156c\197&\DC3S\235C\198\245\163\204=\214fa\201\t\205\248\204\226r%\NUL\SUB\174\187\&7\t"
, tokens = coinToBundle (19999800000 - 1)
}
, withdrawals = mempty
, metadata = Nothing
, scriptValidity = Just TxScriptInvalid
}
]
, delegations = []
}
]
where
slot e s = SlotNo $ flatSlot (EpochLength 21600) (SlotId e s)
Expand Down

0 comments on commit ce940ba

Please sign in to comment.