Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diverse witnesses in shelley #1849

Merged
merged 22 commits into from
Jul 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
2978a22
add tx witness tag
paweljakubas Jul 6, 2020
af3c578
mkWitness -> mkShelleyWitness
paweljakubas Jul 6, 2020
ebfe587
introduce mkByronWitness
paweljakubas Jul 6, 2020
34d1f4c
specialize witness creation in mkTx depending on witness tag
paweljakubas Jul 6, 2020
aae2494
add test in TransactionSpec for byron witness
paweljakubas Jul 6, 2020
2a9e2f2
Regenerate nix
Jul 6, 2020
af140bb
sneaking witness tag into _minimumFee and _estimateMaximumNumberOfInputs
paweljakubas Jul 6, 2020
bcd7c5c
dependant computeTxSize on witness size
paweljakubas Jul 6, 2020
0f6f7cc
make Byron witness rountrip in TransactionSpec working
paweljakubas Jul 8, 2020
e7d8475
make shelley integration main compile
paweljakubas Jul 8, 2020
2405328
add integration test with byron witnesses
paweljakubas Jul 9, 2020
61cbcb0
add toHDAddressPayload
paweljakubas Jul 9, 2020
3370b50
correct partially dummy values
paweljakubas Jul 9, 2020
d02d3b4
add Byron & Icarus faucet wallets to Shelley genesis
KtorZ Jul 9, 2020
ea17c78
sign Byron transaction with unencrypted private keys!
KtorZ Jul 9, 2020
d292723
make sure to unwrap the nested HDPayload when deconstructing Byron ad…
KtorZ Jul 9, 2020
c49c69a
do not create actual Byron witness when estimating
KtorZ Jul 9, 2020
bece3fc
remove traces and fix fee estimation for Byron wallets
KtorZ Jul 9, 2020
d22c284
remove feeEstimator and use fee endpoint
paweljakubas Jul 10, 2020
076a866
address protocolMagic in computeTxSize
paweljakubas Jul 10, 2020
28a2f9f
add tests for both testnet and mainnet
paweljakubas Jul 10, 2020
3abc351
test Icarus wallet
paweljakubas Jul 10, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -73,6 +74,7 @@ import Test.Integration.Framework.DSL
, expectSuccess
, faucetAmt
, faucetUtxoAmt
, fixtureIcarusWallet
, fixturePassphrase
, fixtureRandomWallet
, fixtureWallet
Expand Down Expand Up @@ -464,6 +466,73 @@ 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


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