Skip to content

Commit

Permalink
remove redundant cases & fix fixture wallet sharing common funding UTxOs
Browse files Browse the repository at this point in the history
    It's a bit fucked up. Since the scenario is using fixtureWallet, the
    UtxO from the wallet comes from one of the fixture transaction made
    when initializing the cluster. There are many pre-funded fixture
    wallets with 10 UTxO, but in order not to spend 10 days funding them
    all, the cluster generate pretty large transaction with ~100
    outputs. So a single fixture transaction funds about 10 fixture
    wallets.

    Now it means that, a particular fixture wallet will know the value
    of all inputs of its funding fixture transaction and therefore, when
    picking two fixtureWallet one after the other, it may likely happen
    that both wallets are able to resolve inputs of any UTxO coming from
    their original fixture transaction.

    I fixed it by simply using fixtureWalletWith [...] which generates
    completly new and uncorrelated UTxOs.
  • Loading branch information
KtorZ committed Dec 31, 2020
1 parent 1247f9a commit bd2916b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,11 @@ spec = describe "SHELLEY_STAKE_POOLS" $ do
rSrc <- request @(ApiTransaction n) ctx link Default Empty
verify rSrc
[ expectResponseCode HTTP.status200
-- all tx inputs have address and amount
, expectField #inputs $ \inputs' -> do
let addrAmt = (fmap source inputs')
addrAmt `shouldSatisfy` (all isJust)
, expectField (#direction . #getApiT) (`shouldBe` Outgoing)
, expectField (#status . #getApiT) (`shouldBe` InLedger)
, expectField (#metadata . #getApiTxMetadata) (`shouldBe` Nothing)
, expectField #inputs $ \inputs' -> do
inputs' `shouldSatisfy` all (isJust . source)
]

-- Earn rewards
Expand Down Expand Up @@ -516,32 +514,21 @@ spec = describe "SHELLEY_STAKE_POOLS" $ do
<$> unsafeRequest @[ApiStakePool]
ctx (Link.listStakePools arbitraryStake) Empty

rJoin <- joinStakePool @n ctx pool1 (w, fixturePassphrase)
verify rJoin
joinStakePool @n ctx pool1 (w, fixturePassphrase) >>= flip verify
[ expectResponseCode HTTP.status202
, expectField (#status . #getApiT) (`shouldBe` Pending)
, expectField (#direction . #getApiT) (`shouldBe` Outgoing)
-- all tx inputs have address and amount
, expectField #inputs $ \inputs' -> do
let addrAmt = (fmap source inputs')
addrAmt `shouldSatisfy` (all isJust)
]

let txId = getFromResponse #id rJoin
let link = Link.getTransaction @'Shelley w (ApiTxId txId)
-- Wait for the certificate to be inserted
eventually "Certificates are inserted" $ do
rSrc <- request @(ApiTransaction n) ctx link Default Empty
verify rSrc
[ expectResponseCode HTTP.status200
-- all tx inputs have address and amount
, expectField #inputs $ \inputs' -> do
let addrAmt = (fmap source inputs')
addrAmt `shouldSatisfy` (all isJust)
, expectField (#direction . #getApiT) (`shouldBe` Outgoing)
, expectField (#status . #getApiT) (`shouldBe` InLedger)
, expectField (#metadata . #getApiTxMetadata) (`shouldBe` Nothing)
]
let ep = Link.listTransactions @'Shelley w
request @[ApiTransaction n] ctx ep Default Empty >>= flip verify
[ expectListField 0
(#direction . #getApiT) (`shouldBe` Outgoing)
, expectListField 0
(#status . #getApiT) (`shouldBe` InLedger)
]

request @ApiWallet ctx (Link.getWallet @'Shelley w) Default Empty
>>= flip verify
Expand Down Expand Up @@ -894,28 +881,24 @@ spec = describe "SHELLEY_STAKE_POOLS" $ do
[ expectResponseCode HTTP.status202
, expectField (#status . #getApiT) (`shouldBe` Pending)
, expectField (#direction . #getApiT) (`shouldBe` Outgoing)
-- all tx inputs have address and amount
, expectField #inputs $ \inputs' -> do
let addrAmt = (fmap source inputs')
addrAmt `shouldSatisfy` (all isJust)
inputs' `shouldSatisfy` all (isJust . source)
]

let txId = getFromResponse #id rQuit
let link = Link.getTransaction @'Shelley w (ApiTxId txId)
eventually "delegation transaction is in ledger" $ do
eventually "quit transaction is in ledger" $ do
rSrc <- request @(ApiTransaction n) ctx link Default Empty
verify rSrc
[ expectResponseCode HTTP.status200
-- all tx inputs have address and amount
, expectField #inputs $ \inputs' -> do
let addrAmt = (fmap source inputs')
addrAmt `shouldSatisfy` (all isJust)
, expectField (#direction . #getApiT) (`shouldBe` Outgoing)
, expectField (#direction . #getApiT) (`shouldBe` Incoming)
, expectField (#status . #getApiT) (`shouldBe` InLedger)
, expectField (#metadata . #getApiTxMetadata) (`shouldBe` Nothing)
, expectField #inputs $ \inputs' -> do
inputs' `shouldSatisfy` all (isJust . source)
]
eventually "Wallet is not delegating and it got his deposit back" $
do

eventually "Wallet is not delegating and it got his deposit back" $ do
request @ApiWallet ctx (Link.getWallet @'Shelley w)
Default Empty >>= flip verify
[ expectField #delegation (`shouldBe` notDelegating [])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,89 +294,84 @@ spec = describe "SHELLEY_TRANSACTIONS" $ do
pendingSince tx' `shouldBe` pendingSince tx

it "TRANS_CREATE_01x - Single Output Transaction" $ \ctx -> runResourceT $ do
(wa, wb) <- (,) <$> fixtureWallet ctx <*> fixtureWallet ctx
let initialAmt = 2*minUTxOValue
wa <- fixtureWalletWith @n ctx [initialAmt]
wb <- fixtureWalletWith @n ctx [initialAmt]
let amt = (minUTxOValue :: Natural)

payload <- liftIO $ mkTxPayload ctx wb amt fixturePassphrase

(_, ApiFee (Quantity feeMin) (Quantity feeMax) _) <- unsafeRequest ctx
(Link.getTransactionFee @'Shelley wa) payload

r <- request @(ApiTransaction n) ctx
rTx <- request @(ApiTransaction n) ctx
(Link.createTransaction @'Shelley wa) Default payload
verify r
ra <- request @ApiWallet ctx
(Link.getWallet @'Shelley wa) Default Empty

verify rTx
[ expectSuccess
, expectResponseCode HTTP.status202
, expectField (#amount . #getQuantity) $
between (feeMin + amt, feeMax + amt)
-- all tx inputs have address and amount
, expectField #inputs $ \inputs' -> do
let addrAmt = (fmap source inputs')
addrAmt `shouldSatisfy` (all isJust)
inputs' `shouldSatisfy` all (isJust . source)
, expectField (#direction . #getApiT) (`shouldBe` Outgoing)
, expectField (#status . #getApiT) (`shouldBe` Pending)
, expectField (#metadata . #getApiTxMetadata) (`shouldBe` Nothing)
]

let txid = getFromResponse #id r
verify ra
[ expectSuccess
, expectField (#balance . #getApiT . #total) $
between
( Quantity (initialAmt - feeMax - amt)
, Quantity (initialAmt - feeMin - amt)
)
, expectField
(#balance . #getApiT . #available)
(`shouldBe` Quantity 0)
]

let txid = getFromResponse #id rTx
let linkSrc = Link.getTransaction @'Shelley wa (ApiTxId txid)
let linkDest = Link.getTransaction @'Shelley wb (ApiTxId txid)
eventually "transaction is no longer pending and is OK on both wallets" $ do
eventually "transaction is no longer pending on source wallet" $ do
rSrc <- request @(ApiTransaction n) ctx linkSrc Default Empty
verify rSrc
[ expectSuccess
, expectResponseCode HTTP.status200
[ expectResponseCode HTTP.status200
, expectField (#amount . #getQuantity) $
between (feeMin + amt, feeMax + amt)
-- all tx inputs have address and amount
, expectField #inputs $ \inputs' -> do
let addrAmt = (fmap source inputs')
addrAmt `shouldSatisfy` (all isJust)
inputs' `shouldSatisfy` all (isJust . source)
, expectField (#direction . #getApiT) (`shouldBe` Outgoing)
, expectField (#status . #getApiT) (`shouldBe` InLedger)
, expectField (#metadata . #getApiTxMetadata) (`shouldBe` Nothing)
]

let linkDest = Link.getTransaction @'Shelley wb (ApiTxId txid)
eventually "transaction is discovered by destination wallet" $ do
rDst <- request @(ApiTransaction n) ctx linkDest Default Empty
verify rDst
[ expectSuccess
, expectResponseCode HTTP.status200
[ expectResponseCode HTTP.status200
, expectField (#amount . #getQuantity) (`shouldBe` amt)
-- all tx inputs have NO address and amount
-- as the tx is incoming
, expectField #inputs $ \inputs' -> do
let addrAmt2 = (fmap source inputs')
addrAmt2 `shouldSatisfy` (all isNothing)
inputs' `shouldSatisfy` all (isNothing . source)
, expectField (#direction . #getApiT) (`shouldBe` Incoming)
, expectField (#status . #getApiT) (`shouldBe` InLedger)
, expectField (#metadata . #getApiTxMetadata) (`shouldBe` Nothing)
]

ra <- request @ApiWallet ctx (Link.getWallet @'Shelley wa) Default Empty
verify ra
[ expectSuccess
, expectField (#balance . #getApiT . #total) $
between
( Quantity (faucetAmt - feeMax - amt)
, Quantity (faucetAmt - feeMin - amt)
)
, expectField
(#balance . #getApiT . #available)
(.>= Quantity (faucetAmt - faucetUtxoAmt))
]

eventually "wa and wb balances are as expected" $ do
rb <- request @ApiWallet ctx
(Link.getWallet @'Shelley wb) Default Empty
expectField
(#balance . #getApiT . #available)
(`shouldBe` Quantity (faucetAmt + amt)) rb
(`shouldBe` Quantity (initialAmt + amt)) rb

ra2 <- request @ApiWallet ctx
(Link.getWallet @'Shelley wa) Default Empty
expectField
(#balance . #getApiT . #available)
(`shouldBe` Quantity (faucetAmt - feeMax - amt)) ra2
(`shouldBe` Quantity (initialAmt - feeMax - amt)) ra2

it "TRANS_CREATE_02x - Multiple Output Tx to single wallet" $ \ctx -> runResourceT $ do
wSrc <- fixtureWallet ctx
Expand Down Expand Up @@ -409,54 +404,17 @@ spec = describe "SHELLEY_TRANSACTIONS" $ do

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

ra <- request @ApiWallet ctx (Link.getWallet @'Shelley wSrc) Default Empty

verify r
[ expectResponseCode HTTP.status202
, expectField (#amount . #getQuantity) $
between (feeMin + (2*amt), feeMax + (2*amt))
-- all tx inputs have address and amount
, expectField #inputs $ \inputs' -> do
let addrAmt = (fmap source inputs')
addrAmt `shouldSatisfy` (all isJust)
, expectField (#direction . #getApiT) (`shouldBe` Outgoing)
, expectField (#status . #getApiT) (`shouldBe` Pending)
, expectField (#metadata . #getApiTxMetadata) (`shouldBe` Nothing)
]

let txid = getFromResponse #id r
let linkSrc = Link.getTransaction @'Shelley wSrc (ApiTxId txid)
let linkDest = Link.getTransaction @'Shelley wDest (ApiTxId txid)
eventually "transaction is no longer pending and is OK on both wallets" $ do
rSrc <- request @(ApiTransaction n) ctx linkSrc Default Empty
verify rSrc
[ expectSuccess
, expectResponseCode HTTP.status200
, expectField (#amount . #getQuantity) $
between (feeMin + (2*amt), feeMax + (2*amt))
-- all tx inputs have address and amount
, expectField #inputs $ \inputs' -> do
let addrAmt = (fmap source inputs')
addrAmt `shouldSatisfy` (all isJust)
, expectField (#direction . #getApiT) (`shouldBe` Outgoing)
, expectField (#status . #getApiT) (`shouldBe` InLedger)
, expectField (#metadata . #getApiTxMetadata) (`shouldBe` Nothing)
]

rDst <- request @(ApiTransaction n) ctx linkDest Default Empty
verify rDst
[ expectSuccess
, expectResponseCode HTTP.status200
, expectField (#amount . #getQuantity) (`shouldBe` (2 * amt))
-- all tx inputs have NO address and amount
-- as the tx is incoming
, expectField #inputs $ \inputs' -> do
let addrAmt2 = (fmap source inputs')
addrAmt2 `shouldSatisfy` (all isNothing)
, expectField (#direction . #getApiT) (`shouldBe` Incoming)
, expectField (#status . #getApiT) (`shouldBe` InLedger)
, expectField (#metadata . #getApiTxMetadata) (`shouldBe` Nothing)
]

ra <- request @ApiWallet ctx (Link.getWallet @'Shelley wSrc) Default Empty
verify ra
[ expectField (#balance . #getApiT . #total) $
between
Expand Down

0 comments on commit bd2916b

Please sign in to comment.