Skip to content

Commit

Permalink
Try #1849:
Browse files Browse the repository at this point in the history
  • Loading branch information
iohk-bors[bot] authored Jul 10, 2020
2 parents 0c044ac + 28a2f9f commit ae08613
Show file tree
Hide file tree
Showing 9 changed files with 2,557 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ module Test.Integration.Scenario.API.Shelley.Transactions
import Prelude

import Cardano.Wallet.Api.Types
( ApiFee
( ApiByronWallet
, ApiFee
, ApiT (..)
, ApiTransaction
, ApiTxId (..)
Expand Down Expand Up @@ -464,6 +465,70 @@ spec = do
(Link.createTransaction @'Shelley w) Default payload
expectResponseCode @IO HTTP.status400 r

it "TRANS_CREATE_09 - Single Output Transaction with Byron witnesses" $ \ctx -> do
(wByron, wShelley) <- (,) <$> fixtureRandomWallet 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
1 change: 1 addition & 0 deletions lib/core/src/Cardano/Byron/Codec/Cbor.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ module Cardano.Byron.Codec.Cbor
, inspectNextToken
, decodeList
, decodeListIndef
, decodeNestedBytes
) where

import Prelude
Expand Down
1 change: 1 addition & 0 deletions lib/shelley/cardano-wallet-shelley.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ library
, cardano-binary
, cardano-crypto
, cardano-crypto-class
, cardano-crypto-wrapper
, cardano-ledger
, cardano-slotting
, cardano-wallet-cli
Expand Down
25 changes: 25 additions & 0 deletions lib/shelley/src/Cardano/Wallet/Shelley/Compatibility.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ module Cardano.Wallet.Shelley.Compatibility
, toStakeCredential
, toShelleyCoin
, fromShelleyCoin
, toHDPayloadAddress

-- ** Stake pools
, fromPoolId
Expand All @@ -73,6 +74,7 @@ module Cardano.Wallet.Shelley.Compatibility
, fromChainHash
, fromGenesisData
, fromNetworkMagic
, toByronNetworkMagic
, fromSlotNo
, fromTip
, fromTip'
Expand Down Expand Up @@ -189,6 +191,7 @@ import qualified Cardano.Chain.Common as Byron
import qualified Cardano.Wallet.Primitive.Types as W
import qualified Codec.Binary.Bech32 as Bech32
import qualified Codec.Binary.Bech32.TH as Bech32
import qualified Codec.CBOR.Decoding as CBOR
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as BL
import qualified Data.Map.Strict as Map
Expand Down Expand Up @@ -757,6 +760,13 @@ fromNetworkDiscriminant _ =
Just{} -> SL.Mainnet
Nothing -> SL.Testnet

toByronNetworkMagic :: W.ProtocolMagic -> Byron.NetworkMagic
toByronNetworkMagic pm@(W.ProtocolMagic magic) =
if pm == W.mainnetMagic then
Byron.NetworkMainOrStage
else
Byron.NetworkTestnet (fromIntegral magic)

-- NOTE: Arguably breaks naming conventions. Perhaps fromCardanoSignedTx instead
toSealed :: SL.Tx TPraosStandardCrypto -> (W.Tx, W.SealedTx)
toSealed tx =
Expand Down Expand Up @@ -900,6 +910,21 @@ _decodeAddress serverNetwork text =
Byron.NetworkMainOrStage -> SL.Mainnet
Byron.NetworkTestnet{} -> SL.Testnet

toHDPayloadAddress :: W.Address -> Maybe Byron.HDAddressPayload
toHDPayloadAddress (W.Address addr) = do
payload <- CBOR.deserialiseCbor CBOR.decodeAddressPayload addr
attributes <- CBOR.deserialiseCbor decodeAllAttributes' payload
case filter (\(tag,_) -> tag == 1) attributes of
[(1, bytes)] ->
Byron.HDAddressPayload <$> CBOR.decodeNestedBytes CBOR.decodeBytes bytes
_ ->
Nothing
where
decodeAllAttributes' = do
_ <- CBOR.decodeListLenCanonicalOf 3
_ <- CBOR.decodeBytes
CBOR.decodeAllAttributes

{-------------------------------------------------------------------------------
Logging
-------------------------------------------------------------------------------}
Expand Down
Loading

0 comments on commit ae08613

Please sign in to comment.