Skip to content

Commit

Permalink
tests: add TRANS_CREATE_10 - Pending transaction expiry
Browse files Browse the repository at this point in the history
  • Loading branch information
rvl committed Oct 2, 2020
1 parent c354100 commit 776d478
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/core-integration/src/Test/Integration/Framework/DSL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ import Cardano.Wallet.Api.Types
, ApiNetworkInformation
, ApiNetworkParameters (..)
, ApiT (..)
, ApiTimeReference (..)
, ApiTransaction
, ApiTxId (ApiTxId)
, ApiUtxoStatistics (..)
Expand All @@ -180,7 +181,6 @@ import Cardano.Wallet.Api.Types
, Iso8601Time (..)
, WalletStyle (..)
, insertedAt
, time
)
import Cardano.Wallet.Primitive.AddressDerivation
( AccountingStyle (..)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import Cardano.Wallet.Api.Types
, ApiByronWallet
, ApiFee (..)
, ApiT (..)
, ApiTimeReference (..)
, ApiTransaction
, ApiTxId (..)
, ApiWallet
Expand All @@ -34,7 +35,6 @@ import Cardano.Wallet.Api.Types
, WalletStyle (..)
, insertedAt
, pendingSince
, time
)
import Cardano.Wallet.Primitive.AddressDerivation
( PaymentAddress )
Expand All @@ -43,6 +43,7 @@ import Cardano.Wallet.Primitive.AddressDerivation.Icarus
import Cardano.Wallet.Primitive.Types
( Direction (..)
, Hash (..)
, SlotNo (SlotNo)
, SortOrder (..)
, TxMetadata (..)
, TxMetadataValue (..)
Expand Down Expand Up @@ -593,6 +594,36 @@ spec = describe "SHELLEY_TRANSACTIONS" $ do
(#balance . #available)
(`shouldBe` Quantity (faucetAmt - feeEstMax - amt)) ra2

it "TRANS_CREATE_10 - Pending transaction expiry" $ \ctx -> do
(wa, wb) <- (,) <$> fixtureWallet ctx <*> fixtureWallet ctx
let amt = minUTxOValue :: Natural

payload <- mkTxPayload ctx wb amt fixturePassphrase

r <- request @(ApiTransaction n) ctx
(Link.createTransaction @'Shelley wa) Default payload

verify r
[ expectSuccess
, expectResponseCode HTTP.status202
, expectField (#direction . #getApiT) (`shouldBe` Outgoing)
, expectField (#status . #getApiT) (`shouldBe` Pending)
, expectField #expiresAt (`shouldSatisfy` isJust)
]

-- This stuff would be easier with Control.Lens...

-- Get insertion slot and out of response.
let (_, Right apiTx) = r
let (Just (ApiTimeReference _ sinceBlock)) = apiTx ^. #pendingSince
let sl = sinceBlock ^. #absoluteSlotNumber . #getApiT

-- The expected expiry slot (adds the hardcoded default ttl)
let ttl = sl + SlotNo 7200

(view #absoluteSlotNumber <$> (apiTx ^. #expiresAt))
`shouldBe` Just (ApiT ttl)

it "TRANSMETA_CREATE_01 - Transaction with metadata" $ \ctx -> do
(wa, wb) <- (,) <$> fixtureWallet ctx <*> emptyWallet ctx
let amt = (minUTxOValue :: Natural)
Expand Down Expand Up @@ -1394,7 +1425,7 @@ spec = describe "SHELLEY_TRANSACTIONS" $ do
, replicate 10 (2 * minUTxOValue)
]
txs <- listAllTransactions @n ctx w
let [Just t2, Just t1] = fmap (fmap time . insertedAt) txs
let [Just t2, Just t1] = fmap (fmap (view #time) . insertedAt) txs
let matrix :: [TestCase [ApiTransaction n]] =
[ TestCase -- 1
{ query = toQueryString
Expand Down Expand Up @@ -2412,7 +2443,7 @@ spec = describe "SHELLEY_TRANSACTIONS" $ do
:: [ApiTransaction n]
-> UTCTime
unsafeGetTransactionTime txs =
case fmap time . insertedAt <$> txs of
case fmap (view #time) . insertedAt <$> txs of
(Just t):_ -> t
_ -> error "Expected at least one transaction with a time."

Expand Down
45 changes: 45 additions & 0 deletions lib/core/test/data/Cardano/Wallet/Api/ApiSlotReference.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"seed": -7345331722963020563,
"samples": [
{
"time": "1874-08-19T08:37:41Z",
"absolute_slot_number": 14490878
},
{
"time": "1868-10-26T16:25:56.388468010449Z",
"absolute_slot_number": 5727321
},
{
"time": "1881-06-20T08:33:30Z",
"absolute_slot_number": 14662098
},
{
"time": "1895-09-06T06:00:00Z",
"absolute_slot_number": 14173193
},
{
"time": "1880-12-14T12:30:05Z",
"absolute_slot_number": 7293993
},
{
"time": "1888-07-06T01:21:19Z",
"absolute_slot_number": 1630214
},
{
"time": "1860-05-13T10:00:00Z",
"absolute_slot_number": 3275140
},
{
"time": "1908-10-11T16:19:48Z",
"absolute_slot_number": 14924467
},
{
"time": "1896-02-24T23:00:00Z",
"absolute_slot_number": 14051444
},
{
"time": "1863-03-20T13:50:09Z",
"absolute_slot_number": 1636469
}
]
}
23 changes: 14 additions & 9 deletions lib/core/test/unit/Cardano/Wallet/Api/TypesSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import Cardano.Wallet.Api.Types
, ApiPutAddressesData (..)
, ApiRelativeAddressIndex (..)
, ApiSelectCoinsData (..)
, ApiSlotReference (..)
, ApiStakePool (..)
, ApiStakePoolMetrics (..)
, ApiT (..)
Expand Down Expand Up @@ -316,6 +317,7 @@ spec = do
jsonRoundtripAndGolden $ Proxy @ApiTimeReference
jsonRoundtripAndGolden $ Proxy @ApiNetworkTip
jsonRoundtripAndGolden $ Proxy @ApiBlockReference
jsonRoundtripAndGolden $ Proxy @ApiSlotReference
jsonRoundtripAndGolden $ Proxy @ApiNetworkInformation
jsonRoundtripAndGolden $ Proxy @ApiNetworkParameters
jsonRoundtripAndGolden $ Proxy @ApiNetworkClock
Expand Down Expand Up @@ -1242,8 +1244,8 @@ instance Arbitrary ApiBlockReference where
shrink = genericShrink

instance Arbitrary ApiSlotReference where
arbitrary = genericArbitrary
shrink = genericShrink
arbitrary = ApiSlotReference <$> genUniformTime <*> arbitrary
shrink (ApiSlotReference t sl) = ApiSlotReference t <$> shrink sl

instance Arbitrary ApiNetworkTip where
arbitrary = genericArbitrary
Expand Down Expand Up @@ -1367,14 +1369,17 @@ instance Arbitrary (ApiTransaction t) where
arbitrary = do
txStatus <- arbitrary
txInsertedAt <- case txStatus of
(ApiT Pending) -> pure Nothing
(ApiT InLedger) -> arbitrary
(ApiT Expired) -> pure Nothing
ApiT Pending -> pure Nothing
ApiT InLedger -> arbitrary
ApiT Expired -> pure Nothing
txPendingSince <- case txStatus of
(ApiT Pending) -> arbitrary
(ApiT InLedger) -> pure Nothing
(ApiT Expired) -> arbitrary
let txExpiresAt = txInsertedAt
ApiT Pending -> arbitrary
ApiT InLedger -> pure Nothing
ApiT Expired -> arbitrary
txExpiresAt <- case txStatus of
ApiT Pending -> arbitrary
ApiT InLedger -> pure Nothing
ApiT Expired -> Just <$> arbitrary

ApiTransaction
<$> arbitrary
Expand Down

0 comments on commit 776d478

Please sign in to comment.