Skip to content

Commit

Permalink
Don't run Byron tx test on Jormungandr
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Stachyra committed Jul 13, 2020
1 parent 834923e commit 18d1c34
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 68 deletions.
1 change: 1 addition & 0 deletions lib/core-integration/cardano-wallet-core-integration.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ library
Test.Integration.Scenario.API.Byron.Addresses
Test.Integration.Scenario.API.Byron.Transactions
Test.Integration.Scenario.API.Byron.Migrations
Test.Integration.Scenario.API.Byron.TransactionsShelley
Test.Integration.Scenario.API.Byron.Network
Test.Integration.Scenario.API.Shelley.Addresses
Test.Integration.Scenario.API.Shelley.HWWallets
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}

module Test.Integration.Scenario.API.Byron.TransactionsShelley
( spec
) where

import Prelude

import Cardano.Wallet.Api.Types
( ApiByronWallet
, ApiFee
, ApiTransaction
, ApiWallet
, DecodeAddress
, DecodeStakeAddress
, EncodeAddress
, WalletStyle (..)
)
import Cardano.Wallet.Primitive.Types
( Direction (..), TxStatus (..) )
import Control.Monad
( forM_ )
import Data.Generics.Internal.VL.Lens
( (^.) )
import Data.Quantity
( Quantity (..) )
import Data.Text
( Text )
import Network.HTTP.Types.Method
( Method )
import Numeric.Natural
( Natural )
import Test.Hspec
( SpecWith, describe )
import Test.Hspec.Expectations.Lifted
( shouldBe )
import Test.Hspec.Extra
( it )
import Test.Integration.Framework.DSL
( Context
, Headers (..)
, Payload (..)
, between
, eventually
, expectField
, expectResponseCode
, expectSuccess
, faucetAmt
, faucetUtxoAmt
, fixtureIcarusWallet
, fixturePassphrase
, fixtureRandomWallet
, fixtureWallet
, getFromResponse
, json
, listAddresses
, request
, verify
, (.>=)
)
import Test.Integration.Framework.Request
( RequestException )

import qualified Cardano.Wallet.Api.Link as Link
import qualified Network.HTTP.Types.Status as HTTP

spec :: forall n t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
) => SpecWith (Context t)
spec = do
describe "BYRON_TRANS_SHELLEY_01 - Single Output Transaction with non-Shelley witnesses" $
forM_ [(fixtureRandomWallet, "Byron wallet"), (fixtureIcarusWallet, "Icarus wallet")] $
\(srcFixture,name) -> it name $ \ctx -> do

(wByron, wShelley) <- (,) <$> srcFixture ctx <*> fixtureWallet ctx
addrs <- listAddresses @n ctx wShelley

let amt = 1
let destination = (addrs !! 1) ^. #id
let payload = Json [json|{
"payments": [{
"address": #{destination},
"amount": {
"quantity": #{amt},
"unit": "lovelace"
}
}]
}|]

