Skip to content

Commit

Permalink
make Byron witness rountrip in TransactionSpec working
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljakubas committed Jul 8, 2020
1 parent 2f14210 commit 919f096
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
18 changes: 7 additions & 11 deletions lib/shelley/src/Cardano/Wallet/Shelley/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ import Type.Reflection

import qualified Cardano.Api as Cardano
import qualified Cardano.Api.Typed as CardanoTyped
import qualified Cardano.Byron.Codec.Cbor as CBOR
import qualified Cardano.Chain.Common as Byron
import qualified Cardano.Crypto as Crypto
import qualified Cardano.Crypto.Hash.Class as Hash
Expand Down Expand Up @@ -218,7 +217,6 @@ mkTx proxy pm (TxPayload certs mkExtraWits) timeToLive (rewardAcnt, pwdAcnt) key
<> mkExtraWits unsigned

TxWitnessByronUTxO -> do
let toSigningKey (k,_) = Crypto.SigningKey $ getRawKey k
bootstrapWits <- fmap Set.fromList $ forM (CS.inputs cs) $ \(_, TxOut addr _) -> do
(k, pwd) <- lookupPrivateKey keyFrom addr
pure $ mkByronWitness unsigned pm (getRawKey k, pwd)
Expand Down Expand Up @@ -325,7 +323,6 @@ _estimateMaxNumberOfInputs
:: forall (n :: NetworkDiscriminant) k.
( Typeable n
, TxWitnessTagFor k
, WalletKey k
)
=> Proxy n
-> Quantity "byte" Word16
Expand Down Expand Up @@ -382,7 +379,6 @@ _minimumFee
:: forall (n :: NetworkDiscriminant) k.
( Typeable n
, TxWitnessTagFor k
, WalletKey k
)
=> Proxy (n :: NetworkDiscriminant)
-> FeePolicy
Expand Down Expand Up @@ -475,10 +471,11 @@ computeTxSize proxy witTag action cs =
byronWits = Set.map dummyWitnessUniq $ Set.fromList (fst <$> CS.inputs cs)
where
dummyWitness :: BL.ByteString -> SL.BootstrapWitness TPraosStandardCrypto
dummyWitness chaff = error "waiting for proper cardano-ledger-spec"
--SL.makeBootstrapWitness chaff signingKey addrAttr
dummyWitness chaff =
SL.makeBootstrapWitness credential signingKey addrAttr
where
addrAttr = Byron.AddrAttributes
credential = Hash.UnsafeHash $ L8.toStrict chaff
addrAttr = Byron.mkAttributes $ Byron.AddrAttributes
(Just $ Byron.HDAddressPayload (bloatChaff keyLen))
(toByronNetworkMagic mainnetMagic)
(Just xprv) = xprvFromBytes (bloatChaff sigLen)
Expand Down Expand Up @@ -584,15 +581,14 @@ mkByronWitness
-> ProtocolMagic
-> (XPrv, Passphrase "encryption")
-> SL.BootstrapWitness TPraosStandardCrypto
mkByronWitness body protocolMagic (prv, pwd) =
mkByronWitness body protocolMagic (prv, _pwd) =
let signingKey = Crypto.SigningKey prv
bytes = xprvToBytes prv
addrAttr = Byron.AddrAttributes
addrAttr = Byron.mkAttributes $ Byron.AddrAttributes
(Just $ Byron.HDAddressPayload bytes)
(toByronNetworkMagic protocolMagic)
(SL.TxId txHash) = SL.txid body
in error "waiting for proper cardano-ledger-spec"
--SL.makeBootstrapWitness txHash signingKey addrAttr
in SL.makeBootstrapWitness txHash signingKey addrAttr