rFeeEst <- request @ApiFee ctx
(Link.getTransactionFee @'Byron wByron) Default payload
verify rFeeEst
[ expectSuccess
, expectResponseCode HTTP.status202
]
let (Quantity feeEstMin) = getFromResponse #estimatedMin rFeeEst
let (Quantity feeEstMax) = getFromResponse #estimatedMax rFeeEst

r <- postTx ctx
(wByron, Link.createTransaction @'Byron, fixturePassphrase)
wShelley
amt
verify r
[ expectSuccess
, expectResponseCode HTTP.status202
, expectField (#amount . #getQuantity) $
between (feeEstMin + amt, feeEstMax + amt)
, expectField (#direction . #getApiT) (`shouldBe` Outgoing)
, expectField (#status . #getApiT) (`shouldBe` Pending)
]

ra <- request @ApiByronWallet ctx (Link.getWallet @'Byron wByron) Default Empty
verify ra
[ expectSuccess
, expectField (#balance . #total) $
between
( Quantity (faucetAmt - feeEstMax - amt)
, Quantity (faucetAmt - feeEstMin - amt)
)
, expectField
(#balance . #available)
(.>= Quantity (faucetAmt - faucetUtxoAmt))
]

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

ra2 <- request @ApiByronWallet ctx
(Link.getWallet @'Byron wByron) Default Empty
expectField
(#balance . #available)
(`shouldBe` Quantity (faucetAmt - feeEstMax - amt)) ra2
where

postTx
:: Context t
-> (wal, wal -> (Method, Text), Text)
-> ApiWallet
-> Natural
-> IO (HTTP.Status, Either RequestException (ApiTransaction n))
postTx ctx (wSrc, postTxEndp, pass) wDest amt = do
addrs <- listAddresses @n ctx wDest
let destination = (addrs !! 1) ^. #id
let payload = Json [json|{
"payments": [{
"address": #{destination},
"amount": {
"quantity": #{amt},
"unit": "lovelace"
}
}],
"passphrase": #{pass}
}|]
r <- request @(ApiTransaction n) ctx (postTxEndp wSrc) Default payload
expectResponseCode HTTP.status202 r
return r
Original file line number Diff line number Diff line change
Expand Up @@ -471,73 +471,6 @@ spec = do
(Link.createTransaction @'Shelley w) Default payload
expectResponseCode @IO HTTP.status400 r

describe "TRANS_CREATE_09 - Single Output Transaction with non-Shelley witnesses" $
forM_ [(fixtureRandomWallet, "Byron wallet"), (fixtureIcarusWallet, "Icarus wallet")] $
\(srcFixture,name) -> it name $ \ctx -> do

(wByron, wShelley) <- (,) <$> srcFixture ctx <*> fixtureWallet ctx
addrs <- listAddresses @n ctx wShelley

let amt = 1
let destination = (addrs !! 1) ^. #id
let payload = Json [json|{
"payments": [{
"address": #{destination},
"amount": {
"quantity": #{amt},
"unit": "lovelace"
}
}]
}|]

rFeeEst <- request @ApiFee ctx
(Link.getTransactionFee @'Byron wByron) Default payload
verify rFeeEst
[ expectSuccess
, expectResponseCode HTTP.status202
]
let (Quantity feeEstMin) = getFromResponse #estimatedMin rFeeEst
let (Quantity feeEstMax) = getFromResponse #estimatedMax rFeeEst

r <- postTx ctx
(wByron, Link.createTransaction @'Byron, fixturePassphrase)
wShelley
amt
verify r
[ expectSuccess
, expectResponseCode HTTP.status202
, expectField (#amount . #getQuantity) $
between (feeEstMin + amt, feeEstMax + amt)
, expectField (#direction . #getApiT) (`shouldBe` Outgoing)
, expectField (#status . #getApiT) (`shouldBe` Pending)
]

ra <- request @ApiByronWallet ctx (Link.getWallet @'Byron wByron) Default Empty
verify ra
[ expectSuccess
, expectField (#balance . #total) $
between
( Quantity (faucetAmt - feeEstMax - amt)
, Quantity (faucetAmt - feeEstMin - amt)
)
, expectField
(#balance . #available)
(.>= Quantity (faucetAmt - faucetUtxoAmt))
]

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

ra2 <- request @ApiByronWallet ctx
(Link.getWallet @'Byron wByron) Default Empty
expectField
(#balance . #available)
(`shouldBe` Quantity (faucetAmt - feeEstMax - amt)) ra2

describe "TRANS_ESTIMATE_08 - Bad payload" $ do
let matrix =
[ ( "empty payload", NonJson "" )
Expand Down
4 changes: 3 additions & 1 deletion lib/shelley/test/integration/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,9 @@ import qualified Cardano.Wallet.Api.Link as Link
import qualified Data.Aeson as Aeson
import qualified Data.ByteString as BS
import qualified Data.Text as T
-- TODO: enable when byron transactions/addresses supported in the cardano-node

import qualified Test.Integration.Scenario.API.Byron.Transactions as ByronTransactionsCommon
import qualified Test.Integration.Scenario.API.Byron.TransactionsShelley as ByronTransactionsShelley
import qualified Test.Integration.Scenario.API.Byron.Addresses as ByronAddresses
import qualified Test.Integration.Scenario.API.Byron.Migrations as ByronMigrations
import qualified Test.Integration.Scenario.API.Byron.HWWallets as ByronHWWallets
Expand Down Expand Up @@ -166,6 +167,7 @@ main = withUtf8Encoding $ withTracers $ \tracers -> do
ByronAddresses.spec @n
ByronMigrations.spec @n
ByronHWWallets.spec @n
ByronTransactionsShelley.spec @n
ByronTransactionsCommon.spec @n
describe "CLI Specifications" $ do
AddressesCLI.spec @n
Expand Down

0 comments on commit 18d1c34

Please sign in to comment.