--------------------------------------------------------------------------------
-- Extra validations on coin selection
Expand Down
22 changes: 11 additions & 11 deletions lib/shelley/test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,13 @@ spec = do
describe "estimateMaxNumberOfInputs" $ do
let proxy = Proxy @'Mainnet
it "order of magnitude, nOuts = 1" $
_estimateMaxNumberOfInputs proxy (Quantity 4096) 1 `shouldBe` 27
_estimateMaxNumberOfInputs @_ @ShelleyKey proxy (Quantity 4096) 1 `shouldBe` 27
it "order of magnitude, nOuts = 10" $
_estimateMaxNumberOfInputs proxy (Quantity 4096) 10 `shouldBe` 19
_estimateMaxNumberOfInputs @_ @ShelleyKey proxy (Quantity 4096) 10 `shouldBe` 19
it "order of magnitude, nOuts = 20" $
_estimateMaxNumberOfInputs proxy (Quantity 4096) 20 `shouldBe` 10
_estimateMaxNumberOfInputs @_ @ShelleyKey proxy (Quantity 4096) 20 `shouldBe` 10
it "order of magnitude, nOuts = 30" $
_estimateMaxNumberOfInputs proxy (Quantity 4096) 30 `shouldBe` 1
_estimateMaxNumberOfInputs @_ @ShelleyKey proxy (Quantity 4096) 30 `shouldBe` 1

prop "more outputs ==> less inputs" prop_moreOutputsMeansLessInputs
prop "less outputs ==> more inputs" prop_lessOutputsMeansMoreInputs
Expand Down Expand Up @@ -198,7 +198,7 @@ prop_decodeSignedByronTxRoundtrip (DecodeByronSetup utxo outs slotNo magic pairs
let wits = SL.WitnessSet mempty mempty byronWits
let ledgerTx = SL.Tx unsigned wits metadata

_decodeSignedTx (Cardano.txSignedToCBOR (Cardano.TxSignedShelley ledgerTx))
_decodeSignedTx (Cardano.serialiseToCBOR (Cardano.ShelleyTx ledgerTx))
=== Right (toSealed ledgerTx)

-- | Increasing the number of outputs reduces the number of inputs.
Expand All @@ -208,9 +208,9 @@ prop_moreOutputsMeansLessInputs
-> Property
prop_moreOutputsMeansLessInputs size nOuts = withMaxSuccess 1000 $
nOuts < maxBound ==>
_estimateMaxNumberOfInputs proxy size nOuts
_estimateMaxNumberOfInputs @_ @ShelleyKey proxy size nOuts
>=
_estimateMaxNumberOfInputs proxy size (nOuts + 1)
_estimateMaxNumberOfInputs @_ @ShelleyKey proxy size (nOuts + 1)
where
proxy = Proxy @'Mainnet

Expand All @@ -221,9 +221,9 @@ prop_lessOutputsMeansMoreInputs
-> Property
prop_lessOutputsMeansMoreInputs size nOuts = withMaxSuccess 1000 $
nOuts > minBound ==>
_estimateMaxNumberOfInputs proxy size (nOuts - 1)
_estimateMaxNumberOfInputs @_ @ShelleyKey proxy size (nOuts - 1)
>=
_estimateMaxNumberOfInputs proxy size nOuts
_estimateMaxNumberOfInputs @_ @ShelleyKey proxy size nOuts
where
proxy = Proxy @'Mainnet

Expand All @@ -234,9 +234,9 @@ prop_biggerMaxSizeMeansMoreInputs
-> Property
prop_biggerMaxSizeMeansMoreInputs (Quantity size) nOuts = withMaxSuccess 1000 $
size < maxBound `div` 2 ==>
_estimateMaxNumberOfInputs proxy (Quantity size) nOuts
_estimateMaxNumberOfInputs @_ @ShelleyKey proxy (Quantity size) nOuts
<=
_estimateMaxNumberOfInputs proxy (Quantity (size * 2)) nOuts
_estimateMaxNumberOfInputs @_ @ShelleyKey proxy (Quantity (size * 2)) nOuts
where
proxy = Proxy @'Mainnet

Expand Down

0 comments on commit 919f096

Please sign in to comment.